Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket) {
@Override
public void readCustomNBT(NBTTagCompound nbt, boolean descPacket) {
super.readCustomNBT(nbt, descPacket);
facing = EnumFacing.byIndex(nbt.getInteger("facing"));
EnumFacing loaded = EnumFacing.byIndex(nbt.getInteger("facing"));
facing = loaded.getAxis() != EnumFacing.Axis.Y ? loaded : EnumFacing.NORTH;
wires = nbt.getInteger("wires");
active = nbt.getBoolean("active");
inverted = nbt.getBoolean("inverted");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.micatechnologies.realgrid.blocks.insulators;

import com.micatechnologies.realgrid.util.BoundsUtil;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3d;

Expand All @@ -8,68 +9,50 @@
* {@link TileEntityInsulatorBase} so every leaf TE is just a
* constructor-param wrapper instead of a bespoke subclass.
*
* Four presets cover all current insulators:
* <p>Top-mount presets use a fixed bounding box and offset (no rotation).
* Rotatable presets store NORTH-facing bounds and offset, then rotate
* dynamically via {@link BoundsUtil}.
*
* <p>Five presets cover all current insulators:
* VISE_TOP - Hendrix compact top-mount
* F_NECK - Locke and MacLean PTI tall top-mount
* POST_TOP - MacLean PI full top-mount
* SIDE_MOUNT - every direction-dependent side-mount variant
* DEAD_END - dead-end insulators (elevated, direction-dependent)
*/
public final class InsulatorGeometry
{
private final boolean sideMount;
private final Vec3d topOffset;
private final float[] topBounds;
private final double sideY;
private final float[] sideBoundsNS;
private final float[] sideBoundsEW;

private InsulatorGeometry(Vec3d topOffset, float[] topBounds)
{
this.sideMount = false;
this.topOffset = topOffset;
this.topBounds = topBounds;
this.sideY = 0;
this.sideBoundsNS = null;
this.sideBoundsEW = null;
}
private final boolean usesRotation;
private final Vec3d northOffset;
private final float[] northBounds;

private InsulatorGeometry(double sideY, float[] nsBounds, float[] ewBounds)
private InsulatorGeometry(boolean usesRotation, Vec3d northOffset, float[] northBounds)
{
this.sideMount = true;
this.topOffset = null;
this.topBounds = null;
this.sideY = sideY;
this.sideBoundsNS = nsBounds;
this.sideBoundsEW = ewBounds;
this.usesRotation = usesRotation;
this.northOffset = northOffset;
this.northBounds = northBounds;
}

/** Creates a top-mount geometry with fixed (non-rotating) bounds and offset. */
public static InsulatorGeometry top(Vec3d offset, float[] bounds)
{
return new InsulatorGeometry(offset, bounds);
return new InsulatorGeometry(false, offset, bounds);
}

public static InsulatorGeometry side(double y, float[] nsBounds, float[] ewBounds)
/** Creates a direction-dependent geometry that rotates bounds/offset by facing. */
public static InsulatorGeometry rotatable(Vec3d northOffset, float[] northBounds)
{
return new InsulatorGeometry(y, nsBounds, ewBounds);
return new InsulatorGeometry(true, northOffset, northBounds);
}

public Vec3d connectionOffset(EnumFacing facing)
{
if (!sideMount) return topOffset;
double dx = 0.5, dz = 0.5;
if (facing == EnumFacing.NORTH) dz = 0.125;
else if (facing == EnumFacing.SOUTH) dz = 0.875;
else if (facing == EnumFacing.WEST) dx = 0.125;
else if (facing == EnumFacing.EAST) dx = 0.875;
return new Vec3d(dx, sideY, dz);
return usesRotation ? BoundsUtil.rotateOffset(northOffset, facing) : northOffset;
}

public float[] blockBounds(EnumFacing facing)
{
if (!sideMount) return topBounds;
return (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH)
? sideBoundsNS
: sideBoundsEW;
return usesRotation ? BoundsUtil.rotateBounds(northBounds, facing) : northBounds;
}

// === Presets ===
Expand All @@ -92,10 +75,21 @@ public float[] blockBounds(EnumFacing facing)
new float[]{0.25f, 0.0f, 0.25f, 0.75f, 0.9375f, 0.75f}
);

/** Every direction-dependent side-mount insulator. */
public static final InsulatorGeometry SIDE_MOUNT = side(
0.5625,
new float[]{0.3125f, 0.0f, 0.0625f, 0.6875f, 0.6875f, 0.9375f},
new float[]{0.0625f, 0.0f, 0.3125f, 0.9375f, 0.6875f, 0.6875f}
/**
* Every direction-dependent side-mount insulator.
* NORTH-facing bounds: narrow in X, extends along Z toward the facing direction.
*/
public static final InsulatorGeometry SIDE_MOUNT = rotatable(
new Vec3d(0.5, 0.5625, 0.125),
new float[]{0.3125f, 0.0f, 0.0625f, 0.6875f, 0.6875f, 0.9375f}
);

/**
* Dead-end insulators: elevated models that extend along the facing direction.
* Bounds are raised on Y to match the actual model position.
*/
public static final InsulatorGeometry DEAD_END = rotatable(
new Vec3d(0.5, 0.6875, 0.125),
new float[]{0.25f, 0.375f, 0.0f, 0.75f, 0.8125f, 1.0f}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket)
public void readCustomNBT(NBTTagCompound nbt, boolean descPacket)
{
super.readCustomNBT(nbt, descPacket);
facing = EnumFacing.byIndex(nbt.getInteger("facing"));
EnumFacing loaded = EnumFacing.byIndex(nbt.getInteger("facing"));
facing = loaded.getAxis() != EnumFacing.Axis.Y ? loaded : EnumFacing.NORTH;
wireCount = nbt.getInteger("wireCount");
colorVariant = nbt.getInteger("colorVariant");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI1BellNew extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI1BellNew()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI1BellOld extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI1BellOld()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI2BellNew extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI2BellNew()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI2BellOld extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI2BellOld()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI3BellNew extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI3BellNew()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI3BellOld extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI3BellOld()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI3Core extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI3Core()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI4Core extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI4Core()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI4Core2 extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI4Core2()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.micatechnologies.realgrid.blocks.insulators;


public class TileEntityMacLeanDEI6Core extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI6Core()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI7Core extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI7Core()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI7Core2 extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI7Core2()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI7Core3 extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI7Core3()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI8Core extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI8Core()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class TileEntityMacLeanDEI9Core extends TileEntityInsulatorBase
{
public TileEntityMacLeanDEI9Core()
{
super(InsulatorGeometry.SIDE_MOUNT);
super(InsulatorGeometry.DEAD_END);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket)
public void readCustomNBT(NBTTagCompound nbt, boolean descPacket)
{
super.readCustomNBT(nbt, descPacket);
facing = EnumFacing.byIndex(nbt.getInteger("facing"));
EnumFacing loaded = EnumFacing.byIndex(nbt.getInteger("facing"));
facing = loaded.getAxis() != EnumFacing.Axis.Y ? loaded : EnumFacing.NORTH;
dummy = nbt.getInteger("dummy");
hvCable1 = nbt.hasKey("hvCable1") ? ApiUtils.getWireTypeFromNBT(nbt, "hvCable1") : null;
hvCable2 = nbt.hasKey("hvCable2") ? ApiUtils.getWireTypeFromNBT(nbt, "hvCable2") : null;
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/micatechnologies/realgrid/util/BoundsUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.micatechnologies.realgrid.util;

import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3d;

/**
* Utility for rotating bounding boxes and connection offsets by horizontal
* {@link EnumFacing}. All inputs are assumed to describe the NORTH-facing
* orientation; the utility rotates them clockwise around the block centre.
*
* <p>Adapted from CSM's {@code RotationUtils} for the {@code float[]} format
* used by IE's {@code IBlockBounds} interface.
*/
public final class BoundsUtil
{
private BoundsUtil() {}

/**
* Rotates a NORTH-facing bounding box ({@code [minX, minY, minZ, maxX, maxY, maxZ]})
* to align with the given horizontal facing.
*/
public static float[] rotateBounds(float[] northBounds, EnumFacing facing)
{
float minX = northBounds[0], minY = northBounds[1], minZ = northBounds[2];
float maxX = northBounds[3], maxY = northBounds[4], maxZ = northBounds[5];

switch (facing)
{
case SOUTH:
return new float[]{ 1f - maxX, minY, 1f - maxZ, 1f - minX, maxY, 1f - minZ };
case EAST:
return new float[]{ 1f - maxZ, minY, minX, 1f - minZ, maxY, maxX };
case WEST:
return new float[]{ minZ, minY, 1f - maxX, maxZ, maxY, 1f - minX };
default: // NORTH or unexpected
return northBounds;
}
}

/**
* Rotates a NORTH-facing connection offset to align with the given
* horizontal facing.
*/
public static Vec3d rotateOffset(Vec3d northOffset, EnumFacing facing)
{
double x = northOffset.x, y = northOffset.y, z = northOffset.z;
switch (facing)
{
case SOUTH:
return new Vec3d(1.0 - x, y, 1.0 - z);
case EAST:
return new Vec3d(1.0 - z, y, x);
case WEST:
return new Vec3d(z, y, 1.0 - x);
default: // NORTH or unexpected
return northOffset;
}
}
}