Search in sources :

Example 1 with BeltTileEntity

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

the class BasinBlock method canOutputTo.

public static boolean canOutputTo(BlockGetter world, BlockPos basinPos, Direction direction) {
    BlockPos neighbour = basinPos.relative(direction);
    BlockPos output = neighbour.below();
    BlockState blockState = world.getBlockState(neighbour);
    if (FunnelBlock.isFunnel(blockState)) {
        if (FunnelBlock.getFunnelFacing(blockState) == direction)
            return false;
    } else if (!blockState.getCollisionShape(world, neighbour).isEmpty()) {
        return false;
    } else {
        BlockEntity tileEntity = world.getBlockEntity(output);
        if (tileEntity instanceof BeltTileEntity) {
            BeltTileEntity belt = (BeltTileEntity) tileEntity;
            return belt.getSpeed() == 0 || belt.getMovementFacing() != direction.getOpposite();
        }
    }
    DirectBeltInputBehaviour directBeltInputBehaviour = TileEntityBehaviour.get(world, output, DirectBeltInputBehaviour.TYPE);
    if (directBeltInputBehaviour != null)
        return directBeltInputBehaviour.canInsertFromSide(direction);
    return false;
}
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) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with BeltTileEntity

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

the class BrassTunnelTileEntity method tick.

@Override
public void tick() {
    super.tick();
    BeltTileEntity beltBelow = BeltHelper.getSegmentTE(level, worldPosition.below());
    if (distributionProgress > 0)
        distributionProgress--;
    if (beltBelow == null || beltBelow.getSpeed() == 0)
        return;
    if (stackToDistribute.isEmpty() && !syncedOutputActive)
        return;
    if (level.isClientSide && !isVirtual())
        return;
    if (distributionProgress == -1) {
        distributionTargets.forEach(List::clear);
        distributionDistanceLeft = 0;
        distributionDistanceRight = 0;
        syncSet.clear();
        List<Pair<BrassTunnelTileEntity, Direction>> validOutputs = gatherValidOutputs();
        if (selectionMode.get() == SelectionMode.SYNCHRONIZE) {
            boolean allEmpty = true;
            boolean allFull = true;
            for (BrassTunnelTileEntity te : syncSet) {
                boolean hasStack = !te.stackToDistribute.isEmpty();
                allEmpty &= !hasStack;
                allFull &= hasStack;
            }
            final boolean notifySyncedOut = !allEmpty;
            if (allFull || allEmpty)
                syncSet.forEach(te -> te.syncedOutputActive = notifySyncedOut);
        }
        if (validOutputs == null)
            return;
        if (stackToDistribute.isEmpty())
            return;
        for (Pair<BrassTunnelTileEntity, Direction> pair : validOutputs) {
            BrassTunnelTileEntity tunnel = pair.getKey();
            Direction output = pair.getValue();
            if (insertIntoTunnel(tunnel, output, stackToDistribute, true) == null)
                continue;
            distributionTargets.get(!tunnel.flapFilterEmpty(output)).add(Pair.of(tunnel.worldPosition, output));
            int distance = tunnel.worldPosition.getX() + tunnel.worldPosition.getZ() - worldPosition.getX() - worldPosition.getZ();
            if (distance < 0)
                distributionDistanceLeft = Math.max(distributionDistanceLeft, -distance);
            else
                distributionDistanceRight = Math.max(distributionDistanceRight, distance);
        }
        if (distributionTargets.getFirst().isEmpty() && distributionTargets.getSecond().isEmpty())
            return;
        if (selectionMode.get() != SelectionMode.SYNCHRONIZE || syncedOutputActive) {
            distributionProgress = 10;
            sendData();
        }
        return;
    }
    if (distributionProgress != 0)
        return;
    distributionTargets.forEach(list -> {
        if (stackToDistribute.isEmpty())
            return;
        List<Pair<BrassTunnelTileEntity, Direction>> validTargets = new ArrayList<>();
        for (Pair<BlockPos, Direction> pair : list) {
            BlockPos tunnelPos = pair.getKey();
            Direction output = pair.getValue();
            BlockEntity te = level.getBlockEntity(tunnelPos);
            if (!(te instanceof BrassTunnelTileEntity))
                continue;
            validTargets.add(Pair.of((BrassTunnelTileEntity) te, output));
        }
        distribute(validTargets);
        distributionProgress = -1;
    });
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) Direction(net.minecraft.core.Direction) Random(java.util.Random) AxisDirection(net.minecraft.core.Direction.AxisDirection) Pair(org.apache.commons.lang3.tuple.Pair) ChatFormatting(net.minecraft.ChatFormatting) Map(java.util.Map) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) CenteredSideValueBoxTransform(com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform) IdentityHashMap(java.util.IdentityHashMap) NbtUtils(net.minecraft.nbt.NbtUtils) Set(java.util.Set) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Capability(net.minecraftforge.common.capabilities.Capability) BlockHelper(com.simibubi.create.foundation.utility.BlockHelper) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) Couple(com.simibubi.create.foundation.utility.Couple) BlockPos(net.minecraft.core.BlockPos) ItemEntity(net.minecraft.world.entity.item.ItemEntity) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) Entry(java.util.Map.Entry) ItemStack(net.minecraft.world.item.ItemStack) Tag(net.minecraft.nbt.Tag) BlockState(net.minecraft.world.level.block.state.BlockState) BeltHelper(com.simibubi.create.content.contraptions.relays.belt.BeltHelper) ScrollOptionBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollOptionBehaviour) AllIcons(com.simibubi.create.foundation.gui.AllIcons) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) HashSet(java.util.HashSet) Axis(net.minecraft.core.Direction.Axis) SidedFilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.SidedFilteringBehaviour) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) INamedIconOptions(com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.INamedIconOptions) Lang(com.simibubi.create.foundation.utility.Lang) AllBlocks(com.simibubi.create.AllBlocks) Nullable(javax.annotation.Nullable) Iterate(com.simibubi.create.foundation.utility.Iterate) TileEntityBehaviour(com.simibubi.create.foundation.tileEntity.TileEntityBehaviour) Component(net.minecraft.network.chat.Component) AllTriggers(com.simibubi.create.foundation.advancement.AllTriggers) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) IHaveGoggleInformation(com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation) Vec3(net.minecraft.world.phys.Vec3) NBTHelper(com.simibubi.create.foundation.utility.NBTHelper) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) ArrayList(java.util.ArrayList) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) List(java.util.List) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) Pair(org.apache.commons.lang3.tuple.Pair) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with BeltTileEntity

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

the class BeltMovementHandler method transportEntity.

public static void transportEntity(BeltTileEntity beltTe, Entity entityIn, TransportedEntityInfo info) {
    BlockPos pos = info.lastCollidedPos;
    Level world = beltTe.getLevel();
    BlockEntity te = world.getBlockEntity(pos);
    BlockEntity tileEntityBelowPassenger = world.getBlockEntity(entityIn.blockPosition());
    BlockState blockState = info.lastCollidedState;
    Direction movementFacing = Direction.fromAxisAndDirection(blockState.getValue(BlockStateProperties.HORIZONTAL_FACING).getAxis(), beltTe.getSpeed() < 0 ? POSITIVE : NEGATIVE);
    boolean collidedWithBelt = te instanceof BeltTileEntity;
    boolean betweenBelts = tileEntityBelowPassenger instanceof BeltTileEntity && tileEntityBelowPassenger != te;
    // Don't fight other Belts
    if (!collidedWithBelt || betweenBelts) {
        return;
    }
    // Too slow
    boolean notHorizontal = beltTe.getBlockState().getValue(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL;
    if (Math.abs(beltTe.getSpeed()) < 1)
        return;
    // Not on top
    if (entityIn.getY() - .25f < pos.getY())
        return;
    // Lock entities in place
    boolean isPlayer = entityIn instanceof Player;
    if (entityIn instanceof LivingEntity && !isPlayer)
        ((LivingEntity) entityIn).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 1, false, false));
    final Direction beltFacing = blockState.getValue(BlockStateProperties.HORIZONTAL_FACING);
    final BeltSlope slope = blockState.getValue(BeltBlock.SLOPE);
    final Axis axis = beltFacing.getAxis();
    float movementSpeed = beltTe.getBeltMovementSpeed();
    final Direction movementDirection = Direction.get(axis == Axis.X ? NEGATIVE : POSITIVE, axis);
    Vec3i centeringDirection = Direction.get(POSITIVE, beltFacing.getClockWise().getAxis()).getNormal();
    Vec3 movement = Vec3.atLowerCornerOf(movementDirection.getNormal()).scale(movementSpeed);
    double diffCenter = axis == Axis.Z ? (pos.getX() + .5f - entityIn.getX()) : (pos.getZ() + .5f - entityIn.getZ());
    if (Math.abs(diffCenter) > 48 / 64f)
        return;
    BeltPart part = blockState.getValue(BeltBlock.PART);
    float top = 13 / 16f;
    boolean onSlope = notHorizontal && (part == BeltPart.MIDDLE || part == BeltPart.PULLEY || part == (slope == BeltSlope.UPWARD ? BeltPart.END : BeltPart.START) && entityIn.getY() - pos.getY() < top || part == (slope == BeltSlope.UPWARD ? BeltPart.START : BeltPart.END) && entityIn.getY() - pos.getY() > top);
    boolean movingDown = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.DOWNWARD : BeltSlope.UPWARD);
    boolean movingUp = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.UPWARD : BeltSlope.DOWNWARD);
    if (beltFacing.getAxis() == Axis.Z) {
        boolean b = movingDown;
        movingDown = movingUp;
        movingUp = b;
    }
    if (movingUp)
        movement = movement.add(0, Math.abs(axis.choose(movement.x, movement.y, movement.z)), 0);
    if (movingDown)
        movement = movement.add(0, -Math.abs(axis.choose(movement.x, movement.y, movement.z)), 0);
    Vec3 centering = Vec3.atLowerCornerOf(centeringDirection).scale(diffCenter * Math.min(Math.abs(movementSpeed), .1f) * 4);
    if (!(entityIn instanceof LivingEntity) || ((LivingEntity) entityIn).zza == 0 && ((LivingEntity) entityIn).xxa == 0)
        movement = movement.add(centering);
    float step = entityIn.maxUpStep;
    if (!isPlayer)
        entityIn.maxUpStep = 1;
    // Entity Collisions
    if (Math.abs(movementSpeed) < .5f) {
        Vec3 checkDistance = movement.normalize().scale(0.5);
        AABB bb = entityIn.getBoundingBox();
        AABB checkBB = new AABB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
        checkBB = checkBB.move(checkDistance).inflate(-Math.abs(checkDistance.x), -Math.abs(checkDistance.y), -Math.abs(checkDistance.z));
        List<Entity> list = world.getEntities(entityIn, checkBB);
        list.removeIf(e -> shouldIgnoreBlocking(entityIn, e));
        if (!list.isEmpty()) {
            entityIn.setDeltaMovement(0, 0, 0);
            info.ticksSinceLastCollision--;
            return;
        }
    }
    entityIn.fallDistance = 0;
    if (movingUp) {
        float minVelocity = .13f;
        float yMovement = (float) -(Math.max(Math.abs(movement.y), minVelocity));
        entityIn.move(SELF, new Vec3(0, yMovement, 0));
        entityIn.move(SELF, movement.multiply(1, 0, 1));
    } else if (movingDown) {
        entityIn.move(SELF, movement.multiply(1, 0, 1));
        entityIn.move(SELF, movement.multiply(0, 1, 0));
    } else {
        entityIn.move(SELF, movement);
    }
    entityIn.setOnGround(true);
    if (!isPlayer)
        entityIn.maxUpStep = step;
    boolean movedPastEndingSlope = onSlope && (AllBlocks.BELT.has(world.getBlockState(entityIn.blockPosition())) || AllBlocks.BELT.has(world.getBlockState(entityIn.blockPosition().below())));
    if (movedPastEndingSlope && !movingDown && Math.abs(movementSpeed) > 0)
        entityIn.setPos(entityIn.getX(), entityIn.getY() + movement.y, entityIn.getZ());
    if (movedPastEndingSlope) {
        entityIn.setDeltaMovement(movement);
        entityIn.hurtMarked = true;
    }
}
Also used : Vec3i(net.minecraft.core.Vec3i) LivingEntity(net.minecraft.world.entity.LivingEntity) AbstractContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) BeltPart(com.simibubi.create.content.contraptions.relays.belt.BeltPart) Direction(net.minecraft.core.Direction) LivingEntity(net.minecraft.world.entity.LivingEntity) BeltSlope(com.simibubi.create.content.contraptions.relays.belt.BeltSlope) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Axis(net.minecraft.core.Direction.Axis) AABB(net.minecraft.world.phys.AABB) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 4 with BeltTileEntity

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

the class SchematicannonTileEntity method launchBlockOrBelt.

protected void launchBlockOrBelt(BlockPos target, ItemStack icon, BlockState blockState, BlockEntity tile) {
    if (AllBlocks.BELT.has(blockState)) {
        blockState = stripBeltIfNotLast(blockState);
        if (tile instanceof BeltTileEntity && AllBlocks.BELT.has(blockState))
            launchBelt(target, blockState, ((BeltTileEntity) tile).beltLength);
        else if (blockState != Blocks.AIR.defaultBlockState())
            launchBlock(target, icon, blockState, null);
    } else {
        CompoundTag data = null;
        if (tile != null) {
            if (AllBlockTags.SAFE_NBT.matches(blockState)) {
                data = tile.saveWithFullMetadata();
                data = NBTProcessors.process(tile, data, true);
            } else if (tile instanceof IPartialSafeNBT) {
                data = new CompoundTag();
                ((IPartialSafeNBT) tile).writeSafe(data, false);
                data = NBTProcessors.process(tile, data, true);
            }
        }
        launchBlock(target, icon, blockState, data);
    }
}
Also used : BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) IPartialSafeNBT(com.simibubi.create.foundation.utility.IPartialSafeNBT) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 5 with BeltTileEntity

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

the class BeltTunnelInteractionHandler method stuckAtTunnel.

public static boolean stuckAtTunnel(BeltInventory beltInventory, int offset, ItemStack stack, Direction movementDirection) {
    BeltTileEntity belt = beltInventory.belt;
    BlockPos pos = BeltHelper.getPositionForOffset(belt, offset).above();
    if (!(belt.getLevel().getBlockState(pos).getBlock() instanceof BrassTunnelBlock))
        return false;
    BlockEntity te = belt.getLevel().getBlockEntity(pos);
    if (te == null || !(te instanceof BrassTunnelTileEntity))
        return false;
    BrassTunnelTileEntity tunnel = (BrassTunnelTileEntity) te;
    return !tunnel.canInsert(movementDirection.getOpposite(), stack);
}
Also used : BrassTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) BrassTunnelBlock(com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelBlock) BlockPos(net.minecraft.core.BlockPos) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

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