Merge pull request #1860 from jmongeon/Comparator

Add comparator support to the GasTank
This commit is contained in:
Aidan 2014-09-27 10:22:59 -04:00
commit f72f462c63
2 changed files with 36 additions and 0 deletions

View file

@ -219,6 +219,19 @@ public class BlockGasTank extends BlockContainer
return itemStack; return itemStack;
} }
@Override
public boolean hasComparatorInputOverride()
{
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{
TileEntityGasTank tileEntity = (TileEntityGasTank)world.getTileEntity(x, y, z);
return tileEntity.getRedstoneLevel();
}
@Override @Override
public ForgeDirection[] getValidRotations(World world, int x, int y, int z) public ForgeDirection[] getValidRotations(World world, int x, int y, int z)
{ {

View file

@ -21,6 +21,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
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;
public class TileEntityGasTank extends TileEntityContainerBlock implements IGasHandler, ITubeConnection, IRedstoneControl public class TileEntityGasTank extends TileEntityContainerBlock implements IGasHandler, ITubeConnection, IRedstoneControl
@ -42,6 +43,8 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
public Mode dumping; public Mode dumping;
public int currentGasAmount;
/** This machine's current RedstoneControl type. */ /** This machine's current RedstoneControl type. */
public RedstoneControl controlType; public RedstoneControl controlType;
@ -90,6 +93,17 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
{ {
gasTank.draw(output, true); gasTank.draw(output, true);
} }
if(!worldObj.isRemote)
{
int newGasAmount = gasTank.getStored();
if(newGasAmount != this.currentGasAmount)
{
markDirty();
this.currentGasAmount = newGasAmount;
}
}
} }
@Override @Override
@ -265,6 +279,15 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
return true; return true;
} }
public int getRedstoneLevel()
{
int stored = gasTank.getStored();
if(stored == 0) return 0;
return MathHelper.floor_float((float)stored / (float)MAX_GAS * 14.0f + 1.0f);
}
@Override @Override
public RedstoneControl getControlType() public RedstoneControl getControlType()
{ {