Search in sources :

Example 6 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class EjectorTileEntity method launchItems.

protected void launchItems() {
    ItemStack heldItemStack = depotBehaviour.getHeldItemStack();
    Direction funnelFacing = getFacing().getOpposite();
    if (AbstractFunnelBlock.getFunnelFacing(level.getBlockState(worldPosition.above())) == funnelFacing) {
        DirectBeltInputBehaviour directOutput = getBehaviour(DirectBeltInputBehaviour.TYPE);
        if (depotBehaviour.heldItem != null) {
            ItemStack remainder = directOutput.tryExportingToBeltFunnel(heldItemStack, funnelFacing, false);
            if (remainder == null)
                ;
            else if (remainder.isEmpty())
                depotBehaviour.removeHeldItem();
            else if (!remainder.sameItem(heldItemStack))
                depotBehaviour.heldItem.stack = remainder;
        }
        for (Iterator<TransportedItemStack> iterator = depotBehaviour.incoming.iterator(); iterator.hasNext(); ) {
            TransportedItemStack transportedItemStack = iterator.next();
            ItemStack stack = transportedItemStack.stack;
            ItemStack remainder = directOutput.tryExportingToBeltFunnel(stack, funnelFacing, false);
            if (remainder == null)
                ;
            else if (remainder.isEmpty())
                iterator.remove();
            else if (!remainder.sameItem(stack))
                transportedItemStack.stack = remainder;
        }
        ItemStackHandler outputs = depotBehaviour.processingOutputBuffer;
        for (int i = 0; i < outputs.getSlots(); i++) {
            ItemStack remainder = directOutput.tryExportingToBeltFunnel(outputs.getStackInSlot(i), funnelFacing, false);
            if (remainder != null)
                outputs.setStackInSlot(i, remainder);
        }
        return;
    }
    if (!level.isClientSide)
        for (Direction d : Iterate.directions) {
            BlockState blockState = level.getBlockState(worldPosition.relative(d));
            if (!(blockState.getBlock() instanceof ObserverBlock))
                continue;
            if (blockState.getValue(ObserverBlock.FACING) != d.getOpposite())
                continue;
            blockState.updateShape(d.getOpposite(), blockState, level, worldPosition.relative(d), worldPosition);
        }
    if (depotBehaviour.heldItem != null) {
        addToLaunchedItems(heldItemStack);
        depotBehaviour.removeHeldItem();
    }
    for (TransportedItemStack transportedItemStack : depotBehaviour.incoming) addToLaunchedItems(transportedItemStack.stack);
    depotBehaviour.incoming.clear();
    ItemStackHandler outputs = depotBehaviour.processingOutputBuffer;
    for (int i = 0; i < outputs.getSlots(); i++) {
        ItemStack extractItem = outputs.extractItem(i, 64, false);
        if (!extractItem.isEmpty())
            addToLaunchedItems(extractItem);
    }
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) BlockState(net.minecraft.world.level.block.state.BlockState) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) ObserverBlock(net.minecraft.world.level.block.ObserverBlock) ItemStack(net.minecraft.world.item.ItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Direction(net.minecraft.core.Direction)

Example 7 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class EjectorTileEntity method ejectIfTriggered.

protected void ejectIfTriggered() {
    if (powered)
        return;
    int presentStackSize = depotBehaviour.getPresentStackSize();
    if (presentStackSize == 0)
        return;
    if (presentStackSize < maxStackSize.getValue())
        return;
    if (depotBehaviour.heldItem != null && depotBehaviour.heldItem.beltPosition < .49f)
        return;
    Direction funnelFacing = getFacing().getOpposite();
    ItemStack held = depotBehaviour.getHeldItemStack();
    if (AbstractFunnelBlock.getFunnelFacing(level.getBlockState(worldPosition.above())) == funnelFacing) {
        DirectBeltInputBehaviour directOutput = getBehaviour(DirectBeltInputBehaviour.TYPE);
        if (depotBehaviour.heldItem != null) {
            ItemStack tryFunnel = directOutput.tryExportingToBeltFunnel(held, funnelFacing, true);
            if (tryFunnel == null || !tryFunnel.isEmpty())
                return;
        }
    }
    DirectBeltInputBehaviour targetOpenInv = getTargetOpenInv();
    // Do not eject if target cannot accept held item
    if (targetOpenInv != null && depotBehaviour.heldItem != null && targetOpenInv.handleInsertion(held, Direction.UP, true).getCount() == held.getCount())
        return;
    activate();
    notifyUpdate();
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) ItemStack(net.minecraft.world.item.ItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Direction(net.minecraft.core.Direction)

Example 8 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class EjectorTileEntity method placeItemAtTarget.

protected void placeItemAtTarget(boolean doLogic, float maxTime, IntAttached<ItemStack> intAttached) {
    if (!doLogic)
        return;
    if (intAttached.getSecond() == trackedItem)
        trackedItem = null;
    DirectBeltInputBehaviour targetOpenInv = getTargetOpenInv();
    if (targetOpenInv != null) {
        ItemStack remainder = targetOpenInv.handleInsertion(intAttached.getValue(), Direction.UP, false);
        intAttached.setSecond(remainder);
    }
    if (intAttached.getValue().isEmpty())
        return;
    Vec3 ejectVec = earlyTarget != null ? earlyTarget.getFirst() : getLaunchedItemLocation(maxTime);
    Vec3 ejectMotionVec = getLaunchedItemMotion(maxTime);
    ItemEntity item = new ItemEntity(level, ejectVec.x, ejectVec.y, ejectVec.z, intAttached.getValue());
    item.setDeltaMovement(ejectMotionVec);
    item.setDefaultPickUpDelay();
    level.addFreshEntity(item);
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) Vec3(net.minecraft.world.phys.Vec3) ItemStack(net.minecraft.world.item.ItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)

Example 9 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class BeltTunnelInteractionHandler method flapTunnelsAndCheckIfStuck.

public static boolean flapTunnelsAndCheckIfStuck(BeltInventory beltInventory, TransportedItemStack current, float nextOffset) {
    int currentSegment = (int) current.beltPosition;
    int upcomingSegment = (int) nextOffset;
    Direction movementFacing = beltInventory.belt.getMovementFacing();
    if (!beltInventory.beltMovementPositive && nextOffset == 0)
        upcomingSegment = -1;
    if (currentSegment == upcomingSegment)
        return false;
    if (stuckAtTunnel(beltInventory, upcomingSegment, current.stack, movementFacing)) {
        current.beltPosition = currentSegment + (beltInventory.beltMovementPositive ? .99f : .01f);
        return true;
    }
    Level world = beltInventory.belt.getLevel();
    boolean onServer = !world.isClientSide || beltInventory.belt.isVirtual();
    boolean removed = false;
    BeltTunnelTileEntity nextTunnel = getTunnelOnSegment(beltInventory, upcomingSegment);
    if (nextTunnel instanceof BrassTunnelTileEntity) {
        BrassTunnelTileEntity brassTunnel = (BrassTunnelTileEntity) nextTunnel;
        if (brassTunnel.hasDistributionBehaviour()) {
            if (!brassTunnel.canTakeItems())
                return true;
            if (onServer) {
                brassTunnel.setStackToDistribute(current.stack);
                current.stack = ItemStack.EMPTY;
                beltInventory.belt.sendData();
                beltInventory.belt.setChanged();
            }
            removed = true;
        }
    } else if (nextTunnel != null) {
        BlockState blockState = nextTunnel.getBlockState();
        if (current.stack.getCount() > 1 && AllBlocks.ANDESITE_TUNNEL.has(blockState) && BeltTunnelBlock.isJunction(blockState) && movementFacing.getAxis() == blockState.getValue(BeltTunnelBlock.HORIZONTAL_AXIS)) {
            for (Direction d : Iterate.horizontalDirections) {
                if (d.getAxis() == blockState.getValue(BeltTunnelBlock.HORIZONTAL_AXIS))
                    continue;
                if (!nextTunnel.flaps.containsKey(d))
                    continue;
                BlockPos outpos = nextTunnel.getBlockPos().below().relative(d);
                if (!world.isLoaded(outpos))
                    return true;
                DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(world, outpos, DirectBeltInputBehaviour.TYPE);
                if (behaviour == null)
                    continue;
                if (!behaviour.canInsertFromSide(d))
                    continue;
                ItemStack toinsert = ItemHandlerHelper.copyStackWithSize(current.stack, 1);
                if (!behaviour.handleInsertion(toinsert, d, false).isEmpty())
                    return true;
                if (onServer)
                    flapTunnel(beltInventory, upcomingSegment, d, false);
                current.stack.shrink(1);
                beltInventory.belt.sendData();
                if (current.stack.getCount() <= 1)
                    break;
            }
        }
    }
    if (onServer) {
        flapTunnel(beltInventory, currentSegment, movementFacing, false);
        flapTunnel(beltInventory, upcomingSegment, movementFacing.getOpposite(), true);
    }
    if (removed)
        return true;
    return false;
}
Also used : BrassTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity) BeltTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity) BlockState(net.minecraft.world.level.block.state.BlockState) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Example 10 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour 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)

Aggregations

DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)24 ItemStack (net.minecraft.world.item.ItemStack)14 BlockPos (net.minecraft.core.BlockPos)11 Direction (net.minecraft.core.Direction)11 ItemEntity (net.minecraft.world.entity.item.ItemEntity)8 BlockState (net.minecraft.world.level.block.state.BlockState)8 TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)7 Vec3 (net.minecraft.world.phys.Vec3)7 BeltTileEntity (com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity)4 Level (net.minecraft.world.level.Level)3 SmartTileEntity (com.simibubi.create.foundation.tileEntity.SmartTileEntity)2 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)2 FilteringBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)2 BlockFace (com.simibubi.create.foundation.utility.BlockFace)2 AxisDirection (net.minecraft.core.Direction.AxisDirection)2 AABB (net.minecraft.world.phys.AABB)2 InstancedRenderDispatcher (com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllSoundEvents (com.simibubi.create.AllSoundEvents)1 IHaveHoveringInformation (com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation)1