Aded TE support to flat wires

This commit is contained in:
Calclavia 2013-12-24 14:20:16 +08:00
parent 415a187b0c
commit 18c9e3f94c
9 changed files with 165 additions and 48 deletions

@ -1 +1 @@
Subproject commit b53c78b488458354dc7f0cdb9421f19865458e24 Subproject commit d2034508e7de77a7b64905a0236a6356ad2a2478

View file

@ -67,8 +67,8 @@
<fileset dir="${dir.mcp}/reobf/minecraft"> <fileset dir="${dir.mcp}/reobf/minecraft">
<exclude name=".git/**"/> <exclude name=".git/**"/>
<exclude name="codechicken/**"/> <exclude name="codechicken/**"/>
<exclude name="universalelectricity/**"/> <exclude name="universalelectricity/compatibility/**"/>
<include name="universalelectricity/api/**"/> <exclude name="universalelectricity/core/**"/>
</fileset> </fileset>
<fileset dir="${dir.development}resources"> <fileset dir="${dir.development}resources">

View file

@ -16,7 +16,8 @@ public class MultipartRI implements IPartFactory
{ {
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire", "resonant_induction_multimeter", "resonant_induction_transformer" }); 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("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor");
//MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink"); MultipartGenerator.registerTrait("cofh.api.energy.IEnergyHandler", "resonantinduction.wire.part.TraitEnergyHandler");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink");
} }
@Override @Override

View file

@ -214,7 +214,7 @@ public class ResonantInduction
/** /**
* Set reference itemstacks * Set reference itemstacks
*/ */
TabRI.ITEMSTACK = new ItemStack(itemPartWire); TabRI.ITEMSTACK = new ItemStack(blockBattery);
for (EnumWireMaterial material : EnumWireMaterial.values()) for (EnumWireMaterial material : EnumWireMaterial.values())
{ {

View file

@ -17,15 +17,15 @@ import codechicken.lib.colour.ColourRGBA;
public enum EnumWireMaterial public enum EnumWireMaterial
{ {
/** Copper: General. */ /** Copper: General. */
COPPER("Copper", 1.68f, 5, 10, 184, 115, 51), COPPER("Copper", 1.68f, 5, 30, 184, 115, 51),
/** Tin: Low shock, cheap */ /** Tin: Low shock, cheap */
TIN("Tin", 11f, 1, 5, 132, 132, 130), TIN("Tin", 11f, 1, 15, 132, 132, 130),
/** Iron: High Capacity */ /** Iron: High Capacity */
IRON("Iron", 10f, 3, 80, 97, 102, 105), IRON("Iron", 10f, 3, 100, 97, 102, 105),
/** Aluminum: High Shock */ /** Aluminum: High Shock */
ALUMINUM("Aluminum", 2.82f, 10, 70, 215, 205, 181), ALUMINUM("Aluminum", 2.82f, 10, 80, 215, 205, 181),
/** Aluminum: Low Resistance */ /** Aluminum: Low Resistance */
SILVER("Silver", 1.59f, 5, 20, 192, 192, 192), SILVER("Silver", 1.59f, 5, 40, 192, 192, 192),
/** Superconductor: Over-powered */ /** Superconductor: Over-powered */
SUPERCONDUCTOR("Superconductor", 0, 10, 200, 255, 255, 1); SUPERCONDUCTOR("Superconductor", 0, 10, 200, 255, 255, 1);
@ -40,7 +40,7 @@ public enum EnumWireMaterial
{ {
this.name = name; this.name = name;
/** Multiply the realistic resistance by a factor for game balance. */ /** Multiply the realistic resistance by a factor for game balance. */
this.resistance = resistance * 2; this.resistance = resistance;
this.damage = electrocutionDamage; this.damage = electrocutionDamage;
this.maxAmps = maxAmps; this.maxAmps = maxAmps;
this.color = new ColourRGBA(r, g, b, 255); this.color = new ColourRGBA(r, g, b, 255);

View file

@ -124,7 +124,7 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public void onWorldJoin() public void onWorldJoin()
{ {
if (tile() instanceof IEnergyTile) if (tile() instanceof IEnergyTile && !world().isRemote)
{ {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile())); MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
} }
@ -133,7 +133,7 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
@Override @Override
public void onWorldSeparate() public void onWorldSeparate()
{ {
if (tile() instanceof IEnergyTile) if (tile() instanceof IEnergyTile && !world().isRemote)
{ {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile())); MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile()));
} }

View file

@ -12,7 +12,7 @@ import codechicken.multipart.TileMultipart;
public class TraitConductor extends TileMultipart implements IConductor public class TraitConductor extends TileMultipart implements IConductor
{ {
public Set<IConductor> interfaces = new HashSet<IConductor>(); public Set<IConductor> ueInterfaces = new HashSet<IConductor>();
@Override @Override
public void copyFrom(TileMultipart that) public void copyFrom(TileMultipart that)
@ -21,7 +21,7 @@ public class TraitConductor extends TileMultipart implements IConductor
if (that instanceof TraitConductor) if (that instanceof TraitConductor)
{ {
this.interfaces = ((TraitConductor) that).interfaces; this.ueInterfaces = ((TraitConductor) that).ueInterfaces;
} }
} }
@ -32,7 +32,7 @@ public class TraitConductor extends TileMultipart implements IConductor
if (part instanceof IConductor) if (part instanceof IConductor)
{ {
this.interfaces.add((IConductor) part); this.ueInterfaces.add((IConductor) part);
} }
} }
@ -43,7 +43,7 @@ public class TraitConductor extends TileMultipart implements IConductor
if (part instanceof IConductor) if (part instanceof IConductor)
{ {
this.interfaces.remove(part); this.ueInterfaces.remove(part);
} }
} }
@ -51,13 +51,13 @@ public class TraitConductor extends TileMultipart implements IConductor
public void clearParts() public void clearParts()
{ {
super.clearParts(); super.clearParts();
this.interfaces.clear(); this.ueInterfaces.clear();
} }
@Override @Override
public Object[] getConnections() public Object[] getConnections()
{ {
for (IConductor conductor : this.interfaces) for (IConductor conductor : this.ueInterfaces)
{ {
return conductor.getConnections(); return conductor.getConnections();
} }
@ -68,7 +68,7 @@ public class TraitConductor extends TileMultipart implements IConductor
@Override @Override
public IEnergyNetwork getNetwork() public IEnergyNetwork getNetwork()
{ {
for (IConductor conductor : this.interfaces) for (IConductor conductor : this.ueInterfaces)
{ {
return conductor.getNetwork(); return conductor.getNetwork();
} }
@ -79,7 +79,7 @@ public class TraitConductor extends TileMultipart implements IConductor
@Override @Override
public void setNetwork(IEnergyNetwork network) public void setNetwork(IEnergyNetwork network)
{ {
for (IConductor conductor : this.interfaces) for (IConductor conductor : this.ueInterfaces)
{ {
conductor.setNetwork(network); conductor.setNetwork(network);
} }
@ -88,7 +88,7 @@ public class TraitConductor extends TileMultipart implements IConductor
@Override @Override
public boolean canConnect(ForgeDirection direction) public boolean canConnect(ForgeDirection direction)
{ {
for (IConductor conductor : this.interfaces) for (IConductor conductor : this.ueInterfaces)
{ {
if (conductor.canConnect(direction.getOpposite())) if (conductor.canConnect(direction.getOpposite()))
{ {
@ -113,7 +113,7 @@ public class TraitConductor extends TileMultipart implements IConductor
{ {
TMultiPart part = this.partMap(dir.ordinal()); TMultiPart part = this.partMap(dir.ordinal());
if (this.interfaces.contains(part)) if (this.ueInterfaces.contains(part))
{ {
return ((IConductor) part).onReceiveEnergy(from, receive, doReceive); return ((IConductor) part).onReceiveEnergy(from, receive, doReceive);
} }
@ -135,14 +135,14 @@ public class TraitConductor extends TileMultipart implements IConductor
{ {
long energyLoss = 0; long energyLoss = 0;
if (this.interfaces.size() > 0) if (this.ueInterfaces.size() > 0)
{ {
for (IConductor conductor : this.interfaces) for (IConductor conductor : this.ueInterfaces)
{ {
energyLoss += conductor.getResistance(); energyLoss += conductor.getResistance();
} }
energyLoss /= this.interfaces.size(); energyLoss /= this.ueInterfaces.size();
} }
return energyLoss; return energyLoss;
@ -153,14 +153,14 @@ public class TraitConductor extends TileMultipart implements IConductor
{ {
long capacitance = 0; long capacitance = 0;
if (this.interfaces.size() > 0) if (this.ueInterfaces.size() > 0)
{ {
for (IConductor conductor : this.interfaces) for (IConductor conductor : this.ueInterfaces)
{ {
capacitance += conductor.getTransferCapacity(); capacitance += conductor.getTransferCapacity();
} }
capacitance /= this.interfaces.size(); capacitance /= this.ueInterfaces.size();
} }
return capacitance; return capacitance;

View file

@ -0,0 +1,120 @@
package resonantinduction.wire.part;
import java.util.HashSet;
import java.util.Set;
import net.minecraftforge.common.ForgeDirection;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import cofh.api.energy.IEnergyHandler;
public class TraitEnergyHandler extends TileMultipart implements IEnergyHandler
{
public Set<IEnergyHandler> teInterfaces = new HashSet<IEnergyHandler>();
@Override
public void copyFrom(TileMultipart that)
{
super.copyFrom(that);
if (that instanceof TraitEnergyHandler)
{
this.teInterfaces = ((TraitEnergyHandler) that).teInterfaces;
}
}
@Override
public void bindPart(TMultiPart part)
{
super.bindPart(part);
if (part instanceof IEnergyHandler)
{
this.teInterfaces.add((IEnergyHandler) part);
}
}
@Override
public void partRemoved(TMultiPart part, int p)
{
super.partRemoved(part, p);
if (part instanceof IEnergyHandler)
{
this.teInterfaces.remove(part);
}
}
@Override
public void clearParts()
{
super.clearParts();
this.teInterfaces.clear();
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
{
/**
* Try out different sides to try to inject energy into.
*/
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.teInterfaces.contains(part))
{
return ((IEnergyHandler) part).receiveEnergy(from, maxReceive, simulate);
}
}
}
}
return 0;
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
{
return 0;
}
@Override
public boolean canInterface(ForgeDirection from)
{
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.teInterfaces.contains(part))
{
return ((IEnergyHandler) part).canInterface(from);
}
}
}
}
return false;
}
@Override
public int getEnergyStored(ForgeDirection from)
{
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection from)
{
return 0;
}
}

View file

@ -5,8 +5,6 @@ import ic2.api.energy.tile.IEnergySink;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import universalelectricity.api.CompatibilityType;
import universalelectricity.api.energy.IConductor;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import codechicken.multipart.TMultiPart; import codechicken.multipart.TMultiPart;
@ -14,16 +12,16 @@ import codechicken.multipart.TileMultipart;
public class TraitEnergySink extends TileMultipart implements IEnergySink public class TraitEnergySink extends TileMultipart implements IEnergySink
{ {
public Set<IConductor> interfaces = new HashSet<IConductor>(); public Set<IEnergySink> icInterfaces = new HashSet<IEnergySink>();
@Override @Override
public void copyFrom(TileMultipart that) public void copyFrom(TileMultipart that)
{ {
super.copyFrom(that); super.copyFrom(that);
if (that instanceof TraitConductor) if (that instanceof TraitEnergySink)
{ {
this.interfaces = ((TraitConductor) that).interfaces; this.icInterfaces = ((TraitEnergySink) that).icInterfaces;
} }
} }
@ -32,9 +30,9 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
{ {
super.bindPart(part); super.bindPart(part);
if (part instanceof IConductor) if (part instanceof IEnergySink)
{ {
this.interfaces.add((IConductor) part); this.icInterfaces.add((IEnergySink) part);
} }
} }
@ -43,9 +41,9 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
{ {
super.partRemoved(part, p); super.partRemoved(part, p);
if (part instanceof IConductor) if (part instanceof IEnergySink)
{ {
this.interfaces.remove(part); this.icInterfaces.remove(part);
} }
} }
@ -53,7 +51,7 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
public void clearParts() public void clearParts()
{ {
super.clearParts(); super.clearParts();
this.interfaces.clear(); this.icInterfaces.clear();
} }
@Override @Override
@ -67,9 +65,9 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
{ {
TMultiPart part = this.partMap(dir.ordinal()); TMultiPart part = this.partMap(dir.ordinal());
if (this.interfaces.contains(part)) if (this.icInterfaces.contains(part))
{ {
return ((IConductor) part).canConnect(from); return ((IEnergySink) part).acceptsEnergyFrom(emitter, from);
} }
} }
} }
@ -87,9 +85,9 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
{ {
TMultiPart part = this.partMap(dir.ordinal()); TMultiPart part = this.partMap(dir.ordinal());
if (this.interfaces.contains(part)) if (this.icInterfaces.contains(part))
{ {
return ((IConductor) part).onReceiveEnergy(ForgeDirection.UNKNOWN, Integer.MAX_VALUE, false) * CompatibilityType.INDUSTRIALCRAFT.ratio; return ((IEnergySink) part).demandedEnergyUnits();
} }
} }
@ -99,8 +97,6 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
@Override @Override
public double injectEnergyUnits(ForgeDirection from, double amount) public double injectEnergyUnits(ForgeDirection from, double amount)
{ {
double consumed = 0;
if (this.partMap(from.ordinal()) == null) if (this.partMap(from.ordinal()) == null)
{ {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
@ -109,15 +105,15 @@ public class TraitEnergySink extends TileMultipart implements IEnergySink
{ {
TMultiPart part = this.partMap(dir.ordinal()); TMultiPart part = this.partMap(dir.ordinal());
if (this.interfaces.contains(part)) if (this.icInterfaces.contains(part))
{ {
consumed = ((IConductor) part).onReceiveEnergy(from, (long) (amount * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio), true) * CompatibilityType.INDUSTRIALCRAFT.ratio; return ((IEnergySink) part).injectEnergyUnits(from, amount);
} }
} }
} }
} }
return amount - consumed; return amount;
} }
@Override @Override