Search in sources :

Example 1 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project createaddition by mrh0.

the class TeslaCoilTileEntity method chargeAE2.

protected boolean chargeAE2(ItemStack stack, TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler) {
    if (!CreateAddition.AE2_ACTIVE)
        return false;
    if (!AE2.isCertusQuartz(stack))
        return false;
    int energyRemoved = energy.internalConsumeEnergy(getConsumption());
    if (energyRemoved >= getConsumption() && level.random.nextFloat() > CERTUS_QUARTZ_CHANCE) {
        TransportedItemStack left = transported.copy();
        left.stack.shrink(1);
        List<TransportedItemStack> r = new ArrayList<>();
        r.add(new TransportedItemStack(AE2.getChargedCertusQuartz(1)));
        // .ifPresent(is -> r.add(new TransportedItemStack(is)));
        handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(r, left));
    }
    return true;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ArrayList(java.util.ArrayList)

Example 2 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class ItemDrainTileEntity method tryInsertingFromSide.

private ItemStack tryInsertingFromSide(TransportedItemStack transportedStack, Direction side, boolean simulate) {
    ItemStack inserted = transportedStack.stack;
    ItemStack returned = ItemStack.EMPTY;
    if (!getHeldItemStack().isEmpty())
        return inserted;
    if (inserted.getCount() > 1 && EmptyingByBasin.canItemBeEmptied(level, inserted)) {
        returned = ItemHandlerHelper.copyStackWithSize(inserted, inserted.getCount() - 1);
        inserted = ItemHandlerHelper.copyStackWithSize(inserted, 1);
    }
    if (simulate)
        return returned;
    transportedStack = transportedStack.copy();
    transportedStack.beltPosition = side.getAxis().isVertical() ? .5f : 0;
    transportedStack.prevSideOffset = transportedStack.sideOffset;
    transportedStack.prevBeltPosition = transportedStack.beltPosition;
    setHeldItem(transportedStack, side);
    setChanged();
    sendData();
    return returned;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack 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 4 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class BeltDeployerCallbacks method whenItemHeld.

public static ProcessingResult whenItemHeld(TransportedItemStack s, TransportedItemStackHandlerBehaviour i, DeployerTileEntity deployerTileEntity) {
    if (deployerTileEntity.getSpeed() == 0)
        return ProcessingResult.PASS;
    BlockState blockState = deployerTileEntity.getBlockState();
    if (!blockState.hasProperty(FACING) || blockState.getValue(FACING) != Direction.DOWN)
        return ProcessingResult.PASS;
    DeployerFakePlayer player = deployerTileEntity.getPlayer();
    ItemStack held = player == null ? ItemStack.EMPTY : player.getMainHandItem();
    if (held.isEmpty())
        return ProcessingResult.HOLD;
    Recipe<?> recipe = deployerTileEntity.getRecipe(s.stack);
    if (recipe == null)
        return ProcessingResult.PASS;
    if (deployerTileEntity.state == State.RETRACTING && deployerTileEntity.timer == 1000) {
        activate(s, i, deployerTileEntity, recipe);
        return ProcessingResult.HOLD;
    }
    if (deployerTileEntity.state == State.WAITING) {
        if (deployerTileEntity.redstoneLocked)
            return ProcessingResult.PASS;
        deployerTileEntity.start();
    }
    return ProcessingResult.HOLD;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack 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)

Aggregations

TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)26 ItemStack (net.minecraft.world.item.ItemStack)20 BlockState (net.minecraft.world.level.block.state.BlockState)8 Vec3 (net.minecraft.world.phys.Vec3)8 BlockPos (net.minecraft.core.BlockPos)6 Direction (net.minecraft.core.Direction)6 BeltInventory (com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory)3 ProcessingResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult)3 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)3 TransportedResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 Entity (net.minecraft.world.entity.Entity)3 ItemEntity (net.minecraft.world.entity.item.ItemEntity)3 Level (net.minecraft.world.level.Level)3 TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)2 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 List (java.util.List)2