Skip to content

Commit 79d166c

Browse files
committed
add rule disabledEntityTick and fix bugs
1 parent 5c7f484 commit 79d166c

File tree

9 files changed

+74
-23
lines changed

9 files changed

+74
-23
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ jobs:
1111
strategy:
1212
matrix:
1313
# Use these Java versions
14-
java: [17]
14+
java: [ 17 ]
1515
# and run on both Linux and Windows
16-
os: [ ubuntu-20.04, windows-latest ]
16+
os: [
17+
ubuntu-20.04,
18+
ubuntu-latest,
19+
windows-latest
20+
]
1721
runs-on: ${{ matrix.os }}
1822
steps:
1923
- name: checkout repository

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version '0.11-SNAPSHOT'
2+
id 'fabric-loom' version '0.12-SNAPSHOT'
33
id 'maven-publish'
44
}
55

@@ -85,7 +85,6 @@ publishing {
8585
}
8686
}
8787
}
88-
8988
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
9089
repositories {
9190
// Add repositories to publish to here.

src/main/java/io/github/optijava/opt_carpet_addition/OptCarpetSettings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,10 @@ public class OptCarpetSettings {
109109
category = {RuleCategory.OPTIMIZATION, RuleCategory.FEATURE}
110110
)
111111
public static boolean disabledNetherPortalSpawn = false;
112+
113+
@Rule(
114+
desc = "Disable entity tick(contains all entity and BlockEntity)",
115+
category = {RuleCategory.EXPERIMENTAL}
116+
)
117+
public static boolean disabledEntityTick = false;
112118
}

src/main/java/io/github/optijava/opt_carpet_addition/commands/PlayerTpCommand.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.optijava.opt_carpet_addition.commands;
22

3+
import carpet.CarpetServer;
34
import carpet.CarpetSettings;
45
import carpet.patches.EntityPlayerMPFake;
56
import carpet.utils.Messenger;
@@ -33,24 +34,30 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
3334
}
3435

3536
private static int teleport(CommandContext<ServerCommandSource> context) {
37+
String target = StringArgumentType.getString(context, COMMAND_PREFIX);
38+
39+
if (CarpetServer.minecraft_server.getPlayerManager().getPlayer(target) == null) {
40+
Messenger.m(context.getSource(), "r No such player");
41+
}
42+
3643
final MinecraftServer server = context.getSource().getMinecraftServer();
3744

3845
if (context.getSource().equals(server.getCommandSource())) {
3946
Messenger.m(context.getSource(), "r Console can't tp to player.");
4047
CarpetSettings.LOG.warn("[OptCarpetAddition] Console can't tp to player");
4148
return 0;
4249
}
43-
if (StringArgumentType.getString(context, COMMAND_PREFIX).equals("") || StringArgumentType.getString(context, COMMAND_PREFIX) == null) {
50+
if (target.equals("")) {
4451
Messenger.m(context.getSource(), "r Invalid player name.");
4552
return 0;
4653
}
4754

4855
try {
4956
final String commandSourcePlayerName = context.getSource().getPlayer().getGameProfile().getName();
5057

51-
CarpetSettings.LOG.info("[OptCarpetAddition] " + commandSourcePlayerName + " submit command: player " + StringArgumentType.getString(context, COMMAND_PREFIX) + " tp");
58+
CarpetSettings.LOG.info("[OptCarpetAddition] " + commandSourcePlayerName + " submit command: player " + target + " tp");
5259

53-
if (server.getPlayerManager().getPlayer(StringArgumentType.getString(context, COMMAND_PREFIX)) instanceof EntityPlayerMPFake) {
60+
if (server.getPlayerManager().getPlayer(target) instanceof EntityPlayerMPFake) {
5461

5562
if (OptCarpetSettings.commandTpToFakePlayer.equals("true")) {
5663
executeTp(commandSourcePlayerName, context, server);
@@ -67,10 +74,10 @@ private static int teleport(CommandContext<ServerCommandSource> context) {
6774
} else {
6875

6976
if (OptCarpetSettings.allowTpToRealPlayer.equals("true")) {
70-
server.getCommandManager().execute(server.getCommandSource(), "tp " + commandSourcePlayerName + " " + StringArgumentType.getString(context, "player"));
77+
server.getCommandManager().execute(server.getCommandSource(), "tp " + commandSourcePlayerName + " " + target);
7178
} else if (OptCarpetSettings.allowTpToRealPlayer.equals("ops")) {
7279
if ((server.getPlayerManager().isOperator(context.getSource().getPlayer().getGameProfile()))) {
73-
server.getCommandManager().execute(server.getCommandSource(), "tp " + commandSourcePlayerName + " " + StringArgumentType.getString(context, "player"));
80+
server.getCommandManager().execute(server.getCommandSource(), "tp " + commandSourcePlayerName + " " + target);
7481
} else {
7582
Messenger.m(context.getSource(), "r You have no permission to teleport to real player.You aren't op.");
7683
}
@@ -90,22 +97,28 @@ private static int teleport(CommandContext<ServerCommandSource> context) {
9097
}
9198

9299
private static int teleportHere(CommandContext<ServerCommandSource> context) {
100+
String target = StringArgumentType.getString(context, COMMAND_PREFIX);
101+
102+
if (CarpetServer.minecraft_server.getPlayerManager().getPlayer(target) == null) {
103+
Messenger.m(context.getSource(), "r No such player");
104+
}
105+
93106
final MinecraftServer server = context.getSource().getMinecraftServer();
94107

95108
if (context.getSource().equals(server.getCommandSource())) {
96109
Messenger.m(context.getSource(), "r Console can't tp here player.");
97110
CarpetSettings.LOG.warn("[OptCarpetAddition] Console can't tp here player");
98111
return 0;
99112
}
100-
if (StringArgumentType.getString(context, COMMAND_PREFIX).equals("") || StringArgumentType.getString(context, "player") == null) {
113+
if (target.equals("")) {
101114
Messenger.m(context.getSource(), "r Invalid player name.");
102115
return 0;
103116
}
104117

105118
try {
106119
final String commandSourcePlayerName = context.getSource().getPlayer().getGameProfile().getName();
107120

108-
CarpetSettings.LOG.info("[OptCarpetAddition] " + commandSourcePlayerName + " submit command: player " + StringArgumentType.getString(context, COMMAND_PREFIX) + " tphere");
121+
CarpetSettings.LOG.info("[OptCarpetAddition] " + commandSourcePlayerName + " submit command: player " + target + " tphere");
109122

110123
if (server.getPlayerManager().getPlayer(StringArgumentType.getString(context, COMMAND_PREFIX)) instanceof EntityPlayerMPFake) {
111124

@@ -124,10 +137,10 @@ private static int teleportHere(CommandContext<ServerCommandSource> context) {
124137
} else {
125138

126139
if (OptCarpetSettings.allowTpHereRealPlayer.equals("true")) {
127-
server.getCommandManager().execute(server.getCommandSource(), "tp " + StringArgumentType.getString(context, COMMAND_PREFIX) + " " + commandSourcePlayerName);
140+
server.getCommandManager().execute(server.getCommandSource(), "tp " + target + " " + commandSourcePlayerName);
128141
} else if (OptCarpetSettings.allowTpHereRealPlayer.equals("ops")) {
129142
if ((server.getPlayerManager().isOperator(context.getSource().getPlayer().getGameProfile()))) {
130-
server.getCommandManager().execute(server.getCommandSource(), "tp " + StringArgumentType.getString(context, COMMAND_PREFIX) + " " + commandSourcePlayerName);
143+
server.getCommandManager().execute(server.getCommandSource(), "tp " + target + " " + commandSourcePlayerName);
131144
} else {
132145
Messenger.m(context.getSource(), "r You have no permission to teleport here real player.You aren't op.");
133146
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.github.optijava.opt_carpet_addition.mixins.disabledEntityTick;
2+
3+
import io.github.optijava.opt_carpet_addition.OptCarpetSettings;
4+
import net.minecraft.server.world.ServerWorld;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
@Mixin(ServerWorld.class)
11+
public class ServerWorld_Mixin {
12+
13+
/**
14+
* Mixin ServerWorld.tick(Ljava/util/function/BooleanSupplier;)V
15+
*
16+
* @author OptiJava
17+
* @reason rule: disabledEntityTick
18+
*/
19+
@Inject(method = "tick(Ljava/util/function/BooleanSupplier;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;resetIdleTimeout()V"), cancellable = true)
20+
public void injectTick(CallbackInfo ci) {
21+
if (OptCarpetSettings.disabledEntityTick) {
22+
ci.cancel();
23+
}
24+
}
25+
26+
}

src/main/java/io/github/optijava/opt_carpet_addition/mixins/disabledLayEggs/ChickenEntity_Mixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
import org.spongepowered.asm.mixin.Mixin;
66
import org.spongepowered.asm.mixin.injection.At;
77
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
89

910
@Mixin(ChickenEntity.class)
1011
public class ChickenEntity_Mixin {
11-
1212
/**
1313
* Mixin ChickenEntity.tickMovement()V
1414
*
1515
* @author OptiJava
1616
* @reason rule: disabledLayEggs
1717
*/
1818
@Inject(at = @At("HEAD"), method = "tickMovement()V")
19-
public void injectTickMovement() {
19+
public void injectTickMovement(CallbackInfo ci) {
2020
if (OptCarpetSettings.disabledLayEggs) {
2121
((ChickenEntity) (Object) this).eggLayTime = 50;
2222
}

src/main/java/io/github/optijava/opt_carpet_addition/utils/ConfigUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44

55
import java.io.File;
66
import java.io.IOException;
7+
import java.nio.charset.StandardCharsets;
78
import java.nio.file.Files;
8-
import java.util.Arrays;
9+
import java.util.List;
910

1011
public class ConfigUtil {
1112
public static String load(String fileName) {
1213
try {
13-
return Arrays.toString(Files.readAllBytes(OptCarpetSettings.configDirectory.resolve(fileName)));
14+
StringBuilder sb = new StringBuilder();
15+
List<String> list = Files.readAllLines(OptCarpetSettings.configDirectory.resolve(fileName), StandardCharsets.UTF_8);
16+
for (String s : list) {
17+
sb.append(s).append("\n");
18+
}
19+
return sb.toString();
1420
} catch (IOException e) {
1521
e.printStackTrace();
1622
return "Failed";

src/main/resources/opt-carpet-addition.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"disabledLayEggs.ChickenEntity_Mixin",
88
"disabledEnderManPickupGoal.EnderManEntity_Mixin",
99
"disabledEnderManPlaceBlockGoal.EndermanEntity_Mixin",
10-
"disabledNetherPortalSpawn.NetherPortalBlock_Mixin"
10+
"disabledNetherPortalSpawn.NetherPortalBlock_Mixin",
11+
"disabledEntityTick.ServerWorld_Mixin"
1112
],
1213
"client": [
1314
],
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package io.github.optijava.opt_carpet_addition;
22

33
public class Main {
4-
public static int awa() {
5-
return awa();
6-
}
7-
84
public static void main(String[] args) {
9-
awa();
5+
106
}
117
}

0 commit comments

Comments
 (0)