From b71e0a32b51038ffee64b76370a5f46992bd1a8c Mon Sep 17 00:00:00 2001 From: jchung01 Date: Thu, 9 May 2024 16:44:45 -0700 Subject: [PATCH 1/2] Add fix for MC-121152 --- .../entitylists/mixin/UTWorldClientMixin.java | 28 +++++++++++++++++++ .../config/UTConfigBugfixes.java | 5 ++++ .../universaltweaks/core/UTLoadingPlugin.java | 1 + ....bugfixes.entities.entitylists.client.json | 7 +++++ 4 files changed, 41 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java create mode 100644 src/main/resources/mixins.bugfixes.entities.entitylists.client.json diff --git a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java new file mode 100644 index 00000000..2b3434fc --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java @@ -0,0 +1,28 @@ +package mod.acgaming.universaltweaks.bugfixes.entities.entitylists.mixin; + +import mod.acgaming.universaltweaks.config.UTConfigBugfixes; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.entity.Entity; +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.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +// MC-121152 +// https://bugs.mojang.com/browse/MC-121152 +@Mixin(value = WorldClient.class) +public class UTWorldClientMixin +{ + @Inject(method = "addEntityToWorld", + slice = @Slice(from = @At(value = "HEAD"), + to = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;spawnEntity(Lnet/minecraft/entity/Entity;)Z")), + at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z")) + private void utSetIdBeforeAdd(int entityID, Entity entityToSpawn, CallbackInfo ci) + { + if (UTConfigBugfixes.ENTITIES.utEntityListAdditionToggle) + { + entityToSpawn.setEntityId(entityID); + } + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java index 0b257061..9f015bfb 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java @@ -212,6 +212,11 @@ public static class EntitiesCategory @Config.Comment("Fixes non-functional elytra firework boosting and guardian targeting if the entity ID is 0") public boolean utEntityIDToggle = true; + @Config.RequiresMcRestart + @Config.Name("Entity List Addition") + @Config.Comment("Fixes client-side memory leak where some entity ids are not set before being added to the entity list") + public boolean utEntityListAdditionToggle = true; + @Config.RequiresMcRestart @Config.Name("Entity Lists") @Config.Comment("Fixes entity lists often not getting updated correctly") diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 4c49088c..3c3b2720 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -153,6 +153,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.bugfixes.blocks.blockoverlay.json", () -> UTConfigBugfixes.BLOCKS.BLOCK_OVERLAY.utBlockOverlayToggle); put("mixins.bugfixes.blocks.miningglitch.client.json", () -> UTConfigBugfixes.BLOCKS.MINING_GLITCH.utMiningGlitchToggle); put("mixins.bugfixes.entities.elytra.json", () -> UTConfigBugfixes.ENTITIES.utElytraDeploymentLandingToggle); + put("mixins.bugfixes.entities.entitylists.client.json", () -> UTConfigBugfixes.ENTITIES.utEntityListAdditionToggle); put("mixins.bugfixes.entities.villagermantle.json", () -> UTConfigBugfixes.ENTITIES.utVillagerMantleToggle); put("mixins.bugfixes.misc.depthmask.json", () -> UTConfigBugfixes.MISC.utDepthMaskToggle); put("mixins.bugfixes.misc.modelgap.json", () -> UTConfigBugfixes.MISC.MODEL_GAP.utModelGapToggle); diff --git a/src/main/resources/mixins.bugfixes.entities.entitylists.client.json b/src/main/resources/mixins.bugfixes.entities.entitylists.client.json new file mode 100644 index 00000000..99f1bfea --- /dev/null +++ b/src/main/resources/mixins.bugfixes.entities.entitylists.client.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.bugfixes.entities.entitylists.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "client": ["UTWorldClientMixin"] +} \ No newline at end of file From 122d7c93729f2dfb6fc353020e8f2d5fa3be921f Mon Sep 17 00:00:00 2001 From: jchung01 Date: Thu, 9 May 2024 16:59:19 -0700 Subject: [PATCH 2/2] Group/rename "Entity Lists" bugfixes --- README.md | 4 ++- .../mixin/UTEntityTilePistonMixin.java | 4 +-- .../entitylists/mixin/UTWorldClientMixin.java | 4 +-- .../entitylists/mixin/UTWorldMixin.java | 2 +- .../config/UTConfigBugfixes.java | 27 ++++++++++++------- .../universaltweaks/core/UTLoadingPlugin.java | 4 +-- .../assets/universaltweaks/lang/en_us.lang | 1 + 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f7196c69..b927de34 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,9 @@ All changes are toggleable via config files. * **Entity Bounding Boxes:** Saves entity bounding boxes to tags to prevent breakouts and suffocation * **Entity Desync:** Fixes entity motion desyncs most notable with arrows and thrown items * **Entity ID:** Fixes non-functional elytra firework boosting and guardian targeting if the entity ID is 0 -* **Entity Lists:** Fixes entity lists often not getting updated correctly +* **Entity Lists** + * **Chunk Updates:** Fixes chunk entity lists often not getting updated correctly + * **World Additions:** Fixes client-side memory leak where some entity ids are not set before being added to the world's entity list * **Entity NaN:** Prevents corruption of entities caused by invalid health or damage values * **Entity Suffocation:** Pushes entities out of blocks when growing up to prevent suffocation * **Entity Tracker:** Fixes entity tracker to prevent client-sided desyncs when teleporting or changing dimensions diff --git a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTEntityTilePistonMixin.java b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTEntityTilePistonMixin.java index 13a9def0..9eab16aa 100644 --- a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTEntityTilePistonMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTEntityTilePistonMixin.java @@ -25,12 +25,12 @@ public abstract class UTEntityTilePistonMixin extends TileEntity @Inject(method = "moveCollidedEntities", at = @At(value = "INVOKE", target = "Ljava/lang/ThreadLocal;set(Ljava/lang/Object;)V", ordinal = 1, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD) public void utUpdateEntity(float p_184322_1_, CallbackInfo ci, EnumFacing enumfacing, double d0, List list, AxisAlignedBB axisalignedbb, List list1, boolean flag, int i, Entity entity, double d1) { - if (UTConfigBugfixes.ENTITIES.utEntityListsToggle) world.updateEntityWithOptionalForce(entity, false); + if (UTConfigBugfixes.ENTITIES.ENTITY_LISTS.utChunkUpdatesToggle) world.updateEntityWithOptionalForce(entity, false); } @Surrogate public void utUpdateEntity(float p_184322_1_, CallbackInfo ci, EnumFacing enumfacing, double d0, List list, AxisAlignedBB axisalignedbb, List list1, boolean flag, int i, Entity entity, double d1, int quark0) { - if (UTConfigBugfixes.ENTITIES.utEntityListsToggle) world.updateEntityWithOptionalForce(entity, false); + if (UTConfigBugfixes.ENTITIES.ENTITY_LISTS.utChunkUpdatesToggle) world.updateEntityWithOptionalForce(entity, false); } } \ No newline at end of file diff --git a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java index 2b3434fc..1a53e6bc 100644 --- a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldClientMixin.java @@ -17,10 +17,10 @@ public class UTWorldClientMixin @Inject(method = "addEntityToWorld", slice = @Slice(from = @At(value = "HEAD"), to = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;spawnEntity(Lnet/minecraft/entity/Entity;)Z")), - at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z")) + at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z", ordinal = 0, remap = false)) private void utSetIdBeforeAdd(int entityID, Entity entityToSpawn, CallbackInfo ci) { - if (UTConfigBugfixes.ENTITIES.utEntityListAdditionToggle) + if (UTConfigBugfixes.ENTITIES.ENTITY_LISTS.utWorldAdditionsToggle) { entityToSpawn.setEntityId(entityID); } diff --git a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldMixin.java b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldMixin.java index 2c99dec4..ae00ea31 100644 --- a/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/bugfixes/entities/entitylists/mixin/UTWorldMixin.java @@ -21,7 +21,7 @@ public abstract class UTWorldMixin at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPositionNonDirty()Z", ordinal = 0)) public boolean utAlwaysLoadChunk(Entity entityIn) { - if (UTConfigBugfixes.ENTITIES.utEntityListsToggle) + if (UTConfigBugfixes.ENTITIES.ENTITY_LISTS.utChunkUpdatesToggle) { return true; } diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java index 9f015bfb..9a969bda 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigBugfixes.java @@ -146,6 +146,10 @@ public static class EntitiesCategory @Config.Name("Entity Desync") public final EntityDesyncCategory ENTITY_DESYNC = new EntityDesyncCategory(); + @Config.LangKey("cfg.universaltweaks.bugfixes.entities.entitylists") + @Config.Name("Entity Lists") + public final EntityListsCategory ENTITY_LISTS = new EntityListsCategory(); + @Config.RequiresMcRestart @Config.Name("Attack Radius") @Config.Comment("Improves the attack radius of hostile mobs by checking the line of sight with raytracing") @@ -212,16 +216,6 @@ public static class EntitiesCategory @Config.Comment("Fixes non-functional elytra firework boosting and guardian targeting if the entity ID is 0") public boolean utEntityIDToggle = true; - @Config.RequiresMcRestart - @Config.Name("Entity List Addition") - @Config.Comment("Fixes client-side memory leak where some entity ids are not set before being added to the entity list") - public boolean utEntityListAdditionToggle = true; - - @Config.RequiresMcRestart - @Config.Name("Entity Lists") - @Config.Comment("Fixes entity lists often not getting updated correctly") - public boolean utEntityListsToggle = true; - @Config.Name("Entity NaN Values") @Config.Comment("Prevents corruption of entities caused by invalid health or damage values") public boolean utEntityNaNToggle = true; @@ -307,6 +301,19 @@ public static class EntityDesyncCategory "pixelmon:occupied_pokeball" }; } + + public static class EntityListsCategory + { + @Config.RequiresMcRestart + @Config.Name("Chunk Updates") + @Config.Comment("Fixes chunk entity lists often not getting updated correctly") + public boolean utChunkUpdatesToggle = true; + + @Config.RequiresMcRestart + @Config.Name("World Additions") + @Config.Comment("Fixes client-side memory leak where some entity ids are not set before being added to the world's entity list") + public boolean utWorldAdditionsToggle = true; + } } public static class MiscCategory diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 3c3b2720..a1b43407 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -55,7 +55,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.bugfixes.entities.desync.json", () -> UTConfigBugfixes.ENTITIES.ENTITY_DESYNC.utEntityDesyncToggle); put("mixins.bugfixes.entities.dimensionchange.json", () -> UTConfigBugfixes.ENTITIES.utDimensionChangeToggle); put("mixins.bugfixes.entities.entityid.json", () -> UTConfigBugfixes.ENTITIES.utEntityIDToggle); - put("mixins.bugfixes.entities.entitylists.json", () -> UTConfigBugfixes.ENTITIES.utEntityListsToggle); + put("mixins.bugfixes.entities.entitylists.json", () -> UTConfigBugfixes.ENTITIES.ENTITY_LISTS.utChunkUpdatesToggle); put("mixins.bugfixes.entities.horsefalling.json", () -> UTConfigBugfixes.ENTITIES.utHorseFallingToggle); put("mixins.bugfixes.entities.maxhealth.json", () -> UTConfigBugfixes.ENTITIES.utMaxHealthToggle); put("mixins.bugfixes.entities.minecart.json", () -> UTConfigBugfixes.ENTITIES.utMinecartAIToggle); @@ -153,7 +153,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.bugfixes.blocks.blockoverlay.json", () -> UTConfigBugfixes.BLOCKS.BLOCK_OVERLAY.utBlockOverlayToggle); put("mixins.bugfixes.blocks.miningglitch.client.json", () -> UTConfigBugfixes.BLOCKS.MINING_GLITCH.utMiningGlitchToggle); put("mixins.bugfixes.entities.elytra.json", () -> UTConfigBugfixes.ENTITIES.utElytraDeploymentLandingToggle); - put("mixins.bugfixes.entities.entitylists.client.json", () -> UTConfigBugfixes.ENTITIES.utEntityListAdditionToggle); + put("mixins.bugfixes.entities.entitylists.client.json", () -> UTConfigBugfixes.ENTITIES.ENTITY_LISTS.utWorldAdditionsToggle); put("mixins.bugfixes.entities.villagermantle.json", () -> UTConfigBugfixes.ENTITIES.utVillagerMantleToggle); put("mixins.bugfixes.misc.depthmask.json", () -> UTConfigBugfixes.MISC.utDepthMaskToggle); put("mixins.bugfixes.misc.modelgap.json", () -> UTConfigBugfixes.MISC.MODEL_GAP.utModelGapToggle); diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index 1fa9a226..5dc05f78 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -43,6 +43,7 @@ cfg.universaltweaks.config.world=World cfg.universaltweaks.bugfixes.blocks.blockoverlay=Block Overlay cfg.universaltweaks.bugfixes.entities.desync=Entity Desync +cfg.universaltweaks.bugfixes.entities.entitylists=Entity Lists cfg.universaltweaks.bugfixes.misc.modelgap=Model Gap cfg.universaltweaks.modintegration.abyssalcraft=AbyssalCraft