Fixed register EnergyTileLoadEvent multiple times

This commit is contained in:
Calclavia 2013-12-24 16:18:16 +08:00
parent 5164f86590
commit 6df2b0421f
4 changed files with 47 additions and 16 deletions

View file

@ -24,14 +24,10 @@ public abstract class PartAdvanced extends TMultiPart
ticks++;
}
@Override
public void onAdded()
{
world().notifyBlocksOfNeighborChange(x(), y(), z(), ((Block)MultipartProxy.block()).blockID);
}
/**
* Called on the TileEntity's first tick.
*/
public void initiate() {}
public void initiate()
{
}
}

View file

@ -92,8 +92,8 @@ public class GuiMultimeter extends GuiContainerBase
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
super.drawGuiContainerBackgroundLayer(f, x, y);
int length = Math.min((int) (this.multimeter.getDetectedEnergy() / this.multimeter.getPeak()) * 115, 115);
this.drawTexturedModalRect(this.containerWidth + 14, this.containerHeight + 126 - length, 176, 115 - length, 6, length);
/*int length = Math.min((int) (this.multimeter.getDetectedEnergy() / this.multimeter.getPeak()) * 115, 115);
this.drawTexturedModalRect(this.containerWidth + 14, this.containerHeight + 126 - length, 176, 115 - length, 6, length);*/
}
@Override

View file

@ -226,12 +226,12 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
peakDetection = Math.max(peakDetection, detectedEnergy);
}
public float getDetectedEnergy()
public long getDetectedEnergy()
{
return detectedEnergy;
}
public float getAverageDetectedEnergy()
public long getAverageDetectedEnergy()
{
return detectedAverageEnergy;
}

View file

@ -1,5 +1,6 @@
package resonantinduction.wire.part;
import codechicken.multipart.TMultiPart;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyTile;
@ -114,10 +115,27 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
public void onWorldJoin()
{
if (tile() instanceof IEnergyTile && !world().isRemote)
{
// Check if there's another part that's an IEnergyTile
boolean foundAnotherPart = false;
for (int i = 0; i < tile().partList().size(); i++)
{
TMultiPart part = tile().partMap(i);
if (part instanceof IEnergyTile)
{
foundAnotherPart = true;
break;
}
}
if (!foundAnotherPart)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
}
}
}
@Override
public void preRemove()
@ -127,10 +145,27 @@ public abstract class PartConductor extends PartAdvanced implements IConductor
this.getNetwork().split(this);
if (tile() instanceof IEnergyTile)
{
// Check if there's another part that's an IEnergyTile
boolean foundAnotherPart = false;
for (int i = 0; i < tile().partList().size(); i++)
{
TMultiPart part = tile().partMap(i);
if (part instanceof IEnergyTile)
{
foundAnotherPart = true;
break;
}
}
if (!foundAnotherPart)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile()));
}
}
}
super.preRemove();