Allowed multiple wires to be placed within one block

This commit is contained in:
Calclavia 2013-12-22 15:58:30 +08:00
parent b478e67025
commit 54ed10a33e
8 changed files with 197 additions and 37 deletions

View file

@ -1,9 +1,6 @@
package resonantinduction;
import resonantinduction.wire.IAdvancedConductor;
import resonantinduction.wire.IBlockableConnection;
import resonantinduction.wire.part.FlatWire;
import buildcraft.api.power.IPowerReceptor;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator;
@ -15,11 +12,10 @@ public class MultipartRI implements IPartFactory
public MultipartRI()
{
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" });
MultipartGenerator.registerPassThroughInterface(IAdvancedConductor.class.getName());
MultipartGenerator.registerPassThroughInterface(IPowerReceptor.class.getName());
MultipartGenerator.registerPassThroughInterface(IBlockableConnection.class.getName());
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.TEnergySink");
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" });
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor");
}
@Override

View file

@ -1,8 +0,0 @@
package resonantinduction.wire;
import net.minecraftforge.common.ForgeDirection;
public interface IBlockableConnection
{
public boolean isBlockedOnSide(ForgeDirection side);
}

View file

@ -22,6 +22,7 @@ import codechicken.lib.vec.Vector3;
import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

View file

@ -4,6 +4,7 @@ import java.util.Arrays;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
@ -203,6 +204,8 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
updateExternalConnections();
}
this.recalculateConnections();
this.getNetwork().reconstruct();
tile().markDirty();
}
}
@ -222,6 +225,27 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (changed)
{
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();
}
}
@ -240,11 +264,33 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (updateExternalConnections())
{
sendConnUpdate();
this.recalculateConnections();
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()
{
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++)
{
/*
* if (!maskOpen(r))
* {
* continue;
* }
*/
if (!maskOpen(r))
{
continue;
}
if (connectStraight(r))
{
@ -292,11 +336,15 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
else
{
int cnrMode = connectCorner(r);
if (cnrMode != 0)
{
newConn |= 1 << r;
if (cnrMode == 2)
{
newConn |= 0x100000 << r;// render flag
}
}
}
}
@ -306,13 +354,18 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
int diff = connMap ^ newConn;
connMap = connMap & ~0xF000FF | newConn;
// notify corner disconnections
// Notify corner disconnections
for (int r = 0; r < 4; r++)
{
if ((diff & 1 << r) != 0)
{
notifyCornerChange(r);
}
}
return true;
}
return false;
}
@ -394,14 +447,17 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (t != null)
{
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));
if (b)
{
// let them connect to us
if (tp instanceof FlatWire && !renderThisCorner((FlatWire) tp))
{
return 1;
}
return 2;
}
@ -413,11 +469,15 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
public boolean canConnectThroughCorner(BlockCoord pos, int side1, int side2)
{
if (world().isAirBlock(pos.x, pos.y, pos.z))
{
return true;
}
TileMultipart t = Utility.getMultipartTile(world(), pos);
if (t != null)
{
return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null;
}
return false;
}
@ -431,8 +491,11 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
if (t != null)
{
TMultiPart tp = t.partMap(side);
if (tp instanceof FlatWire)
{
return ((FlatWire) tp).connectStraight(this, (r + 2) % 4);
}
}
return connectStraightOverride(absDir);
@ -451,8 +514,11 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
return false;
TMultiPart tp = tile().partMap(absDir);
if (tp instanceof FlatWire)
{
return ((FlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side));
}
return connectInternalOverride(tp, r);
}
@ -465,8 +531,11 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
public boolean connectCenter()
{
TMultiPart t = tile().partMap(6);
if (t instanceof FlatWire)
{
return ((FlatWire) t).connectInternal(this, side);
}
return false;
}
@ -566,7 +635,7 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
@Override
public int getSlotMask()
{
return 1 << side;
return 1 << this.side;
}
@Override
@ -589,7 +658,7 @@ public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusio
public int getThickness()
{
return 1;
return 0;
}
@Override

View file

@ -37,9 +37,9 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
@Override
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;
@ -93,4 +93,6 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
public abstract boolean canConnect(IConductor conductor);
public abstract boolean isBlockedOnSide(ForgeDirection side);
}

View file

@ -14,7 +14,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.IAdvancedConductor;
import resonantinduction.wire.IBlockableConnection;
import universalelectricity.api.energy.IConductor;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
@ -23,7 +22,7 @@ import codechicken.lib.data.MCDataOutput;
* @author Calclavia
*
*/
public abstract class PartWireBase extends PartConductor implements IBlockableConnection
public abstract class PartWireBase extends PartConductor
{
public static final int DEFAULT_COLOR = 16;
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;
}

View 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;
}
}

View file

@ -1,4 +1,4 @@
package resonantinduction.wire;
package resonantinduction.wire.part;
import ic2.api.energy.tile.IEnergySink;
@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeDirection;
import codechicken.multipart.TMultiPart;
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>();
@ -19,9 +19,9 @@ public class TEnergySink extends TileMultipart implements IEnergySink
{
super.copyFrom(that);
if(that instanceof TEnergySink)
if(that instanceof TraitEnergySink)
{
ic2Sinks = ((TEnergySink)that).ic2Sinks;
ic2Sinks = ((TraitEnergySink)that).ic2Sinks;
}
}