Skip to content

Commit

Permalink
add fluid/energy caps to scanning, change redstone signal function in…
Browse files Browse the repository at this point in the history
… encoder
  • Loading branch information
LemmaEOF committed Jul 30, 2018
1 parent a87e79d commit d430b98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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));
}
Expand Down

0 comments on commit d430b98

Please sign in to comment.