From 1205c9fdd14418dfa300fddb9ccb36abcb758f9f Mon Sep 17 00:00:00 2001 From: silnarm Date: Sun, 13 Aug 2023 08:36:27 +1000 Subject: [PATCH] fix-players-pushing-entities-in-tick-freeze * cancel pushEntities() if game paused * fixes #1779 --- .../mixins/LivingEntity_tickSpeedMixin.java | 25 +++++++++++++++++++ src/main/resources/carpet.mixins.json | 1 + 2 files changed, 26 insertions(+) create mode 100644 src/main/java/carpet/mixins/LivingEntity_tickSpeedMixin.java diff --git a/src/main/java/carpet/mixins/LivingEntity_tickSpeedMixin.java b/src/main/java/carpet/mixins/LivingEntity_tickSpeedMixin.java new file mode 100644 index 0000000000..e972f77957 --- /dev/null +++ b/src/main/java/carpet/mixins/LivingEntity_tickSpeedMixin.java @@ -0,0 +1,25 @@ +package carpet.mixins; + +import carpet.fakes.MinecraftServerInterface; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; +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.CallbackInfo; + +@Mixin(LivingEntity.class) +public class LivingEntity_tickSpeedMixin +{ + @Inject(method = "pushEntities", at = @At("HEAD"), cancellable = true) + private void onPushEntities(CallbackInfo ci) + { + if ((LivingEntity)(Object)this instanceof ServerPlayer) { + var server = (MinecraftServerInterface)((LivingEntity)(Object)this).level().getServer(); + if(server.getTickRateManager().gameIsPaused()) { + ci.cancel(); + } + } + } +} + diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index f9daa6206f..a5db8a8bea 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -67,6 +67,7 @@ "PistonStructureResolver_pushLimitMixin", "PoweredRailBlock_powerLimitMixin", "LivingEntity_maxCollisionsMixin", + "LivingEntity_tickSpeedMixin", "Level_getOtherEntitiesLimited", "CoralPlantBlock_renewableCoralMixin", "CoralFanBlock_renewableCoralMixin",