Add comparator support to Energy Cubes
This commit is contained in:
parent
e6c630a125
commit
3e79a32806
2 changed files with 30 additions and 0 deletions
|
@ -314,4 +314,16 @@ public class BlockEnergyCube extends BlockContainer
|
|||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public boolean hasComparatorInputOverride()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
|
||||
{
|
||||
TileEntityEnergyCube tileEntity = (TileEntityEnergyCube)world.getBlockTileEntity(x, y, z);
|
||||
return tileEntity.getRedstoneLevel();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
|
@ -44,6 +45,8 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
/** This Energy Cube's tier. */
|
||||
public EnergyCubeTier tier = EnergyCubeTier.BASIC;
|
||||
|
||||
public int currentRedstoneLevel;
|
||||
|
||||
/**
|
||||
* A block used to store and transfer electricity.
|
||||
* @param energy - maximum energy this block can hold.
|
||||
|
@ -433,4 +436,19 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
{
|
||||
return side == ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy) {
|
||||
super.setEnergy(energy);
|
||||
int newRedstoneLevel = getRedstoneLevel();
|
||||
if (newRedstoneLevel != currentRedstoneLevel) {
|
||||
onInventoryChanged();
|
||||
currentRedstoneLevel = newRedstoneLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public int getRedstoneLevel() {
|
||||
double fractionFull = getEnergy()/getMaxEnergy();
|
||||
return MathHelper.floor_float((float) (fractionFull * 14.0F)) + (fractionFull > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue