Search in sources :

Example 11 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class CartAssemblerTileEntity method tryAssemble.

public void tryAssemble(AbstractMinecart cart) {
    if (cart == null)
        return;
    if (!isMinecartUpdateValid())
        return;
    resetTicksSinceMinecartUpdate();
    BlockState state = level.getBlockState(worldPosition);
    if (!AllBlocks.CART_ASSEMBLER.has(state))
        return;
    CartAssemblerBlock block = (CartAssemblerBlock) state.getBlock();
    CartAssemblerBlock.CartAssemblerAction action = CartAssemblerBlock.getActionForCart(state, cart);
    if (action.shouldAssemble())
        assemble(level, worldPosition, cart);
    if (action.shouldDisassemble())
        disassemble(level, worldPosition, cart);
    if (action == CartAssemblerBlock.CartAssemblerAction.ASSEMBLE_ACCELERATE) {
        if (cart.getDeltaMovement().length() > 1 / 128f) {
            Direction facing = cart.getMotionDirection();
            RailShape railShape = state.getValue(CartAssemblerBlock.RAIL_SHAPE);
            for (Direction d : Iterate.directionsInAxis(railShape == RailShape.EAST_WEST ? Axis.X : Axis.Z)) if (level.getBlockState(worldPosition.relative(d)).isRedstoneConductor(level, worldPosition.relative(d)))
                facing = d.getOpposite();
            float speed = block.getRailMaxSpeed(state, level, worldPosition, cart);
            cart.setDeltaMovement(facing.getStepX() * speed, facing.getStepY() * speed, facing.getStepZ() * speed);
        }
    }
    if (action == CartAssemblerBlock.CartAssemblerAction.ASSEMBLE_ACCELERATE_DIRECTIONAL) {
        Vec3i accelerationVector = ControllerRailBlock.getAccelerationVector(AllBlocks.CONTROLLER_RAIL.getDefaultState().setValue(ControllerRailBlock.SHAPE, state.getValue(CartAssemblerBlock.RAIL_SHAPE)).setValue(ControllerRailBlock.BACKWARDS, state.getValue(CartAssemblerBlock.BACKWARDS)));
        float speed = block.getRailMaxSpeed(state, level, worldPosition, cart);
        cart.setDeltaMovement(Vec3.atLowerCornerOf(accelerationVector).scale(speed));
    }
    if (action == CartAssemblerBlock.CartAssemblerAction.DISASSEMBLE_BRAKE) {
        Vec3 diff = VecHelper.getCenterOf(worldPosition).subtract(cart.position());
        cart.setDeltaMovement(diff.x / 16f, 0, diff.z / 16f);
    }
}
Also used : Vec3i(net.minecraft.core.Vec3i) BlockState(net.minecraft.world.level.block.state.BlockState) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Vec3(net.minecraft.world.phys.Vec3) Direction(net.minecraft.core.Direction)

Example 12 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class ControllerRailBlock method mirror.

@Override
public BlockState mirror(BlockState state, Mirror mirror) {
    if (mirror == Mirror.NONE)
        return state;
    RailShape railshape = Blocks.POWERED_RAIL.defaultBlockState().setValue(SHAPE, state.getValue(SHAPE)).mirror(mirror).getValue(SHAPE);
    state = state.setValue(SHAPE, railshape);
    if ((getPointingTowards(state).getAxis() == Axis.Z) == (mirror == Mirror.LEFT_RIGHT))
        return state.cycle(BACKWARDS);
    return state;
}
Also used : RailShape(net.minecraft.world.level.block.state.properties.RailShape)

Example 13 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class ControllerRailGenerator method getModel.

@Override
public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov, BlockState state) {
    RailShape shape = state.getValue(ControllerRailBlock.SHAPE);
    boolean backwards = ControllerRailBlock.isStateBackwards(state);
    String model = shape.isAscending() ? backwards ? "ascending_south" : "ascending_north" : "north_south";
    return AssetLookup.partialBaseModel(ctx, prov, model);
}
Also used : RailShape(net.minecraft.world.level.block.state.properties.RailShape)

Example 14 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class OrientedContraptionEntity method updateOrientation.

protected boolean updateOrientation(boolean rotationLock, boolean wasStalled, Entity riding, boolean isOnCoupling) {
    if (isOnCoupling) {
        Couple<MinecartController> coupledCarts = getCoupledCartsIfPresent();
        if (coupledCarts == null)
            return false;
        Vec3 positionVec = coupledCarts.getFirst().cart().position();
        Vec3 coupledVec = coupledCarts.getSecond().cart().position();
        double diffX = positionVec.x - coupledVec.x;
        double diffY = positionVec.y - coupledVec.y;
        double diffZ = positionVec.z - coupledVec.z;
        prevYaw = yaw;
        prevPitch = pitch;
        yaw = (float) (Mth.atan2(diffZ, diffX) * 180 / Math.PI);
        pitch = (float) (Math.atan2(diffY, Math.sqrt(diffX * diffX + diffZ * diffZ)) * 180 / Math.PI);
        if (getCouplingId().equals(riding.getUUID())) {
            pitch *= -1;
            yaw += 180;
        }
        return false;
    }
    if (contraption instanceof StabilizedContraption) {
        if (!(riding instanceof OrientedContraptionEntity))
            return false;
        StabilizedContraption stabilized = (StabilizedContraption) contraption;
        Direction facing = stabilized.getFacing();
        if (facing.getAxis().isVertical())
            return false;
        OrientedContraptionEntity parent = (OrientedContraptionEntity) riding;
        prevYaw = yaw;
        yaw = -parent.getViewYRot(1);
        return false;
    }
    prevYaw = yaw;
    if (wasStalled)
        return false;
    boolean rotating = false;
    Vec3 movementVector = riding.getDeltaMovement();
    Vec3 locationDiff = riding.position().subtract(riding.xo, riding.yo, riding.zo);
    if (!(riding instanceof AbstractMinecart))
        movementVector = locationDiff;
    Vec3 motion = movementVector.normalize();
    if (!rotationLock) {
        if (riding instanceof AbstractMinecart) {
            AbstractMinecart minecartEntity = (AbstractMinecart) riding;
            BlockPos railPosition = minecartEntity.getCurrentRailPosition();
            BlockState blockState = level.getBlockState(railPosition);
            if (blockState.getBlock() instanceof BaseRailBlock) {
                BaseRailBlock abstractRailBlock = (BaseRailBlock) blockState.getBlock();
                RailShape railDirection = abstractRailBlock.getRailDirection(blockState, level, railPosition, minecartEntity);
                motion = VecHelper.project(motion, MinecartSim2020.getRailVec(railDirection));
            }
        }
        if (motion.length() > 0) {
            targetYaw = yawFromVector(motion);
            if (targetYaw < 0)
                targetYaw += 360;
            if (yaw < 0)
                yaw += 360;
        }
        prevYaw = yaw;
        float maxApproachSpeed = (float) (motion.length() * 12f / (Math.max(1, getBoundingBox().getXsize() / 6f)));
        float yawHint = AngleHelper.getShortestAngleDiff(yaw, yawFromVector(locationDiff));
        float approach = AngleHelper.getShortestAngleDiff(yaw, targetYaw, yawHint);
        approach = Mth.clamp(approach, -maxApproachSpeed, maxApproachSpeed);
        yaw += approach;
        if (Math.abs(AngleHelper.getShortestAngleDiff(yaw, targetYaw)) < 1f)
            yaw = targetYaw;
        else
            rotating = true;
    }
    return rotating;
}
Also used : AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) MinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController) CapabilityMinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController) Direction(net.minecraft.core.Direction) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos)

Aggregations

RailShape (net.minecraft.world.level.block.state.properties.RailShape)14 BlockState (net.minecraft.world.level.block.state.BlockState)9 BaseRailBlock (net.minecraft.world.level.block.BaseRailBlock)8 BlockPos (net.minecraft.core.BlockPos)7 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)6 Direction (net.minecraft.core.Direction)5 Vec3 (net.minecraft.world.phys.Vec3)5 Level (net.minecraft.world.level.Level)4 Nonnull (javax.annotation.Nonnull)2 AxisDirection (net.minecraft.core.Direction.AxisDirection)2 Vec3i (net.minecraft.core.Vec3i)2 Player (net.minecraft.world.entity.player.Player)2 ItemStack (net.minecraft.world.item.ItemStack)2 Block (net.minecraft.world.level.block.Block)2 EntityPoolMinecart (vazkii.botania.common.entity.EntityPoolMinecart)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DirectionalAxisKineticBlock (com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock)1 StabilizedContraption (com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption)1 LinearChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.LinearChassisBlock)1