Merge pull request #1985 from Toshayo/master

Support for more unusual pylons
This commit is contained in:
HbmMods 2025-03-17 08:09:03 +01:00 committed by GitHub
commit 11e9bc22ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 77 additions and 75 deletions

View File

@ -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,25 @@ 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);
this.bindTexture(pyl.color == 0 ? ResourceManager.wire_tex : ResourceManager.wire_greyscale_tex);
pyl.getConnected().forEach(wire -> {
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 +53,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,
@ -75,9 +73,9 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer {
first.zCoord + (sZ - first.zCoord) * 0.5);
}
}
}
});
}
/**
* Renders half a line
* First coords: the relative render position
@ -101,12 +99,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 +122,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 +160,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 +176,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 +198,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;
}

View File

@ -23,45 +23,45 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
public List<int[]> connected = new ArrayList<int[]>();
protected List<int[]> 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,95 @@ 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);
}
public List<int[]> getConnected() {
return connected;
}
@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,24 +168,24 @@ 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());
}
public static enum ConnectionType {
public enum ConnectionType {
SINGLE,
TRIPLE,
QUAD
//more to follow
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;