Fixed wires connecting through strips and panels

This commit is contained in:
Calclavia 2013-12-23 10:57:13 +08:00
parent 7f6c7cd678
commit 5e8dc4da03

View file

@ -4,7 +4,6 @@ import java.util.Arrays;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -19,7 +18,6 @@ import resonantinduction.Utility;
import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.render.RenderFlatWire;
import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.lighting.LazyLightMatrix;
@ -295,27 +293,31 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
public void recalculateConnections()
{
this.connections = new Object[6];
this.updateOpenConnections();
/**
* Calculate all external connections of this conductor.
* Check external connections.
*/
for (byte r = 0; r < 4; r++)
{
if (!maskOpen(r))
{
continue;
}
boolean didConnect = false;
int absDir = Rotation.rotateSide(this.side, r);
this.setExternalConnection(absDir);
// Check Corner
if (maskOpen(r))
{
// Check direct connection.
if (this.setExternalConnection(absDir))
{
didConnect |= true;
}
// Check Corner Connection
BlockCoord cornerPos = new BlockCoord(tile());
cornerPos.offset(absDir);
if (!canConnectThroughCorner(cornerPos, absDir ^ 1, this.side))
continue;
if (canConnectThroughCorner(cornerPos, absDir ^ 1, this.side))
{
cornerPos.offset(this.side);
TileMultipart tpCorner = Utility.getMultipartTile(world(), cornerPos);
@ -325,12 +327,19 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
if (this.canConnectTo(tp))
{
// We found a wire, merge networks!
this.connections[absDir] = tp;
this.getNetwork().merge(((PartFlatWire) tp).getNetwork());
didConnect |= true;
}
}
}
}
}
/**
* Check internal connections.
*/
for (byte r = 0; r < 4; r++)
{
int absDir = Rotation.rotateSide(this.side, r);
@ -342,14 +351,12 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
if (this.canConnectTo(tp))
{
// We found a wire! Merge networks!
this.connections[absDir] = tp;
this.getNetwork().merge(((PartFlatWire) tp).getNetwork());
continue;
}
}
// Cannot find any wire connections on this side. Set null.
this.connections[absDir] = null;
}
// Connect to the face of the block the wire is placed on.
@ -358,7 +365,9 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
this.getNetwork().reconstruct();
}
public void setExternalConnection(int absSide)
public boolean setExternalConnection(int absSide)
{
if (this.maskOpen(absSide))
{
BlockCoord pos = new BlockCoord(tile()).offset(absSide);
TileMultipart t = Utility.getMultipartTile(world(), pos);
@ -369,9 +378,10 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
if (this.canConnectTo(tp))
{
// We found a wire! Merge connection.
this.connections[absSide] = tp;
this.getNetwork().merge(((PartFlatWire) tp).getNetwork());
return;
return true;
}
}
@ -380,8 +390,11 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
if (this.canConnectTo(tileEntity))
{
this.connections[absSide] = tileEntity;
return true;
}
}
return false;
}
@Override