Of course IC2 would be awkward. Add a prewritten java trait as I don't think it's possible to make auto-generated ones not crash.

This commit is contained in:
Ben Spiers 2013-09-30 02:52:42 +01:00
parent 39b28888cd
commit a2d05d04ec
2 changed files with 93 additions and 1 deletions

View file

@ -21,10 +21,10 @@ public class MultipartRI implements IPartFactory
{
MultiPartRegistry.registerParts(this, new String[]{"resonant_induction_wire"});
MultipartGenerator.registerPassThroughInterface("universalelectricity.core.block.IConductor");
MultipartGenerator.registerPassThroughInterface("ic2.api.energy.tile.IEnergySink");
MultipartGenerator.registerPassThroughInterface("buildcraft.api.power.IPowerReceptor");
MultipartGenerator.registerPassThroughInterface("resonantinduction.wire.IInsulatedMaterial");
MultipartGenerator.registerPassThroughInterface("resonantinduction.wire.multipart.IBlockableConnection");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.multipart.javatraits.TEnergySink");
}
}

View file

@ -0,0 +1,92 @@
package resonantinduction.wire.multipart.javatraits;
import java.util.Set;
import java.util.HashSet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import ic2.api.energy.tile.IEnergySink;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class TEnergySink extends TileMultipart implements IEnergySink
{
public Set<IEnergySink> ic2Sinks = new HashSet<IEnergySink>();
@Override
public void copyFrom(TileMultipart that)
{
super.copyFrom(that);
if(that instanceof TEnergySink)
ic2Sinks = ((TEnergySink)that).ic2Sinks;
}
@Override
public void bindPart(TMultiPart part)
{
super.bindPart(part);
if(part instanceof IEnergySink)
ic2Sinks.add((IEnergySink)part);
}
@Override
public void partRemoved(TMultiPart part, int p)
{
super.partRemoved(part, p);
if(part instanceof IEnergySink)
ic2Sinks.remove((IEnergySink)part);
}
@Override
public void clearParts()
{
super.clearParts();
ic2Sinks.clear();
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
for (IEnergySink sink: this.ic2Sinks)
{
if (sink.acceptsEnergyFrom(emitter, direction))
return true;
}
return false;
}
@Override
public double demandedEnergyUnits()
{
double demanded = 0;
for (IEnergySink sink: this.ic2Sinks)
{
demanded += sink.demandedEnergyUnits();
}
return demanded;
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
for (IEnergySink sink: this.ic2Sinks)
{
amount = sink.injectEnergyUnits(directionFrom, Math.min(amount, sink.demandedEnergyUnits()));
}
return amount;
}
@Override
public int getMaxSafeInput()
{
int safe = 0;
for (IEnergySink sink: this.ic2Sinks)
{
safe += sink.getMaxSafeInput();
}
return safe;
}
}