Got multipart interface passthrough working

This commit is contained in:
Calclavia 2013-12-21 23:59:18 +08:00
parent 405d1450b3
commit 635ed87a6e
10 changed files with 111 additions and 134 deletions

@ -1 +1 @@
Subproject commit ac3604f037fda53e100a34dc7b61b524f5ec3e0e
Subproject commit 1bc4a8bf21e124ca5f650d1d9da86a2962a71747

View file

@ -1,11 +1,9 @@
package resonantinduction;
import buildcraft.api.power.IPowerReceptor;
import resonantinduction.wire.IAdvancedConductor;
import resonantinduction.wire.IBlockableConnection;
import resonantinduction.wire.IInsulatedMaterial;
import resonantinduction.wire.part.PartFlatWire;
import resonantinduction.wire.part.PartWire;
import universalelectricity.api.energy.IConductor;
import buildcraft.api.power.IPowerReceptor;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator;
@ -17,10 +15,9 @@ public class MultipartRI implements IPartFactory
public MultipartRI()
{
MultiPartRegistry.registerParts(this, new String[] {/* "resonant_induction_wire",*/ "resonant_induction_flat_wire" });
MultipartGenerator.registerPassThroughInterface(IConductor.class.getName());
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" });
MultipartGenerator.registerPassThroughInterface(IAdvancedConductor.class.getName());
MultipartGenerator.registerPassThroughInterface(IPowerReceptor.class.getName());
MultipartGenerator.registerPassThroughInterface(IInsulatedMaterial.class.getName());
MultipartGenerator.registerPassThroughInterface(IBlockableConnection.class.getName());
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.TEnergySink");
}
@ -28,11 +25,6 @@ public class MultipartRI implements IPartFactory
@Override
public TMultiPart createPart(String name, boolean client)
{
/*if (name.equals("resonant_induction_wire"))
{
return new PartWire();
}
else */
if (name.equals("resonant_induction_flat_wire"))
{
return new PartFlatWire();

View file

@ -34,9 +34,9 @@ public class MultimeterEventHandler
{
IEnergyNetwork network = evt.network;
if (network.getDistribution(null) != 0)
if (network.getLastBuffer() != 0)
{
networkEnergyCache.put(network, network.getDistribution(null));
networkEnergyCache.put(network, network.getLastBuffer());
}
}
}

View file

@ -0,0 +1,27 @@
package resonantinduction.wire;
import universalelectricity.api.energy.IConductor;
/**
* A connector for {EnergyNetwork}.
*
* @author Calclavia
*
*/
public interface IAdvancedConductor extends IConductor
{
/**
* The insulatation methods.
*
* @return
*/
public boolean isInsulated();
public void setInsulated(boolean insulated);
public int getInsulationColor();
public void setInsulationColor(int dye);
public EnumWireMaterial getMaterial();
}

View file

@ -1,6 +0,0 @@
package resonantinduction.wire;
public interface IInsulatedMaterial extends IInsulation, IWireMaterial
{
}

View file

@ -1,12 +0,0 @@
package resonantinduction.wire;
public interface IInsulation
{
public boolean isInsulated();
public void setInsulated(boolean insulated);
public int getInsulationColor();
public void setInsulationColor(int dye);
}

View file

@ -1,6 +0,0 @@
package resonantinduction.wire;
public interface IWireMaterial
{
public EnumWireMaterial getMaterial();
}

View file

@ -4,10 +4,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.base.PartAdvanced;
import universalelectricity.api.UniversalClass;
import resonantinduction.wire.IAdvancedConductor;
import universalelectricity.api.energy.EnergyNetworkLoader;
import universalelectricity.api.energy.IConductor;
import universalelectricity.api.energy.IEnergyInterface;
import universalelectricity.api.energy.IEnergyNetwork;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
@ -15,57 +14,44 @@ import calclavia.lib.tile.EnergyStorage;
import codechicken.multipart.TileMultipart;
//@UniversalClass
public abstract class PartConductor extends PartAdvanced implements IConductor
public abstract class PartConductor extends PartAdvanced implements IAdvancedConductor
{
private IEnergyNetwork network;
private EnergyStorage buffer = new EnergyStorage(ResonantInduction.FURNACE_WATTAGE * 5);
public TileEntity[] cachedConnections = null;
public byte currentWireConnections = 0x00;
public byte currentAcceptorConnections = 0x00;
/**
* Universal Electricity conductor functions.
*/
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
return this.buffer.receiveEnergy(receive, doReceive);
return this.getNetwork().produce(receive);
}
@Override
public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract)
{
return this.buffer.extractEnergy(request, doExtract);
return 0;
}
@Override
public void distribute()
public IEnergyNetwork getNetwork()
{
Object[] receivers = this.getConnections();
int energyUsed = 0;
for (int i = 0; i < receivers.length; i++)
if (this.network == null && tile() instanceof IAdvancedConductor)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
Object receiver = receivers[i];
if (receiver instanceof IEnergyInterface && !(receiver instanceof IConductor))
{
energyUsed += ((IEnergyInterface) receiver).onReceiveEnergy(direction.getOpposite(), this.getNetwork().getDistribution(this), true);
}
setNetwork(EnergyNetworkLoader.getNewNetwork((IConductor) tile()));
}
this.buffer.extractEnergy(energyUsed, true);
return network;
}
@Override
public int getEnergyLoss()
public void setNetwork(IEnergyNetwork network)
{
return 0;
}
@Override
public int getEnergyCapacitance()
{
return 0;
this.network = network;
}
public byte getAllCurrentConnections()
@ -92,7 +78,7 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
{
getNetwork().getConnectors().remove(tile());
super.bind(t);
getNetwork().getConnectors().add((IConductor) tile());
getNetwork().getConnectors().add((IAdvancedConductor) tile());
}
else
{
@ -103,9 +89,9 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override
public void preRemove()
{
if (!world().isRemote && tile() instanceof IConductor)
if (!world().isRemote && tile() instanceof IAdvancedConductor)
{
getNetwork().split((IConductor) tile());
getNetwork().split((IAdvancedConductor) tile());
}
super.preRemove();
@ -117,35 +103,18 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
return false;
}
@Override
public IEnergyNetwork getNetwork()
{
if (network == null && tile() instanceof IConductor)
{
setNetwork(EnergyNetworkLoader.getNewNetwork((IConductor) tile()));
}
return network;
}
public boolean canConnectBothSides(TileEntity tile, ForgeDirection side)
{
boolean notPrevented = !isConnectionPrevented(tile, side);
if (tile instanceof IConductor)
if (tile instanceof IAdvancedConductor)
{
notPrevented &= ((IConductor) tile).canConnect(side.getOpposite());
notPrevented &= ((IAdvancedConductor) tile).canConnect(side.getOpposite());
}
return notPrevented;
}
@Override
public void setNetwork(IEnergyNetwork net)
{
network = net;
}
/**
* Override if there are ways of preventing a connection
*
@ -165,9 +134,9 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
System.out.println("WORK"+tileEntity + " : "+(tileEntity instanceof IConductor));
System.out.println("WORK" + tileEntity + " : " + (tileEntity instanceof IAdvancedConductor));
if (tileEntity instanceof IConductor && canConnectBothSides(tileEntity, side))
if (tileEntity instanceof IAdvancedConductor && canConnectBothSides(tileEntity, side))
{
connections |= 1 << side.ordinal();
}
@ -198,7 +167,7 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
*/
public boolean isValidAcceptor(TileEntity tile)
{
return tile instanceof IConductor;
return tile instanceof IAdvancedConductor;
}
public void refresh()
@ -227,9 +196,9 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
{
TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side);
if (tileEntity instanceof IConductor)
if (tileEntity instanceof IAdvancedConductor)
{
getNetwork().merge(((IConductor) tileEntity).getNetwork());
getNetwork().merge(((IAdvancedConductor) tileEntity).getNetwork());
}
}
}

View file

@ -13,9 +13,9 @@ import org.lwjgl.opengl.GL11;
import resonantinduction.Utility;
import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.IAdvancedConductor;
import resonantinduction.wire.render.RenderLainWire;
import resonantinduction.wire.render.RenderPartWire;
import universalelectricity.api.energy.IConductor;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.lighting.LazyLightMatrix;
@ -44,7 +44,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* @author Modified by Calclavia, MrTJP
*
*/
public class PartFlatWire extends PartWireBase implements IConductor, TFacePart, JNormalOcclusion
public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOcclusion
{
public static Cuboid6[][] selectionBounds = new Cuboid6[3][6];
public static Cuboid6[][] occlusionBounds = new Cuboid6[3][6];
@ -53,7 +53,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
{
for (int t = 0; t < 3; t++)
{
// subtract the box a little because we'd like things like posts to get first hit
// Subtract the box a little because we'd like things like posts to get first hit
Cuboid6 selection = new Cuboid6(0, 0, 0, 1, (t + 2) / 16D, 1).expand(-0.005);
Cuboid6 occlusion = new Cuboid6(2 / 8D, 0, 2 / 8D, 6 / 8D, (t + 2) / 16D, 6 / 8D);
for (int s = 0; s < 6; s++)
@ -118,24 +118,24 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
public void save(NBTTagCompound tag)
{
super.save(tag);
tag.setByte("side", side);
tag.setInteger("connMap", connMap);
tag.setByte("side", this.side);
tag.setInteger("connMap", this.connMap);
}
@Override
public void readDesc(MCDataInput packet)
{
super.readDesc(packet);
/*this.side = packet.readByte();
this.connMap = packet.readInt();*/
// super.readDesc(packet);
this.side = packet.readByte();
this.connMap = packet.readInt();
}
@Override
public void writeDesc(MCDataOutput packet)
{
super.writeDesc(packet);
/*packet.writeByte(this.side);
packet.writeInt(this.connMap);*/
// super.writeDesc(packet);
packet.writeByte(this.side);
packet.writeInt(this.connMap);
}
@Override
@ -144,11 +144,11 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
read(packet, packet.readUByte());
}
public void read(MCDataInput packet, int switch_key)
public void read(MCDataInput packet, int packetID)
{
if (switch_key == 0)
if (packetID == 0)
{
connMap = packet.readInt();
this.connMap = packet.readInt();
tile().markRender();
}
}
@ -164,12 +164,22 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
super.onRemoved();
if (!world().isRemote)
{
for (int r = 0; r < 4; r++)
{
if (maskConnects(r))
{
if ((connMap & 1 << r) != 0)
{
notifyCornerChange(r);
}
else if ((connMap & 0x10 << r) != 0)
{
notifyStraightChange(r);
}
}
}
}
}
@Override
@ -332,7 +342,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
if (t != null)
{
TMultiPart tp = t.partMap(absDir ^ 1);
if (tp instanceof IConductor)
if (tp instanceof IAdvancedConductor)
{
boolean b = ((PartFlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1));
if (b)
@ -409,7 +419,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
return false;
}
public boolean renderThisCorner(IConductor part)
public boolean renderThisCorner(IAdvancedConductor part)
{
if (!(part instanceof PartFlatWire))
return false;
@ -421,7 +431,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
return wire.getThickness() > getThickness();
}
public boolean connectCorner(IConductor wire, int r)
public boolean connectCorner(IAdvancedConductor wire, int r)
{
if (canConnectToType(wire) && maskOpen(r))
{
@ -437,7 +447,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
return false;
}
public boolean connectStraight(IConductor wire, int r)
public boolean connectStraight(IAdvancedConductor wire, int r)
{
if (canConnectToType(wire) && maskOpen(r))
{
@ -450,7 +460,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
return false;
}
public boolean connectInternal(IConductor wire, int r)
public boolean connectInternal(IAdvancedConductor wire, int r)
{
if (canConnectToType(wire))
{
@ -494,11 +504,6 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
return (connMap & 0x1000 << r) != 0;
}
public boolean isWireSide(int side)
{
return true;
}
/** START TILEMULTIPART INTERACTIONS **/
@Override
public float getStrength(MovingObjectPosition hit, EntityPlayer player)
@ -575,7 +580,7 @@ public class PartFlatWire extends PartWireBase implements IConductor, TFacePart,
public boolean useStaticRenderer()
{
return true;
return false;
}
@Override

View file

@ -13,10 +13,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.IAdvancedConductor;
import resonantinduction.wire.IBlockableConnection;
import resonantinduction.wire.IInsulatedMaterial;
import resonantinduction.wire.IInsulation;
import resonantinduction.wire.IWireMaterial;
import universalelectricity.api.energy.IConductor;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
@ -25,18 +23,18 @@ import codechicken.lib.data.MCDataOutput;
* @author Calclavia
*
*/
public abstract class PartWireBase extends PartConductor implements IInsulatedMaterial, IBlockableConnection
public abstract class PartWireBase extends PartConductor implements IBlockableConnection
{
public static final int DEFAULT_COLOR = 16;
public int dyeID = DEFAULT_COLOR;
public EnumWireMaterial material = EnumWireMaterial.COPPER;
public boolean isInsulated = false;
public boolean canConnectToType(IConductor wire)
public boolean canConnectToType(Object wire)
{
if (wire instanceof IWireMaterial)
if (wire instanceof IAdvancedConductor)
{
IWireMaterial wireTile = (IWireMaterial) wire;
IAdvancedConductor wireTile = (IAdvancedConductor) wire;
if (wireTile.getMaterial() != getMaterial())
{
@ -44,9 +42,9 @@ public abstract class PartWireBase extends PartConductor implements IInsulatedMa
}
}
if (isInsulated() && wire instanceof IInsulation)
if (isInsulated() && wire instanceof IAdvancedConductor)
{
IInsulation insulatedTile = (IInsulation) wire;
IAdvancedConductor insulatedTile = (IAdvancedConductor) wire;
if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != getInsulationColor() && getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
{
@ -57,6 +55,21 @@ public abstract class PartWireBase extends PartConductor implements IInsulatedMa
return false;
}
@Override
public long getEnergyLoss()
{
/**
* TODO: FIX THIS!
*/
return (int) (this.getMaterial().resistance * 1000);
}
@Override
public long getEnergyCapacitance()
{
return this.getMaterial().maxAmps;
}
@Override
public EnumWireMaterial getMaterial()
{
@ -200,11 +213,6 @@ public abstract class PartWireBase extends PartConductor implements IInsulatedMa
this.isInsulated = packet.readBoolean();
this.currentWireConnections = packet.readByte();
this.currentAcceptorConnections = packet.readByte();
if (tile() != null)
{
tile().markRender();
}
}
@Override
@ -231,8 +239,8 @@ public abstract class PartWireBase extends PartConductor implements IInsulatedMa
{
super.load(nbt);
setMaterialFromID(nbt.getInteger("typeID"));
dyeID = nbt.getInteger("dyeID");
isInsulated = nbt.getBoolean("isInsulated");
this.isInsulated = nbt.getBoolean("isInsulated");
this.dyeID = nbt.getInteger("dyeID");
}
}