From 5ead78349cbb18c43645c35e1567fd11310e87a8 Mon Sep 17 00:00:00 2001 From: Toshayo Date: Thu, 13 Mar 2025 23:08:19 +0100 Subject: [PATCH 1/2] Updated TileEntityPylonBase and RenderPylonBase according .editorconfig --- .../render/tileentity/RenderPylonBase.java | 60 +++++++------- .../network/TileEntityPylonBase.java | 78 +++++++++---------- 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java index 4db727ba5..d784d34e7 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java +++ b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java @@ -14,7 +14,7 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; public abstract class RenderPylonBase extends TileEntitySpecialRenderer { - + /** * The closest we have to a does-all solution. It will figure out if it needs to draw multiple lines, * iterate through all the mounting points, try to find the matching mounting points and then draw the lines. @@ -24,27 +24,27 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { * @param z */ public void renderLinesGeneric(TileEntityPylonBase pyl, double x, double y, double z) { - + this.bindTexture(pyl.color == 0 ? ResourceManager.wire_tex : ResourceManager.wire_greyscale_tex); - + for(int i = 0; i < pyl.connected.size(); i++) { int[] wire = pyl.connected.get(i); TileEntity tile = pyl.getWorldObj().getTileEntity(wire[0], wire[1], wire[2]); - + if(tile instanceof TileEntityPylonBase) { TileEntityPylonBase pylon = (TileEntityPylonBase) tile; - + Vec3[] m1 = pyl.getMountPos(); Vec3[] m2 = pylon.getMountPos(); - + int lineCount = Math.min(m1.length, m2.length); - + for(int line = 0; line < lineCount; line++) { Vec3 first = m1[line % m1.length]; int secondIndex = line % m2.length; - + /* * hacky hacky hack * this will shift the mount point order by 2 to prevent wires from crossing @@ -55,17 +55,17 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { if(lineCount == 4 && ( (pyl.getBlockMetadata() - 10 == 5 && pylon.getBlockMetadata() - 10 == 2) || (pyl.getBlockMetadata() - 10 == 2 && pylon.getBlockMetadata() - 10 == 5))) { - + secondIndex += 2; secondIndex %= m2.length; } - + Vec3 second = m2[secondIndex]; - + double sX = second.xCoord + pylon.xCoord - pyl.xCoord; double sY = second.yCoord + pylon.yCoord - pyl.yCoord; double sZ = second.zCoord + pylon.zCoord - pyl.zCoord; - + renderLine(pyl.getWorldObj(), pyl, x, y, z, first.xCoord, first.yCoord, @@ -77,7 +77,7 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { } } } - + /** * Renders half a line * First coords: the relative render position @@ -101,12 +101,12 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { GL11.glTranslated(x, y, z); float count = 10; Tessellator tess = Tessellator.instance; - + GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_CULL_FACE); tess.startDrawingQuads(); Vec3 delta = Vec3.createVectorHelper(x0 - x1, y0 - y1, z0 - z1); - + double girth = 0.03125D; double hyp = Math.sqrt(delta.xCoord * delta.xCoord + delta.zCoord * delta.zCoord); double yaw = Math.atan2(delta.xCoord, delta.zCoord); @@ -124,31 +124,31 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { tess.setColorOpaque_I(pyl.color == 0 ? 0xffffff : pyl.color); drawLineSegment(tess, x0, y0, z0, x1, y1, z1, iX, iY, iZ, jX, jZ); } else { - + double hang = Math.min(delta.lengthVector() / 15D, 2.5D); - + for(float j = 0; j < count; j++) { - + float k = j + 1; - + double sagJ = Math.sin(j / count * Math.PI * 0.5) * hang; double sagK = Math.sin(k / count * Math.PI * 0.5) * hang; double sagMean = (sagJ + sagK) / 2D; - + double deltaX = x1 - x0; double deltaY = y1 - y0; double deltaZ = z1 - z0; - + double ja = j + 0.5D; double ix = pyl.xCoord + x0 + deltaX / (double)(count) * ja; double iy = pyl.yCoord + y0 + deltaY / (double)(count) * ja - sagMean; double iz = pyl.zCoord + z0 + deltaZ / (double)(count) * ja; - + int brightness = world.getLightBrightnessForSkyBlocks(MathHelper.floor_double(ix), MathHelper.floor_double(iy), MathHelper.floor_double(iz), 0); tess.setBrightness(brightness); - + tess.setColorOpaque_I(pyl.color == 0 ? 0xffffff : pyl.color); - + drawLineSegment(tess, x0 + (deltaX * j / count), y0 + (deltaY * j / count) - sagJ, @@ -162,10 +162,10 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { tess.draw(); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_CULL_FACE); - + GL11.glPopMatrix(); } - + /** * Draws a single segment from the first to the second 3D coordinate. * Not fantastic but it looks good enough. @@ -178,19 +178,19 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { * @param c */ public void drawLineSegment(Tessellator tessellator, double x, double y, double z, double a, double b, double c, double iX, double iY, double iZ, double jX, double jZ) { - + double deltaX = a - x; double deltaY = b - y; double deltaZ = c - z; double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); int wrap = (int) Math.ceil(length * 8); - + if(deltaX + deltaZ < 0) { wrap *= -1; jZ *= -1; jX *= -1; } - + tessellator.addVertexWithUV(x + iX, y + iY, z + iZ, 0, 0); tessellator.addVertexWithUV(x - iX, y - iY, z - iZ, 0, 1); tessellator.addVertexWithUV(a - iX, b - iY, c - iZ, wrap, 1); @@ -200,6 +200,6 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { tessellator.addVertexWithUV(a - jX, b, c - jZ, wrap, 1); tessellator.addVertexWithUV(a + jX, b, c + jZ, wrap, 0); } - + public static final int LINE_COLOR = 0xBB3311; } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java index 7581ddaed..d9a5a97bc 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java @@ -23,45 +23,45 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.ForgeDirection; public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { - + public List connected = new ArrayList(); public int color; - + public static int canConnect(TileEntityPylonBase first, TileEntityPylonBase second) { - + if(first.getConnectionType() != second.getConnectionType()) return 1; - + if(first == second) return 2; - + double len = Math.min(first.getMaxWireLength(), second.getMaxWireLength()); - + Vec3 firstPos = first.getConnectionPoint(); Vec3 secondPos = second.getConnectionPoint(); - + Vec3 delta = Vec3.createVectorHelper( (secondPos.xCoord) - (firstPos.xCoord), (secondPos.yCoord) - (firstPos.yCoord), (secondPos.zCoord) - (firstPos.zCoord) ); - + return len >= delta.lengthVector() ? 0 : 3; } - + public boolean setColor(ItemStack stack) { if(stack == null) return false; int color = ColorUtil.getColorFromDye(stack); if(color == 0 || color == this.color) return false; stack.stackSize--; this.color = color; - + this.markDirty(); if(worldObj instanceof WorldServer) { WorldServer world = (WorldServer) worldObj; world.getPlayerManager().markBlockForUpdate(xCoord, yCoord, zCoord); } - + return true; } @@ -72,91 +72,91 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN)); return node; } - + public void addConnection(int x, int y, int z) { - + connected.add(new int[] {x, y, z}); - + PowerNode node = Nodespace.getNode(worldObj, xCoord, yCoord, zCoord); node.recentlyChanged = true; node.addConnection(new DirPos(x, y, z, ForgeDirection.UNKNOWN)); - + this.markDirty(); - + if(worldObj instanceof WorldServer) { WorldServer world = (WorldServer) worldObj; world.getPlayerManager().markBlockForUpdate(xCoord, yCoord, zCoord); } } - + public void disconnectAll() { - + for(int[] pos : connected) { - + TileEntity te = worldObj.getTileEntity(pos[0], pos[1], pos[2]); - + if(te == this) continue; - + if(te instanceof TileEntityPylonBase) { TileEntityPylonBase pylon = (TileEntityPylonBase) te; Nodespace.destroyNode(worldObj, pos[0], pos[1], pos[2]); - + for(int i = 0; i < pylon.connected.size(); i++) { int[] conPos = pylon.connected.get(i); - + if(conPos[0] == xCoord && conPos[1] == yCoord && conPos[2] == zCoord) { pylon.connected.remove(i); i--; } } - + pylon.markDirty(); - + if(worldObj instanceof WorldServer) { WorldServer world = (WorldServer) worldObj; world.getPlayerManager().markBlockForUpdate(pylon.xCoord, pylon.yCoord, pylon.zCoord); } } } - + Nodespace.destroyNode(worldObj, xCoord, yCoord, zCoord); } - + public abstract ConnectionType getConnectionType(); public abstract Vec3[] getMountPos(); public abstract double getMaxWireLength(); - + public Vec3 getConnectionPoint() { Vec3[] mounts = this.getMountPos(); - + if(mounts == null || mounts.length == 0) return Vec3.createVectorHelper(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - + return mounts[0].addVector(xCoord, yCoord, zCoord); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setInteger("conCount", connected.size()); nbt.setInteger("color", color); - + for(int i = 0; i < connected.size(); i++) { nbt.setIntArray("con" + i, connected.get(i)); } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - + int count = nbt.getInteger("conCount"); this.color = nbt.getInteger("color"); - + this.connected.clear(); - + for(int i = 0; i < count; i++) { connected.add(nbt.getIntArray("con" + i)); } @@ -164,12 +164,12 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { @Override public Packet getDescriptionPacket() { - + NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); } - + @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); @@ -181,7 +181,7 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { QUAD //more to follow } - + @Override public AxisAlignedBB getRenderBoundingBox() { return TileEntity.INFINITE_EXTENT_AABB; From 98f4b22a19f4fabb44db21849c26c253ce0c3671 Mon Sep 17 00:00:00 2001 From: Toshayo Date: Thu, 13 Mar 2025 23:09:41 +0100 Subject: [PATCH 2/2] Upgraded base pylon code to support more unusual pylon types --- .../java/com/hbm/render/tileentity/RenderPylonBase.java | 6 ++---- .../com/hbm/tileentity/network/TileEntityPylonBase.java | 8 ++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java index d784d34e7..ecb027e11 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java +++ b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java @@ -27,9 +27,7 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { this.bindTexture(pyl.color == 0 ? ResourceManager.wire_tex : ResourceManager.wire_greyscale_tex); - for(int i = 0; i < pyl.connected.size(); i++) { - - int[] wire = pyl.connected.get(i); + pyl.getConnected().forEach(wire -> { TileEntity tile = pyl.getWorldObj().getTileEntity(wire[0], wire[1], wire[2]); if(tile instanceof TileEntityPylonBase) { @@ -75,7 +73,7 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { first.zCoord + (sZ - first.zCoord) * 0.5); } } - } + }); } /** diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java index d9a5a97bc..f3041922b 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java @@ -24,7 +24,7 @@ import net.minecraftforge.common.util.ForgeDirection; public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { - public List connected = new ArrayList(); + protected List connected = new ArrayList<>(); public int color; public static int canConnect(TileEntityPylonBase first, TileEntityPylonBase second) { @@ -136,6 +136,10 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { return mounts[0].addVector(xCoord, yCoord, zCoord); } + public List getConnected() { + return connected; + } + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -175,7 +179,7 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { this.readFromNBT(pkt.func_148857_g()); } - public static enum ConnectionType { + public enum ConnectionType { SINGLE, TRIPLE, QUAD