Search in sources :

Example 21 with DirectBeltInputBehaviour

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

the class ItemDrainTileEntity method tick.

@Override
public void tick() {
    super.tick();
    if (heldItem == null) {
        processingTicks = 0;
        return;
    }
    boolean onClient = level.isClientSide && !isVirtual();
    if (processingTicks > 0) {
        heldItem.prevBeltPosition = .5f;
        boolean wasAtBeginning = processingTicks == FILLING_TIME;
        if (!onClient || processingTicks < FILLING_TIME)
            processingTicks--;
        if (!continueProcessing()) {
            processingTicks = 0;
            notifyUpdate();
            return;
        }
        if (wasAtBeginning != (processingTicks == FILLING_TIME))
            sendData();
        return;
    }
    heldItem.prevBeltPosition = heldItem.beltPosition;
    heldItem.prevSideOffset = heldItem.sideOffset;
    heldItem.beltPosition += itemMovementPerTick();
    if (heldItem.beltPosition > 1) {
        heldItem.beltPosition = 1;
        if (onClient)
            return;
        Direction side = heldItem.insertedFrom;
        ItemStack tryExportingToBeltFunnel = getBehaviour(DirectBeltInputBehaviour.TYPE).tryExportingToBeltFunnel(heldItem.stack, side.getOpposite(), false);
        if (tryExportingToBeltFunnel != null) {
            if (tryExportingToBeltFunnel.getCount() != heldItem.stack.getCount()) {
                if (tryExportingToBeltFunnel.isEmpty())
                    heldItem = null;
                else
                    heldItem.stack = tryExportingToBeltFunnel;
                notifyUpdate();
                return;
            }
            if (!tryExportingToBeltFunnel.isEmpty())
                return;
        }
        BlockPos nextPosition = worldPosition.relative(side);
        DirectBeltInputBehaviour directBeltInputBehaviour = TileEntityBehaviour.get(level, nextPosition, DirectBeltInputBehaviour.TYPE);
        if (directBeltInputBehaviour == null) {
            if (!BlockHelper.hasBlockSolidSide(level.getBlockState(nextPosition), level, nextPosition, side.getOpposite())) {
                ItemStack ejected = heldItem.stack;
                Vec3 outPos = VecHelper.getCenterOf(worldPosition).add(Vec3.atLowerCornerOf(side.getNormal()).scale(.75));
                float movementSpeed = itemMovementPerTick();
                Vec3 outMotion = Vec3.atLowerCornerOf(side.getNormal()).scale(movementSpeed).add(0, 1 / 8f, 0);
                outPos.add(outMotion.normalize());
                ItemEntity entity = new ItemEntity(level, outPos.x, outPos.y + 6 / 16f, outPos.z, ejected);
                entity.setDeltaMovement(outMotion);
                entity.setDefaultPickUpDelay();
                entity.hurtMarked = true;
                level.addFreshEntity(entity);
                heldItem = null;
                notifyUpdate();
            }
            return;
        }
        if (!directBeltInputBehaviour.canInsertFromSide(side))
            return;
        ItemStack returned = directBeltInputBehaviour.handleInsertion(heldItem.copy(), side, false);
        if (returned.isEmpty()) {
            if (level.getBlockEntity(nextPosition) instanceof ItemDrainTileEntity)
                AllTriggers.triggerForNearbyPlayers(AllTriggers.CHAINED_ITEM_DRAIN, level, worldPosition, 5);
            heldItem = null;
            notifyUpdate();
            return;
        }
        if (returned.getCount() != heldItem.stack.getCount()) {
            heldItem.stack = returned;
            notifyUpdate();
            return;
        }
        return;
    }
    if (heldItem.prevBeltPosition < .5f && heldItem.beltPosition >= .5f) {
        if (!EmptyingByBasin.canItemBeEmptied(level, heldItem.stack))
            return;
        heldItem.beltPosition = .5f;
        if (onClient)
            return;
        processingTicks = FILLING_TIME;
        sendData();
    }
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Example 22 with DirectBeltInputBehaviour

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

the class BrassTunnelTileEntity method addValidOutputsOf.

private void addValidOutputsOf(BrassTunnelTileEntity tunnelTE, List<Pair<BrassTunnelTileEntity, Direction>> validOutputs) {
    syncSet.add(tunnelTE);
    BeltTileEntity below = BeltHelper.getSegmentTE(level, tunnelTE.worldPosition.below());
    if (below == null)
        return;
    Direction movementFacing = below.getMovementFacing();
    BlockState blockState = getBlockState();
    if (!AllBlocks.BRASS_TUNNEL.has(blockState))
        return;
    boolean prioritizeSides = tunnelTE == this;
    for (boolean sidePass : Iterate.trueAndFalse) {
        if (!prioritizeSides && sidePass)
            continue;
        for (Direction direction : Iterate.horizontalDirections) {
            if (direction == movementFacing && below.getSpeed() == 0)
                continue;
            if (prioritizeSides && sidePass == (direction.getAxis() == movementFacing.getAxis()))
                continue;
            if (direction == movementFacing.getOpposite())
                continue;
            if (tunnelTE.sides.contains(direction)) {
                BlockPos offset = tunnelTE.worldPosition.below().relative(direction);
                DirectBeltInputBehaviour inputBehaviour = TileEntityBehaviour.get(level, offset, DirectBeltInputBehaviour.TYPE);
                if (inputBehaviour == null) {
                    if (direction == movementFacing)
                        if (!BlockHelper.hasBlockSolidSide(level.getBlockState(offset), level, offset, direction.getOpposite()))
                            validOutputs.add(Pair.of(tunnelTE, direction));
                    continue;
                }
                if (inputBehaviour.canInsertFromSide(direction))
                    validOutputs.add(Pair.of(tunnelTE, direction));
                continue;
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 23 with DirectBeltInputBehaviour

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

the class BrassTunnelTileEntity method insertIntoTunnel.

@Nullable
protected ItemStack insertIntoTunnel(BrassTunnelTileEntity tunnel, Direction side, ItemStack stack, boolean simulate) {
    if (stack.isEmpty())
        return stack;
    if (!tunnel.testFlapFilter(side, stack))
        return null;
    BeltTileEntity below = BeltHelper.getSegmentTE(level, tunnel.worldPosition.below());
    if (below == null)
        return null;
    BlockPos offset = tunnel.getBlockPos().below().relative(side);
    DirectBeltInputBehaviour sideOutput = TileEntityBehaviour.get(level, offset, DirectBeltInputBehaviour.TYPE);
    if (sideOutput != null) {
        if (!sideOutput.canInsertFromSide(side))
            return null;
        ItemStack result = sideOutput.handleInsertion(stack, side, simulate);
        if (result.isEmpty() && !simulate)
            tunnel.flap(side, false);
        return result;
    }
    Direction movementFacing = below.getMovementFacing();
    if (side == movementFacing)
        if (!BlockHelper.hasBlockSolidSide(level.getBlockState(offset), level, offset, side.getOpposite())) {
            BeltTileEntity controllerTE = below.getControllerTE();
            if (controllerTE == null)
                return null;
            if (!simulate) {
                tunnel.flap(side, true);
                ItemStack ejected = stack;
                float beltMovementSpeed = below.getDirectionAwareBeltMovementSpeed();
                float movementSpeed = Math.max(Math.abs(beltMovementSpeed), 1 / 8f);
                int additionalOffset = beltMovementSpeed > 0 ? 1 : 0;
                Vec3 outPos = BeltHelper.getVectorForOffset(controllerTE, below.index + additionalOffset);
                Vec3 outMotion = Vec3.atLowerCornerOf(side.getNormal()).scale(movementSpeed).add(0, 1 / 8f, 0);
                outPos.add(outMotion.normalize());
                ItemEntity entity = new ItemEntity(level, outPos.x, outPos.y + 6 / 16f, outPos.z, ejected);
                entity.setDeltaMovement(outMotion);
                entity.setDefaultPickUpDelay();
                entity.hurtMarked = true;
                level.addFreshEntity(entity);
            }
            return ItemStack.EMPTY;
        }
    return null;
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) Vec3(net.minecraft.world.phys.Vec3) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Nullable(javax.annotation.Nullable)

Example 24 with DirectBeltInputBehaviour

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

the class DepotBehaviour method addSubBehaviours.

public void addSubBehaviours(List<TileEntityBehaviour> behaviours) {
    behaviours.add(new DirectBeltInputBehaviour(tileEntity).allowingBeltFunnels().setInsertionHandler(this::tryInsertingFromSide));
    transportedHandler = new TransportedItemStackHandlerBehaviour(tileEntity, this::applyToAllItems).withStackPlacement(this::getWorldPositionOf);
    behaviours.add(transportedHandler);
}
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