Started working on IC2 Trait
This commit is contained in:
parent
1369a9af98
commit
415a187b0c
5 changed files with 87 additions and 36 deletions
|
@ -16,7 +16,7 @@ public class MultipartRI implements IPartFactory
|
|||
{
|
||||
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire", "resonant_induction_multimeter", "resonant_induction_transformer" });
|
||||
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor");
|
||||
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
|
||||
//MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
package resonantinduction.wire.part;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import resonantinduction.base.PartAdvanced;
|
||||
import universalelectricity.api.CompatibilityModule;
|
||||
import universalelectricity.api.UniversalClass;
|
||||
import universalelectricity.api.energy.EnergyNetworkLoader;
|
||||
import universalelectricity.api.energy.IConductor;
|
||||
import universalelectricity.api.energy.IEnergyNetwork;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import universalelectricity.api.vector.VectorHelper;
|
||||
|
||||
//@UniversalClass
|
||||
@UniversalClass
|
||||
public abstract class PartConductor extends PartAdvanced implements IConductor
|
||||
{
|
||||
private IEnergyNetwork network;
|
||||
|
@ -112,4 +117,25 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IC2 Functions
|
||||
*/
|
||||
@Override
|
||||
public void onWorldJoin()
|
||||
{
|
||||
if (tile() instanceof IEnergyTile)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldSeparate()
|
||||
{
|
||||
if (tile() instanceof IEnergyTile)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,6 +215,8 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
|
|||
}
|
||||
|
||||
this.recalculateConnections();
|
||||
|
||||
super.onChunkLoad();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -257,6 +259,8 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
|
|||
|
||||
this.recalculateConnections();
|
||||
}
|
||||
|
||||
super.onPartChanged(part);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -276,6 +280,7 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
|
|||
|
||||
this.recalculateConnections();
|
||||
}
|
||||
super.onNeighborChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TraitConductor extends TileMultipart implements IConductor
|
|||
{
|
||||
for (IConductor conductor : this.interfaces)
|
||||
{
|
||||
if (conductor.canConnect(direction))
|
||||
if (conductor.canConnect(direction.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import ic2.api.energy.tile.IEnergySink;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import universalelectricity.api.CompatibilityType;
|
||||
import universalelectricity.api.energy.IConductor;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
@ -12,16 +14,16 @@ import codechicken.multipart.TileMultipart;
|
|||
|
||||
public class TraitEnergySink extends TileMultipart implements IEnergySink
|
||||
{
|
||||
public Set<IEnergySink> ic2Sinks = new HashSet<IEnergySink>();
|
||||
public Set<IConductor> interfaces = new HashSet<IConductor>();
|
||||
|
||||
@Override
|
||||
public void copyFrom(TileMultipart that)
|
||||
{
|
||||
super.copyFrom(that);
|
||||
|
||||
if(that instanceof TraitEnergySink)
|
||||
if (that instanceof TraitConductor)
|
||||
{
|
||||
ic2Sinks = ((TraitEnergySink)that).ic2Sinks;
|
||||
this.interfaces = ((TraitConductor) that).interfaces;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,9 +32,9 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
|
|||
{
|
||||
super.bindPart(part);
|
||||
|
||||
if(part instanceof IEnergySink)
|
||||
if (part instanceof IConductor)
|
||||
{
|
||||
ic2Sinks.add((IEnergySink) part);
|
||||
this.interfaces.add((IConductor) part);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,9 +43,9 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
|
|||
{
|
||||
super.partRemoved(part, p);
|
||||
|
||||
if(part instanceof IEnergySink)
|
||||
if (part instanceof IConductor)
|
||||
{
|
||||
ic2Sinks.remove(part);
|
||||
this.interfaces.remove(part);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,18 +53,25 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
|
|||
public void clearParts()
|
||||
{
|
||||
super.clearParts();
|
||||
|
||||
ic2Sinks.clear();
|
||||
this.interfaces.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection from)
|
||||
{
|
||||
for(IEnergySink sink : ic2Sinks)
|
||||
if (this.partMap(from.ordinal()) == null)
|
||||
{
|
||||
if(sink.acceptsEnergyFrom(emitter, direction))
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
return true;
|
||||
if (dir != from.getOpposite())
|
||||
{
|
||||
TMultiPart part = this.partMap(dir.ordinal());
|
||||
|
||||
if (this.interfaces.contains(part))
|
||||
{
|
||||
return ((IConductor) part).canConnect(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,36 +83,47 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
|
|||
{
|
||||
double demanded = 0;
|
||||
|
||||
for(IEnergySink sink : ic2Sinks)
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
demanded += sink.demandedEnergyUnits();
|
||||
TMultiPart part = this.partMap(dir.ordinal());
|
||||
|
||||
if (this.interfaces.contains(part))
|
||||
{
|
||||
return ((IConductor) part).onReceiveEnergy(ForgeDirection.UNKNOWN, Integer.MAX_VALUE, false) * CompatibilityType.INDUSTRIALCRAFT.ratio;
|
||||
}
|
||||
}
|
||||
|
||||
return demanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
||||
public double injectEnergyUnits(ForgeDirection from, double amount)
|
||||
{
|
||||
for(IEnergySink sink : ic2Sinks)
|
||||
double consumed = 0;
|
||||
|
||||
if (this.partMap(from.ordinal()) == null)
|
||||
{
|
||||
amount = sink.injectEnergyUnits(directionFrom, Math.min(amount, sink.demandedEnergyUnits()));
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (dir != from.getOpposite())
|
||||
{
|
||||
TMultiPart part = this.partMap(dir.ordinal());
|
||||
|
||||
if (this.interfaces.contains(part))
|
||||
{
|
||||
consumed = ((IConductor) part).onReceiveEnergy(from, (long) (amount * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio), true) * CompatibilityType.INDUSTRIALCRAFT.ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return amount;
|
||||
return amount - consumed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
int safe = 0;
|
||||
|
||||
for(IEnergySink sink : ic2Sinks)
|
||||
{
|
||||
safe += sink.getMaxSafeInput();
|
||||
}
|
||||
|
||||
return safe;
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue