Search in sources :

Example 1 with BeltPart

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

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

the class BeltConnectorItem method createBelts.

public static void createBelts(Level world, BlockPos start, BlockPos end) {
    world.playSound(null, new BlockPos(VecHelper.getCenterOf(start.offset(end)).scale(.5f)), SoundEvents.WOOL_PLACE, SoundSource.BLOCKS, 0.5F, 1F);
    BeltSlope slope = getSlopeBetween(start, end);
    Direction facing = getFacingFromTo(start, end);
    BlockPos diff = end.subtract(start);
    if (diff.getX() == diff.getZ())
        facing = Direction.get(facing.getAxisDirection(), world.getBlockState(start).getValue(BlockStateProperties.AXIS) == Axis.X ? Axis.Z : Axis.X);
    List<BlockPos> beltsToCreate = getBeltChainBetween(start, end, slope, facing);
    BlockState beltBlock = AllBlocks.BELT.getDefaultState();
    for (BlockPos pos : beltsToCreate) {
        BeltPart part = pos.equals(start) ? BeltPart.START : pos.equals(end) ? BeltPart.END : BeltPart.MIDDLE;
        BlockState shaftState = world.getBlockState(pos);
        boolean pulley = ShaftBlock.isShaft(shaftState);
        if (part == BeltPart.MIDDLE && pulley)
            part = BeltPart.PULLEY;
        if (pulley && shaftState.getValue(AbstractShaftBlock.AXIS) == Axis.Y)
            slope = BeltSlope.SIDEWAYS;
        KineticTileEntity.switchToBlockState(world, pos, beltBlock.setValue(BeltBlock.SLOPE, slope).setValue(BeltBlock.PART, part).setValue(BeltBlock.HORIZONTAL_FACING, facing));
    }
}
Also used : BeltSlope(com.simibubi.create.content.contraptions.relays.belt.BeltSlope) BlockState(net.minecraft.world.level.block.state.BlockState) BeltPart(com.simibubi.create.content.contraptions.relays.belt.BeltPart) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 3 with BeltPart

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

the class SchematicannonTileEntity method stripBeltIfNotLast.

public static BlockState stripBeltIfNotLast(BlockState blockState) {
    BeltPart part = blockState.getValue(BeltBlock.PART);
    if (part == BeltPart.MIDDLE)
        return Blocks.AIR.defaultBlockState();
    // is highest belt?
    boolean isLastSegment = false;
    Direction facing = blockState.getValue(BeltBlock.HORIZONTAL_FACING);
    BeltSlope slope = blockState.getValue(BeltBlock.SLOPE);
    boolean positive = facing.getAxisDirection() == AxisDirection.POSITIVE;
    boolean start = part == BeltPart.START;
    boolean end = part == BeltPart.END;
    switch(slope) {
        case DOWNWARD:
            isLastSegment = start;
            break;
        case UPWARD:
            isLastSegment = end;
            break;
        default:
            isLastSegment = positive && end || !positive && start;
    }
    if (isLastSegment)
        return blockState;
    return AllBlocks.SHAFT.getDefaultState().setValue(AbstractShaftBlock.AXIS, slope == BeltSlope.SIDEWAYS ? Axis.Y : facing.getClockWise().getAxis());
}
Also used : BeltSlope(com.simibubi.create.content.contraptions.relays.belt.BeltSlope) BeltPart(com.simibubi.create.content.contraptions.relays.belt.BeltPart) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Aggregations

BeltPart (com.simibubi.create.content.contraptions.relays.belt.BeltPart)3 BeltSlope (com.simibubi.create.content.contraptions.relays.belt.BeltSlope)3 Direction (net.minecraft.core.Direction)3 BlockPos (net.minecraft.core.BlockPos)2 AxisDirection (net.minecraft.core.Direction.AxisDirection)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 AbstractContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity)1 BeltTileEntity (com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity)1 Axis (net.minecraft.core.Direction.Axis)1 Vec3i (net.minecraft.core.Vec3i)1 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)1 Entity (net.minecraft.world.entity.Entity)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 HangingEntity (net.minecraft.world.entity.decoration.HangingEntity)1 Player (net.minecraft.world.entity.player.Player)1 Level (net.minecraft.world.level.Level)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 AABB (net.minecraft.world.phys.AABB)1 Vec3 (net.minecraft.world.phys.Vec3)1