diff --git a/gradle.properties b/gradle.properties index 907acc6..d35ef97 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.19.4 - yarn_mappings=1.19.4+build.1 - loader_version=0.14.17 + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.2 + loader_version=0.14.21 + # Mod Properties - mod_version = 0.5.1 + mod_version = 0.6.0 maven_group = com.github.zly2006 archives_base_name = carpet-sls-addition # Dependencies - fabric_version=0.76.0+1.19.4 - carpet_core_version=1.19.4-1.4.100+v230314 + fabric_version=0.83.1+1.20.1 + carpet_core_version=1.20-pre6-1.4.111+v230525 diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java index b6e4417..c263de6 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java @@ -37,6 +37,9 @@ public class SLSCarpetSettings { @Rule(categories = {CARPET_ID, RuleCategory.FEATURE}) public static boolean canUseSitCommand = false; + @Rule(categories = {CARPET_ID, RuleCategory.CREATIVE}) + public static int maxUpdateQueueSize = -1; + @Rule(categories = {CARPET_ID, PCA, PROTOCOL}) public static boolean pcaSyncProtocol = false; diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java b/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java index a333a3b..8256c18 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java @@ -131,7 +131,7 @@ public class ServerMain implements ModInitializer, CarpetExtension { ServerPlayerEntity player = context.getSource().getPlayer(); assert player != null; - if (player.getVehicle() != null) { // 防止重复的坐下行为 + if (player.getVehicle() != null || !player.isOnGround()) { // 防止错误的坐下行为 return 1; } diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/block/MixinAbstractSignBlock.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/block/MixinAbstractSignBlock.java deleted file mode 100644 index 0dbe2b6..0000000 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/block/MixinAbstractSignBlock.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.github.zly2006.carpetslsaddition.mixin.block; - -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.SignBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(AbstractSignBlock.class) -public class MixinAbstractSignBlock { - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - private void use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (state.getBlock() instanceof WallSignBlock && false) { - BlockPos pos1 = pos.offset(state.get(WallSignBlock.FACING).getOpposite()); - BlockState state1 = world.getBlockState(pos1); - if (state1.getBlock() instanceof ChestBlock || state1.getBlock() instanceof BarrelBlock) { - SignBlockEntity signBlockEntity = (SignBlockEntity) world.getBlockEntity(pos); - BlockEntity blockEntity = world.getBlockEntity(pos1); - if (blockEntity instanceof Inventory inventory) { - if (signBlockEntity.getTextOnRow(0, true).getString().equals("[[Once]]")) { - int i = 0; - for (; i < inventory.size(); i++) { - if (!inventory.getStack(i).isEmpty()) { - break; - } - } - if (i == inventory.size()) { - return; - } - ItemStack stack = inventory.removeStack(i); - inventory.markDirty(); - if (player.getInventory().insertStack(stack)) { - cir.setReturnValue(ActionResult.SUCCESS); - } - } - } - } - } - } -} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinFallingBlockEntity.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinFallingBlockEntity.java index f1cfa24..06dd2de 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinFallingBlockEntity.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinFallingBlockEntity.java @@ -1,8 +1,15 @@ package com.github.zly2006.carpetslsaddition.mixin.entity; +import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; import net.minecraft.entity.FallingBlockEntity; +import net.minecraft.entity.ItemEntity; import net.minecraft.entity.damage.DamageSource; +import net.minecraft.predicate.entity.EntityPredicates; +import net.minecraft.world.World; 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; @@ -11,9 +18,17 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.function.Predicate; @Mixin(FallingBlockEntity.class) -public class MixinFallingBlockEntity { - @Inject(method = "handleFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;"), locals = LocalCapture.CAPTURE_FAILSOFT) - private void handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable cir, int i, Predicate predicate, DamageSource damageSource2, float f) { +public abstract class MixinFallingBlockEntity extends Entity { + public MixinFallingBlockEntity(EntityType type, World world) { + super(type, world); + } + + @Inject(method = "handleFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILSOFT) + private void handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable cir, int i, Predicate predicate, DamageSource damageSource2, float f) { + if (SLSCarpetSettings.obtainableReinforcedDeepSlate) { + predicate = entity -> entity instanceof ItemEntity; + this.getWorld().getOtherEntities(this, this.getBoundingBox(), predicate).forEach((entity) -> entity.damage(damageSource2, f)); + } } } diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinServerPlayerEntity.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinServerPlayerEntity.java index 1418c99..64497dd 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinServerPlayerEntity.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/entity/MixinServerPlayerEntity.java @@ -14,10 +14,11 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(ServerPlayerEntity.class) -public abstract class MixinServerPlayerEntity extends PlayerEntity { +public abstract class MixinServerPlayerEntity extends PlayerEntity { @Shadow public ServerPlayNetworkHandler networkHandler; + private int sneakTimes = 0; private long lastSneakTime = 0; @@ -42,9 +43,9 @@ public abstract class MixinServerPlayerEntity extends PlayerEntity { if (this.isOnGround() && nowTime - lastSneakTime < 400) { sneakTimes += 1; if (sneakTimes == 3) { - ArmorStandEntity armorStandEntity = new ArmorStandEntity(world, this.getX(), this.getY() - 0.16, this.getZ()); + ArmorStandEntity armorStandEntity = new ArmorStandEntity(getWorld(), this.getX(), this.getY() - 0.16, this.getZ()); ((SitEntity) armorStandEntity).setSitEntity(true); - world.spawnEntity(armorStandEntity); + getWorld().spawnEntity(armorStandEntity); this.setSneaking(false); this.startRiding(armorStandEntity); sneakTimes = 0; diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/protocol/pcaSyncProtocol/entity/MixinMerchantEntity.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/protocol/pcaSyncProtocol/entity/MixinMerchantEntity.java index 8b2abff..6520c39 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/protocol/pcaSyncProtocol/entity/MixinMerchantEntity.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/protocol/pcaSyncProtocol/entity/MixinMerchantEntity.java @@ -33,7 +33,7 @@ public abstract class MixinMerchantEntity extends PassiveEntity implements Npc, @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At(value = "RETURN")) private void addInventoryListener(EntityType entityType, World world, CallbackInfo info) { - if (this.world.isClient()) { + if (this.getWorld().isClient()) { return; } this.inventory.addListener(this); diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinChainRestrictedNeighborUpdater.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinChainRestrictedNeighborUpdater.java new file mode 100644 index 0000000..84abb02 --- /dev/null +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/world/MixinChainRestrictedNeighborUpdater.java @@ -0,0 +1,31 @@ +package com.github.zly2006.carpetslsaddition.mixin.world; + +import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; +import net.minecraft.world.block.ChainRestrictedNeighborUpdater; +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.CallbackInfo; + +import java.util.ArrayDeque; + +@Mixin(ChainRestrictedNeighborUpdater.class) +public class MixinChainRestrictedNeighborUpdater { + + @Shadow + @Final + private ArrayDeque queue; + + @Inject(method = "runQueuedUpdates", at = @At(value = "INVOKE", target = "Ljava/util/List;clear()V", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true) + public void injectRunQueuedUpdates(CallbackInfo ci) { + int maxSize = SLSCarpetSettings.maxUpdateQueueSize; + if (maxSize > 0) { + if (this.queue.size() > maxSize) { + ci.cancel(); + // throw new OutOfMemoryError("The update queue exceeded the maximum allowed allocation of heap space set by SLS Addition!"); + } + } + } +} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/network/pca/PcaSyncProtocol.java b/src/main/java/com/github/zly2006/carpetslsaddition/network/pca/PcaSyncProtocol.java index ed289dc..2207643 100644 --- a/src/main/java/com/github/zly2006/carpetslsaddition/network/pca/PcaSyncProtocol.java +++ b/src/main/java/com/github/zly2006/carpetslsaddition/network/pca/PcaSyncProtocol.java @@ -164,7 +164,7 @@ public class PcaSyncProtocol { return; } BlockPos pos = buf.readBlockPos(); - ServerWorld world = player.getWorld(); + ServerWorld world = player.getServerWorld(); BlockState blockState = world.getBlockState(pos); clearPlayerWatchData(player); ServerMain.LOGGER.debug("{} watch blockpos {}: {}", player.getName().getString(), pos, blockState); @@ -219,7 +219,7 @@ public class PcaSyncProtocol { return; } int entityId = buf.readInt(); - ServerWorld world = player.getWorld(); + ServerWorld world = player.getServerWorld(); Entity entity = world.getEntityById(entityId); if (entity == null) { ServerMain.LOGGER.debug("Can't find entity {}.", entityId); diff --git a/src/main/resources/assets/slsaddition/lang/en_us.json b/src/main/resources/assets/slsaddition/lang/en_us.json index 5cf10e5..398a8ec 100644 --- a/src/main/resources/assets/slsaddition/lang/en_us.json +++ b/src/main/resources/assets/slsaddition/lang/en_us.json @@ -19,6 +19,7 @@ "carpet.rule.playerSit.name": "Player can sit", "carpet.rule.canUseHatCommand.name": "Enable hat command", "carpet.rule.canUseSitCommand.name": "Enable sit command", + "carpet.rule.maxUpdateQueueSize.name": "Maximum allowed capacity of update queue", "carpet.rule.obtainableReinforcedDeepSlate.desc": "When an anvil falls on 64 dropped deepslates, they will be turned in a reinforced deepslate instead of disappearing.", "carpet.rule.skipTicksForJoblessVillager.desc": "For jobless/nitwit villagers, after performing a set number of tick operations, skip the 1 tick operation.", @@ -35,11 +36,14 @@ "carpet.rule.playerSit.desc": "Player can sit down when fast sneak 3 times.", "carpet.rule.canUseHatCommand.desc": "Allows all players to use the /hat command to place their main hand items in the helmet slot", "carpet.rule.canUseSitCommand.desc": "Allows all players to use the /sit command to sit down", + "carpet.rule.maxUpdateQueueSize.desc": "Set the maximum allowed length of the update queue", "carpet.rule.autoUrl.extra.0": "The URL sent by players to be directly clicked and redirected by other players", "carpet.rule.skipTicksForJoblessVillager.extra.0": "Set to 0 to maintain the vanilla behavior", "carpet.rule.skipTicksForJoblessVillager.extra.1": "Set to a number greater than 0, the value will be +1 based on the setting", "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.", diff --git a/src/main/resources/assets/slsaddition/lang/zh_cn.json b/src/main/resources/assets/slsaddition/lang/zh_cn.json index 7540733..1114f3f 100644 --- a/src/main/resources/assets/slsaddition/lang/zh_cn.json +++ b/src/main/resources/assets/slsaddition/lang/zh_cn.json @@ -19,6 +19,7 @@ "carpet.rule.playerSit.name": "玩家可坐下", "carpet.rule.canUseHatCommand.name": "启用戴帽指令", "carpet.rule.canUseSitCommand.name": "启用坐下指令", + "carpet.rule.maxUpdateQueueSize.name": "最大更新队列容量", "carpet.rule.maxVillagersInABlock.desc": "每个方块中最大村民数量,设置-1为无限制", "carpet.rule.obtainableReinforcedDeepSlate.desc": "当铁砧在64个深板岩的掉落物上时,可以获得强化深板岩", @@ -35,11 +36,14 @@ "carpet.rule.playerSit.desc": "在快速潜行 3 次后玩家可以坐下", "carpet.rule.canUseHatCommand.desc": "可让所有玩家使用/hat指令,将手中的物品置于头盔位", "carpet.rule.canUseSitCommand.desc": "可让所有玩家使用/sit指令,以在原地坐下", + "carpet.rule.maxUpdateQueueSize.desc": "设定最大允许的更新队列长度", "carpet.rule.autoUrl.extra.0": "使玩家发出的URL可以被其他玩家直接点击跳转", "carpet.rule.skipTicksForJoblessVillager.extra.0": "设置为0则保持原版行为", "carpet.rule.skipTicksForJoblessVillager.extra.1": "设置为大于0的数,将在设置的基础上将该值+1", "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 可以同步所有玩家的数据", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index eb0c6fe..04f580b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ "depends": { "fabricloader": ">=0.13", "fabric-api": "*", - "minecraft": "~1.19", + "minecraft": ">=1.20", "java": ">=17", "carpet": "*" }, diff --git a/src/main/resources/slsaddition.mixins.json b/src/main/resources/slsaddition.mixins.json index 43d1e59..a77e028 100644 --- a/src/main/resources/slsaddition.mixins.json +++ b/src/main/resources/slsaddition.mixins.json @@ -4,7 +4,6 @@ "package": "com.github.zly2006.carpetslsaddition.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "block.MixinAbstractSignBlock", "block.MixinBlock", "carpet.MixinFakePlayer", "carpet.MixinSettingsManager", @@ -34,6 +33,7 @@ "screen.MixinScreenHandler", "screen.MixinSlot", "server.MixinPlayerManager", + "world.MixinChainRestrictedNeighborUpdater", "world.MixinSpawnHelper" ], "client": [