Fixed generator not working
This commit is contained in:
parent
f4fc1a7910
commit
aa10031979
7 changed files with 48 additions and 33 deletions
|
@ -43,9 +43,23 @@ public class TileGenerator extends TileElectrical implements IRotatable, IMechan
|
|||
return gearRatio = (byte) ((gearRatio + 1) % 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
node.reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
node.deconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!isInversed)
|
||||
{
|
||||
receiveMechanical();
|
||||
|
@ -61,6 +75,7 @@ public class TileGenerator extends TileElectrical implements IRotatable, IMechan
|
|||
public void receiveMechanical()
|
||||
{
|
||||
double power = node.getEnergy();
|
||||
// System.out.println(power);
|
||||
long receive = energy.receiveEnergy((long) power, true);
|
||||
|
||||
if (receive > 0)
|
||||
|
|
|
@ -206,32 +206,31 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
|
|||
|
||||
if (with instanceof MechanicalNode)
|
||||
{
|
||||
IMechanicalNodeProvider source = ((MechanicalNode) with).parent;
|
||||
IMechanicalNodeProvider parent = ((MechanicalNode) with).parent;
|
||||
|
||||
/**
|
||||
* Check for flat connections (gear face on gear face) to make sure it's
|
||||
* actually on
|
||||
* this gear block.
|
||||
* actually on this gear block.
|
||||
*/
|
||||
if (from == placementSide.getOpposite())
|
||||
{
|
||||
if (source instanceof PartGear || source instanceof PartGearShaft)
|
||||
if (parent instanceof PartGear || parent instanceof PartGearShaft)
|
||||
{
|
||||
if (source instanceof PartGearShaft)
|
||||
if (parent instanceof PartGearShaft)
|
||||
{
|
||||
PartGearShaft shaft = (PartGearShaft) source;
|
||||
PartGearShaft shaft = (PartGearShaft) parent;
|
||||
return shaft.tile().partMap(from.getOpposite().ordinal()) == PartGear.this && Math.abs(shaft.placementSide.offsetX) == Math.abs(placementSide.offsetX) && Math.abs(shaft.placementSide.offsetY) == Math.abs(placementSide.offsetY) && Math.abs(shaft.placementSide.offsetZ) == Math.abs(placementSide.offsetZ);
|
||||
}
|
||||
else if (source instanceof PartGear)
|
||||
else if (parent instanceof PartGear)
|
||||
{
|
||||
if (((PartGear) source).tile() == tile() && !getMultiBlock().isConstructed())
|
||||
if (((PartGear) parent).tile() == tile() && !getMultiBlock().isConstructed())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (((PartGear) source).placementSide != placementSide)
|
||||
if (((PartGear) parent).placementSide != placementSide)
|
||||
{
|
||||
TMultiPart part = tile().partMap(((PartGear) source).placementSide.ordinal());
|
||||
TMultiPart part = tile().partMap(((PartGear) parent).placementSide.ordinal());
|
||||
|
||||
if (part instanceof PartGear)
|
||||
{
|
||||
|
@ -253,12 +252,12 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
|
|||
/** Small gear attempting to connect to large gear. */
|
||||
if (getMultiBlock().isConstructed())
|
||||
{
|
||||
TMultiPart checkPart = ((PartGear) source).tile().partMap(placementSide.ordinal());
|
||||
TMultiPart checkPart = ((PartGear) parent).tile().partMap(placementSide.ordinal());
|
||||
|
||||
if (checkPart instanceof PartGear)
|
||||
{
|
||||
ForgeDirection requiredDirection = ((PartGear) checkPart).getPosition().subtract(position()).toForgeDirection();
|
||||
return ((PartGear) checkPart).isCenterMultiBlock() && ((PartGear) source).placementSide == requiredDirection;
|
||||
return ((PartGear) checkPart).isCenterMultiBlock() && ((PartGear) parent).placementSide == requiredDirection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,7 +271,7 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
|
|||
if (sourceTile instanceof IMechanicalNodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = ((IMechanicalNodeProvider) sourceTile).getNode(from);
|
||||
return sourceInstance == source;
|
||||
return sourceInstance == with;
|
||||
}
|
||||
}
|
||||
else if (from == placementSide)
|
||||
|
@ -283,7 +282,7 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
|
|||
if (sourceTile instanceof IMechanicalNodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = ((IMechanicalNodeProvider) sourceTile).getNode(from.getOpposite());
|
||||
return sourceInstance == source;
|
||||
return sourceInstance == with;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -85,7 +85,7 @@ public class MechanicalNode extends EnergyNode
|
|||
/**
|
||||
* Energy loss
|
||||
*/
|
||||
double torqueLoss = Math.min(Math.abs(getAngularVelocity()), (Math.abs(getTorque() * getTorqueLoad()) + getTorqueLoad() / 10) * deltaTime);
|
||||
double torqueLoss = Math.min(Math.abs(getTorque()), (Math.abs(getTorque() * getTorqueLoad()) + getTorqueLoad() / 10) * deltaTime);
|
||||
|
||||
if (torque > 0)
|
||||
torque -= torqueLoss;
|
||||
|
@ -231,7 +231,7 @@ public class MechanicalNode extends EnergyNode
|
|||
@Override
|
||||
public double getEnergy()
|
||||
{
|
||||
return torque * angularVelocity;
|
||||
return getTorque() * getAngularVelocity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -243,7 +243,7 @@ public class MechanicalNode extends EnergyNode
|
|||
@Override
|
||||
public Grid newGrid()
|
||||
{
|
||||
return new TickingGrid<MechanicalNode>(this);
|
||||
return new TickingGrid<MechanicalNode>(this, MechanicalNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -64,12 +64,9 @@ public class TraitMechanical extends TileMultipart implements IMechanicalNodePro
|
|||
part = partMap(PartMap.CENTER.ordinal());
|
||||
}
|
||||
|
||||
if (part != null)
|
||||
if (part instanceof IMechanicalNodeProvider)
|
||||
{
|
||||
if (part instanceof IMechanicalNodeProvider)
|
||||
{
|
||||
return ((IMechanicalNodeProvider) part).getNode(from);
|
||||
}
|
||||
return ((IMechanicalNodeProvider) part).getNode(from);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -33,6 +33,7 @@ public abstract class Node<G extends Grid, N>
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO: Try inject tile validate and invalidate events so this does not have to be called.
|
||||
* This constructs the node. It should be called whenever the connections of the node are
|
||||
* updated OR when the node is first initiated and can access its connections.
|
||||
*/
|
||||
|
|
|
@ -34,11 +34,10 @@ public abstract class NodeGrid<N extends Node> extends Grid<N>
|
|||
if (isValidNode(connection) && connection instanceof Node)
|
||||
{
|
||||
Node connectedNode = (Node) connection;
|
||||
|
||||
|
||||
if (connectedNode.getGrid() != this)
|
||||
{
|
||||
connectedNode.getGrid().getNodes().clear();
|
||||
connectedNode.setGrid(this);
|
||||
add((N) connectedNode);
|
||||
reconstructNode((N) connectedNode);
|
||||
}
|
||||
|
|
|
@ -13,24 +13,28 @@ public class TickingGrid<N extends Node> extends NodeGrid<N> implements IUpdate
|
|||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
public TickingGrid(N node)
|
||||
{
|
||||
this(node, node.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* An grid update called only server side.
|
||||
* TODO: Make actual ticker an independent thread.
|
||||
*/
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
synchronized (nodes)
|
||||
new Thread()
|
||||
{
|
||||
for (Node node : nodes)
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
node.update(1 / 20f);
|
||||
synchronized (nodes)
|
||||
{
|
||||
for (Node node : nodes)
|
||||
{
|
||||
node.update(1 / 20f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue