use of com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour in project Create by Creators-of-Create.
the class BasinTileEntity method acceptOutputsInner.
private boolean acceptOutputsInner(List<ItemStack> outputItems, List<FluidStack> outputFluids, boolean simulate) {
BlockState blockState = getBlockState();
if (!(blockState.getBlock() instanceof BasinBlock))
return false;
Direction direction = blockState.getValue(BasinBlock.FACING);
if (direction != Direction.DOWN) {
BlockEntity te = level.getBlockEntity(worldPosition.below().relative(direction));
InvManipulationBehaviour inserter = te == null ? null : TileEntityBehaviour.get(level, te.getBlockPos(), InvManipulationBehaviour.TYPE);
IItemHandler targetInv = te == null ? null : te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(inserter == null ? null : inserter.getInventory());
IFluidHandler targetTank = te == null ? null : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
boolean externalTankNotPresent = targetTank == null;
if (!outputItems.isEmpty() && targetInv == null)
return false;
if (!outputFluids.isEmpty() && externalTankNotPresent) {
// Special case - fluid outputs but output only accepts items
targetTank = outputTank.getCapability().orElse(null);
if (targetTank == null)
return false;
if (!acceptFluidOutputsIntoBasin(outputFluids, simulate, targetTank))
return false;
}
if (simulate)
return true;
for (ItemStack itemStack : outputItems) {
if (itemStack.hasContainerItem() && itemStack.getContainerItem().sameItem(itemStack))
continue;
spoutputBuffer.add(itemStack.copy());
}
if (!externalTankNotPresent)
for (FluidStack fluidStack : outputFluids) spoutputFluidBuffer.add(fluidStack.copy());
return true;
}
IItemHandler targetInv = outputInventory;
IFluidHandler targetTank = outputTank.getCapability().orElse(null);
if (targetInv == null && !outputItems.isEmpty())
return false;
if (!acceptItemOutputsIntoBasin(outputItems, simulate, targetInv))
return false;
if (outputFluids.isEmpty())
return true;
if (targetTank == null)
return false;
if (!acceptFluidOutputsIntoBasin(outputFluids, simulate, targetTank))
return false;
return true;
}
use of com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour in project Create by Creators-of-Create.
the class BasinTileEntity method tryClearingSpoutputOverflow.
private void tryClearingSpoutputOverflow() {
BlockState blockState = getBlockState();
if (!(blockState.getBlock() instanceof BasinBlock))
return;
Direction direction = blockState.getValue(BasinBlock.FACING);
BlockEntity te = level.getBlockEntity(worldPosition.below().relative(direction));
FilteringBehaviour filter = null;
InvManipulationBehaviour inserter = null;
if (te != null) {
filter = TileEntityBehaviour.get(level, te.getBlockPos(), FilteringBehaviour.TYPE);
inserter = TileEntityBehaviour.get(level, te.getBlockPos(), InvManipulationBehaviour.TYPE);
}
IItemHandler targetInv = te == null ? null : te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(inserter == null ? null : inserter.getInventory());
IFluidHandler targetTank = te == null ? null : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
boolean update = false;
for (Iterator<ItemStack> iterator = spoutputBuffer.iterator(); iterator.hasNext(); ) {
ItemStack itemStack = iterator.next();
if (direction == Direction.DOWN) {
Block.popResource(level, worldPosition, itemStack);
iterator.remove();
update = true;
continue;
}
if (targetInv == null)
break;
if (!ItemHandlerHelper.insertItemStacked(targetInv, itemStack, true).isEmpty())
continue;
if (filter != null && !filter.test(itemStack))
continue;
update = true;
ItemHandlerHelper.insertItemStacked(targetInv, itemStack.copy(), false);
iterator.remove();
visualizedOutputItems.add(IntAttached.withZero(itemStack));
}
for (Iterator<FluidStack> iterator = spoutputFluidBuffer.iterator(); iterator.hasNext(); ) {
FluidStack fluidStack = iterator.next();
if (direction == Direction.DOWN) {
iterator.remove();
update = true;
continue;
}
if (targetTank == null)
break;
for (boolean simulate : Iterate.trueAndFalse) {
FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE;
int fill = targetTank instanceof SmartFluidTankBehaviour.InternalFluidHandler ? ((SmartFluidTankBehaviour.InternalFluidHandler) targetTank).forceFill(fluidStack.copy(), action) : targetTank.fill(fluidStack.copy(), action);
if (fill != fluidStack.getAmount())
break;
if (simulate)
continue;
update = true;
iterator.remove();
visualizedOutputFluids.add(IntAttached.withZero(fluidStack));
}
}
if (update) {
notifyChangeOfContents();
sendData();
}
}
use of com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour in project Create by Creators-of-Create.
the class MechanicalCrafterTileEntity method blockChanged.
public void blockChanged() {
removeBehaviour(InvManipulationBehaviour.TYPE);
inserting = new InvManipulationBehaviour(this, this::getTargetFace);
attachBehaviourLate(inserting);
}
use of com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour in project Create by Creators-of-Create.
the class MechanicalCrafterTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
super.addBehaviours(behaviours);
inserting = new InvManipulationBehaviour(this, this::getTargetFace);
connectivity = new EdgeInteractionBehaviour(this, ConnectedInputHandler::toggleConnection).connectivity(ConnectedInputHandler::shouldConnect).require(AllItems.WRENCH.get());
behaviours.add(inserting);
behaviours.add(connectivity);
}
use of com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour 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;
}
Aggregations