Wrap NBTTagCompound#setTag in static helper with safeguards against circular references, fixes #299

This commit is contained in:
Electroblob77
2020-01-27 13:45:47 +00:00
parent 6cd6411c25
commit f5da195605
31 changed files with 96 additions and 48 deletions
@@ -7,6 +7,7 @@ import electroblob.wizardry.item.ItemCrystal;
import electroblob.wizardry.item.ItemSpellBook;
import electroblob.wizardry.registry.WizardryBlocks;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.util.NBTExtras;
import electroblob.wizardry.util.WandHelper;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
@@ -205,7 +206,7 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
}
}
tagCompound.setTag("Inventory", itemList);
NBTExtras.storeTagSafely(tagCompound, "Inventory", itemList);
return tagCompound;
}
@@ -184,7 +184,7 @@ public class TileEntityShrineCore extends TileEntity implements ITickable {
for(EntityLivingBase entity : entities){
entity.addPotionEffect(new PotionEffect(WizardryPotions.containment, 219));
entity.getEntityData().setTag(PotionContainment.ENTITY_TAG, NBTUtil.createPosTag(this.pos));
NBTExtras.storeTagSafely(entity.getEntityData(), PotionContainment.ENTITY_TAG, NBTUtil.createPosTag(this.pos));
}
}
@@ -192,13 +192,13 @@ public class TileEntityShrineCore extends TileEntity implements ITickable {
public NBTTagCompound writeToNBT(NBTTagCompound compound){
compound.setBoolean("activated", this.activated);
if(linkedContainer != null) compound.setTag("linkedContainerPos", NBTUtil.createPosTag(linkedContainer.getPos()));
if(linkedContainer != null) NBTExtras.storeTagSafely(compound, "linkedContainerPos", NBTUtil.createPosTag(linkedContainer.getPos()));
NBTTagList tagList = new NBTTagList();
for(UUID uuid : linkedWizards){
if(uuid != null) tagList.appendTag(NBTUtil.createUUIDTag(uuid));
}
compound.setTag("wizards", tagList);
NBTExtras.storeTagSafely(compound, "wizards", tagList);
return super.writeToNBT(compound);
}
@@ -1,5 +1,6 @@
package electroblob.wizardry.tileentity;
import electroblob.wizardry.util.NBTExtras;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityList;
@@ -152,7 +153,7 @@ public class TileEntityStatue extends TileEntity implements ITickable {
tagCompound.setFloat("entityYawHead", creature.rotationYawHead);
tagCompound.setFloat("entityYawOffset", creature.renderYawOffset);
}
tagCompound.setTag("entity", entityCompound);
NBTExtras.storeTagSafely(tagCompound, "entity", entityCompound);
tagCompound.setInteger("timer", timer);
tagCompound.setInteger("lifetime", lifetime);
tagCompound.setBoolean("isIce", isIce);