use of com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour 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.TransportedItemStackHandlerBehaviour in project Create by Creators-of-Create.
the class BeltDeployerCallbacks method activate.
public static void activate(TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler, DeployerTileEntity deployerTileEntity, Recipe<?> recipe) {
List<TransportedItemStack> collect = InWorldProcessing.applyRecipeOn(ItemHandlerHelper.copyStackWithSize(transported.stack, 1), recipe).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;
}).map(t -> {
t.locked = false;
return t;
}).collect(Collectors.toList());
TransportedItemStack left = transported.copy();
deployerTileEntity.player.spawnedItemEffects = transported.stack.copy();
left.stack.shrink(1);
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(left));
else
handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(collect, left));
ItemStack heldItem = deployerTileEntity.player.getMainHandItem();
boolean unbreakable = heldItem.hasTag() && heldItem.getTag().getBoolean("Unbreakable");
boolean keepHeld = recipe instanceof DeployerApplicationRecipe && ((DeployerApplicationRecipe) recipe).shouldKeepHeldItem();
if (!unbreakable && !keepHeld) {
if (heldItem.isDamageableItem())
heldItem.hurtAndBreak(1, deployerTileEntity.player, s -> s.broadcastBreakEvent(InteractionHand.MAIN_HAND));
else
heldItem.shrink(1);
}
BlockPos pos = deployerTileEntity.getBlockPos();
Level world = deployerTileEntity.getLevel();
if (heldItem.isEmpty())
world.playSound(null, pos, SoundEvents.ITEM_BREAK, SoundSource.BLOCKS, .25f, 1);
world.playSound(null, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, .25f, .75f);
if (recipe instanceof SandPaperPolishingRecipe)
AllSoundEvents.SANDING_SHORT.playOnServer(world, pos, .35f, 1f);
deployerTileEntity.sendData();
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour in project Create by Creators-of-Create.
the class BeltTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
super.addBehaviours(behaviours);
behaviours.add(new DirectBeltInputBehaviour(this).onlyInsertWhen(this::canInsertFrom).setInsertionHandler(this::tryInsertingFromSide));
behaviours.add(new TransportedItemStackHandlerBehaviour(this, this::applyToAllItems).withStackPlacement(this::getWorldPositionOf));
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour in project Create by Creators-of-Create.
the class ChuteTileEntity method updateAirFlow.
private void updateAirFlow(float itemSpeed) {
updateAirFlow = false;
// airCurrent.rebuild();
if (itemSpeed > 0 && level != null && !level.isClientSide) {
float speed = pull - push;
beltBelow = null;
float maxPullDistance;
if (speed >= 128)
maxPullDistance = 3;
else if (speed >= 64)
maxPullDistance = 2;
else if (speed >= 32)
maxPullDistance = 1;
else
maxPullDistance = Mth.lerp(speed / 32, 0, 1);
if (AbstractChuteBlock.isChute(level.getBlockState(worldPosition.below())))
maxPullDistance = 0;
float flowLimit = maxPullDistance;
if (flowLimit > 0)
flowLimit = AirCurrent.getFlowLimit(level, worldPosition, maxPullDistance, Direction.DOWN);
for (int i = 1; i <= flowLimit + 1; i++) {
TransportedItemStackHandlerBehaviour behaviour = TileEntityBehaviour.get(level, worldPosition.below(i), TransportedItemStackHandlerBehaviour.TYPE);
if (behaviour == null)
continue;
beltBelow = behaviour;
beltBelowOffset = i - 1;
break;
}
this.bottomPullDistance = Math.max(0, flowLimit);
}
sendData();
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour 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