use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.
the class BeltFunnelInteractionHandler method checkForFunnels.
public static boolean checkForFunnels(BeltInventory beltInventory, TransportedItemStack currentItem, float nextOffset) {
boolean beltMovementPositive = beltInventory.beltMovementPositive;
int firstUpcomingSegment = (int) Math.floor(currentItem.beltPosition);
int step = beltMovementPositive ? 1 : -1;
firstUpcomingSegment = Mth.clamp(firstUpcomingSegment, 0, beltInventory.belt.beltLength - 1);
for (int segment = firstUpcomingSegment; beltMovementPositive ? segment <= nextOffset : segment + 1 >= nextOffset; segment += step) {
BlockPos funnelPos = BeltHelper.getPositionForOffset(beltInventory.belt, segment).above();
Level world = beltInventory.belt.getLevel();
BlockState funnelState = world.getBlockState(funnelPos);
if (!(funnelState.getBlock() instanceof BeltFunnelBlock))
continue;
Direction funnelFacing = funnelState.getValue(BeltFunnelBlock.HORIZONTAL_FACING);
Direction movementFacing = beltInventory.belt.getMovementFacing();
boolean blocking = funnelFacing == movementFacing.getOpposite();
if (funnelFacing == movementFacing)
continue;
if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.PUSHING)
continue;
float funnelEntry = segment + .5f;
if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.EXTENDED)
funnelEntry += .499f * (beltMovementPositive ? -1 : 1);
boolean hasCrossed = nextOffset > funnelEntry && beltMovementPositive || nextOffset < funnelEntry && !beltMovementPositive;
if (!hasCrossed)
return false;
if (blocking)
currentItem.beltPosition = funnelEntry;
if (world.isClientSide || funnelState.getOptionalValue(BeltFunnelBlock.POWERED).orElse(false))
if (blocking)
return true;
else
continue;
BlockEntity te = world.getBlockEntity(funnelPos);
if (!(te instanceof FunnelTileEntity))
return true;
FunnelTileEntity funnelTE = (FunnelTileEntity) te;
InvManipulationBehaviour inserting = funnelTE.getBehaviour(InvManipulationBehaviour.TYPE);
FilteringBehaviour filtering = funnelTE.getBehaviour(FilteringBehaviour.TYPE);
if (inserting == null || filtering != null && !filtering.test(currentItem.stack))
if (blocking)
return true;
else
continue;
int amountToExtract = funnelTE.getAmountToExtract();
ItemStack toInsert = currentItem.stack.copy();
if (amountToExtract > toInsert.getCount())
if (blocking)
return true;
else
continue;
if (amountToExtract != -1) {
toInsert.setCount(amountToExtract);
ItemStack remainder = inserting.simulate().insert(toInsert);
if (!remainder.isEmpty())
if (blocking)
return true;
else
continue;
}
ItemStack remainder = inserting.insert(toInsert);
if (toInsert.equals(remainder, false))
if (blocking)
return true;
else
continue;
int notFilled = currentItem.stack.getCount() - toInsert.getCount();
if (!remainder.isEmpty()) {
remainder.grow(notFilled);
} else if (notFilled > 0)
remainder = ItemHandlerHelper.copyStackWithSize(currentItem.stack, notFilled);
funnelTE.flap(true);
funnelTE.onTransfer(toInsert);
currentItem.stack = remainder;
beltInventory.belt.sendData();
if (blocking)
return true;
}
return false;
}
use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.
the class DeployerTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
super.addBehaviours(behaviours);
filtering = new FilteringBehaviour(this, new DeployerFilterSlot());
behaviours.add(filtering);
processingBehaviour = new BeltProcessingBehaviour(this).whenItemEnters((s, i) -> BeltDeployerCallbacks.onItemReceived(s, i, this)).whileItemHeld((s, i) -> BeltDeployerCallbacks.whenItemHeld(s, i, this));
behaviours.add(processingBehaviour);
}
use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.
the class BasinTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
behaviours.add(new DirectBeltInputBehaviour(this));
filtering = new FilteringBehaviour(this, new BasinValueBox()).moveText(new Vec3(2, -8, 0)).withCallback(newFilter -> contentsChanged = true).forRecipes();
behaviours.add(filtering);
inputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.INPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true);
outputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.OUTPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true).forbidInsertion();
behaviours.add(inputTank);
behaviours.add(outputTank);
fluidCapability = LazyOptional.of(() -> {
LazyOptional<? extends IFluidHandler> inputCap = inputTank.getCapability();
LazyOptional<? extends IFluidHandler> outputCap = outputTank.getCapability();
return new CombinedTankWrapper(inputCap.orElse(null), outputCap.orElse(null));
});
}
use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.
the class StockpileSwitchTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
filtering = new FilteringBehaviour(this, new FilteredDetectorFilterSlot()).moveText(new Vec3(0, 5, 0)).withCallback($ -> updateCurrentLevel());
behaviours.add(filtering);
InterfaceProvider towardBlockFacing = InterfaceProvider.towardBlockFacing();
behaviours.add(observedInventory = new InvManipulationBehaviour(this, towardBlockFacing).bypassSidedness());
behaviours.add(observedTank = new TankManipulationBehaviour(this, towardBlockFacing).bypassSidedness());
}
use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.
the class FunnelTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
invManipulation = new InvManipulationBehaviour(this, (w, p, s) -> new BlockFace(p, AbstractFunnelBlock.getFunnelFacing(s).getOpposite()));
behaviours.add(invManipulation);
filtering = new FilteringBehaviour(this, new FunnelFilterSlotPositioning());
filtering.showCountWhen(this::supportsAmountOnFilter);
filtering.onlyActiveWhen(this::supportsFiltering);
behaviours.add(filtering);
behaviours.add(new DirectBeltInputBehaviour(this).onlyInsertWhen(this::supportsDirectBeltInput).setInsertionHandler(this::handleDirectBeltInput));
}
Aggregations