diff --git a/src/resonantinduction/MultipartRI.java b/src/resonantinduction/MultipartRI.java index 1282f527a..389e79b77 100644 --- a/src/resonantinduction/MultipartRI.java +++ b/src/resonantinduction/MultipartRI.java @@ -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"); } } diff --git a/src/resonantinduction/wire/multipart/javatraits/TEnergySink.java b/src/resonantinduction/wire/multipart/javatraits/TEnergySink.java new file mode 100644 index 000000000..ba5c023d3 --- /dev/null +++ b/src/resonantinduction/wire/multipart/javatraits/TEnergySink.java @@ -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 ic2Sinks = new HashSet(); + + @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; + } + +}