Search in sources :

Example 1 with TransportedItemStackHandlerBehaviour

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;
}
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 TransportedItemStackHandlerBehaviour

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();
}
Also used : SoundSource(net.minecraft.sounds.SoundSource) TransportedItemStackHandlerBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour) SandPaperPolishingRecipe(com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe) InWorldProcessing(com.simibubi.create.content.contraptions.processing.InWorldProcessing) Direction(net.minecraft.core.Direction) FACING(com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING) State(com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State) BlockState(net.minecraft.world.level.block.state.BlockState) BeltHelper(com.simibubi.create.content.contraptions.relays.belt.BeltHelper) Collectors(java.util.stream.Collectors) Mode(com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode) List(java.util.List) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Create(com.simibubi.create.Create) BlockPos(net.minecraft.core.BlockPos) Recipe(net.minecraft.world.item.crafting.Recipe) ProcessingResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) TransportedResult(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult) SoundEvents(net.minecraft.sounds.SoundEvents) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) AllSoundEvents(com.simibubi.create.AllSoundEvents) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) SandPaperPolishingRecipe(com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with TransportedItemStackHandlerBehaviour

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

Example 4 with TransportedItemStackHandlerBehaviour

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

Example 5 with TransportedItemStackHandlerBehaviour

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;
}
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

TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)8 TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)3 ProcessingResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult)3 BlockPos (net.minecraft.core.BlockPos)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 Create (com.simibubi.create.Create)2 InWorldProcessing (com.simibubi.create.content.contraptions.processing.InWorldProcessing)2 BeltHelper (com.simibubi.create.content.contraptions.relays.belt.BeltHelper)2 DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)2 TransportedResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Direction (net.minecraft.core.Direction)2 ItemStack (net.minecraft.world.item.ItemStack)2 Level (net.minecraft.world.level.Level)2 ItemHandlerHelper (net.minecraftforge.items.ItemHandlerHelper)2 AllSoundEvents (com.simibubi.create.AllSoundEvents)1 FACING (com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING)1 Mode (com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode)1 State (com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State)1