Allowed multiple wires to be placed within one block
This commit is contained in:
parent
b478e67025
commit
54ed10a33e
8 changed files with 197 additions and 37 deletions
|
@ -1,9 +1,6 @@
|
||||||
package resonantinduction;
|
package resonantinduction;
|
||||||
|
|
||||||
import resonantinduction.wire.IAdvancedConductor;
|
|
||||||
import resonantinduction.wire.IBlockableConnection;
|
|
||||||
import resonantinduction.wire.part.FlatWire;
|
import resonantinduction.wire.part.FlatWire;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
|
||||||
import codechicken.multipart.MultiPartRegistry;
|
import codechicken.multipart.MultiPartRegistry;
|
||||||
import codechicken.multipart.MultiPartRegistry.IPartFactory;
|
import codechicken.multipart.MultiPartRegistry.IPartFactory;
|
||||||
import codechicken.multipart.MultipartGenerator;
|
import codechicken.multipart.MultipartGenerator;
|
||||||
|
@ -16,10 +13,9 @@ public class MultipartRI implements IPartFactory
|
||||||
public MultipartRI()
|
public MultipartRI()
|
||||||
{
|
{
|
||||||
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" });
|
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" });
|
||||||
MultipartGenerator.registerPassThroughInterface(IAdvancedConductor.class.getName());
|
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
|
||||||
MultipartGenerator.registerPassThroughInterface(IPowerReceptor.class.getName());
|
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor");
|
||||||
MultipartGenerator.registerPassThroughInterface(IBlockableConnection.class.getName());
|
|
||||||
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.TEnergySink");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package resonantinduction.wire;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
|
|
||||||
public interface IBlockableConnection
|
|
||||||
{
|
|
||||||
public boolean isBlockedOnSide(ForgeDirection side);
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@ import codechicken.lib.vec.Vector3;
|
||||||
import codechicken.multipart.JItemMultiPart;
|
import codechicken.multipart.JItemMultiPart;
|
||||||
import codechicken.multipart.MultiPartRegistry;
|
import codechicken.multipart.MultiPartRegistry;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
|
import codechicken.multipart.TileMultipart;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderBlocks;
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
@ -203,6 +204,8 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
updateExternalConnections();
|
updateExternalConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.recalculateConnections();
|
||||||
|
this.getNetwork().reconstruct();
|
||||||
tile().markDirty();
|
tile().markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,6 +225,27 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
sendConnUpdate();
|
sendConnUpdate();
|
||||||
|
this.recalculateConnections();
|
||||||
|
this.getNetwork().reconstruct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPartChanged(TMultiPart part)
|
||||||
|
{
|
||||||
|
if (!world().isRemote)
|
||||||
|
{
|
||||||
|
boolean changed = updateInternalConnections();
|
||||||
|
if (updateOpenConnections())
|
||||||
|
{
|
||||||
|
changed |= updateExternalConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
sendConnUpdate();
|
||||||
|
this.recalculateConnections();
|
||||||
this.getNetwork().reconstruct();
|
this.getNetwork().reconstruct();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,11 +264,33 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
if (updateExternalConnections())
|
if (updateExternalConnections())
|
||||||
{
|
{
|
||||||
sendConnUpdate();
|
sendConnUpdate();
|
||||||
|
this.recalculateConnections();
|
||||||
this.getNetwork().reconstruct();
|
this.getNetwork().reconstruct();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
|
||||||
|
{
|
||||||
|
if (!world().isRemote)
|
||||||
|
{
|
||||||
|
System.out.println(this.getNetwork());
|
||||||
|
System.out.println(Integer.toHexString(this.connMap));
|
||||||
|
}
|
||||||
|
return super.activate(player, part, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recalculateConnections()
|
||||||
|
{
|
||||||
|
this.cachedConnections = new Object[4];
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canStay()
|
public boolean canStay()
|
||||||
{
|
{
|
||||||
BlockCoord pos = new BlockCoord(tile()).offset(side);
|
BlockCoord pos = new BlockCoord(tile()).offset(side);
|
||||||
|
@ -278,12 +324,10 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
|
|
||||||
for (int r = 0; r < 4; r++)
|
for (int r = 0; r < 4; r++)
|
||||||
{
|
{
|
||||||
/*
|
if (!maskOpen(r))
|
||||||
* if (!maskOpen(r))
|
{
|
||||||
* {
|
continue;
|
||||||
* continue;
|
}
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (connectStraight(r))
|
if (connectStraight(r))
|
||||||
{
|
{
|
||||||
|
@ -292,27 +336,36 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int cnrMode = connectCorner(r);
|
int cnrMode = connectCorner(r);
|
||||||
|
|
||||||
if (cnrMode != 0)
|
if (cnrMode != 0)
|
||||||
{
|
{
|
||||||
newConn |= 1 << r;
|
newConn |= 1 << r;
|
||||||
|
|
||||||
if (cnrMode == 2)
|
if (cnrMode == 2)
|
||||||
|
{
|
||||||
newConn |= 0x100000 << r;// render flag
|
newConn |= 0x100000 << r;// render flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (newConn != (connMap & 0xF000FF))
|
if (newConn != (connMap & 0xF000FF))
|
||||||
{
|
{
|
||||||
int diff = connMap ^ newConn;
|
int diff = connMap ^ newConn;
|
||||||
connMap = connMap & ~0xF000FF | newConn;
|
connMap = connMap & ~0xF000FF | newConn;
|
||||||
|
|
||||||
// notify corner disconnections
|
// Notify corner disconnections
|
||||||
for (int r = 0; r < 4; r++)
|
for (int r = 0; r < 4; r++)
|
||||||
|
{
|
||||||
if ((diff & 1 << r) != 0)
|
if ((diff & 1 << r) != 0)
|
||||||
|
{
|
||||||
notifyCornerChange(r);
|
notifyCornerChange(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,14 +447,17 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
if (t != null)
|
if (t != null)
|
||||||
{
|
{
|
||||||
TMultiPart tp = t.partMap(absDir ^ 1);
|
TMultiPart tp = t.partMap(absDir ^ 1);
|
||||||
if (tp instanceof IAdvancedConductor)
|
|
||||||
|
if (tp instanceof FlatWire)
|
||||||
{
|
{
|
||||||
boolean b = ((FlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1));
|
boolean b = ((FlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1));
|
||||||
if (b)
|
if (b)
|
||||||
{
|
{
|
||||||
// let them connect to us
|
// let them connect to us
|
||||||
if (tp instanceof FlatWire && !renderThisCorner((FlatWire) tp))
|
if (tp instanceof FlatWire && !renderThisCorner((FlatWire) tp))
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -413,11 +469,15 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
public boolean canConnectThroughCorner(BlockCoord pos, int side1, int side2)
|
public boolean canConnectThroughCorner(BlockCoord pos, int side1, int side2)
|
||||||
{
|
{
|
||||||
if (world().isAirBlock(pos.x, pos.y, pos.z))
|
if (world().isAirBlock(pos.x, pos.y, pos.z))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
TileMultipart t = Utility.getMultipartTile(world(), pos);
|
TileMultipart t = Utility.getMultipartTile(world(), pos);
|
||||||
if (t != null)
|
if (t != null)
|
||||||
|
{
|
||||||
return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null;
|
return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -431,9 +491,12 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
if (t != null)
|
if (t != null)
|
||||||
{
|
{
|
||||||
TMultiPart tp = t.partMap(side);
|
TMultiPart tp = t.partMap(side);
|
||||||
|
|
||||||
if (tp instanceof FlatWire)
|
if (tp instanceof FlatWire)
|
||||||
|
{
|
||||||
return ((FlatWire) tp).connectStraight(this, (r + 2) % 4);
|
return ((FlatWire) tp).connectStraight(this, (r + 2) % 4);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return connectStraightOverride(absDir);
|
return connectStraightOverride(absDir);
|
||||||
}
|
}
|
||||||
|
@ -451,8 +514,11 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TMultiPart tp = tile().partMap(absDir);
|
TMultiPart tp = tile().partMap(absDir);
|
||||||
|
|
||||||
if (tp instanceof FlatWire)
|
if (tp instanceof FlatWire)
|
||||||
|
{
|
||||||
return ((FlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side));
|
return ((FlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side));
|
||||||
|
}
|
||||||
|
|
||||||
return connectInternalOverride(tp, r);
|
return connectInternalOverride(tp, r);
|
||||||
}
|
}
|
||||||
|
@ -465,8 +531,11 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
public boolean connectCenter()
|
public boolean connectCenter()
|
||||||
{
|
{
|
||||||
TMultiPart t = tile().partMap(6);
|
TMultiPart t = tile().partMap(6);
|
||||||
|
|
||||||
if (t instanceof FlatWire)
|
if (t instanceof FlatWire)
|
||||||
|
{
|
||||||
return ((FlatWire) t).connectInternal(this, side);
|
return ((FlatWire) t).connectInternal(this, side);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -566,7 +635,7 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
@Override
|
@Override
|
||||||
public int getSlotMask()
|
public int getSlotMask()
|
||||||
{
|
{
|
||||||
return 1 << side;
|
return 1 << this.side;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -589,7 +658,7 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
|
||||||
|
|
||||||
public int getThickness()
|
public int getThickness()
|
||||||
{
|
{
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,9 +37,9 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
|
||||||
@Override
|
@Override
|
||||||
public IEnergyNetwork getNetwork()
|
public IEnergyNetwork getNetwork()
|
||||||
{
|
{
|
||||||
if (this.network == null && tile() instanceof IConductor)
|
if (this.network == null)
|
||||||
{
|
{
|
||||||
setNetwork(EnergyNetworkLoader.getNewNetwork(this));
|
this.setNetwork(EnergyNetworkLoader.getNewNetwork(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.network;
|
return this.network;
|
||||||
|
@ -93,4 +93,6 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
|
||||||
|
|
||||||
public abstract boolean canConnect(IConductor conductor);
|
public abstract boolean canConnect(IConductor conductor);
|
||||||
|
|
||||||
|
public abstract boolean isBlockedOnSide(ForgeDirection side);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import resonantinduction.wire.EnumWireMaterial;
|
import resonantinduction.wire.EnumWireMaterial;
|
||||||
import resonantinduction.wire.IAdvancedConductor;
|
import resonantinduction.wire.IAdvancedConductor;
|
||||||
import resonantinduction.wire.IBlockableConnection;
|
|
||||||
import universalelectricity.api.energy.IConductor;
|
import universalelectricity.api.energy.IConductor;
|
||||||
import codechicken.lib.data.MCDataInput;
|
import codechicken.lib.data.MCDataInput;
|
||||||
import codechicken.lib.data.MCDataOutput;
|
import codechicken.lib.data.MCDataOutput;
|
||||||
|
@ -23,7 +22,7 @@ import codechicken.lib.data.MCDataOutput;
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class PartWireBase extends PartConductor implements IBlockableConnection
|
public abstract class PartWireBase extends PartConductor
|
||||||
{
|
{
|
||||||
public static final int DEFAULT_COLOR = 16;
|
public static final int DEFAULT_COLOR = 16;
|
||||||
public int dyeID = DEFAULT_COLOR;
|
public int dyeID = DEFAULT_COLOR;
|
||||||
|
@ -162,9 +161,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!world().isRemote)
|
|
||||||
System.out.println(this.getNetwork());
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
104
src/resonantinduction/wire/part/TraitConductor.java
Normal file
104
src/resonantinduction/wire/part/TraitConductor.java
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
package resonantinduction.wire.part;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
import universalelectricity.api.energy.IConductor;
|
||||||
|
import universalelectricity.api.energy.IEnergyNetwork;
|
||||||
|
import codechicken.multipart.TMultiPart;
|
||||||
|
import codechicken.multipart.TileMultipart;
|
||||||
|
|
||||||
|
public class TraitConductor extends TileMultipart implements IConductor
|
||||||
|
{
|
||||||
|
public Set<IConductor> interfaces = new HashSet<IConductor>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copyFrom(TileMultipart that)
|
||||||
|
{
|
||||||
|
super.copyFrom(that);
|
||||||
|
|
||||||
|
if (that instanceof TraitConductor)
|
||||||
|
{
|
||||||
|
this.interfaces = ((TraitConductor) that).interfaces;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindPart(TMultiPart part)
|
||||||
|
{
|
||||||
|
super.bindPart(part);
|
||||||
|
|
||||||
|
if (part instanceof IConductor)
|
||||||
|
{
|
||||||
|
this.interfaces.add((IConductor) part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void partRemoved(TMultiPart part, int p)
|
||||||
|
{
|
||||||
|
super.partRemoved(part, p);
|
||||||
|
|
||||||
|
if (part instanceof IConductor)
|
||||||
|
{
|
||||||
|
this.interfaces.remove(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearParts()
|
||||||
|
{
|
||||||
|
super.clearParts();
|
||||||
|
this.interfaces.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] getConnections()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEnergyNetwork getNetwork()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNetwork(IEnergyNetwork network)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canConnect(ForgeDirection direction)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getEnergyLoss()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getEnergyCapacitance()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package resonantinduction.wire;
|
package resonantinduction.wire.part;
|
||||||
|
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
import ic2.api.energy.tile.IEnergySink;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeDirection;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
import codechicken.multipart.TileMultipart;
|
import codechicken.multipart.TileMultipart;
|
||||||
|
|
||||||
public class TEnergySink extends TileMultipart implements IEnergySink
|
public class TraitEnergySink extends TileMultipart implements IEnergySink
|
||||||
{
|
{
|
||||||
public Set<IEnergySink> ic2Sinks = new HashSet<IEnergySink>();
|
public Set<IEnergySink> ic2Sinks = new HashSet<IEnergySink>();
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@ public class TEnergySink extends TileMultipart implements IEnergySink
|
||||||
{
|
{
|
||||||
super.copyFrom(that);
|
super.copyFrom(that);
|
||||||
|
|
||||||
if(that instanceof TEnergySink)
|
if(that instanceof TraitEnergySink)
|
||||||
{
|
{
|
||||||
ic2Sinks = ((TEnergySink)that).ic2Sinks;
|
ic2Sinks = ((TraitEnergySink)that).ic2Sinks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue