* Portable Grids keep their enchantments when placed fixes #2198 * don't crash without enchants and save on world un-/load
This commit is contained in:
@@ -47,6 +47,7 @@ import net.minecraft.inventory.InventoryCraftResult;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -107,7 +108,7 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
private static final String NBT_STORAGE_TRACKER = "StorageTracker";
|
||||
private static final String NBT_FLUID_STORAGE_TRACKER = "FluidStorageTracker";
|
||||
private static final String NBT_TYPE = "Type";
|
||||
|
||||
private static final String NBT_ENCHANTMENTS = "ench";
|
||||
private EnergyStorage energyStorage = recreateEnergyStorage(0);
|
||||
private PortableGridType type;
|
||||
|
||||
@@ -148,6 +149,7 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
|
||||
private StorageTrackerItem storageTracker = new StorageTrackerItem(this::markDirty);
|
||||
private StorageTrackerFluid fluidStorageTracker = new StorageTrackerFluid(this::markDirty);
|
||||
private NBTTagList enchants = null;
|
||||
|
||||
public TilePortableGrid() {
|
||||
dataManager.addWatchedParameter(REDSTONE_MODE);
|
||||
@@ -245,6 +247,10 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
if (stack.getTagCompound().hasKey(PortableGrid.NBT_FLUID_STORAGE_TRACKER)) {
|
||||
fluidStorageTracker.readFromNbt(stack.getTagCompound().getTagList(PortableGrid.NBT_FLUID_STORAGE_TRACKER, Constants.NBT.TAG_COMPOUND));
|
||||
}
|
||||
if (stack.getTagCompound().hasKey(NBT_ENCHANTMENTS)) {
|
||||
enchants = stack.getTagCompound().getTagList(NBT_ENCHANTMENTS, Constants.NBT.TAG_COMPOUND);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.diskState = getDiskState(this);
|
||||
@@ -270,6 +276,10 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
|
||||
stack.getTagCompound().setTag(PortableGrid.NBT_STORAGE_TRACKER, storageTracker.serializeNbt());
|
||||
stack.getTagCompound().setTag(PortableGrid.NBT_FLUID_STORAGE_TRACKER, fluidStorageTracker.serializeNbt());
|
||||
if (enchants != null) {
|
||||
stack.getTagCompound().setTag(NBT_ENCHANTMENTS, enchants);
|
||||
}
|
||||
|
||||
|
||||
stack.getCapability(CapabilityEnergy.ENERGY, null).receiveEnergy(energyStorage.getEnergyStored(), false);
|
||||
|
||||
@@ -601,6 +611,7 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
|
||||
tag.setTag(NBT_STORAGE_TRACKER, storageTracker.serializeNbt());
|
||||
tag.setTag(NBT_FLUID_STORAGE_TRACKER, fluidStorageTracker.serializeNbt());
|
||||
tag.setTag(NBT_ENCHANTMENTS, enchants);
|
||||
|
||||
return tag;
|
||||
}
|
||||
@@ -649,6 +660,10 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
if (tag.hasKey(NBT_FLUID_STORAGE_TRACKER)) {
|
||||
fluidStorageTracker.readFromNbt(tag.getTagList(NBT_FLUID_STORAGE_TRACKER, Constants.NBT.TAG_COMPOUND));
|
||||
}
|
||||
if (tag.hasKey(NBT_ENCHANTMENTS)) {
|
||||
enchants = tag.getTagList(NBT_ENCHANTMENTS, Constants.NBT.TAG_COMPOUND);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user