From a3e3fb361ff55272cc8b6fe2327f3bb51e43915d Mon Sep 17 00:00:00 2001 From: Disy Date: Sat, 22 Jun 2024 22:29:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=81=87=E4=BA=BA=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E7=94=9F=E6=88=90bug=E4=BF=AE=E5=A4=8D=E5=8F=8A=E9=99=84?= =?UTF-8?q?=E9=AD=94=E6=9C=BA=E5=88=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../carpetslsaddition/SLSCarpetSettings.java | 6 ++++ .../carpetslsaddition/command/BotCommand.java | 9 ++++-- .../mixin/screen/MixinAnvilScreenHandler.java | 29 +++++++++++++++++++ .../util/ShulkerBoxItemUtil.java | 7 ++--- .../assets/slsaddition/lang/en_us.json | 13 +++------ .../assets/slsaddition/lang/zh_cn.json | 13 +++------ src/main/resources/slsaddition.mixins.json | 3 ++ 7 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/github/zly2006/carpetslsaddition/mixin/screen/MixinAnvilScreenHandler.java diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java index 3206bb1..6b55106 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java @@ -27,6 +27,12 @@ public class SLSCarpetSettings { @Rule(categories = {CARPET_ID, RuleCategory.FEATURE}) public static boolean canUseSitCommand = false; + @Rule(categories = {CARPET_ID}, strict = false, options = {"#none"}) + public static String botPrefix = "#none"; + + @Rule(categories = {CARPET_ID, RuleCategory.FEATURE}) + public static boolean creativeObeyEnchantmentRule = false; + @Rule(categories = {CARPET_ID, RuleCategory.FEATURE}) public static boolean fakePlayersNotOccupiedSleepQuota = false; diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/command/BotCommand.java b/src/main/java/com/github/zly2006/carpetslsaddition/command/BotCommand.java index d9850f3..a86b24d 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/command/BotCommand.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/command/BotCommand.java @@ -6,6 +6,7 @@ import carpet.helpers.EntityPlayerActionPack; import carpet.patches.EntityPlayerMPFake; import carpet.patches.FakeClientConnection; import carpet.utils.Messenger; +import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; import com.github.zly2006.carpetslsaddition.ServerMain; import com.github.zly2006.carpetslsaddition.util.access.PlayerAccess; import com.mojang.authlib.GameProfile; @@ -197,7 +198,7 @@ public class BotCommand { private static boolean cantSpawn(CommandContext context) { - String playerName = StringArgumentType.getString(context, "player"); + String playerName = getBotPrefix() + StringArgumentType.getString(context, "player"); MinecraftServer server = context.getSource().getServer(); PlayerManager manager = server.getPlayerManager(); @@ -231,6 +232,10 @@ public class BotCommand { return false; } + private static String getBotPrefix() { + return SLSCarpetSettings.botPrefix.equals("#none") ? "" : SLSCarpetSettings.botPrefix; + } + private static int kill(CommandContext context) { if (cantReMove(context)) return 0; @@ -274,7 +279,7 @@ public class BotCommand { source.getWorld().getRegistryKey() ); - String playerName = "bot_" + StringArgumentType.getString(context, "player"); + String playerName = getBotPrefix() + StringArgumentType.getString(context, "player"); if (playerName.length() > maxNameLength(source.getServer())) { Messenger.m(source, "rb Player name: " + playerName + " is too long"); diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/screen/MixinAnvilScreenHandler.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/screen/MixinAnvilScreenHandler.java new file mode 100644 index 0000000..c0433a5 --- /dev/null +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/screen/MixinAnvilScreenHandler.java @@ -0,0 +1,29 @@ +package com.github.zly2006.carpetslsaddition.mixin.screen; + +import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; +import net.minecraft.entity.player.PlayerAbilities; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.screen.AnvilScreenHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(AnvilScreenHandler.class) +public class MixinAnvilScreenHandler { + @Redirect( + method = "updateResult", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/player/PlayerEntity;getAbilities()Lnet/minecraft/entity/player/PlayerAbilities;" + ) + ) + private PlayerAbilities updateResult(PlayerEntity instance) { + if (SLSCarpetSettings.creativeObeyEnchantmentRule) { + var ability = new PlayerAbilities(); + ability.creativeMode = false; + return ability; + } + + return instance.getAbilities(); + } +} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/util/ShulkerBoxItemUtil.java b/src/main/java/com/github/zly2006/carpetslsaddition/util/ShulkerBoxItemUtil.java index 56f63c8..e5cd945 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/util/ShulkerBoxItemUtil.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/util/ShulkerBoxItemUtil.java @@ -30,11 +30,8 @@ public class ShulkerBoxItemUtil { if (itemStack.getItem() instanceof BlockItem && ((BlockItem) itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock) { NbtComponent tag = itemStack.getComponents().get(DataComponentTypes.BLOCK_ENTITY_DATA); - if (tag != null) { - if (tag.contains("Items")) { - NbtList tagList = tag.getNbt().getList("Items", 10); - return tagList.size() <= 0; - } + if (tag != null && tag.contains("Items")) { + return tag.getNbt().getList("Items", 10).isEmpty(); } return true; } else { diff --git a/src/main/resources/assets/slsaddition/lang/en_us.json b/src/main/resources/assets/slsaddition/lang/en_us.json index 69434fa..2304536 100644 --- a/src/main/resources/assets/slsaddition/lang/en_us.json +++ b/src/main/resources/assets/slsaddition/lang/en_us.json @@ -8,8 +8,8 @@ "carpet.rule.skipTicksForJoblessVillager.name": "Skip ticks for jobless villager", "carpet.rule.creativeNoInfinitePickup.name": "Creative mode cannot infinite pickup", "carpet.rule.noBatSpawning.name": "No bat spawning", - "carpet.rule.pcaSyncProtocol.name": "Enable PCA Sync Protocol", - "carpet.rule.pcaSyncPlayerEntity.name": "Set PCA Sync Protocol's entity scope", + "carpet.rule.botPrefix.name": "The prefix of the bot", + "carpet.rule.creativeObeyEnchantmentRule.name": "Creative player enchantments follows the rules of vanilla", "carpet.rule.emptyShulkerBoxStack.name": "Empty shulker boxes can be stacked", "carpet.rule.useDyeOnShulkerBox.name": "Shulker box blocks can be dyed", "carpet.rule.xaeroWorldName.name": "Xaero world name", @@ -27,8 +27,8 @@ "carpet.rule.skipTicksForJoblessVillager.desc": "For jobless/nitwit villagers, after performing a set number of tick operations, skip the 1 tick operation.", "carpet.rule.creativeNoInfinitePickup.desc": "If my inventory is full, don't pick up items in creative mode.", "carpet.rule.noBatSpawning.desc": "Prevents bats from spawning.", - "carpet.rule.pcaSyncProtocol.desc": "Using PCA protocol to support sync entity and blockEntity from server", - "carpet.rule.pcaSyncPlayerEntity.desc": "Which player entity can be sync", + "carpet.rule.botPrefix.desc": "Set the prefix for the bot players, value #none for no prefix.", + "carpet.rule.creativeObeyEnchantmentRule.desc": "Making creative player to enchant with anvils and enchanted books also need to follow the vanilla rules", "carpet.rule.emptyShulkerBoxStack.desc": "Empty shulker boxes stack", "carpet.rule.useDyeOnShulkerBox.desc": "Dyes can be used on shulker boxes, empty potion will clean color", "carpet.rule.xaeroWorldName.desc": "set xaero world name to sync word id to xaerominimap, \"#none\" is disable.", @@ -47,11 +47,6 @@ "carpet.rule.skipTicksForJoblessVillager.extra.2": "To prevents villagers from getting completely stuck when set to 1", "carpet.rule.maxUpdateQueueSize.extra.0": "If set to a value not greater than 0, turn off this function and run according to Vanilla", "carpet.rule.maxUpdateQueueSize.extra.1": "Otherwise, when the number of single updates exceeds the set value, an OutOfMemoryError will be thrown to generate update suppression", - "carpet.rule.pcaSyncPlayerEntity.extra.0": "NOBODY: nobody will be sync", - "carpet.rule.pcaSyncPlayerEntity.extra.1": "BOT: carpet bot will be sync", - "carpet.rule.pcaSyncPlayerEntity.extra.2": "OPS: carpet bot will be sync, and op can sync everyone's player entity data.", - "carpet.rule.pcaSyncPlayerEntity.extra.3": "OPS_AND_SELF: carpet bot and self data will be sync, and op can sync everyone's player entity data.", - "carpet.rule.pcaSyncPlayerEntity.extra.4": "EVERYONE: everyone's player entity will be sync", "carpet.rule.emptyShulkerBoxStack.extra.0": "Empty shulker boxes can stack in a player's inventory or hand", "carpet.rule.emptyShulkerBoxStack.extra.1": "Empty shulker boxes will not stack in other inventories, such as chests or hoppers" } diff --git a/src/main/resources/assets/slsaddition/lang/zh_cn.json b/src/main/resources/assets/slsaddition/lang/zh_cn.json index 85987b4..324f0e7 100644 --- a/src/main/resources/assets/slsaddition/lang/zh_cn.json +++ b/src/main/resources/assets/slsaddition/lang/zh_cn.json @@ -8,8 +8,8 @@ "carpet.rule.skipTicksForJoblessVillager.name": "无业村民跳刻", "carpet.rule.creativeNoInfinitePickup.name": "创造模式满背包无法拾取", "carpet.rule.noBatSpawning.name": "禁止蝙蝠生成", - "carpet.rule.pcaSyncProtocol.name": "启动兼容PCA的同步协议", - "carpet.rule.pcaSyncPlayerEntity.name": "PCA同步协议作用范围", + "carpet.rule.botPrefix.name": "机器人前缀", + "carpet.rule.creativeObeyEnchantmentRule.name": "创造铁砧附魔遵守基本法", "carpet.rule.emptyShulkerBoxStack.name": "空潜影盒背包可堆叠", "carpet.rule.useDyeOnShulkerBox.name": "潜影盒方块可染色", "carpet.rule.xaeroWorldName.name": "Xaero 小地图世界名", @@ -27,8 +27,8 @@ "carpet.rule.skipTicksForJoblessVillager.desc": "对于无业/傻子村民,执行设定数量的tick运算后,跳过1tick的运算", "carpet.rule.creativeNoInfinitePickup.desc": "创造模式下,玩家不能无限制地拾取物品", "carpet.rule.noBatSpawning.desc": "禁止任何区域蝙蝠生成", - "carpet.rule.pcaSyncProtocol.desc": "借助PCA同步协议,支持同步 BlockEntity 和 Entity 到客户端", - "carpet.rule.pcaSyncPlayerEntity.desc": "决定哪些玩家的数据将会被同步", + "carpet.rule.botPrefix.desc": "设定使用/bot召唤出的假人玩家名称前缀,#none代表无前缀", + "carpet.rule.creativeObeyEnchantmentRule.desc": "让创造玩家使用铁砧与附魔书为物品附魔时,也需要遵守原版的附魔规则", "carpet.rule.emptyShulkerBoxStack.desc": "空潜影盒可堆叠,但是不会改变容器中潜影盒的堆叠行为", "carpet.rule.useDyeOnShulkerBox.desc": "可以使用染料直接对地上的潜影盒染色,用水瓶可以洗掉潜影盒的颜色", "carpet.rule.xaeroWorldName.desc": "设置 Xaero 世界名来同步世界 ID,\"#none\" 表示不同步", @@ -47,11 +47,6 @@ "carpet.rule.skipTicksForJoblessVillager.extra.2": "以此避免在设置为1的时候,村民完全卡死", "carpet.rule.maxUpdateQueueSize.extra.0": "如果设定了不超过0的值,将关闭该功能,更新机制继续依照Vanilla运行", "carpet.rule.maxUpdateQueueSize.extra.1": "否则,在单次更新数量超过设定最大容量后,服务器将抛出OutOfMemoryError,以达到快速更新抑制的效果", - "carpet.rule.pcaSyncPlayerEntity.extra.0": "NOBODY:所有玩家数据都无法同步", - "carpet.rule.pcaSyncPlayerEntity.extra.1": "BOT:地毯 mod 召唤出的 bot 的数据可以被同步", - "carpet.rule.pcaSyncPlayerEntity.extra.2": "OPS:地毯 mod 召唤出的 bot 的数据可以被同步, op 可以同步所有玩家的数据", - "carpet.rule.pcaSyncPlayerEntity.extra.3": "OPS_AND_SELF:地毯 mod 召唤出的 bot 和玩家自己的数据可以被同步,op 可以同步所有玩家的数据", - "carpet.rule.pcaSyncPlayerEntity.extra.4": "EVERYONE:所有人的数据都可以被同步", "carpet.rule.emptyShulkerBoxStack.extra.0": "空潜影盒可以在玩家的背包进行自动堆叠,同时玩家可以手动堆叠空潜影盒", "carpet.rule.emptyShulkerBoxStack.extra.1": "但是空潜影盒无法在容器中自动堆叠,比如箱子,漏斗" } diff --git a/src/main/resources/slsaddition.mixins.json b/src/main/resources/slsaddition.mixins.json index b8dd2ae..961ccbc 100644 --- a/src/main/resources/slsaddition.mixins.json +++ b/src/main/resources/slsaddition.mixins.json @@ -22,6 +22,9 @@ "entity.MixinServerPlayerEntity", "entity.MixinVillagerEntity", "player.MixinPlayerInventory", + "player.AccessorPlayerAbilities", + "screen.MixinAnvilScreenHandler", + "screen.MixinSlot", "server.MixinMinecraftServer", "shulker.MixinItemStack", "shulker.MixinScreenHandler",