Search in sources :

Example 6 with BeltTileEntity

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

the class PonderWorld method fixControllerTileEntities.

public void fixControllerTileEntities() {
    for (BlockEntity tileEntity : tileEntities.values()) {
        if (tileEntity instanceof BeltTileEntity) {
            BeltTileEntity beltTileEntity = (BeltTileEntity) tileEntity;
            if (!beltTileEntity.isController())
                continue;
            BlockPos controllerPos = tileEntity.getBlockPos();
            for (BlockPos blockPos : BeltBlock.getBeltChain(this, controllerPos)) {
                BlockEntity tileEntity2 = getBlockEntity(blockPos);
                if (!(tileEntity2 instanceof BeltTileEntity))
                    continue;
                BeltTileEntity belt2 = (BeltTileEntity) tileEntity2;
                belt2.setController(controllerPos);
            }
        }
        if (tileEntity instanceof IMultiTileContainer) {
            IMultiTileContainer multiTile = (IMultiTileContainer) tileEntity;
            BlockPos lastKnown = multiTile.getLastKnownPos();
            BlockPos current = tileEntity.getBlockPos();
            if (lastKnown == null || current == null)
                continue;
            if (multiTile.isController())
                continue;
            if (!lastKnown.equals(current)) {
                BlockPos newControllerPos = multiTile.getController().offset(current.subtract(lastKnown));
                multiTile.setController(newControllerPos);
            }
        }
    }
}
Also used : BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) IMultiTileContainer(com.simibubi.create.foundation.tileEntity.IMultiTileContainer) BlockPos(net.minecraft.core.BlockPos) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 7 with BeltTileEntity

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

the class FunnelTileEntity method determineCurrentMode.

public Mode determineCurrentMode() {
    BlockState state = getBlockState();
    if (!FunnelBlock.isFunnel(state))
        return Mode.INVALID;
    if (state.getOptionalValue(BlockStateProperties.POWERED).orElse(false))
        return Mode.PAUSED;
    if (state.getBlock() instanceof BeltFunnelBlock) {
        Shape shape = state.getValue(BeltFunnelBlock.SHAPE);
        if (shape == Shape.PULLING)
            return Mode.TAKING_FROM_BELT;
        if (shape == Shape.PUSHING)
            return Mode.PUSHING_TO_BELT;
        BeltTileEntity belt = BeltHelper.getSegmentTE(level, worldPosition.below());
        if (belt != null)
            return belt.getMovementFacing() == state.getValue(BeltFunnelBlock.HORIZONTAL_FACING) ? Mode.PUSHING_TO_BELT : Mode.TAKING_FROM_BELT;
        return Mode.INVALID;
    }
    if (state.getBlock() instanceof FunnelBlock)
        return state.getValue(FunnelBlock.EXTRACTING) ? Mode.EXTRACT : Mode.COLLECT;
    return Mode.INVALID;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Shape(com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock.Shape) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity)

Example 8 with BeltTileEntity

use of com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity 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 9 with BeltTileEntity

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

Aggregations

BeltTileEntity (com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity)9 BlockPos (net.minecraft.core.BlockPos)7 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)5 BlockState (net.minecraft.world.level.block.state.BlockState)5 DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)4 Direction (net.minecraft.core.Direction)4 AxisDirection (net.minecraft.core.Direction.AxisDirection)3 Vec3 (net.minecraft.world.phys.Vec3)3 Nullable (javax.annotation.Nullable)2 Axis (net.minecraft.core.Direction.Axis)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 AllBlocks (com.simibubi.create.AllBlocks)1 AbstractContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity)1 IHaveGoggleInformation (com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation)1 BeltHelper (com.simibubi.create.content.contraptions.relays.belt.BeltHelper)1 BeltPart (com.simibubi.create.content.contraptions.relays.belt.BeltPart)1 BeltSlope (com.simibubi.create.content.contraptions.relays.belt.BeltSlope)1 BrassTunnelBlock (com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelBlock)1 BrassTunnelTileEntity (com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity)1 Shape (com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock.Shape)1