Fixed NPE and some connections in network
s
This commit is contained in:
parent
bebde23242
commit
6c5f2f5ecb
9 changed files with 48 additions and 24 deletions
|
@ -8,6 +8,11 @@ import universalelectricity.core.net.Network;
|
|||
|
||||
public class EnergyDistributionNetwork extends Network<EnergyDistributionNetwork, TileEnergyDistribution>
|
||||
{
|
||||
public EnergyDistributionNetwork()
|
||||
{
|
||||
super(TileEnergyDistribution.class);
|
||||
}
|
||||
|
||||
public void redistribute(TileEnergyDistribution... exclusion)
|
||||
{
|
||||
long totalEnergy = 0;
|
||||
|
|
|
@ -28,8 +28,8 @@ public class BlockGenerator extends BlockRotatable
|
|||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
((TileGenerator) tileEntity).isInversed = !((TileGenerator) tileEntity).isInversed;
|
||||
entityPlayer.addChatMessage("Generator now producing " + (((TileGenerator) tileEntity).isInversed ? "mechanical" : "electrical") + " energy.");
|
||||
int gear = ((TileGenerator) tileEntity).toggleGearRatio();
|
||||
entityPlayer.addChatMessage("Generator set to " + (gear == 0 ? "low" : gear == 1 ? "medium" : "high") + " gear.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -47,8 +47,8 @@ public class BlockGenerator extends BlockRotatable
|
|||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
int gear = ((TileGenerator) tileEntity).toggleGearRatio();
|
||||
entityPlayer.addChatMessage("Generator set to " + (gear == 0 ? "low" : gear == 1 ? "medium" : "high") + " gear.");
|
||||
((TileGenerator) tileEntity).isInversed = !((TileGenerator) tileEntity).isInversed;
|
||||
entityPlayer.addChatMessage("Generator now producing " + (((TileGenerator) tileEntity).isInversed ? "mechanical" : "electrical") + " energy.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
|||
{
|
||||
if (extract > 0)
|
||||
{
|
||||
long torqueRatio = (long) ((gearRatio + 1) / 4d * (extract));
|
||||
long torqueRatio = (long) ((gearRatio + 1) / 2.2d * (extract));
|
||||
|
||||
if (torqueRatio > 0)
|
||||
{
|
||||
|
|
|
@ -66,6 +66,7 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
|
||||
public MultimeterNetwork()
|
||||
{
|
||||
super(PartMultimeter.class);
|
||||
graphs.add(energyGraph);
|
||||
graphs.add(powerGraph);
|
||||
graphs.add(energyCapacityGraph);
|
||||
|
@ -155,9 +156,9 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidConnector(PartMultimeter node)
|
||||
public boolean isValidConnector(Object node)
|
||||
{
|
||||
return node.world() != null && node.tile() != null;
|
||||
return node instanceof PartMultimeter && ((PartMultimeter) node).world() != null && ((PartMultimeter) node).tile() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package resonantinduction.mechanical.energy.network;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -31,11 +33,15 @@ import universalelectricity.core.net.NetworkTickHandler;
|
|||
*/
|
||||
public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical> implements IMechanicalNetwork, IUpdate
|
||||
{
|
||||
public MechanicalNetwork()
|
||||
{
|
||||
super(IMechanical.class);
|
||||
}
|
||||
|
||||
public static final float ACCELERATION = 0.2f;
|
||||
|
||||
/** The current rotation of the network */
|
||||
/** The current rotation of the network. Used by covneyor belts. */
|
||||
private float rotation = 0;
|
||||
|
||||
private long lastRotateTime;
|
||||
|
||||
/**
|
||||
|
@ -43,8 +49,6 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
*/
|
||||
private final WeakHashMap<IMechanical, WeakReference[]> connectionCache = new WeakHashMap<IMechanical, WeakReference[]>();
|
||||
|
||||
private boolean markUpdateRotation = true;
|
||||
|
||||
/**
|
||||
* Only add the exact instance of the connector into the network. Multipart tiles allowed!
|
||||
*/
|
||||
|
@ -53,7 +57,6 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
{
|
||||
super.addConnector(connector);
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
markUpdateRotation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,6 +127,13 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
return canUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
connectionCache.clear();
|
||||
super.reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reconstructConnector(IMechanical node)
|
||||
{
|
||||
|
@ -189,9 +199,12 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
Object[] conn = new Object[6];
|
||||
WeakReference[] connections = connectionCache.get(connector);
|
||||
|
||||
for (int i = 0; i < connections.length; i++)
|
||||
if (connections[i] != null)
|
||||
conn[i] = connections[i].get();
|
||||
if (connections != null)
|
||||
{
|
||||
for (int i = 0; i < connections.length; i++)
|
||||
if (connections[i] != null)
|
||||
conn[i] = connections[i].get();
|
||||
}
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package resonantinduction.mechanical.energy.network;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
|
@ -97,7 +95,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preRemove()
|
||||
public void onWorldSeparate()
|
||||
{
|
||||
getNetwork().split(this);
|
||||
}
|
||||
|
|
|
@ -99,8 +99,8 @@ public abstract class TileMechanical extends TileAdvanced implements IMechanical
|
|||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
getNetwork().split(this);
|
||||
super.invalidate();
|
||||
getNetwork().split(this);
|
||||
}
|
||||
|
||||
protected float getLoad()
|
||||
|
|
|
@ -75,4 +75,10 @@ public class TankNetwork extends FluidNetwork
|
|||
{
|
||||
return new TankNetwork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,18 @@ import calclavia.lib.utility.FluidUtility;
|
|||
*/
|
||||
public abstract class FluidNetwork extends NodeNetwork<IFluidNetwork, IFluidConnector, IFluidHandler> implements IFluidNetwork, IUpdate
|
||||
{
|
||||
|
||||
protected FluidTank tank = new FluidTank(0);
|
||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
||||
|
||||
// TODO: Make animated distribution to create a smooth flow transition.
|
||||
public boolean animateDistribution = false;
|
||||
|
||||
public FluidNetwork()
|
||||
{
|
||||
super(IFluidConnector.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnector(IFluidConnector connector)
|
||||
{
|
||||
|
@ -36,11 +42,6 @@ public abstract class FluidNetwork extends NodeNetwork<IFluidNetwork, IFluidConn
|
|||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue