Generators now sustain fluid and gas data

This commit is contained in:
Aidan C. Brady 2014-07-26 19:10:17 -04:00
parent ab34edc46a
commit 3abd80f1a2
5 changed files with 64 additions and 7 deletions

View file

@ -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))
{

View file

@ -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)
{

View file

@ -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"));
}
}

View file

@ -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")));
}
}

View file

@ -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")));
}
}