Add RedstoneControl to Electric Pump.

This commit is contained in:
Ben Spiers 2014-12-15 17:28:57 +00:00
parent ee585c05dc
commit e14501f3b5
2 changed files with 38 additions and 4 deletions

View file

@ -39,6 +39,7 @@ public class GuiElectricPump extends GuiMekanism
return tileEntity.fluidTank; return tileEntity.fluidTank;
} }
}, GuiGauge.Type.STANDARD, this, guiLocation, 6, 13)); }, GuiGauge.Type.STANDARD, this, guiLocation, 6, 13));
guiElements.add(new GuiRedstoneControl(this, tileEntity, guiLocation));
} }

View file

@ -12,6 +12,7 @@ import mekanism.api.Coord4D;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.IConfigurable; import mekanism.api.IConfigurable;
import mekanism.common.ISustainedTank; import mekanism.common.ISustainedTank;
import mekanism.common.IRedstoneControl;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.util.ChargeUtils; import mekanism.common.util.ChargeUtils;
import mekanism.common.util.FluidContainerUtils; import mekanism.common.util.FluidContainerUtils;
@ -36,7 +37,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class TileEntityElectricPump extends TileEntityElectricBlock implements IFluidHandler, ISustainedTank, IConfigurable public class TileEntityElectricPump extends TileEntityElectricBlock implements IFluidHandler, ISustainedTank, IConfigurable, IRedstoneControl
{ {
/** This pump's tank */ /** This pump's tank */
public FluidTank fluidTank = new FluidTank(10000); public FluidTank fluidTank = new FluidTank(10000);
@ -44,6 +45,9 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
/** The nodes that have full sources near them or in them */ /** The nodes that have full sources near them or in them */
public Set<Coord4D> recurringNodes = new HashSet<Coord4D>(); public Set<Coord4D> recurringNodes = new HashSet<Coord4D>();
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
public TileEntityElectricPump() public TileEntityElectricPump()
{ {
super("ElectricPump", 10000); super("ElectricPump", 10000);
@ -118,11 +122,18 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
} }
} }
if(!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) if(!worldObj.isRemote && ticker % 20 == 0)
{ {
if(getEnergy() >= Mekanism.electricPumpUsage && (fluidTank.getFluid() == null || fluidTank.getFluid().amount+FluidContainerRegistry.BUCKET_VOLUME <= fluidTank.getCapacity())) if(MekanismUtils.canFunction(this))
{ {
suck(true); if(getEnergy() >= Mekanism.electricPumpUsage && (fluidTank.getFluid() == null || fluidTank.getFluid().amount + FluidContainerRegistry.BUCKET_VOLUME <= fluidTank.getCapacity()))
{
suck(true);
}
}
else
{
ticker--;
} }
} }
@ -237,6 +248,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
else { else {
fluidTank.setFluid(null); fluidTank.setFluid(null);
} }
controlType = RedstoneControl.values()[dataStream.readInt()];
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
} }
@ -255,6 +267,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
else { else {
data.add(0); data.add(0);
} }
data.add(controlType.ordinal());
return data; return data;
} }
@ -274,6 +287,8 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
nbtTags.setTag("fluidTank", fluidTank.writeToNBT(new NBTTagCompound())); nbtTags.setTag("fluidTank", fluidTank.writeToNBT(new NBTTagCompound()));
} }
nbtTags.setInteger("controlType", controlType.ordinal());
NBTTagList recurringList = new NBTTagList(); NBTTagList recurringList = new NBTTagList();
for(Coord4D wrapper : recurringNodes) for(Coord4D wrapper : recurringNodes)
@ -299,6 +314,11 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank")); fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank"));
} }
if(nbtTags.hasKey("controlType"))
{
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
}
if(nbtTags.hasKey("recurringNodes")) if(nbtTags.hasKey("recurringNodes"))
{ {
NBTTagList tagList = nbtTags.getTagList("recurringNodes", NBT.TAG_COMPOUND); NBTTagList tagList = nbtTags.getTagList("recurringNodes", NBT.TAG_COMPOUND);
@ -456,4 +476,17 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
{ {
return false; return false;
} }
@Override
public RedstoneControl getControlType()
{
return controlType;
}
@Override
public void setControlType(RedstoneControl type)
{
controlType = type;
MekanismUtils.saveChunk(this);
}
} }