Search in sources :

Example 1 with ProcessingResult

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;
}
Also used : TransportedItemStackHandlerBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour) Mode(com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity.Mode) InWorldProcessing(com.simibubi.create.content.contraptions.processing.InWorldProcessing) HOLD(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult.HOLD) AllTriggers(com.simibubi.create.foundation.advancement.AllTriggers) BeltHelper(com.simibubi.create.content.contraptions.relays.belt.BeltHelper) PASS(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult.PASS) Collectors(java.util.stream.Collectors) List(java.util.List) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Create(com.simibubi.create.Create) ProcessingResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult) Optional(java.util.Optional) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) TransportedResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)

Example 2 with ProcessingResult

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();
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Vec3(net.minecraft.world.phys.Vec3) ProcessingResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) BeltProcessingBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with ProcessingResult

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;
}
Also used : ProcessingResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult) BeltProcessingBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour) TransportedItemStackHandlerBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)

Aggregations

ProcessingResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult)3 TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)2 BeltProcessingBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour)2 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)2 Create (com.simibubi.create.Create)1 Mode (com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity.Mode)1 InWorldProcessing (com.simibubi.create.content.contraptions.processing.InWorldProcessing)1 BeltHelper (com.simibubi.create.content.contraptions.relays.belt.BeltHelper)1 AllTriggers (com.simibubi.create.foundation.advancement.AllTriggers)1 HOLD (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult.HOLD)1 PASS (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult.PASS)1 TransportedResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 BlockPos (net.minecraft.core.BlockPos)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 Vec3 (net.minecraft.world.phys.Vec3)1 ItemHandlerHelper (net.minecraftforge.items.ItemHandlerHelper)1