diff --git a/src/main/java/mekanism/generators/common/block/BlockGenerator.java b/src/main/java/mekanism/generators/common/block/BlockGenerator.java index cc31bc86d..0f94d9688 100644 --- a/src/main/java/mekanism/generators/common/block/BlockGenerator.java +++ b/src/main/java/mekanism/generators/common/block/BlockGenerator.java @@ -7,6 +7,7 @@ import mekanism.api.energy.IEnergizedItem; import mekanism.common.IActiveState; import mekanism.common.IBoundingBlock; import mekanism.common.ISpecialBounds; +import mekanism.common.ISustainedData; import mekanism.common.ISustainedInventory; import mekanism.common.ISustainedTank; import mekanism.common.ItemAttacher; @@ -18,8 +19,8 @@ import mekanism.generators.client.GeneratorsClientProxy; import mekanism.generators.common.MekanismGenerators; import mekanism.generators.common.tile.TileEntityAdvancedSolarGenerator; import mekanism.generators.common.tile.TileEntityBioGenerator; -import mekanism.generators.common.tile.TileEntityHeatGenerator; import mekanism.generators.common.tile.TileEntityGasGenerator; +import mekanism.generators.common.tile.TileEntityHeatGenerator; import mekanism.generators.common.tile.TileEntitySolarGenerator; import mekanism.generators.common.tile.TileEntityWindTurbine; import net.minecraft.block.Block; @@ -39,7 +40,6 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.tools.IToolWrench; - import cpw.mods.fml.common.ModAPIManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -459,6 +459,11 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds ISustainedInventory inventory = (ISustainedInventory)itemStack.getItem(); inventory.setInventory(((ISustainedInventory)tileEntity).getInventory(), itemStack); + + if(tileEntity instanceof ISustainedData) + { + ((ISustainedData)tileEntity).writeSustainedData(itemStack); + } if(((ISustainedTank)itemStack.getItem()).hasTank(itemStack)) { diff --git a/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java b/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java index 33e373e8f..83b05f678 100644 --- a/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java +++ b/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java @@ -8,6 +8,7 @@ import java.util.List; import mekanism.api.EnumColor; import mekanism.api.energy.IEnergizedItem; import mekanism.client.MekanismKeyHandler; +import mekanism.common.ISustainedData; import mekanism.common.ISustainedInventory; import mekanism.common.ISustainedTank; import mekanism.common.Mekanism; @@ -31,7 +32,6 @@ import net.minecraftforge.fluids.FluidStack; import org.lwjgl.input.Keyboard; import cofh.api.energy.IEnergyContainerItem; - import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.InterfaceList; import cpw.mods.fml.common.Optional.Method; @@ -169,6 +169,14 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp tileEntity.electricityStored = getEnergy(stack); ((ISustainedInventory)tileEntity).setInventory(getInventory(stack)); + + if(tileEntity instanceof ISustainedData) + { + if(stack.stackTagCompound != null) + { + ((ISustainedData)tileEntity).readSustainedData(stack); + } + } if(tileEntity instanceof ISustainedTank) { diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java index 916fab482..33170f7a6 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java @@ -7,6 +7,7 @@ import java.util.EnumSet; import mekanism.client.sound.TileSound; import mekanism.common.FluidSlot; +import mekanism.common.ISustainedData; import mekanism.common.Mekanism; import mekanism.common.util.ChargeUtils; import mekanism.common.util.MekanismUtils; @@ -26,7 +27,7 @@ import cpw.mods.fml.relauncher.SideOnly; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.peripheral.IComputerAccess; -public class TileEntityBioGenerator extends TileEntityGenerator implements IFluidHandler +public class TileEntityBioGenerator extends TileEntityGenerator implements IFluidHandler, ISustainedData { /** The Sound instance for this machine. */ @SideOnly(Side.CLIENT) @@ -317,4 +318,16 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui { return null; } + + @Override + public void writeSustainedData(ItemStack itemStack) + { + itemStack.stackTagCompound.setInteger("fluidStored", bioFuelSlot.fluidStored); + } + + @Override + public void readSustainedData(ItemStack itemStack) + { + bioFuelSlot.setFluid(itemStack.stackTagCompound.getInteger("fluidStored")); + } } \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java index e04492126..db53d2050 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java @@ -14,6 +14,7 @@ import mekanism.api.gas.GasTransmission; import mekanism.api.gas.IGasHandler; import mekanism.api.gas.IGasItem; import mekanism.api.gas.ITubeConnection; +import mekanism.common.ISustainedData; import mekanism.common.Mekanism; import mekanism.common.util.ChargeUtils; import mekanism.common.util.MekanismUtils; @@ -21,11 +22,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional.Method; - import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.peripheral.IComputerAccess; -public class TileEntityGasGenerator extends TileEntityGenerator implements IGasHandler, ITubeConnection +public class TileEntityGasGenerator extends TileEntityGenerator implements IGasHandler, ITubeConnection, ISustainedData { /** The maximum amount of gas this block can store. */ public int MAX_GAS = 18000; @@ -277,4 +277,19 @@ public class TileEntityGasGenerator extends TileEntityGenerator implements IGasH { return side != ForgeDirection.getOrientation(facing); } + + @Override + public void writeSustainedData(ItemStack itemStack) + { + if(fuelTank.getGas() != null) + { + itemStack.stackTagCompound.setTag("fuelTank", fuelTank.write(new NBTTagCompound())); + } + } + + @Override + public void readSustainedData(ItemStack itemStack) + { + fuelTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("fuelTank"))); + } } diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java index 92af05136..84216e171 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; +import mekanism.common.ISustainedData; import mekanism.common.Mekanism; import mekanism.common.util.ChargeUtils; import mekanism.common.util.FluidContainerUtils; @@ -27,7 +28,7 @@ import cpw.mods.fml.common.Optional.Method; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.peripheral.IComputerAccess; -public class TileEntityHeatGenerator extends TileEntityGenerator implements IFluidHandler +public class TileEntityHeatGenerator extends TileEntityGenerator implements IFluidHandler, ISustainedData { /** The FluidTank for this generator. */ public FluidTank lavaTank = new FluidTank(24000); @@ -335,4 +336,19 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu { return new FluidTankInfo[] {lavaTank.getInfo()}; } + + @Override + public void writeSustainedData(ItemStack itemStack) + { + if(lavaTank.getFluid() != null) + { + itemStack.stackTagCompound.setTag("lavaTank", lavaTank.getFluid().writeToNBT(new NBTTagCompound())); + } + } + + @Override + public void readSustainedData(ItemStack itemStack) + { + lavaTank.setFluid(FluidStack.loadFluidStackFromNBT(itemStack.stackTagCompound.getCompoundTag("lavaTank"))); + } }