diff options
author | BucketBrigade <138534411+CookieBrigade@users.noreply.github.com> | 2024-09-15 17:41:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-15 22:41:39 +0000 |
commit | 43af160db2e04f06bba3792a11860ee42c3d1947 (patch) | |
tree | 5d8e32ceca09e0a494fddb7282f1475a1dde5c3d /src/main/java/gregtech/common/tileentities/render | |
parent | b2f39ffd9736eab3c5bf56b54b1e04da1a3df556 (diff) | |
download | GT5-Unofficial-43af160db2e04f06bba3792a11860ee42c3d1947.tar.gz GT5-Unofficial-43af160db2e04f06bba3792a11860ee42c3d1947.tar.bz2 GT5-Unofficial-43af160db2e04f06bba3792a11860ee42c3d1947.zip |
Fix for render rotations on antimatter forge (again) and HILE (#3200)
Diffstat (limited to 'src/main/java/gregtech/common/tileentities/render')
-rw-r--r-- | src/main/java/gregtech/common/tileentities/render/TileEntityLaser.java | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/src/main/java/gregtech/common/tileentities/render/TileEntityLaser.java b/src/main/java/gregtech/common/tileentities/render/TileEntityLaser.java index b719039fe0..dfbb771785 100644 --- a/src/main/java/gregtech/common/tileentities/render/TileEntityLaser.java +++ b/src/main/java/gregtech/common/tileentities/render/TileEntityLaser.java @@ -7,6 +7,9 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; +import org.joml.AxisAngle4f; +import org.joml.Matrix4f; + import com.gtnewhorizon.structurelib.alignment.enumerable.Flip; import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; @@ -52,26 +55,48 @@ public class TileEntityLaser extends TileEntity { } public void setRotationFields(ForgeDirection direction, Rotation rotation, Flip flip) { - setRotationAngle(rotation, flip); - setRotationAxis(direction); - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - } - - private void setRotationAngle(Rotation rotation, Flip flip) { - int invert = (flip == Flip.HORIZONTAL || flip == Flip.VERTICAL) ? 1 : -1; - switch (rotation) { - case NORMAL -> rotationAngle = 0; - case CLOCKWISE -> rotationAngle = 90 * invert; - case COUNTER_CLOCKWISE -> rotationAngle = -90 * invert; - case UPSIDE_DOWN -> rotationAngle = 180; - } - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - } - - public void setRotationAxis(ForgeDirection direction) { - rotAxisX = direction.offsetX; - rotAxisY = direction.offsetY; - rotAxisZ = direction.offsetZ; + Matrix4f rotationMatrix = new Matrix4f().identity(); + + float localAngle = switch (rotation) { + case NORMAL -> 0; + case CLOCKWISE -> 90; + case COUNTER_CLOCKWISE -> -90; + case UPSIDE_DOWN -> 180; + }; + localAngle *= (flip == Flip.HORIZONTAL || flip == Flip.VERTICAL) ? 1 : -1; + localAngle = (float) Math.toRadians(localAngle); + rotationMatrix.rotate(localAngle, direction.offsetX, direction.offsetY, direction.offsetZ); + + float x = 0, y = 0; + float angle = switch (direction) { + case DOWN -> { + x = 1; + yield -90; + } + case UP -> { + x = 1; + yield -90; + } + case EAST, SOUTH -> { + y = 1; + yield 90; + } + case WEST, NORTH -> { + y = 1; + yield -90; + } + case UNKNOWN -> 0.0F; + }; + angle = (float) Math.toRadians(angle); + rotationMatrix.rotate(angle, x, y, 0); + + AxisAngle4f rotationVector = new AxisAngle4f(); + rotationMatrix.getRotation(rotationVector); + + rotationAngle = rotationVector.angle / (float) Math.PI * 180; + rotAxisX = rotationVector.x; + rotAxisY = rotationVector.y; + rotAxisZ = rotationVector.z; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } |