From 42eefdbef23fc808f1c1e6f5d2e6433afb9aa59e Mon Sep 17 00:00:00 2001 From: Liyan Zhao Date: Sat, 13 Jul 2024 16:24:08 +0800 Subject: [PATCH] docs --- README.md | 6 +- rules.md | 76 ++++++++ rules_zh.md | 76 ++++++++ .../carpetslsaddition/SLSCarpetSettings.java | 12 -- .../zly2006/carpetslsaddition/ServerMain.java | 25 +-- ...RewriteChainRestrictedNeighborUpdater.java | 183 ------------------ .../mixin/carpet/MixinSettingsManager.java | 43 ---- .../mixin/elytra/MixinRecipe.java | 9 - .../mixin/entity/MixinVillagerEntity.java | 89 --------- .../server/MixinMinecraftDedicatedServer.java | 24 --- .../mixin/server/MixinMinecraftServer.java | 34 ---- .../mixin/world/MixinWorld.java | 43 ---- .../util/NeighborUpdaterChanger.java | 5 - .../util/access/ServerAccessor.java | 7 - .../util/access/SettingsManagerAccessor.java | 5 - src/main/resources/slsaddition.mixins.json | 10 +- 16 files changed, 165 insertions(+), 482 deletions(-) create mode 100644 rules.md create mode 100644 rules_zh.md delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/block/RewriteChainRestrictedNeighborUpdater.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/carpet/MixinSettingsManager.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/elytra/MixinRecipe.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinVillagerEntity.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftDedicatedServer.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftServer.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinWorld.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/util/NeighborUpdaterChanger.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/util/access/ServerAccessor.java delete mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/util/access/SettingsManagerAccessor.java diff --git a/README.md b/README.md index 37a458c..b995f40 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Carpet SLS Addition -This is an extension of the [Carpet Mod](https://github.com/gnembon/fabric-carpet). +This is an extension of the [Carpet Mod](https://github.com/gnembon/fabric-carpet) that is made for [StarLight Server](https://www.starlight.cool/). -## StarLight Server +# Rules -[Homepage](https://www.starlight.cool/) \ No newline at end of file +[English](rules.md) | [简体中文](rules_zh.md) diff --git a/rules.md b/rules.md new file mode 100644 index 0000000..4cd5359 --- /dev/null +++ b/rules.md @@ -0,0 +1,76 @@ +# Bot + +SLS addition provides a bot system, with better permission control and more features. + +## Permission + +You can use LuckPerms or any other permission plugin to control the permission of the bot. +The permission node of the bot is `slsaddition.command.bot`. + +## Carpet rules + +### botPrefix (carpet rule) + +The name prefix of bots. set to `#none` to disable. + +### botMaxOnlineTime (carpet rule) + +The maximum online time of a bot in seconds. set to 0 to disable. +The bot will be kicked if it exceeds this time. + +# Rules +### obtainableReinforcedDeepSlate + +If a falling anvil lands on 9 stacks of deepslate block, it will turn into a reinforced deepslate block. + +### creativeNoInfinitePickup + +In creative mode, you can't pick up items if your inventory is full. + +### noBatSpawning + +Bats will not spawn naturally. + +### canUseHatCommand + +Players can use the `/hat` command to wear a block on their head. + +### canUseSitCommand + +Players can use the `/sit` command to sit on a stair block. + +### creativeObeyEnchantmentRule + +In creative mode, the enchantment rule will be obeyed as in survival mode. + +### fakePlayersNotOccupiedSleepQuota + +Fake players will not occupy the sleep quota, and sleeping fake players will not skip the night. + +### emptyShulkerBoxStack + +Shulker boxes will be empty when stacked. + +### playerSit + +Players can sit by pressing sneaking key three times. + +### endermanCanPickUpMushroom + +Endermen can pick up mushrooms. Default is true. + +### oldRedstoneConnectionLogic + +Use the old redstone connection logic, the redstone can connect to redstone wries on trapdoors. + +### optimizedOnDragonRespawn + +Optimized the dragon respawn logic, for endstone farms. Ported from Carpet AMS Addition. + +### elytraCraftable + +Elytra in crafting recipes won't be consumed. This allows players to craft extra elytras. + +### spectatorCannotUseLeash + +When player becomes spectator, the leash will be detached. diff --git a/rules_zh.md b/rules_zh.md new file mode 100644 index 0000000..d2e7b49 --- /dev/null +++ b/rules_zh.md @@ -0,0 +1,76 @@ +# Bot 系统 + +SLS 添加提供了一个机器人系统,具有更好的权限控制和更多功能。 + +## 权限 + +您可以使用 LuckPerms 或任何其他权限插件来控制机器人的权限。 +机器人的权限节点为 `slsaddition.command.bot`。 + +## Carpet 规则 + +### botPrefix (carpet 规则) + +机器人名称的前缀。设置为 `#none` 以禁用。 + +### botMaxOnlineTime (carpet 规则) + +机器人的最大在线时间(秒)。设置为 0 以禁用。 +如果超过此时间,机器人将被踢出。 + +# 规则 +### obtainableReinforcedDeepSlate + +如果一个下落的铁砧落在 9 堆深板岩块上,它将变成强化深板岩块。 + +### creativeNoInfinitePickup + +在创造模式下,如果你的物品栏已满,你不能捡起物品。 + +### noBatSpawning + +蝙蝠不会自然生成。 + +### canUseHatCommand + +玩家可以使用 `/hat` 命令将一个方块戴在头上。 + +### canUseSitCommand + +玩家可以使用 `/sit` 命令坐在楼梯方块上。 + +### creativeObeyEnchantmentRule + +在创造模式下,将遵守生存模式下的附魔规则。 + +### fakePlayersNotOccupiedSleepQuota + +假玩家不会占用睡眠配额,睡眠的假玩家不会跳过夜晚。 + +### emptyShulkerBoxStack + +潜影盒堆叠时将为空。 + +### playerSit + +玩家可以通过三次按下潜行键来坐下。 + +### endermanCanPickUpMushroom + +末影人可以捡起蘑菇。默认为 true。 + +### oldRedstoneConnectionLogic + +使用旧的红石连接逻辑,红石可以连接到活板门上的红石线。 + +### optimizedOnDragonRespawn + +优化了龙的重生逻辑,用于末地石农场。从 Carpet AMS Addition 移植。 + +### elytraCraftable + +在制作配方中,鞘翅不会被消耗。这允许玩家制作额外的鞘翅。 + +### spectatorCannotUseLeash + +当玩家成为旁观者时,拴绳将断开。 diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java index cf16f18..f5a4937 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java @@ -12,10 +12,6 @@ public class SLSCarpetSettings { @Rule(categories = {SLSA, RuleCategory.SURVIVAL}) public static boolean obtainableReinforcedDeepSlate = false; - /** Carpet SLS Addition original **/ - @Rule(categories = {SLSA, RuleCategory.OPTIMIZATION}) - public static int skipTicksForJoblessVillager = 0; - /** Carpet SLS Addition original **/ @Rule(categories = {SLSA, RuleCategory.CREATIVE}) public static boolean creativeNoInfinitePickup = false; @@ -48,10 +44,6 @@ public class SLSCarpetSettings { @Rule(categories = {SLSA, RuleCategory.FEATURE}) public static boolean fakePlayersNotOccupiedSleepQuota = false; - /** Carpet SLS Addition original **/ - @Rule(categories = {SLSA, RuleCategory.CREATIVE}) - public static int maxUpdateQueueSize = -1; - /** From Plusls Carpet Addition **/ @Rule(categories = {SLSA, RuleCategory.FEATURE, NEED_CLIENT}) public static boolean emptyShulkerBoxStack = false; @@ -72,10 +64,6 @@ public class SLSCarpetSettings { @Rule(categories = {SLSA, FROM_AMS, RuleCategory.OPTIMIZATION}) public static boolean optimizedOnDragonRespawn = false; - /** Carpet SLS Addition original **/ - @Rule(categories = {SLSA, RuleCategory.FEATURE}) - public static boolean printStackTraceOnVillagerSpawn = false; - /** Carpet SLS Addition original **/ @Rule(categories = {SLSA, RuleCategory.FEATURE}) public static boolean elytraCraftable = false; diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java b/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java index c8db903..c73a7b1 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java @@ -5,11 +5,9 @@ import carpet.CarpetServer; import com.github.zly2006.carpetslsaddition.command.BotCommand; import com.github.zly2006.carpetslsaddition.command.HatCommand; import com.github.zly2006.carpetslsaddition.command.SitCommand; -import com.github.zly2006.carpetslsaddition.util.access.SettingsManagerAccessor; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; @@ -22,7 +20,7 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; +import java.io.InputStreamReader; import java.util.Map; public class ServerMain implements ModInitializer, CarpetExtension { @@ -44,40 +42,35 @@ public class ServerMain implements ModInitializer, CarpetExtension { CarpetServer.manageExtension(this); } + @Override + public void onGameStarted() { + CarpetServer.settingsManager.parseSettingsClass(SLSCarpetSettings.class); + } + @Override public void onServerLoaded(MinecraftServer server) { ServerMain.server = server; - CarpetServer.settingsManager.parseSettingsClass(SLSCarpetSettings.class); - ((SettingsManagerAccessor) CarpetServer.settingsManager).carpet_SLS_Addition$loadSettings(); } @Override public Map canHasTranslations(String lang) { Map translation = Maps.newHashMap(); - String jsonFile; try { try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted(lang))) { assert stream != null; - jsonFile = new String(stream.readAllBytes(), StandardCharsets.UTF_8); + return GSON.fromJson(new InputStreamReader(stream), Map.class); } } catch (IOException | NullPointerException ignored) { try { - try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted("en_us"))) { + try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/en_us.json")) { assert stream != null; - jsonFile = new String(stream.readAllBytes(), StandardCharsets.UTF_8); + return GSON.fromJson(new InputStreamReader(stream), Map.class); } } catch (IOException | NullPointerException e) { return translation; } } - GSON.fromJson(jsonFile, JsonObject.class).entrySet().stream() - .filter(entry -> entry.getValue().isJsonPrimitive()) - .map(entry -> Map.entry(entry.getKey(), entry.getValue().getAsString())) - .forEach(entry -> { - translation.put(entry.getKey(), entry.getValue()); - }); - return translation; } @Override diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/block/RewriteChainRestrictedNeighborUpdater.java b/src/main/java/com/github/zly2006/carpetslsaddition/block/RewriteChainRestrictedNeighborUpdater.java deleted file mode 100644 index 0ff0d08..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/block/RewriteChainRestrictedNeighborUpdater.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.github.zly2006.carpetslsaddition.block; - -import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.block.NeighborUpdater; -import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.List; - -public class RewriteChainRestrictedNeighborUpdater implements NeighborUpdater { - private static final Logger LOGGER = LoggerFactory.getLogger("Minecraft"); - private final World world; - private final int maxChainDepth; - private final ArrayDeque queue = new ArrayDeque<>(); - private final List pending = new ArrayList<>(); - private int depth = 0; - - // rewrite part - private boolean needUpdate = true; - - - public RewriteChainRestrictedNeighborUpdater(World world, int maxChainDepth) { - this.world = world; - this.maxChainDepth = maxChainDepth; - } - - public void replaceWithStateForNeighborUpdate(Direction direction, BlockState neighborState, BlockPos pos, BlockPos neighborPos, int flags, int maxUpdateDepth) { - this.enqueue(pos, new StateReplacementEntry(direction, neighborState, pos.toImmutable(), neighborPos.toImmutable(), flags, maxUpdateDepth)); - } - - public void updateNeighbor(BlockPos pos, Block sourceBlock, BlockPos sourcePos) { - this.enqueue(pos, new SimpleEntry(pos, sourceBlock, sourcePos.toImmutable())); - } - - public void updateNeighbor(BlockState state, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { - this.enqueue(pos, new StatefulEntry(state, pos.toImmutable(), sourceBlock, sourcePos.toImmutable(), notify)); - } - - public void updateNeighbors(BlockPos pos, Block sourceBlock, @Nullable Direction except) { - this.enqueue(pos, new SixWayEntry(pos.toImmutable(), sourceBlock, except)); - } - - private void enqueue(BlockPos pos, Entry entry) { - if (!needUpdate) { - return; - } - - int maxSize = SLSCarpetSettings.maxUpdateQueueSize; - - if (maxSize > 0) { - needUpdate = this.pending.size() + this.queue.size() + 1 <= maxSize; - } - - boolean notEmpty = this.depth > 0; - boolean isFull = this.maxChainDepth >= 0 && this.depth >= this.maxChainDepth; - ++this.depth; - if (!isFull) { - if (notEmpty) { - this.pending.add(entry); - } else { - this.queue.push(entry); - } - } - else if (this.depth - 1 == this.maxChainDepth) { - LOGGER.error("Too many chained neighbor updates. Skipping the rest. First skipped position: " + pos.toShortString()); - } - - if (!notEmpty) { - this.runQueuedUpdates(); - } - - } - - private void runQueuedUpdates() { - try { - while(!this.queue.isEmpty() || !this.pending.isEmpty()) { - if (SLSCarpetSettings.maxUpdateQueueSize == 0) { - break; - } - - for(int i = this.pending.size() - 1; i >= 0; --i) { - this.queue.push(this.pending.get(i)); - } - - this.pending.clear(); - Entry entry = this.queue.peek(); - assert entry != null; - - while(this.pending.isEmpty()) { - if (needUpdate) { - if (!entry.update(this.world)) { - this.queue.pop(); - break; - } - } - else { - entry.update(this.world); - throw new OutOfMemoryError("Create by Carpet-SLS-Addition"); - } - } - } - } - catch (OutOfMemoryError e) { - if (e.getMessage().endsWith("Carpet-SLS-Addition")) { - LOGGER.error("The update queue exceeded the maximum allowed allocation of heap space set by SLS Addition!", e); - } - else { - throw e; - } - } - finally { - this.queue.clear(); - this.pending.clear(); - this.depth = 0; - needUpdate = true; - } - } - - - private interface Entry { - boolean update(World world); - } - - private record StateReplacementEntry(Direction direction, BlockState neighborState, BlockPos pos, BlockPos neighborPos, int updateFlags, int updateLimit) implements Entry { - - public boolean update(World world) { - NeighborUpdater.replaceWithStateForNeighborUpdate(world, this.direction, this.neighborState, this.pos, this.neighborPos, this.updateFlags, this.updateLimit); - return false; - } - } - - record SimpleEntry(BlockPos pos, Block sourceBlock, BlockPos sourcePos) implements Entry { - public boolean update(World world) { - BlockState blockState = world.getBlockState(this.pos); - NeighborUpdater.tryNeighborUpdate(world, blockState, this.pos, this.sourceBlock, this.sourcePos, false); - return false; - } - } - - record StatefulEntry(BlockState state, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean movedByPiston) implements Entry { - public boolean update(World world) { - NeighborUpdater.tryNeighborUpdate(world, this.state, this.pos, this.sourceBlock, this.sourcePos, this.movedByPiston); - return false; - } - } - - static final class SixWayEntry implements Entry { - private final BlockPos pos; - private final Block sourceBlock; - @Nullable - private final Direction except; - private int currentDirectionIndex = 0; - - SixWayEntry(BlockPos pos, Block sourceBlock, @Nullable Direction except) { - this.pos = pos; - this.sourceBlock = sourceBlock; - this.except = except; - if (NeighborUpdater.UPDATE_ORDER[this.currentDirectionIndex] == except) { - ++this.currentDirectionIndex; - } - - } - - public boolean update(World world) { - BlockPos blockPos = this.pos.offset(NeighborUpdater.UPDATE_ORDER[this.currentDirectionIndex++]); - BlockState blockState = world.getBlockState(blockPos); - blockState.neighborUpdate(world, blockPos, this.sourceBlock, this.pos, false); - if (this.currentDirectionIndex < NeighborUpdater.UPDATE_ORDER.length && NeighborUpdater.UPDATE_ORDER[this.currentDirectionIndex] == this.except) { - ++this.currentDirectionIndex; - } - - return this.currentDirectionIndex < NeighborUpdater.UPDATE_ORDER.length; - } - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/carpet/MixinSettingsManager.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/carpet/MixinSettingsManager.java deleted file mode 100644 index a888c31..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/carpet/MixinSettingsManager.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.carpet; - -import carpet.api.settings.CarpetRule; -import carpet.api.settings.SettingsManager; -import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; -import com.github.zly2006.carpetslsaddition.ServerMain; -import com.github.zly2006.carpetslsaddition.util.NeighborUpdaterChanger; -import com.github.zly2006.carpetslsaddition.util.access.SettingsManagerAccessor; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.world.ServerWorld; -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; - -@Mixin(value = SettingsManager.class, remap = false) -public abstract class MixinSettingsManager implements SettingsManagerAccessor { - @Shadow protected abstract void loadConfigurationFromConf(); - - @Override - public void carpet_SLS_Addition$loadSettings() { - this.loadConfigurationFromConf(); - } - - @Inject(method = "setRule", at = @At(value = "INVOKE", target = "Lcarpet/utils/Messenger;m(Lnet/minecraft/server/command/ServerCommandSource;[Ljava/lang/Object;)V", shift = At.Shift.BEFORE), remap = true) - private void injectSetRule(ServerCommandSource source, CarpetRule rule, String newValue, CallbackInfoReturnable cir) { - if ("maxUpdateQueueSize".equals(rule.name())) { - MinecraftServer server = ServerMain.server; - - if (server != null) - { - server.execute(() -> { - for (ServerWorld world : server.getWorlds()) - { - ((NeighborUpdaterChanger)world).useRewriteChainNeighborUpdater(SLSCarpetSettings.maxUpdateQueueSize > -1); - } - }); - } - } - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/elytra/MixinRecipe.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/elytra/MixinRecipe.java deleted file mode 100644 index 115a0f6..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/elytra/MixinRecipe.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.elytra; - -import net.minecraft.recipe.Recipe; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(Recipe.class) -public interface MixinRecipe { - -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinVillagerEntity.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinVillagerEntity.java deleted file mode 100644 index a25f49e..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinVillagerEntity.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.entity; - -import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; -import com.github.zly2006.carpetslsaddition.ServerMain; -import net.minecraft.entity.EntityData; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.passive.MerchantEntity; -import net.minecraft.entity.passive.VillagerEntity; -import net.minecraft.village.VillagerData; -import net.minecraft.village.VillagerProfession; -import net.minecraft.world.LocalDifficulty; -import net.minecraft.world.ServerWorldAccess; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(VillagerEntity.class) -public abstract class MixinVillagerEntity extends MerchantEntity { - @Shadow public abstract VillagerData getVillagerData(); - - @Shadow protected abstract void decayGossip(); - - @Unique - int tickCount = 0; - - public MixinVillagerEntity(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(at = @At("HEAD"), method = "initialize") - private void injectInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CallbackInfoReturnable cir) { - if (SLSCarpetSettings.printStackTraceOnVillagerSpawn) { - var logBuilder = new StringBuilder("\n=== Villager Spawn Report ===\n"); - logBuilder.append("// Generated by Carpet SLS Addition\n"); - try { - logBuilder.append("- Spawn Reason: ").append(spawnReason.toString()).append("\n"); - logBuilder.append("- World: ").append(this.getWorld().getRegistryKey().getValue().toString()).append("\n"); - logBuilder.append("- Position: ").append("(x=%.2f, y=%.2f, z=%.2f)".formatted(this.getX(), this.getY(), this.getZ())).append("\n"); - logBuilder.append("- Stack Trance: "); - - var exception = new Exception(); - for (var element : exception.getStackTrace()) { - logBuilder.append("\n ").append(element.toString()); - } - } - catch (Exception e) { - logBuilder.append("// Sorry but we fail to generate the villager spawn report.\n"); - logBuilder.append("- Error Stack Trance: "); - - for (var element : e.getStackTrace()) { - logBuilder.append("\n ").append(element.toString()); - } - } - - logBuilder.append("\n ================================"); - ServerMain.LOGGER.warn(logBuilder.toString()); - } - } - - @Inject(at = @At("HEAD"), method = "tick", cancellable = true) - private void onTick(CallbackInfo ci) { - if (SLSCarpetSettings.skipTicksForJoblessVillager != 0) { - VillagerProfession profession = this.getVillagerData().getProfession(); - if (profession != VillagerProfession.NONE && profession != VillagerProfession.NITWIT) { - tickCount = 0; - return; - } - - if (tickCount > 0) { - tickCount--; - } - else { - tickCount = SLSCarpetSettings.skipTicksForJoblessVillager; - ci.cancel(); - - if (this.getHeadRollingTimeLeft() > 0) { - this.setHeadRollingTimeLeft(this.getHeadRollingTimeLeft() - 1); - } - this.decayGossip(); - } - } - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftDedicatedServer.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftDedicatedServer.java deleted file mode 100644 index 1e493c6..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftDedicatedServer.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.server; - -import com.github.zly2006.carpetslsaddition.util.access.ServerAccessor; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.server.dedicated.MinecraftDedicatedServer; -import net.minecraft.server.dedicated.ServerPropertiesLoader; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Environment(EnvType.SERVER) -@Mixin(MinecraftDedicatedServer.class) -public class MixinMinecraftDedicatedServer implements ServerAccessor { - - @Shadow - @Final - private ServerPropertiesLoader propertiesLoader; - - @Override - public ServerPropertiesLoader getPropertiesLoader() { - return propertiesLoader; - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftServer.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftServer.java deleted file mode 100644 index b1f0210..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/server/MixinMinecraftServer.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.server; - -import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.function.BooleanSupplier; - -@Mixin(MinecraftServer.class) -public abstract class MixinMinecraftServer { - @Redirect(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tick(Ljava/util/function/BooleanSupplier;)V")) - private void redirectTicking(MinecraftServer instance, BooleanSupplier shouldKeepTicking) { - if (SLSCarpetSettings.maxUpdateQueueSize != -1) { - try { - instance.tick(shouldKeepTicking); - } - catch (Throwable throwable) { - if (throwable instanceof OutOfMemoryError oom) { - if (!oom.getMessage().startsWith("Create by Carpet-SLS-Addition")) { - throw throwable; - } - } - else { - throw throwable; - } - } - } - else { - instance.tick(shouldKeepTicking); - } - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinWorld.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinWorld.java deleted file mode 100644 index 2707bad..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinWorld.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.world; - -import com.github.zly2006.carpetslsaddition.ServerMain; -import com.github.zly2006.carpetslsaddition.block.RewriteChainRestrictedNeighborUpdater; -import com.github.zly2006.carpetslsaddition.util.NeighborUpdaterChanger; -import com.github.zly2006.carpetslsaddition.util.access.ServerAccessor; -import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.world.World; -import net.minecraft.world.block.NeighborUpdater; -import org.spongepowered.asm.mixin.*; - -@Mixin(World.class) -public abstract class MixinWorld implements NeighborUpdaterChanger { - @Mutable - @Shadow - @Final - protected NeighborUpdater neighborUpdater; - - @Unique - private NeighborUpdater previousUpdater = null; - - @Override - public void useRewriteChainNeighborUpdater(boolean use) { - if (use) { - this.previousUpdater = this.neighborUpdater; - int maxDepth; - - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { - maxDepth = ((ServerAccessor) ServerMain.server).getPropertiesLoader().getPropertiesHandler().maxChainedNeighborUpdates; - } - else { - maxDepth = 1000000; - } - - this.neighborUpdater = new RewriteChainRestrictedNeighborUpdater((World)(Object)this, maxDepth); - - } - else { - this.neighborUpdater = previousUpdater; - } - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/util/NeighborUpdaterChanger.java b/src/main/java/com/github/zly2006/carpetslsaddition/util/NeighborUpdaterChanger.java deleted file mode 100644 index 9e27e23..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/util/NeighborUpdaterChanger.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.zly2006.carpetslsaddition.util; - -public interface NeighborUpdaterChanger { - void useRewriteChainNeighborUpdater(boolean use); -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/util/access/ServerAccessor.java b/src/main/java/com/github/zly2006/carpetslsaddition/util/access/ServerAccessor.java deleted file mode 100644 index f4cc900..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/util/access/ServerAccessor.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.zly2006.carpetslsaddition.util.access; - -import net.minecraft.server.dedicated.ServerPropertiesLoader; - -public interface ServerAccessor { - ServerPropertiesLoader getPropertiesLoader(); -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/util/access/SettingsManagerAccessor.java b/src/main/java/com/github/zly2006/carpetslsaddition/util/access/SettingsManagerAccessor.java deleted file mode 100644 index 2d155cf..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/util/access/SettingsManagerAccessor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.zly2006.carpetslsaddition.util.access; - -public interface SettingsManagerAccessor { - void carpet_SLS_Addition$loadSettings(); -} diff --git a/src/main/resources/slsaddition.mixins.json b/src/main/resources/slsaddition.mixins.json index ae16933..a70ec0e 100644 --- a/src/main/resources/slsaddition.mixins.json +++ b/src/main/resources/slsaddition.mixins.json @@ -3,20 +3,15 @@ "minVersion": "0.8", "package": "com.github.zly2006.carpetslsaddition.mixin", "compatibilityLevel": "JAVA_17", - "server": [ - "server.MixinMinecraftDedicatedServer" - ], "client": [ ], "mixins": [ "block.BlockPatternTestTransformInvoker", "block.MixinRedstoneWireBlock", "carpet.MixinEntityPlayerMPFake", - "carpet.MixinSettingsManager", "datapack.MixinVanillaResourcePackProvider", "elytra.MixinElytraItem", "elytra.MixinItem", - "elytra.MixinRecipe", "entity.MixinArmorStandEntity", "entity.MixinBoatEntity", "entity.MixinEnderDragonFight", @@ -25,18 +20,15 @@ "entity.MixinMobEntity", "entity.MixinPlayerEntity", "entity.MixinServerPlayerEntity", - "entity.MixinVillagerEntity", "player.MixinPlayerInventory", "screen.MixinAnvilScreenHandler", - "server.MixinMinecraftServer", "shulker.MixinItemStack", "shulker.MixinPlayerInventory", "shulker.MixinScreenHandler", "shulker.MixinServerPlayNetworkHandler", "shulker.MixinSlot", "world.MixinSleepManager", - "world.MixinSpawnHelper", - "world.MixinWorld" + "world.MixinSpawnHelper" ], "injectors": { "defaultRequire": 1