package dev.lumareth.improvedAerodynamics.exhaust; import net.minecraft.core.Direction; import net.minecraft.world.phys.Vec3; import org.joml.Quaternionf; import org.joml.Vector3f; /** * Where the exhaust leaves the nozzle and which way it goes, in the block's own coordinates (ship coordinates on a * ship). Matches the model: the nozzle sits in the north half of the block, tilted by the hinge bone and swung by the * rotation bone, and the block is turned by its facing the way AzureLib turns the model. */ public final class NozzleGeometry { /** Static tilt of the hinge bone around the thrust axis, in degrees, see the model. */ private static final float HINGE_TILT = 32.5F; /** The right engine swings about the mirrored axis, so the same deflection turns the opposite way there. */ public static final float RIGHT_ENGINE_SIGN = -1.0F; private NozzleGeometry() { } /** Center of the nozzle exit, on the block face the exhaust leaves through. */ public static Vec3 exit(net.minecraft.core.BlockPos pos, Direction facing) { return new Vec3(pos.getX() + 0.5 + facing.getStepX() * 0.5, pos.getY() + 0.5 + facing.getStepY() * 0.5, pos.getZ() + 0.5 + facing.getStepZ() * 0.5); } /** * Unit vector the exhaust moves along. At no deflection it is the facing, a deflection swings it around the axis the * rotation bone turns about: the hinge's tilt applied to X for the left engine, to Y for the right one. */ public static Vec3 exhaustDirection(Direction facing, float deflection, boolean rightEngine) { Vector3f swing = new Vector3f(0.0F, 0.0F, -1.0F); swing.rotateAxis((rightEngine ? RIGHT_ENGINE_SIGN : 1.0F) * deflection, rightEngine ? 0.0F : 1.0F, rightEngine ? 1.0F : 0.0F, 0.0F); // The deflection is about an axis turned by the hinge, the counter bone turns the nozzle back swing.rotateZ((float) Math.toRadians(HINGE_TILT)); swing.rotate(facingRotation(facing)); return new Vec3(swing.x, swing.y, swing.z); } /** The turn AzureLib applies to a model for a block facing, from facing north. */ private static Quaternionf facingRotation(Direction facing) { Quaternionf rotation = new Quaternionf(); switch (facing) { case SOUTH -> rotation.rotateY((float) Math.toRadians(180)); case WEST -> rotation.rotateY((float) Math.toRadians(90)); case EAST -> rotation.rotateY((float) Math.toRadians(270)); case UP -> rotation.rotateX((float) Math.toRadians(90)); case DOWN -> rotation.rotateX((float) Math.toRadians(-90)); default -> { } } return rotation; } }