mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-19 03:49:05 +00:00
Carry player version stamps across respawns
This commit is contained in:
5 files changed
+45
-1
No files matched your search
@@ -46,6 +46,7 @@ public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoading
|
||||
mixins.add("MixinItemStack");
|
||||
mixins.add("MixinChunk");
|
||||
mixins.add("MixinEntity");
|
||||
mixins.add("MixinEntityPlayer");
|
||||
mixins.add("MixinAnvilChunkLoader");
|
||||
mixins.add("MixinNBTTagList");
|
||||
return mixins;
|
||||
|
||||
@@ -10,14 +10,26 @@ 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 {
|
||||
public abstract class MixinEntity implements IPlayerStampsMixin {
|
||||
|
||||
// The stamps a server player's data was read with; carried across respawns by MixinEntityPlayer.
|
||||
@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) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.gtnewhorizons.postea.mixins.early;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
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;
|
||||
|
||||
import com.gtnewhorizons.postea.mixins.interfaces.IPlayerStampsMixin;
|
||||
|
||||
@Mixin(EntityPlayer.class)
|
||||
public abstract class MixinEntityPlayer {
|
||||
|
||||
// A respawned player is a fresh entity built from the old one without going 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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.gtnewhorizons.postea.mixins.interfaces;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IPlayerStampsMixin {
|
||||
|
||||
NBTTagCompound Postea$getVersionStamps();
|
||||
|
||||
void Postea$setVersionStamps(NBTTagCompound stamps);
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
"MixinAnvilChunkLoader",
|
||||
"MixinChunk",
|
||||
"MixinEntity",
|
||||
"MixinEntityPlayer",
|
||||
"MixinItemStack",
|
||||
"MixinNBTTagList"
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user