Skip to content

Commit

Permalink
Code dedup & Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Jan 4, 2025
1 parent 5668034 commit c35b5e5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,8 +20,6 @@ public abstract class PlayerListMixin {
remap = false
)
public void onMoveToWorld(EntityPlayerMP playerIn, int i, boolean b, Location loc, boolean b1, CallbackInfoReturnable<EntityPlayerMP> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand All @@ -29,8 +23,6 @@ public abstract class PlayerListMixin {
remap = false
)
public void func(EntityPlayerMP playerIn, int i, boolean b, CallbackInfoReturnable<EntityPlayerMP> 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);
}
}
15 changes: 14 additions & 1 deletion src/main/resources/hybridfix_at.cfg
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit c35b5e5

Please sign in to comment.