diff --git a/src/main/java/com/elytradev/infraredstone/api/IEncoderScannable.java b/src/main/java/com/elytradev/infraredstone/api/IEncoderScannable.java index a9b4a06..aee5329 100644 --- a/src/main/java/com/elytradev/infraredstone/api/IEncoderScannable.java +++ b/src/main/java/com/elytradev/infraredstone/api/IEncoderScannable.java @@ -6,7 +6,8 @@ public interface IEncoderScannable { /** * @return a value from 0-63 depending on the state of your object. - * It may be helpful to format the value in binaru: `0b00_0000` + * See the Encoder Guidelines page on the InfraRedstone wiki for usage examples. + * It may be helpful to format the value in binary: `0b00_0000` */ int getComparatorValue(); } diff --git a/src/main/java/com/elytradev/infraredstone/api/ISimpleEncoderScannable.java b/src/main/java/com/elytradev/infraredstone/api/ISimpleEncoderScannable.java index 457e73c..e5eec51 100644 --- a/src/main/java/com/elytradev/infraredstone/api/ISimpleEncoderScannable.java +++ b/src/main/java/com/elytradev/infraredstone/api/ISimpleEncoderScannable.java @@ -17,7 +17,8 @@ public interface ISimpleEncoderScannable { * @param state the current blockstate of your object. * @param inspectingFrom the direction the infra-comparator is looking from. * @return a value from 0-63 depending on the state of your object and the given parameters. - * It may be helpful to format the value in binaru: `0b00_0000` + * See the Encoder Guidelines page on the InfraRedstone wiki for usage examples. + * It may be helpful to format the value in binary: `0b00_0000` */ int getComparatorValue(World world, BlockPos pos, IBlockState state, EnumFacing inspectingFrom); } diff --git a/src/main/java/com/elytradev/infraredstone/tile/TileEntityEncoder.java b/src/main/java/com/elytradev/infraredstone/tile/TileEntityEncoder.java index 83b2a35..3da7680 100644 --- a/src/main/java/com/elytradev/infraredstone/tile/TileEntityEncoder.java +++ b/src/main/java/com/elytradev/infraredstone/tile/TileEntityEncoder.java @@ -26,6 +26,11 @@ import net.minecraft.world.WorldServer; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -60,12 +65,27 @@ public void update() { // no encoder API, so check for a tile entity } else if (world.getTileEntity(backPos) != null) { TileEntity te = world.getTileEntity(backPos); - // check for a capability on the tile entity, make sure we only move on if we don't find one + // check for capabilities on the tile entity, make sure we only move on if we don't find any if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, back.getOpposite())) { IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, back); signal.setNextSignalValue(getInventoryCapacity(inv)); markDirty(); return; + } if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, back.getOpposite())) { + IFluidHandler fluid = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, back); + IFluidTankProperties[] props = fluid.getTankProperties(); + for (IFluidTankProperties prop : props) { + if (prop.getContents() == null) signal.setNextSignalValue(0b00_0000); + else signal.setNextSignalValue(((prop.getContents().amount/prop.getCapacity()) * 62) + 1); + } + markDirty(); + return; + } if (te.hasCapability(CapabilityEnergy.ENERGY, back.getOpposite())) { + IEnergyStorage energy = te.getCapability(CapabilityEnergy.ENERGY, back); + if (energy.getEnergyStored() == 0) signal.setNextSignalValue(0b00_0000); + else signal.setNextSignalValue(((energy.getEnergyStored()/energy.getMaxEnergyStored()) * 62) + 1); + markDirty(); + return; } // this if is the reason for all the markDirty(); return; garbage up above // check for a vanilla comparator interface @@ -76,7 +96,7 @@ public void update() { // redstone first so inred's redstone-catching doesn't override it int sigBack = world.getRedstonePower(backPos, back); if (sigBack != 0) { - signal.setNextSignalValue(4*sigBack); + signal.setNextSignalValue(sigBack); } else { signal.setNextSignalValue(InRedLogic.findIRValue(world, pos, back)); }