Skip to content

Commit

Permalink
Delete some laggy feature from /interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
wendavid552 committed Oct 28, 2022
1 parent e929ce3 commit b0edea1
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 603 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,11 @@

`optimizedDragonRespawn`: 大幅度优化了龙战判定代码的性能表现,可能影响原版特性。

### 交互控制/Interaction Commands
### 区块加载控制/Ghost Commands

控制玩家与游戏世界的交互行为,如区块加载等等。玩家上下线时会将交互状态重置回默认状态以避免[MC-157812](https://bugs.mojang.com/browse/MC-157812)
控制玩家的区块加载。玩家上下线时会将交互状态重置回默认状态以避免[MC-157812](https://bugs.mojang.com/browse/MC-157812)
的发生
格式:`/interaction [interaction_name] [true/false]`

#### 交互列表

- `all`: 全部交互
- `chunkloading`: 区块加载,注意新的区块过不去
- `entities`:实体交互,如碰撞等
- `blocks`:方块交互
- `updates`:放置方块等操作不会产生更新
格式:`/ghost [true/false]`

### 相关链接

Expand All @@ -55,7 +47,7 @@
2. `zeroTick`
系列主要功能实现代码来自1.16.4/1.16.5的[OhMyVanillaMinecraf](https://github.com/hit-mc/OhMyVanillaMinecraft)

3. `interaction`交互控制功能实现代码来自1.16.5/1.17.1的[Intricarpet](https://github.com/lntricate1/intricarpet)
3. `ghost`交互控制功能实现代码来自1.16.5/1.17.1的[Intricarpet](https://github.com/lntricate1/intricarpet)

### 致谢

Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set APP_HOME=%DIRNAME%
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" "-Dfile.encoding=GBK"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/club/mcams/carpet/AmsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

import carpet.CarpetExtension;
import carpet.CarpetServer;
import club.mcams.carpet.command.InteractionCommand;
import club.mcams.carpet.function.Interactions;
import club.mcams.carpet.command.GhostCommand;
import club.mcams.carpet.function.Ghost;
import club.mcams.carpet.logging.amscarpetLoggerRegistry;
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AmsServer implements CarpetExtension, ModInitializer {

Expand All @@ -22,17 +20,17 @@ public void registerLoggers() {

@Override
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
InteractionCommand.register(dispatcher);
GhostCommand.register(dispatcher);
}

@Override
public void onPlayerLoggedIn(ServerPlayerEntity player) {
Interactions.onPlayerConnect(player);
Ghost.onPlayerConnect(player);
}

@Override
public void onPlayerLoggedOut(ServerPlayerEntity player) {
Interactions.onPlayerDisconnect(player);
Ghost.onPlayerDisconnect(player);
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/club/mcams/carpet/AmsServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ public class AmsServerSettings
desc = "末影龙复活过程检测优化",
category = {AMS, OPTIMIZATION}
)
public static boolean optimizationDragonRespawn = false;
public static boolean optimizedDragonRespawn = false;

@Rule(
desc = "玩家区块加载控制",
category = {AMS, COMMAND}
)
public static String commandGhost = "false";
}
50 changes: 50 additions & 0 deletions src/main/java/club/mcams/carpet/command/GhostCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package club.mcams.carpet.command;

import carpet.utils.Messenger;
import club.mcams.carpet.AmsServerSettings;
import club.mcams.carpet.function.Ghost;
import club.mcams.carpet.util.CommandHelper;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;

import static com.mojang.brigadier.arguments.BoolArgumentType.getBool;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;

public class GhostCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("ghost")
.requires((player) -> CommandHelper.canUseCommand(player, AmsServerSettings.commandGhost))
.executes((c) -> listPlayerInteractions(c.getSource(), c.getSource().getName()))
.then(argument("boolean", BoolArgumentType.bool()).
executes((c) -> setPlayerInteraction(c.getSource(), c.getSource().getName(), getBool(c, "boolean")))
));

}

private static int setPlayerInteraction(ServerCommandSource source, String playerName, boolean b) {
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(playerName);
if (player == null) {
Messenger.m(source, "r No player specified");
return 0;
}
Ghost.setPlayerInteraction(playerName, !b, true);
Messenger.m(source, "w Set interaction ", "g " + "chunkloading", "w to ", "g " + b);
return 1;
}

private static int listPlayerInteractions(ServerCommandSource source, String playerName) {
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(playerName);
if (player == null) {
Messenger.m(source, "r No player specified");
return 0;
}
boolean playerInteractions = Ghost.onlinePlayerMap.getOrDefault(playerName, true);

if (playerInteractions) Messenger.m(source, "w " + "chunk loading" + ": ", "g false");
else Messenger.m(source, "w " + "chunk loading" + ": ", "g true");
return 1;
}
}
67 changes: 0 additions & 67 deletions src/main/java/club/mcams/carpet/command/InteractionCommand.java

This file was deleted.

42 changes: 42 additions & 0 deletions src/main/java/club/mcams/carpet/function/Ghost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package club.mcams.carpet.function;

import carpet.CarpetServer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;

import java.util.HashMap;
import java.util.Map;

public class Ghost {
public static Map<String, Boolean> onlinePlayerMap = new HashMap<>();
public static Map<String, Boolean> offlinePlayerMap = new HashMap<>();

public static void setPlayerInteraction(String playerName, boolean b, boolean online) {
if (playerFromName(playerName) == null) return;
if (online) {
onlinePlayerMap.put(playerName, b);
} else {
offlinePlayerMap.put(playerName, b);
}
}

public static void onPlayerConnect(PlayerEntity player) {
String playerName = player.getName().getString();
if (offlinePlayerMap.containsKey(playerName)) {
setPlayerInteraction(playerName, true, true);
offlinePlayerMap.remove(playerName);
}
}

public static void onPlayerDisconnect(PlayerEntity player) {
String playerName = player.getName().getString();
if (onlinePlayerMap.containsKey(playerName)) {
setPlayerInteraction(playerName, true, false);
onlinePlayerMap.remove(playerName);
}
}

protected static ServerPlayerEntity playerFromName(String name) {
return CarpetServer.minecraft_server.getPlayerManager().getPlayer(name);
}
}
77 changes: 0 additions & 77 deletions src/main/java/club/mcams/carpet/function/Interactions.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class amscarpetLoggerRegistry {
public static boolean __dragonPortalLocation;

public static void registerLoggers() {
LoggerRegistry.registerLogger("dragonPortalLocation", standardLogger("dragonPortalLocation", null, null, false));
LoggerRegistry.registerLogger("dragonPortalLocation", standardLogger("dragonPortalLocation", null, null));
}

static Logger standardLogger(String logName, String def, String[] options, boolean strictOption) {
static Logger standardLogger(String logName, String def, String[] options) {
try {
return new Logger(amscarpetLoggerRegistry.class.getField("__" + logName), logName, def, options, strictOption);
return new Logger(amscarpetLoggerRegistry.class.getField("__" + logName), logName, def, options);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Failed to create logger " + logName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package club.mcams.carpet.mixin.interation;
package club.mcams.carpet.mixin.interaction;

import club.mcams.carpet.function.Interactions;
import club.mcams.carpet.function.Ghost;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.world.GameRules;

@Mixin(ThreadedAnvilChunkStorage.class)
public class ThreadedAnvilChunkStorageMixin {
@Shadow
Expand All @@ -22,7 +20,9 @@ public class ThreadedAnvilChunkStorageMixin {
@Inject(method = "doesNotGenerateChunks", at = @At("HEAD"), cancellable = true)
private void doesNotGenerateChunks(ServerPlayerEntity player, CallbackInfoReturnable<Boolean> cir) {
String playerName = player.getName().getString();
cir.setReturnValue(Interactions.onlinePlayerMap.containsKey(playerName) && Interactions.onlinePlayerMap.get(playerName).contains("chunkloading") ||
(player.isSpectator() && !this.world.getGameRules().getBoolean(GameRules.SPECTATORS_GENERATE_CHUNKS)));
if (!Ghost.onlinePlayerMap.getOrDefault(playerName, true)) {
cir.setReturnValue(true);
cir.cancel();
}
}
}
Loading

0 comments on commit b0edea1

Please sign in to comment.