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);
}
}
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;
}
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);
}
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;
}
Aggregations