From c35b5e52ca175951d24fd9286861fbeda4a4d000 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Sat, 4 Jan 2025 02:43:53 -0800 Subject: [PATCH] Code dedup & Bug fixes --- .../fix/capability/CBRespawnFixLogic.java | 32 +++++++++++++++++++ .../mixin/fix/capability/PlayerListMixin.java | 5 +-- .../capability/mohist/PlayerListMixin.java | 12 ++----- src/main/resources/hybridfix_at.cfg | 15 ++++++++- 4 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/main/java/io/wdsj/hybridfix/mixin/fix/capability/CBRespawnFixLogic.java diff --git a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/CBRespawnFixLogic.java b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/CBRespawnFixLogic.java new file mode 100644 index 0000000..8d330c5 --- /dev/null +++ b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/CBRespawnFixLogic.java @@ -0,0 +1,32 @@ +package io.wdsj.hybridfix.mixin.fix.capability; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; + +import static net.minecraft.entity.Entity.*; + +public class CBRespawnFixLogic { + private CBRespawnFixLogic() { + } + public static void fixRespawn(EntityPlayerMP playerIn) { + try { + playerIn.getDataManager().lock.writeLock().lock(); + playerIn.getDataManager().entries.clear(); + } finally { + playerIn.getDataManager().lock.writeLock().unlock(); + } + playerIn.getDataManager().empty = true; + // Entity data params + playerIn.getDataManager().register(FLAGS, Byte.valueOf((byte)0)); + playerIn.getDataManager().register(AIR, Integer.valueOf(300)); + playerIn.getDataManager().register(CUSTOM_NAME_VISIBLE, Boolean.valueOf(false)); + playerIn.getDataManager().register(CUSTOM_NAME, ""); + playerIn.getDataManager().register(SILENT, Boolean.valueOf(false)); + playerIn.getDataManager().register(NO_GRAVITY, Boolean.valueOf(false)); + + playerIn.entityInit(); + + net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(playerIn)); + ((EntityCapabilityAccessor) (Entity) playerIn).setCapabilities(net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(playerIn)); + } +} diff --git a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java index 7c952f6..8fff666 100644 --- a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java +++ b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java @@ -1,6 +1,5 @@ package io.wdsj.hybridfix.mixin.fix.capability; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.management.PlayerList; import org.bukkit.Location; @@ -21,8 +20,6 @@ public abstract class PlayerListMixin { remap = false ) public void onMoveToWorld(EntityPlayerMP playerIn, int i, boolean b, Location loc, boolean b1, CallbackInfoReturnable cir) { - playerIn.getDataManager().entries.clear(); - net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(playerIn)); - ((EntityCapabilityAccessor) (Entity) playerIn).setCapabilities(net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(playerIn)); + CBRespawnFixLogic.fixRespawn(playerIn); } } diff --git a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java index 66f1306..f04e47c 100644 --- a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java +++ b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java @@ -1,12 +1,9 @@ package io.wdsj.hybridfix.mixin.fix.capability.mohist; -import io.wdsj.hybridfix.mixin.fix.capability.EntityCapabilityAccessor; -import net.minecraft.entity.Entity; +import io.wdsj.hybridfix.mixin.fix.capability.CBRespawnFixLogic; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.management.PlayerList; -import net.minecraft.world.storage.IPlayerFileData; 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; @@ -17,9 +14,6 @@ */ @Mixin(PlayerList.class) public abstract class PlayerListMixin { - - @Shadow private IPlayerFileData playerDataManager; - @Inject( method = "func_72368_a(Lnet/minecraft/entity/player/EntityPlayerMP;IZ)Lnet/minecraft/entity/player/EntityPlayerMP;", at = @At( @@ -29,8 +23,6 @@ public abstract class PlayerListMixin { remap = false ) public void func(EntityPlayerMP playerIn, int i, boolean b, CallbackInfoReturnable cir) { - playerIn.getDataManager().entries.clear(); - net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(playerIn)); - ((EntityCapabilityAccessor) (Entity) playerIn).setCapabilities(net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(playerIn)); + CBRespawnFixLogic.fixRespawn(playerIn); } } diff --git a/src/main/resources/hybridfix_at.cfg b/src/main/resources/hybridfix_at.cfg index 8699408..6177981 100644 --- a/src/main/resources/hybridfix_at.cfg +++ b/src/main/resources/hybridfix_at.cfg @@ -1,3 +1,16 @@ public net.minecraft.world.Explosion field_77283_e # exploder public net.minecraft.world.Explosion field_77280_f # size -public net.minecraft.network.datasync.EntityDataManager field_187234_c # entries \ No newline at end of file +public net.minecraft.network.datasync.EntityDataManager field_187234_c # entries +public net.minecraft.network.datasync.EntityDataManager field_187236_e # empty +public net.minecraft.network.datasync.EntityDataManager field_187235_d # lock + +# Entity data keys +public net.minecraft.entity.Entity field_184240_ax # FLAGS +public net.minecraft.entity.Entity field_184241_ay # AIR +public net.minecraft.entity.Entity field_184242_az # CUSTOM_NAME +public net.minecraft.entity.Entity field_184233_aA # CUSTOM_NAME_VISIBLE +public net.minecraft.entity.Entity field_184234_aB # SILENT +public net.minecraft.entity.Entity field_189655_aD # NO_GRAVITY + +# EntityPlayer method +public net.minecraft.entity.player.EntityPlayer func_70088_a()V # entityInit \ No newline at end of file