Skip to content

Commit c50081a

Browse files
committed
fix direction for extendon axis renderer + other stuff
1 parent bd7fb0d commit c50081a

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonBlockEntity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block
186186
compound.putInt("ConnectedPosX",connectedBe!!.pos.x)
187187
compound.putInt("ConnectedPosY",connectedBe!!.pos.y)
188188
compound.putInt("ConnectedPosZ",connectedBe!!.pos.z)
189+
compound.putBoolean("IsMain", main)
189190
}
190191

191192
super.write(compound, clientPacket)
@@ -197,6 +198,7 @@ class ExtendonBlockEntity(type: BlockEntityType<*>?, pos: BlockPos, state: Block
197198
if (compound.contains("ConnectedPosX")) {
198199
connectedBe = level?.getBlockEntity(BlockPos(compound.getInt("ConnectedPosX"),compound.getInt("ConnectedPosY"),compound.getInt("ConnectedPosZ"))) as? ExtendonBlockEntity
199200
connectedJoint = connectedBe
201+
main = compound.getBoolean("IsMain")
200202
}
201203

202204
super.read(compound, clientPacket)

common/src/main/kotlin/org/valkyrienskies/clockwork/content/physicalities/extendon/ExtendonRenderer.kt

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,44 @@ class ExtendonRenderer(context: BlockEntityRendererProvider.Context?) : SmartBlo
4141

4242
if (be.connectedBe != null) {
4343
val thisShip = be.level!!.getShipManagingPos(be.blockPos) as ClientShip?
44-
val thisPos = if (thisShip == null) be.blockPos.toJOMLD()!! + 0.5 else thisShip.renderTransform.shipToWorld.transformPosition(be.blockPos.toJOMLD() + 0.5)!!
44+
val thisPos = if (thisShip == null) be.blockPos.toJOMLD() + 0.5 else thisShip.renderTransform.shipToWorld.transformPosition(be.blockPos.toJOMLD() + 0.5)!!
4545

4646
val otherShip = be.level!!.getShipManagingPos(be.connectedBe!!.pos) as ClientShip?
4747
val otherPos = if (otherShip == null)be.connectedBe!!.pos.toJOMLD() + 0.5 else otherShip.renderTransform.shipToWorld.transformPosition(be.connectedBe!!.pos.toJOMLD() + 0.5)!!
4848

49-
var direction = otherPos - thisPos
49+
val direction = otherPos - thisPos
5050

51-
var angleTriple = getEulerAngles(direction)
52-
axis0 = axis0.rotateCentered(Direction.UP, angleTriple.second.toFloat())
51+
val angles = if (thisShip == null) getEulerAngles(direction) else getEulerAngles(thisShip.renderTransform.worldToShip.transformDirection(direction, Vector3d()))
5352

54-
axis1 = axis1.rotateCentered(Direction.UP, angleTriple.second.toFloat())
55-
axis1 = axis1.rotateCentered(Direction.WEST, angleTriple.first.toFloat())
53+
//Rotate Partials
54+
axis0 = axis0.rotateCentered(Direction.UP, angles.second.toFloat())
5655

57-
val minX = thisPos.x - 0.25
58-
val minY = thisPos.y - 0.25
59-
val minZ = thisPos.z - 0.25
60-
val maxX = thisPos.x - 0.25 + thisPos.distance(otherPos)
61-
val maxY = thisPos.y + 0.25
62-
val maxZ = thisPos.z + 0.25
56+
axis1 = axis1.rotateCentered(Direction.UP, angles.second.toFloat())
57+
axis1 = axis1.rotateCentered(Direction.WEST, angles.first.toFloat())
6358

64-
val aabb = AABB(minX, minY, minZ, maxX, maxY, maxZ)
6559

66-
// Create and configure the outline
67-
val outline = RotatedAABBOutline(aabb, direction)
60+
if (be.main) {
61+
//Rotated AABB creation
62+
val minX = thisPos.x - 0.25
63+
val minY = thisPos.y - 0.25
64+
val minZ = thisPos.z - 0.25
65+
val maxX = thisPos.x - 0.25 + thisPos.distance(otherPos)
66+
val maxY = thisPos.y + 0.25
67+
val maxZ = thisPos.z + 0.25
6868

69-
if (!outliner.getOutlines().containsKey(be) || (outliner.getOutlines()[be]?.outline !is RotatedAABBOutline)) outliner.showCustomOutline(be, outline)
70-
else outliner.editCustomOutline(be, outline)
71-
72-
// Keep the outline alive for next frame
73-
outliner.keep(be)
69+
val aabb = AABB(minX, minY, minZ, maxX, maxY, maxZ)
70+
71+
// Create and configure the outline
72+
val outline = RotatedAABBOutline(aabb, direction)
73+
74+
if (!outliner.getOutlines()
75+
.containsKey(be) || (outliner.getOutlines()[be]?.outline !is RotatedAABBOutline)
76+
) outliner.showCustomOutline(be, outline)
77+
else outliner.editCustomOutline(be, outline)
78+
79+
// Keep the outline alive for next frame
80+
outliner.keep(be)
81+
}
7482
} else {
7583
// Remove outline if no connection
7684
outliner.remove(be)
@@ -122,3 +130,9 @@ public fun Outliner.editCustomOutline(key: Any, outline: Outline) {
122130
.let { it as MutableMap<Any, Outliner.OutlineEntry> }[key] = Outliner.OutlineEntry(outline)
123131
}
124132

133+
public fun Outline.OutlineParams.disableFadeLineWidth() {
134+
this::class.java.getDeclaredField("fadeLineWidth")
135+
.apply { isAccessible = true }
136+
.set(this, false)
137+
138+
}

common/src/main/kotlin/org/valkyrienskies/clockwork/util/render/outline/RotatedAABBOutline.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ import com.simibubi.create.foundation.render.SuperRenderTypeBuffer
66
import net.minecraft.world.phys.AABB
77
import net.minecraft.world.phys.Vec3
88
import org.joml.Vector3dc
9+
import org.valkyrienskies.clockwork.content.physicalities.extendon.disableFadeLineWidth
910
import org.valkyrienskies.mod.common.util.toMinecraft
1011
import org.valkyrienskies.clockwork.util.*
1112

1213
class RotatedAABBOutline(aabb: AABB, var directon: Vector3dc) : AABBOutline(aabb) {
1314

15+
init {
16+
params.disableCull()
17+
params.disableLineNormals()
18+
params.disableFadeLineWidth()
19+
}
20+
1421
override fun render(ms: PoseStack, buffer: SuperRenderTypeBuffer, camera: Vec3, pt: Float) {
1522
ms.pushPose()
1623

0 commit comments

Comments
 (0)