Move the player data hooks from Entity onto EntityPlayerMP

This commit is contained in:
Ruling-0 committed 2026-11-25 14:45:59 -06:00
1 parent 7af0b24e3e
commit b0c79d9439
5 files changed
+76 -49

No files matched your search

@@ -45,8 +45,8 @@ public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoading
final List<String> mixins = new ArrayList<>();
mixins.add("MixinItemStack");
mixins.add("MixinChunk");
mixins.add("MixinEntity");
mixins.add("MixinEntityPlayer");
mixins.add("MixinEntityPlayerMP");
mixins.add("MixinAnvilChunkLoader");
mixins.add("MixinNBTTagList");
mixins.add("MixinSaveHandler");
@@ -1,46 +0,0 @@
package com.gtnewhorizons.postea.mixins.early;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.gtnewhorizons.postea.mixins.interfaces.IPlayerStampsMixin;
import com.gtnewhorizons.postea.utility.PlayerDataFixerUtility;
@Mixin(Entity.class)
public abstract class MixinEntity implements IPlayerStampsMixin {
/// The stamps a server player's data was read with. [MixinEntityPlayer] carries them across respawns.
@Unique
private NBTTagCompound postea$versionStamps;
@Unique
public NBTTagCompound Postea$getVersionStamps() {
return postea$versionStamps;
}
@Unique
public void Postea$setVersionStamps(NBTTagCompound stamps) {
this.postea$versionStamps = stamps;
}
@Inject(method = "readFromNBT", at = @At("HEAD"), require = 1)
private void postea$transformPlayerData(NBTTagCompound tag, CallbackInfo ci) {
if ((Object) this instanceof EntityPlayerMP player) {
postea$versionStamps = PlayerDataFixerUtility.onPlayerRead(player, tag);
}
}
@Inject(method = "writeToNBT", at = @At("RETURN"), require = 1)
private void postea$stampPlayerData(NBTTagCompound tag, CallbackInfo ci) {
if ((Object) this instanceof EntityPlayerMP) {
PlayerDataFixerUtility.onPlayerWrite(tag, postea$versionStamps);
}
}
}
@@ -15,6 +15,8 @@ public abstract class MixinEntityPlayer {
/// Copies the version stamps from the old player, because a respawned player is not built through NBT.
@Inject(method = "clonePlayer", at = @At("RETURN"), require = 1)
private void postea$carryVersionStamps(EntityPlayer oldPlayer, boolean respawn, CallbackInfo ci) {
((IPlayerStampsMixin) this).Postea$setVersionStamps(((IPlayerStampsMixin) oldPlayer).Postea$getVersionStamps());
if ((Object) this instanceof IPlayerStampsMixin player && oldPlayer instanceof IPlayerStampsMixin old) {
player.Postea$setVersionStamps(old.Postea$getVersionStamps());
}
}
}
@@ -0,0 +1,71 @@
package com.gtnewhorizons.postea.mixins.early;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.gtnewhorizons.postea.mixins.interfaces.IPlayerStampsMixin;
import com.gtnewhorizons.postea.utility.PlayerDataFixerUtility;
import com.mojang.authlib.GameProfile;
/// Transforms a server player's saved data on read and stamps it on write.
///
/// The hooks override `Entity.readFromNBT` and `writeToNBT` so the transform also reaches `ForgeData` and the extended
/// properties, which Forge reads before `readEntityFromNBT`. The class extends [EntityPlayer] so the overrides
/// reobfuscate to `Entity`'s srg names.
@Mixin(EntityPlayerMP.class)
public abstract class MixinEntityPlayerMP extends EntityPlayer implements IPlayerStampsMixin {
/// The stamps the player's data was read with. [MixinEntityPlayer] carries them across respawns.
@Unique
private NBTTagCompound postea$versionStamps;
private MixinEntityPlayerMP(World world, GameProfile profile) {
super(world, profile);
}
@Unique
public NBTTagCompound Postea$getVersionStamps() {
return postea$versionStamps;
}
@Unique
public void Postea$setVersionStamps(NBTTagCompound stamps) {
this.postea$versionStamps = stamps;
}
@Intrinsic
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
}
@Intrinsic
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
}
@Dynamic("Merged into EntityPlayerMP by readFromNBT above")
@SuppressWarnings("target")
@Inject(method = "readFromNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("HEAD"), require = 1)
private void postea$transformPlayerData(NBTTagCompound tag, CallbackInfo ci) {
postea$versionStamps = PlayerDataFixerUtility.onPlayerRead((EntityPlayerMP) (Object) this, tag);
}
@Dynamic("Merged into EntityPlayerMP by writeToNBT above")
@SuppressWarnings("target")
@Inject(method = "writeToNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("RETURN"), require = 1)
private void postea$stampPlayerData(NBTTagCompound tag, CallbackInfo ci) {
PlayerDataFixerUtility.onPlayerWrite(tag, postea$versionStamps);
}
}
+1 -1
View File
@@ -8,8 +8,8 @@
"mixins": [
"MixinAnvilChunkLoader",
"MixinChunk",
"MixinEntity",
"MixinEntityPlayer",
"MixinEntityPlayerMP",
"MixinItemStack",
"MixinNBTTagList",
"MixinSaveHandler"