Implemented new container edit modes in Portable Tank and Dynamic Tank, still need to set up IFluidContainerItem integration with the Dynamic Tank

This commit is contained in:
Aidan C. Brady 2014-07-10 18:08:53 -04:00
parent 12f3ef8665
commit fc878661d5
3 changed files with 63 additions and 7 deletions

View file

@ -15,6 +15,7 @@ import mekanism.common.tank.SynchronizedTankData;
import mekanism.common.tank.SynchronizedTankData.ValveData;
import mekanism.common.tank.TankUpdateProtocol;
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -23,6 +24,7 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -202,7 +204,18 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
if(structure.inventory[0] != null)
{
if(FluidContainerRegistry.isEmptyContainer(structure.inventory[0]))
if(structure.inventory[0].getItem() instanceof IFluidContainerItem)
{
if(structure.editMode == ContainerEditMode.FILL)
{
//TODO
}
else if(structure.editMode == ContainerEditMode.EMPTY)
{
//TODO
}
}
else if(FluidContainerRegistry.isEmptyContainer(structure.inventory[0]) && (structure.editMode == ContainerEditMode.BOTH || structure.editMode == ContainerEditMode.FILL))
{
if(structure.fluidStored != null && structure.fluidStored.amount >= FluidContainerRegistry.BUCKET_VOLUME)
{
@ -241,7 +254,7 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
}
}
}
else if(FluidContainerRegistry.isFilledContainer(structure.inventory[0]))
else if(FluidContainerRegistry.isFilledContainer(structure.inventory[0]) && (structure.editMode == ContainerEditMode.BOTH || structure.editMode == ContainerEditMode.EMPTY))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(structure.inventory[0]);
@ -270,7 +283,6 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
structure.inventory[1].stackSize++;
}
markDirty();
filled = true;
}
}
@ -294,6 +306,8 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
else {
structure.fluidStored.amount += itemFluid.amount;
}
markDirty();
}
Mekanism.packetHandler.sendToAll(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())));

View file

@ -13,6 +13,7 @@ import mekanism.common.ISustainedTank;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer;
@ -26,6 +27,7 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler;
public class TileEntityPortableTank extends TileEntityContainerBlock implements IActiveState, IConfigurable, IFluidHandler, ISustainedTank, IFluidContainerManager
@ -151,7 +153,42 @@ public class TileEntityPortableTank extends TileEntityContainerBlock implements
{
if(inventory[0] != null)
{
if(FluidContainerRegistry.isEmptyContainer(inventory[0]))
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
if(editMode == ContainerEditMode.FILL)
{
int prev = fluidTank.getFluidAmount();
fluidTank.drain(FluidContainerUtils.insertFluid(fluidTank, inventory[0]), true);
if(prev == fluidTank.getFluidAmount() || fluidTank.getFluidAmount() == 0)
{
if(inventory[1] == null)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
}
}
}
else if(editMode == ContainerEditMode.EMPTY)
{
fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);
if(((IFluidContainerItem)inventory[0].getItem()).getFluid(inventory[0]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
{
if(inventory[1] == null)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
}
}
}
}
else if(FluidContainerRegistry.isEmptyContainer(inventory[0]) && (editMode == ContainerEditMode.BOTH || editMode == ContainerEditMode.FILL))
{
if(fluidTank.getFluid() != null && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME)
{
@ -181,7 +218,7 @@ public class TileEntityPortableTank extends TileEntityContainerBlock implements
}
}
}
else if(FluidContainerRegistry.isFilledContainer(inventory[0]))
else if(FluidContainerRegistry.isFilledContainer(inventory[0]) && (editMode == ContainerEditMode.BOTH || editMode == ContainerEditMode.EMPTY))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
int needed = getCurrentNeeded();

View file

@ -10,14 +10,19 @@ public final class FluidContainerUtils
{
public static FluidStack extractFluid(FluidTank tileTank, ItemStack container)
{
return extractFluid(tileTank, container, null);
return extractFluid(tileTank, container, tileTank.getFluid() != null ? tileTank.getFluid().getFluid() : null);
}
public static FluidStack extractFluid(FluidTank tileTank, ItemStack container, Fluid fluid)
{
IFluidContainerItem item = (IFluidContainerItem)container.getItem();
if(fluid != null && item.getFluid(container) != null && item.getFluid(container).getFluid() != fluid)
if(item.getFluid(container) == null)
{
return null;
}
if(fluid != null && item.getFluid(container).getFluid() != fluid)
{
return null;
}