From 41ea222aab2bbc947e6ac61c4812fe726596b166 Mon Sep 17 00:00:00 2001 From: aidancbrady Date: Thu, 30 Jun 2016 12:45:15 -0400 Subject: [PATCH] Added Fluid Tank comparator support, fixed Gas Tank comparator support --- .../mekanism/common/block/BlockMachine.java | 19 +++++++++++++++++++ .../common/tile/TileEntityFluidTank.java | 17 +++++++++++++++++ .../common/tile/TileEntityGasTank.java | 10 ++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index c8a1a05e2..d613fd447 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -802,6 +802,25 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IBlo 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) { ItemStack itemStack = player.getCurrentEquippedItem(); diff --git a/src/main/java/mekanism/common/tile/TileEntityFluidTank.java b/src/main/java/mekanism/common/tile/TileEntityFluidTank.java index ef7c1d18b..c4b79424e 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFluidTank.java +++ b/src/main/java/mekanism/common/tile/TileEntityFluidTank.java @@ -27,6 +27,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; @@ -60,6 +61,8 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc public boolean needsPacket; + public int currentRedstoneLevel; + public TileComponentSecurity securityComponent = new TileComponentSecurity(this); public TileEntityFluidTank() @@ -139,6 +142,14 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc activeEmit(); } + int newRedstoneLevel = getRedstoneLevel(); + + if(newRedstoneLevel != currentRedstoneLevel) + { + markDirty(); + currentRedstoneLevel = newRedstoneLevel; + } + if(needsPacket) { 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() { int needed = fluidTank.getCapacity()-fluidTank.getFluidAmount(); diff --git a/src/main/java/mekanism/common/tile/TileEntityGasTank.java b/src/main/java/mekanism/common/tile/TileEntityGasTank.java index c1c6a4e15..6e14b1494 100644 --- a/src/main/java/mekanism/common/tile/TileEntityGasTank.java +++ b/src/main/java/mekanism/common/tile/TileEntityGasTank.java @@ -52,6 +52,8 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH public GasMode dumping; public int currentGasAmount; + + public int currentRedstoneLevel; /** This machine's current RedstoneControl type. */ public RedstoneControl controlType; @@ -127,6 +129,14 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH } currentGasAmount = newGasAmount; + + int newRedstoneLevel = getRedstoneLevel(); + + if(newRedstoneLevel != currentRedstoneLevel) + { + markDirty(); + currentRedstoneLevel = newRedstoneLevel; + } } }