|
| 1 | +package dev.propulsionteam.propulsionsimulated.content.thruster; |
| 2 | + |
| 3 | +import net.createmod.catnip.math.VecHelper; |
| 4 | +import dev.propulsionteam.propulsionsimulated.content.thruster.creative_thruster.CreativeThrusterBlockEntity; |
| 5 | +import dev.propulsionteam.propulsionsimulated.content.thruster.ion_thruster.IonThrusterBlockEntity; |
| 6 | +import dev.propulsionteam.propulsionsimulated.content.thruster.solid_fuel_thruster.SolidFuelThrusterBlockEntity; |
| 7 | +import net.minecraft.core.Direction; |
| 8 | +import net.minecraft.world.phys.Vec3; |
| 9 | + |
| 10 | +/** |
| 11 | + * Maps model-space nozzle openings (voxel coords) into world block space (0–1 from block min corner), |
| 12 | + * using the same centered rotations as {@link net.createmod.catnip.math.VecHelper} / |
| 13 | + * blockstate variants. |
| 14 | + */ |
| 15 | +public final class ThrusterPlumeAnchors { |
| 16 | + private ThrusterPlumeAnchors() { |
| 17 | + } |
| 18 | + |
| 19 | + /** Offset from block center (0.5, 0.5, 0.5) for BER pose stack. */ |
| 20 | + public static Vec3 offsetFromBlockCenter(AbstractThrusterBlockEntity blockEntity) { |
| 21 | + Vec3 model = modelNozzleOpening(blockEntity); |
| 22 | + Vec3 world = rotateModelToWorld(model, blockEntity.getFacing(), layout(blockEntity)); |
| 23 | + return world.subtract(0.5, 0.5, 0.5); |
| 24 | + } |
| 25 | + |
| 26 | + private static Vec3 modelNozzleOpening(AbstractThrusterBlockEntity blockEntity) { |
| 27 | + if (blockEntity instanceof SolidFuelThrusterBlockEntity) { |
| 28 | + return voxel(13, 8, 8); |
| 29 | + } |
| 30 | + if (blockEntity instanceof IonThrusterBlockEntity) { |
| 31 | + return voxel(8, 1, 8); |
| 32 | + } |
| 33 | + if (blockEntity instanceof CreativeThrusterBlockEntity) { |
| 34 | + return voxel(8, 8, 10); |
| 35 | + } |
| 36 | + // Standard / fluid thruster — nozzle mouth at low +Z in model file |
| 37 | + return voxel(8, 8, 14); |
| 38 | + } |
| 39 | + |
| 40 | + private static Vec3 voxel(float x, float y, float z) { |
| 41 | + return new Vec3(x / 16.0, y / 16.0, z / 16.0); |
| 42 | + } |
| 43 | + |
| 44 | + private static Layout layout(AbstractThrusterBlockEntity blockEntity) { |
| 45 | + if (blockEntity instanceof SolidFuelThrusterBlockEntity) { |
| 46 | + return Layout.SOLID_FUEL; |
| 47 | + } |
| 48 | + if (blockEntity instanceof IonThrusterBlockEntity) { |
| 49 | + return Layout.ION; |
| 50 | + } |
| 51 | + return Layout.THRUSTER; |
| 52 | + } |
| 53 | + |
| 54 | + private static Vec3 rotateModelToWorld(Vec3 point, Direction facing, Layout layout) { |
| 55 | + return switch (layout) { |
| 56 | + case THRUSTER -> rotateThruster(point, facing); |
| 57 | + case SOLID_FUEL -> rotateSolidFuel(point, facing); |
| 58 | + case ION -> rotateIon(point, facing); |
| 59 | + }; |
| 60 | + } |
| 61 | + |
| 62 | + /** Same as {@code VectorThrusterBlockEntity.VectorThrusterLinkTransform#rotatePointForFacing}. */ |
| 63 | + private static Vec3 rotateThruster(Vec3 vec, Direction facing) { |
| 64 | + return switch (facing) { |
| 65 | + case NORTH -> vec; |
| 66 | + case EAST -> VecHelper.rotateCentered(vec, -90, Direction.Axis.Y); |
| 67 | + case SOUTH -> VecHelper.rotateCentered(vec, 180, Direction.Axis.Y); |
| 68 | + case WEST -> VecHelper.rotateCentered(vec, 90, Direction.Axis.Y); |
| 69 | + case UP -> VecHelper.rotateCentered(vec, 90, Direction.Axis.X); |
| 70 | + case DOWN -> VecHelper.rotateCentered(vec, -90, Direction.Axis.X); |
| 71 | + }; |
| 72 | + } |
| 73 | + |
| 74 | + /** Matches {@code assets/.../blockstates/solid_fuel_thruster.json}. */ |
| 75 | + private static Vec3 rotateSolidFuel(Vec3 vec, Direction facing) { |
| 76 | + return switch (facing) { |
| 77 | + case WEST -> vec; |
| 78 | + case EAST -> VecHelper.rotateCentered(vec, 180, Direction.Axis.Y); |
| 79 | + case NORTH -> VecHelper.rotateCentered(vec, 90, Direction.Axis.Y); |
| 80 | + case SOUTH -> VecHelper.rotateCentered(vec, -90, Direction.Axis.Y); |
| 81 | + case UP -> VecHelper.rotateCentered( |
| 82 | + VecHelper.rotateCentered(vec, -90, Direction.Axis.X), |
| 83 | + 90, Direction.Axis.Y); |
| 84 | + case DOWN -> VecHelper.rotateCentered( |
| 85 | + VecHelper.rotateCentered(vec, 90, Direction.Axis.X), |
| 86 | + 90, Direction.Axis.Y); |
| 87 | + }; |
| 88 | + } |
| 89 | + |
| 90 | + /** Matches {@code assets/.../blockstates/ion_thruster.json}. */ |
| 91 | + private static Vec3 rotateIon(Vec3 vec, Direction facing) { |
| 92 | + return switch (facing) { |
| 93 | + case UP -> vec; |
| 94 | + case DOWN -> VecHelper.rotateCentered(vec, 180, Direction.Axis.X); |
| 95 | + case NORTH -> VecHelper.rotateCentered(vec, 90, Direction.Axis.X); |
| 96 | + case SOUTH -> VecHelper.rotateCentered( |
| 97 | + VecHelper.rotateCentered(vec, 180, Direction.Axis.Y), |
| 98 | + 90, Direction.Axis.X); |
| 99 | + case EAST -> VecHelper.rotateCentered( |
| 100 | + VecHelper.rotateCentered(vec, 90, Direction.Axis.Y), |
| 101 | + 90, Direction.Axis.X); |
| 102 | + case WEST -> VecHelper.rotateCentered( |
| 103 | + VecHelper.rotateCentered(vec, -90, Direction.Axis.Y), |
| 104 | + 90, Direction.Axis.X); |
| 105 | + }; |
| 106 | + } |
| 107 | + |
| 108 | + private enum Layout { |
| 109 | + THRUSTER, |
| 110 | + SOLID_FUEL, |
| 111 | + ION |
| 112 | + } |
| 113 | +} |
0 commit comments