use of com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult in project Create by Creators-of-Create.
the class BeltPressingCallbacks method whenItemHeld.
static ProcessingResult whenItemHeld(TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler, MechanicalPressTileEntity pressTe) {
if (pressTe.getSpeed() == 0)
return PASS;
if (!pressTe.running)
return PASS;
if (pressTe.runningTicks != MechanicalPressTileEntity.CYCLE / 2)
return HOLD;
Optional<PressingRecipe> recipe = pressTe.getRecipe(transported.stack);
pressTe.pressedItems.clear();
pressTe.pressedItems.add(transported.stack);
if (!recipe.isPresent())
return PASS;
boolean bulk = MechanicalPressTileEntity.canProcessInBulk() || transported.stack.getCount() == 1;
List<TransportedItemStack> collect = InWorldProcessing.applyRecipeOn(bulk ? transported.stack : ItemHandlerHelper.copyStackWithSize(transported.stack, 1), recipe.get()).stream().map(stack -> {
TransportedItemStack copy = transported.copy();
boolean centered = BeltHelper.isItemUpright(stack);
copy.stack = stack;
copy.locked = true;
copy.angle = centered ? 180 : Create.RANDOM.nextInt(360);
return copy;
}).collect(Collectors.toList());
if (bulk) {
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.removeItem());
else
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(collect));
} else {
TransportedItemStack left = transported.copy();
left.stack.shrink(1);
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(left));
else
handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(collect, left));
}
AllTriggers.triggerForNearbyPlayers(AllTriggers.BONK, pressTe.getLevel(), pressTe.getBlockPos(), 4);
pressTe.sendData();
return HOLD;
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult in project Create by Creators-of-Create.
the class DepotBehaviour method tick.
@Override
public void tick() {
super.tick();
Level world = tileEntity.getLevel();
for (Iterator<TransportedItemStack> iterator = incoming.iterator(); iterator.hasNext(); ) {
TransportedItemStack ts = iterator.next();
if (!tick(ts))
continue;
if (world.isClientSide && !tileEntity.isVirtual())
continue;
if (heldItem == null) {
heldItem = ts;
} else {
if (!ItemHelper.canItemStackAmountsStack(heldItem.stack, ts.stack)) {
Vec3 vec = VecHelper.getCenterOf(tileEntity.getBlockPos());
Containers.dropItemStack(tileEntity.getLevel(), vec.x, vec.y + .5f, vec.z, ts.stack);
} else {
heldItem.stack.grow(ts.stack.getCount());
}
}
iterator.remove();
tileEntity.notifyUpdate();
}
if (heldItem == null)
return;
if (!tick(heldItem))
return;
BlockPos pos = tileEntity.getBlockPos();
if (world.isClientSide)
return;
if (handleBeltFunnelOutput())
return;
BeltProcessingBehaviour processingBehaviour = TileEntityBehaviour.get(world, pos.above(2), BeltProcessingBehaviour.TYPE);
if (processingBehaviour == null)
return;
if (!heldItem.locked && BeltProcessingBehaviour.isBlocked(world, pos))
return;
ItemStack previousItem = heldItem.stack;
boolean wasLocked = heldItem.locked;
ProcessingResult result = wasLocked ? processingBehaviour.handleHeldItem(heldItem, transportedHandler) : processingBehaviour.handleReceivedItem(heldItem, transportedHandler);
if (result == ProcessingResult.REMOVE) {
heldItem = null;
tileEntity.sendData();
return;
}
heldItem.locked = result == ProcessingResult.HOLD;
if (heldItem.locked != wasLocked || !previousItem.equals(heldItem.stack, false))
tileEntity.sendData();
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult in project Create by Creators-of-Create.
the class BeltInventory method handleBeltProcessingAndCheckIfRemoved.
protected boolean handleBeltProcessingAndCheckIfRemoved(TransportedItemStack currentItem, float nextOffset, boolean noMovement) {
int currentSegment = (int) currentItem.beltPosition;
// Continue processing if held
if (currentItem.locked) {
BeltProcessingBehaviour processingBehaviour = getBeltProcessingAtSegment(currentSegment);
TransportedItemStackHandlerBehaviour stackHandlerBehaviour = getTransportedItemStackHandlerAtSegment(currentSegment);
if (stackHandlerBehaviour == null)
return false;
if (processingBehaviour == null) {
currentItem.locked = false;
belt.sendData();
return false;
}
ProcessingResult result = processingBehaviour.handleHeldItem(currentItem, stackHandlerBehaviour);
if (result == ProcessingResult.REMOVE)
return true;
if (result == ProcessingResult.HOLD)
return false;
currentItem.locked = false;
belt.sendData();
return false;
}
if (noMovement)
return false;
// See if any new belt processing catches the item
if (currentItem.beltPosition > .5f || beltMovementPositive) {
int firstUpcomingSegment = (int) (currentItem.beltPosition + (beltMovementPositive ? .5f : -.5f));
int step = beltMovementPositive ? 1 : -1;
for (int segment = firstUpcomingSegment; beltMovementPositive ? segment + .5f <= nextOffset : segment + .5f >= nextOffset; segment += step) {
BeltProcessingBehaviour processingBehaviour = getBeltProcessingAtSegment(segment);
TransportedItemStackHandlerBehaviour stackHandlerBehaviour = getTransportedItemStackHandlerAtSegment(segment);
if (processingBehaviour == null)
continue;
if (stackHandlerBehaviour == null)
continue;
if (BeltProcessingBehaviour.isBlocked(belt.getLevel(), BeltHelper.getPositionForOffset(belt, segment)))
continue;
ProcessingResult result = processingBehaviour.handleReceivedItem(currentItem, stackHandlerBehaviour);
if (result == ProcessingResult.REMOVE)
return true;
if (result == ProcessingResult.HOLD) {
currentItem.beltPosition = segment + .5f + (beltMovementPositive ? 1 / 512f : -1 / 512f);
currentItem.locked = true;
belt.sendData();
return false;
}
}
}
return false;
}
Aggregations