Search in sources :

Example 11 with TransportedItemStack

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

the class DepotBehaviour method insert.

public ItemStack insert(TransportedItemStack heldItem, boolean simulate) {
    if (!canAcceptItems.get())
        return heldItem.stack;
    if (canMergeItems()) {
        int remainingSpace = getRemainingSpace();
        ItemStack inserted = heldItem.stack;
        if (remainingSpace <= 0)
            return inserted;
        if (this.heldItem != null && !ItemHelper.canItemStackAmountsStack(this.heldItem.stack, inserted))
            return inserted;
        ItemStack returned = ItemStack.EMPTY;
        if (remainingSpace < inserted.getCount()) {
            returned = ItemHandlerHelper.copyStackWithSize(heldItem.stack, inserted.getCount() - remainingSpace);
            if (!simulate) {
                TransportedItemStack copy = heldItem.copy();
                copy.stack.setCount(remainingSpace);
                if (this.heldItem != null)
                    incoming.add(copy);
                else
                    this.heldItem = copy;
            }
        } else {
            if (!simulate) {
                if (this.heldItem != null)
                    incoming.add(heldItem);
                else
                    this.heldItem = heldItem;
            }
        }
        return returned;
    }
    if (!simulate) {
        if (this.isEmpty()) {
            if (heldItem.insertedFrom.getAxis().isHorizontal())
                AllSoundEvents.DEPOT_SLIDE.playOnServer(getWorld(), getPos());
            else
                AllSoundEvents.DEPOT_PLOP.playOnServer(getWorld(), getPos());
        }
        this.heldItem = heldItem;
    }
    return ItemStack.EMPTY;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 12 with TransportedItemStack

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

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

the class SharedDepotBlockMethods method onReplaced.

public static void onReplaced(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
    if (!state.hasBlockEntity() || state.getBlock() == newState.getBlock())
        return;
    DepotBehaviour behaviour = get(worldIn, pos);
    if (behaviour == null)
        return;
    ItemHelper.dropContents(worldIn, pos, behaviour.processingOutputBuffer);
    for (TransportedItemStack transportedItemStack : behaviour.incoming) Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), transportedItemStack.stack);
    if (!behaviour.getHeldItemStack().isEmpty())
        Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), behaviour.getHeldItemStack());
    worldIn.removeBlockEntity(pos);
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)

Example 14 with TransportedItemStack

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

the class SharedDepotBlockMethods method onUse.

public static InteractionResult onUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult ray) {
    if (ray.getDirection() != Direction.UP)
        return InteractionResult.PASS;
    if (world.isClientSide)
        return InteractionResult.SUCCESS;
    DepotBehaviour behaviour = get(world, pos);
    if (behaviour == null)
        return InteractionResult.PASS;
    if (!behaviour.canAcceptItems.get())
        return InteractionResult.SUCCESS;
    ItemStack heldItem = player.getItemInHand(hand);
    boolean wasEmptyHanded = heldItem.isEmpty();
    boolean shouldntPlaceItem = AllBlocks.MECHANICAL_ARM.isIn(heldItem);
    ItemStack mainItemStack = behaviour.getHeldItemStack();
    if (!mainItemStack.isEmpty()) {
        player.getInventory().placeItemBackInInventory(mainItemStack);
        behaviour.removeHeldItem();
        world.playSound(null, pos, SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, .2f, 1f + Create.RANDOM.nextFloat());
    }
    ItemStackHandler outputs = behaviour.processingOutputBuffer;
    for (int i = 0; i < outputs.getSlots(); i++) player.getInventory().placeItemBackInInventory(outputs.extractItem(i, 64, false));
    if (!wasEmptyHanded && !shouldntPlaceItem) {
        TransportedItemStack transported = new TransportedItemStack(heldItem);
        transported.insertedFrom = player.getDirection();
        transported.prevBeltPosition = .25f;
        transported.beltPosition = .25f;
        behaviour.setHeldItem(transported);
        player.setItemInHand(hand, ItemStack.EMPTY);
        AllSoundEvents.DEPOT_SLIDE.playOnServer(world, pos);
    }
    behaviour.tileEntity.notifyUpdate();
    return InteractionResult.SUCCESS;
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 15 with TransportedItemStack

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

the class DepotItemHandler method extractItem.

@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if (slot != MAIN_SLOT)
        return te.processingOutputBuffer.extractItem(slot - 1, amount, simulate);
    TransportedItemStack held = te.heldItem;
    if (held == null)
        return ItemStack.EMPTY;
    ItemStack stack = held.stack.copy();
    ItemStack extracted = stack.split(amount);
    if (!simulate) {
        te.heldItem.stack = stack;
        if (stack.isEmpty())
            te.heldItem = null;
        te.tileEntity.notifyUpdate();
    }
    return extracted;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) 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