Wire merge now working

This commit is contained in:
Calclavia 2013-12-22 23:24:09 +08:00
parent bbe89086a1
commit da4d87d6b5
8 changed files with 130 additions and 59 deletions

@ -1 +1 @@
Subproject commit 1bc4a8bf21e124ca5f650d1d9da86a2962a71747
Subproject commit c263c191ede3ada3d5f1d0c76231398df60d5b9a

View file

@ -14,8 +14,7 @@ public class MultipartRI implements IPartFactory
{
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" });
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor");
// MultipartGenerator.registerTrait("resonantinduction.wire.part.ITest",
// "resonantinduction.wire.part.TraitTest");
//MultipartGenerator.registerTrait("resonantinduction.wire.part.ITest", "resonantinduction.wire.part.TraitTest");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
}

View file

@ -184,6 +184,8 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
}
}
}
this.getNetwork().split(this);
}
}
@ -201,13 +203,12 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
updateInternalConnections();
// if (updateOpenConnections())
if (updateOpenConnections())
{
updateExternalConnections();
}
this.recalculateConnections();
this.getNetwork().reconstruct();
tile().markDirty();
}
}
@ -227,9 +228,9 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (changed)
{
sendConnUpdate();
this.recalculateConnections();
this.getNetwork().reconstruct();
}
this.recalculateConnections();
}
}
@ -240,6 +241,7 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
{
boolean changed = updateInternalConnections();
if (updateOpenConnections())
{
changed |= updateExternalConnections();
@ -248,9 +250,9 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (changed)
{
sendConnUpdate();
this.recalculateConnections();
this.getNetwork().reconstruct();
}
this.recalculateConnections();
}
}
@ -267,9 +269,9 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (updateExternalConnections())
{
sendConnUpdate();
this.recalculateConnections();
this.getNetwork().reconstruct();
}
this.recalculateConnections();
}
}
@ -279,62 +281,42 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (!world().isRemote)
{
System.out.println(this.getNetwork());
System.out.println(Integer.toHexString(this.connMap));
this.getConnections();
this.recalculateConnections();
}
return super.activate(player, part, item);
}
@Override
public Object[] getConnections()
public void recalculateConnections()
{
this.cachedConnections = new Object[6];
this.connections = new Object[6];
/**
* Calculate all external connections of this conductor.
*/
for (byte r = 0; r < 4; r++)
{
int absDir = Rotation.rotateSide(side, r);
ForgeDirection dir = ForgeDirection.getOrientation(absDir);
BlockCoord pos = new BlockCoord(tile()).offset(absDir);
TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z);
TileMultipart t = Utility.getMultipartTile(world(), pos);
if (this.canConnect(dir))
{
this.cachedConnections[r] = tileEntity;
System.out.println("EXT" + tileEntity);
}
int absDir = Rotation.rotateSide(this.side, r);
this.setExternalConnection(absDir);
}
// Connect to the face of the block the wire is placed on.
BlockCoord pos = new BlockCoord(tile()).offset(this.side);
TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z);
TileMultipart t = Utility.getMultipartTile(world(), pos);
if (this.canConnect(ForgeDirection.getOrientation(this.side)))
{
this.cachedConnections[this.side] = tileEntity;
System.out.println("EXT" + tileEntity);
}
this.setExternalConnection(this.side);
for (byte r = 0; r < 4; r++)
{
int absDir = Rotation.rotateSide(side, r);
int absDir = Rotation.rotateSide(this.side, r);
// Check straight ahead.
if (tile().partMap(PartMap.edgeBetween(absDir, side)) == null)
if (tile().partMap(PartMap.edgeBetween(absDir, this.side)) == null)
{
TMultiPart tp = tile().partMap(absDir);
if (tp instanceof FlatWire)
if (this.canConnectTo(tp))
{
this.cachedConnections[absDir] = tp;
System.out.println("INT" + tp);
this.connections[absDir] = tp;
this.getNetwork().merge(((FlatWire) tp).getNetwork());
continue;
}
}
@ -343,25 +325,60 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
BlockCoord cornerPos = new BlockCoord(tile());
cornerPos.offset(absDir);
if (!canConnectThroughCorner(cornerPos, absDir ^ 1, side))
if (!canConnectThroughCorner(cornerPos, absDir ^ 1, this.side))
continue;
cornerPos.offset(side);
cornerPos.offset(this.side);
TileMultipart tpCorner = Utility.getMultipartTile(world(), cornerPos);
if (tpCorner != null)
{
TMultiPart tp = tpCorner.partMap(absDir ^ 1);
if (tp instanceof FlatWire)
if (this.canConnectTo(tp))
{
this.cachedConnections[absDir] = tp;
System.out.println("COR" + tp);
this.connections[absDir] = tp;
this.getNetwork().merge(((FlatWire) tp).getNetwork());
}
}
// Cannot find any wire connections on this side. Set null.
this.connections[absDir] = null;
}
this.getNetwork().reconstruct();
}
public void setExternalConnection(int absSide)
{
BlockCoord pos = new BlockCoord(tile()).offset(absSide);
TileMultipart t = Utility.getMultipartTile(world(), pos);
if (t != null)
{
TMultiPart tp = t.partMap(this.side);
if (this.canConnectTo(tp))
{
this.connections[absSide] = tp;
this.getNetwork().merge(((FlatWire) tp).getNetwork());
return;
}
}
return this.cachedConnections;
TileEntity tileEntity = world().getBlockTileEntity(pos.x, pos.y, pos.z);
if (this.canConnectTo(tileEntity))
{
this.connections[absSide] = tileEntity;
}
}
@Override
public Object[] getConnections()
{
return this.connections;
}
public boolean canStay()

View file

@ -0,0 +1,23 @@
package resonantinduction.wire.part;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.energy.IEnergyInterface;
/**
* @author Calclavia
*
*/
public interface ITest
{
/**
* Adds energy to an block. Returns the quantity of energy that was accepted. This should always
* return 0 if the block cannot be externally charged.
*
* @param from Orientation the energy is sent in from.
* @param receive Maximum amount of energy (joules) to be sent into the block.
* @param doReceive If false, the charge will only be simulated.
* @return Amount of energy that was accepted by the block.
*/
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive);
}

View file

@ -3,7 +3,6 @@ package resonantinduction.wire.part;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.base.PartAdvanced;
import resonantinduction.wire.IAdvancedConductor;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.energy.EnergyNetworkLoader;
import universalelectricity.api.energy.IConductor;
@ -12,11 +11,11 @@ import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
//@UniversalClass
public abstract class PartConductor extends PartAdvanced implements IAdvancedConductor
public abstract class PartConductor extends PartAdvanced implements IConductor
{
private IEnergyNetwork network;
protected Object[] cachedConnections = new Object[6];
protected Object[] connections = new Object[6];
/**
* Universal Electricity conductor functions.
@ -24,7 +23,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
return this.getNetwork().produce(this, receive, doReceive);
return this.getNetwork().produce(new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(world()), from.getOpposite(), receive, doReceive);
}
@Override
@ -70,7 +69,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
@Override
public Object[] getConnections()
{
return this.cachedConnections;
return this.connections;
}
/**
@ -94,11 +93,11 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
public abstract boolean canConnectTo(Object obj);
/**
* Recalculates all the netwirk connections
* Recalculates all the network connections
*/
protected void recalculateConnections()
{
this.cachedConnections = new Object[6];
this.connections = new Object[6];
/**
* Calculate all external connections with this conductor.
*/
@ -109,7 +108,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
if (this.canConnect(side))
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
cachedConnections[i] = tileEntity;
connections[i] = tileEntity;
}
}
}

View file

@ -23,7 +23,7 @@ import codechicken.lib.data.MCDataOutput;
* @author Calclavia
*
*/
public abstract class PartWireBase extends PartConductor
public abstract class PartWireBase extends PartConductor implements IAdvancedConductor
{
public static final int DEFAULT_COLOR = 16;
public int dyeID = DEFAULT_COLOR;

View file

@ -88,8 +88,6 @@ public class TraitConductor extends TileMultipart implements IConductor
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
System.out.println("RECEIVING"+receive);
/*TMultiPart part = partMap(from.ordinal());
if (part != null)

View file

@ -0,0 +1,35 @@
package resonantinduction.wire.part;
import java.util.HashSet;
import java.util.Set;
import net.minecraftforge.common.ForgeDirection;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class TraitTest extends TileMultipart implements ITest
{
public Set<ITest> interfaces = new HashSet<ITest>();
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
TMultiPart part = partMap(from.ordinal());
if (part != null)
{
for (ITest conductor : this.interfaces)
{
if (conductor == part)
{
((ITest) conductor).onReceiveEnergy(from, receive, doReceive);
System.out.println("RECEIVING");
}
}
}
return 0;
}
}