Added Fluid Tank comparator support, fixed Gas Tank comparator support

This commit is contained in:
aidancbrady 2016-06-30 12:45:15 -04:00
parent 3b214376ba
commit 41ea222aab
3 changed files with 46 additions and 0 deletions

View file

@ -802,6 +802,25 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IBlo
return world.setBlockToAir(x, y, z); return world.setBlockToAir(x, y, z);
} }
@Override
public boolean hasComparatorInputOverride()
{
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(tileEntity instanceof TileEntityFluidTank)
{
return ((TileEntityFluidTank)tileEntity).getRedstoneLevel();
}
return 0;
}
private boolean manageInventory(EntityPlayer player, TileEntityFluidTank tileEntity) private boolean manageInventory(EntityPlayer player, TileEntityFluidTank tileEntity)
{ {
ItemStack itemStack = player.getCurrentEquippedItem(); ItemStack itemStack = player.getCurrentEquippedItem();

View file

@ -27,6 +27,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry;
@ -60,6 +61,8 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
public boolean needsPacket; public boolean needsPacket;
public int currentRedstoneLevel;
public TileComponentSecurity securityComponent = new TileComponentSecurity(this); public TileComponentSecurity securityComponent = new TileComponentSecurity(this);
public TileEntityFluidTank() public TileEntityFluidTank()
@ -139,6 +142,14 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
activeEmit(); activeEmit();
} }
int newRedstoneLevel = getRedstoneLevel();
if(newRedstoneLevel != currentRedstoneLevel)
{
markDirty();
currentRedstoneLevel = newRedstoneLevel;
}
if(needsPacket) if(needsPacket)
{ {
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50)); Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50));
@ -353,6 +364,12 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
} }
} }
public int getRedstoneLevel()
{
double fractionFull = (float)fluidTank.getFluidAmount()/(float)fluidTank.getCapacity();
return MathHelper.floor_float((float)(fractionFull * 14.0F)) + (fractionFull > 0 ? 1 : 0);
}
public int getCurrentNeeded() public int getCurrentNeeded()
{ {
int needed = fluidTank.getCapacity()-fluidTank.getFluidAmount(); int needed = fluidTank.getCapacity()-fluidTank.getFluidAmount();

View file

@ -53,6 +53,8 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
public int currentGasAmount; public int currentGasAmount;
public int currentRedstoneLevel;
/** This machine's current RedstoneControl type. */ /** This machine's current RedstoneControl type. */
public RedstoneControl controlType; public RedstoneControl controlType;
@ -127,6 +129,14 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
} }
currentGasAmount = newGasAmount; currentGasAmount = newGasAmount;
int newRedstoneLevel = getRedstoneLevel();
if(newRedstoneLevel != currentRedstoneLevel)
{
markDirty();
currentRedstoneLevel = newRedstoneLevel;
}
} }
} }