From 86e3ae87fdf51ea7d498c024d6f88ea4319ade98 Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 3 Mar 2016 22:01:33 -0800 Subject: [PATCH] Save the owner NBT without gameprofile properties --- .../arboriculture/tiles/TileLeaves.java | 6 +++--- .../tiles/TileTreeContainer.java | 5 ++--- .../forestry/core/access/AccessHandler.java | 6 ++---- .../forestry/core/fluids/TankManager.java | 6 +++--- .../core/genetics/ItemResearchNote.java | 6 +++--- .../MultiblockTileEntityForestry.java | 14 +++++++++---- .../{NBTUtil.java => NBTUtilForestry.java} | 2 +- .../java/forestry/core/utils/PlayerUtil.java | 20 +++++++++++++++++++ src/main/java/forestry/mail/MailAddress.java | 5 ++--- src/main/java/forestry/mail/TradeStation.java | 6 +++--- 10 files changed, 49 insertions(+), 27 deletions(-) rename src/main/java/forestry/core/utils/{NBTUtil.java => NBTUtilForestry.java} (98%) diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index 57f252ca0..9346fc976 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -20,7 +20,6 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import net.minecraft.util.BlockPos; import net.minecraft.world.World; @@ -63,6 +62,7 @@ import forestry.core.render.TextureManager; import forestry.core.utils.ColourUtil; import forestry.core.utils.GeneticsUtil; import forestry.core.utils.Log; +import forestry.core.utils.PlayerUtil; public class TileLeaves extends TileTreeContainer implements IPollinatable, IFruitBearer, IButterflyNursery, IRipeningPacketReceiver { @@ -105,7 +105,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru setTree(containedTree); } else { if (nbttagcompound.hasKey("owner")) { - setOwner(NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner"))); + setOwner(PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner"))); } ripeningTime = nbttagcompound.getShort("RT"); @@ -149,7 +149,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru GameProfile owner = getOwner(); if (owner != null) { NBTTagCompound nbt = new NBTTagCompound(); - NBTUtil.writeGameProfile(nbt, owner); + PlayerUtil.writeGameProfile(nbt, owner); nbtTagCompound.setTag("owner", nbt); } diff --git a/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java b/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java index 9e80016f9..732f00190 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java +++ b/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java @@ -16,7 +16,6 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; @@ -54,7 +53,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl containedTree = new Tree(nbttagcompound.getCompoundTag("ContainedTree")); } if (nbttagcompound.hasKey("owner")) { - owner = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner")); + owner = PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner")); } } @@ -69,7 +68,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl } if (this.owner != null) { NBTTagCompound nbt = new NBTTagCompound(); - NBTUtil.writeGameProfile(nbt, owner); + PlayerUtil.writeGameProfile(nbt, owner); nbttagcompound.setTag("owner", nbt); } } diff --git a/src/main/java/forestry/core/access/AccessHandler.java b/src/main/java/forestry/core/access/AccessHandler.java index 4a40474fc..85ca9ccf9 100644 --- a/src/main/java/forestry/core/access/AccessHandler.java +++ b/src/main/java/forestry/core/access/AccessHandler.java @@ -18,7 +18,6 @@ import java.util.UUID; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import net.minecraft.world.World; import com.mojang.authlib.GameProfile; @@ -167,7 +166,7 @@ public final class AccessHandler implements IAccessHandler { access = EnumAccess.values()[data.getInteger("Access")]; if (data.hasKey("owner")) { - owner = NBTUtil.readGameProfileFromNBT(data.getCompoundTag("owner")); + owner = PlayerUtil.readGameProfileFromNBT(data.getCompoundTag("owner")); } } @@ -177,8 +176,7 @@ public final class AccessHandler implements IAccessHandler { if (this.owner != null) { NBTTagCompound nbt = new NBTTagCompound(); - NBTUtil.writeGameProfile(nbt, owner); - nbt.removeTag("Properties"); + PlayerUtil.writeGameProfile(nbt, owner); data.setTag("owner", nbt); } } diff --git a/src/main/java/forestry/core/fluids/TankManager.java b/src/main/java/forestry/core/fluids/TankManager.java index c067b978d..c87fdb32b 100644 --- a/src/main/java/forestry/core/fluids/TankManager.java +++ b/src/main/java/forestry/core/fluids/TankManager.java @@ -46,8 +46,8 @@ import forestry.core.proxy.Proxies; import forestry.core.render.EnumTankLevel; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.IRenderableTile; -import forestry.core.utils.NBTUtil; -import forestry.core.utils.NBTUtil.NBTList; +import forestry.core.utils.NBTUtilForestry; +import forestry.core.utils.NBTUtilForestry.NBTList; /** * @author CovertJaguar @@ -106,7 +106,7 @@ public class TankManager implements ITankManager, ITankUpdateHandler, IStreamabl @Override public void readFromNBT(NBTTagCompound data) { - NBTList tagList = NBTUtil.getNBTList(data, "tanks", NBTUtil.EnumNBTType.COMPOUND); + NBTList tagList = NBTUtilForestry.getNBTList(data, "tanks", NBTUtilForestry.EnumNBTType.COMPOUND); for (NBTTagCompound tag : tagList) { int slot = tag.getByte("tank"); if (slot >= 0 && slot < tanks.size()) { diff --git a/src/main/java/forestry/core/genetics/ItemResearchNote.java b/src/main/java/forestry/core/genetics/ItemResearchNote.java index 5f2d062ff..0c7e0b3c1 100755 --- a/src/main/java/forestry/core/genetics/ItemResearchNote.java +++ b/src/main/java/forestry/core/genetics/ItemResearchNote.java @@ -18,7 +18,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; @@ -34,6 +33,7 @@ import forestry.api.genetics.ISpeciesRoot; import forestry.core.genetics.mutations.EnumMutateChance; import forestry.core.items.ItemForestry; import forestry.core.proxy.Proxies; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.StringUtil; public class ItemResearchNote extends ItemForestry { @@ -216,7 +216,7 @@ public class ItemResearchNote extends ItemForestry { public ResearchNote(NBTTagCompound compound) { if (compound != null) { if (compound.hasKey("res")) { - this.researcher = NBTUtil.readGameProfileFromNBT(compound.getCompoundTag("res")); + this.researcher = PlayerUtil.readGameProfileFromNBT(compound.getCompoundTag("res")); } else { this.researcher = null; } @@ -232,7 +232,7 @@ public class ItemResearchNote extends ItemForestry { public void writeToNBT(NBTTagCompound compound) { if (this.researcher != null) { NBTTagCompound nbt = new NBTTagCompound(); - NBTUtil.writeGameProfile(nbt, researcher); + PlayerUtil.writeGameProfile(nbt, researcher); compound.setTag("res", nbt); } compound.setByte("TYP", (byte) type.ordinal()); diff --git a/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java b/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java index 83b1b5dac..3b4b9b0ba 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java +++ b/src/main/java/forestry/core/multiblock/MultiblockTileEntityForestry.java @@ -10,11 +10,13 @@ ******************************************************************************/ package forestry.core.multiblock; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import net.minecraft.util.EnumFacing; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; @@ -30,8 +32,10 @@ import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; import forestry.core.tiles.IFilterSlotDelegate; import forestry.core.tiles.ILocatable; +import forestry.core.utils.PlayerUtil; public abstract class MultiblockTileEntityForestry extends MultiblockTileEntityBase implements ISidedInventory, IFilterSlotDelegate, ILocatable, IGuiHandlerTile { + @Nullable private GameProfile owner; public MultiblockTileEntityForestry(T multiblockLogic) { @@ -50,7 +54,8 @@ public abstract class MultiblockTileEntityForestry e super.readFromNBT(data); if (data.hasKey("owner")) { - owner = NBTUtil.readGameProfileFromNBT(data.getCompoundTag("owner")); + NBTTagCompound ownerNbt = data.getCompoundTag("owner"); + this.owner = PlayerUtil.readGameProfileFromNBT(ownerNbt); } getInternalInventory().readFromNBT(data); @@ -62,7 +67,7 @@ public abstract class MultiblockTileEntityForestry e if (this.owner != null) { NBTTagCompound nbt = new NBTTagCompound(); - nbt.removeTag("Properties"); + PlayerUtil.writeGameProfile(nbt, owner); data.setTag("owner", nbt); } @@ -187,12 +192,13 @@ public abstract class MultiblockTileEntityForestry e } /* IMultiblockComponent */ + @Nullable @Override public final GameProfile getOwner() { return owner; } - public final void setOwner(GameProfile owner) { + public final void setOwner(@Nonnull GameProfile owner) { this.owner = owner; } diff --git a/src/main/java/forestry/core/utils/NBTUtil.java b/src/main/java/forestry/core/utils/NBTUtilForestry.java similarity index 98% rename from src/main/java/forestry/core/utils/NBTUtil.java rename to src/main/java/forestry/core/utils/NBTUtilForestry.java index 2e398e1e4..c75213aff 100644 --- a/src/main/java/forestry/core/utils/NBTUtil.java +++ b/src/main/java/forestry/core/utils/NBTUtilForestry.java @@ -34,7 +34,7 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; /** * @author CovertJaguar */ -public abstract class NBTUtil { +public abstract class NBTUtilForestry { public enum EnumNBTType { diff --git a/src/main/java/forestry/core/utils/PlayerUtil.java b/src/main/java/forestry/core/utils/PlayerUtil.java index 96868f11a..f0d9e29ce 100644 --- a/src/main/java/forestry/core/utils/PlayerUtil.java +++ b/src/main/java/forestry/core/utils/PlayerUtil.java @@ -10,9 +10,14 @@ ******************************************************************************/ package forestry.core.utils; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.UUID; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.util.StringUtils; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -74,4 +79,19 @@ public abstract class PlayerUtil { } return player; } + + public static void writeGameProfile(@Nonnull NBTTagCompound tagCompound, @Nonnull GameProfile profile) { + if (!StringUtils.isNullOrEmpty(profile.getName())) { + tagCompound.setString("Name", profile.getName()); + } + + if (profile.getId() != null) { + tagCompound.setString("Id", profile.getId().toString()); + } + } + + @Nullable + public static GameProfile readGameProfileFromNBT(@Nonnull NBTTagCompound compound) { + return NBTUtil.readGameProfileFromNBT(compound); + } } diff --git a/src/main/java/forestry/mail/MailAddress.java b/src/main/java/forestry/mail/MailAddress.java index 3af1515f8..4e915d21b 100644 --- a/src/main/java/forestry/mail/MailAddress.java +++ b/src/main/java/forestry/mail/MailAddress.java @@ -15,7 +15,6 @@ import java.util.Locale; import java.util.UUID; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import com.mojang.authlib.GameProfile; @@ -69,7 +68,7 @@ public class MailAddress implements INbtWritable, IMailAddress { gameProfile = invalidGameProfile; } else if (nbt.hasKey("profile")) { NBTTagCompound profileTag = nbt.getCompoundTag("profile"); - gameProfile = NBTUtil.readGameProfileFromNBT(profileTag); + gameProfile = PlayerUtil.readGameProfileFromNBT(profileTag); } this.type = type; @@ -141,7 +140,7 @@ public class MailAddress implements INbtWritable, IMailAddress { if (gameProfile != null) { NBTTagCompound profileNbt = new NBTTagCompound(); - NBTUtil.writeGameProfile(profileNbt, gameProfile); + PlayerUtil.writeGameProfile(profileNbt, gameProfile); nbttagcompound.setTag("profile", profileNbt); } } diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index fd27fad15..cdbe7db2d 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -16,7 +16,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; import net.minecraft.util.EnumFacing; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; @@ -36,6 +35,7 @@ import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.StringUtil; import forestry.mail.inventory.InventoryTradeStation; import forestry.mail.items.EnumStampDefinition; @@ -86,7 +86,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve @Override public void readFromNBT(NBTTagCompound nbttagcompound) { if (nbttagcompound.hasKey("owner")) { - owner = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner")); + owner = PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner")); } if (nbttagcompound.hasKey("address")) { @@ -102,7 +102,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve public void writeToNBT(NBTTagCompound nbttagcompound) { if (owner != null) { NBTTagCompound nbt = new NBTTagCompound(); - NBTUtil.writeGameProfile(nbt, owner); + PlayerUtil.writeGameProfile(nbt, owner); nbttagcompound.setTag("owner", nbt); }