Gears now update client side showing animation, Fixed a NPE when breaking gears

This commit is contained in:
Robert S 2014-06-07 06:54:36 -04:00
parent 4fbbdd101b
commit 9f4c9edf7d
2 changed files with 42 additions and 17 deletions

View file

@ -13,6 +13,7 @@ import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonant.lib.utility.nbt.ISaveObj;
import resonantinduction.core.interfaces.IMechanicalNode;
import universalelectricity.api.vector.IVectorWorld;
import universalelectricity.api.vector.Vector3;
import codechicken.multipart.TMultiPart;
@ -31,7 +32,7 @@ import codechicken.multipart.TMultiPart;
* can be added by extending the gui.
*
* @author Calclavia, Darkguardsman */
public class MechanicalNode implements IMechanicalNode, ISaveObj
public class MechanicalNode implements IMechanicalNode, ISaveObj, IVectorWorld
{
/** Is debug enabled for the node */
public boolean doDebug = false;
@ -261,15 +262,7 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
return load;
}
public World world()
{
return getParent() instanceof TMultiPart ? ((TMultiPart) getParent()).world() : getParent() instanceof TileEntity ? ((TileEntity) getParent()).getWorldObj() : null;
}
public Vector3 position()
{
return getParent() instanceof TMultiPart ? new Vector3(((TMultiPart) getParent()).x(), ((TMultiPart) getParent()).y(), ((TMultiPart) getParent()).z()) : getParent() instanceof TileEntity ? new Vector3((TileEntity) getParent()) : null;
}
/** Checks to see if a connection is allowed from side and from a source */
public boolean canConnect(ForgeDirection from, Object source)
@ -319,6 +312,7 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
{
for (Entry<MechanicalNode, ForgeDirection> entry : getConnections().entrySet())
{
entry.getKey().getConnections().remove(this);
entry.getKey().recache();
}
getConnections().clear();
@ -371,4 +365,33 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
{
return connections;
}
@Override
public World world()
{
return getParent() instanceof TMultiPart ? ((TMultiPart) getParent()).world() : getParent() instanceof TileEntity ? ((TileEntity) getParent()).getWorldObj() : null;
}
public Vector3 position()
{
return new Vector3(x(), y(), z());
}
@Override
public double z()
{
return this.getParent() instanceof TMultiPart && ((TMultiPart)this.getParent()).tile() != null ? ((TMultiPart)this.getParent()).z() : 0;
}
@Override
public double x()
{
return this.getParent() instanceof TMultiPart && ((TMultiPart)this.getParent()).tile() != null ? ((TMultiPart)this.getParent()).x() : 0;
}
@Override
public double y()
{
return this.getParent() instanceof TMultiPart && ((TMultiPart)this.getParent()).tile() != null ? ((TMultiPart)this.getParent()).y() : 0;
}
}

View file

@ -25,11 +25,11 @@ import codechicken.multipart.TFacePart;
* @author Calclavia */
public abstract class PartMechanical extends JCuboidPart implements JNormalOcclusion, TFacePart, INodeProvider
{
/** Node that handles mechanical action of the machine */
public MechanicalNode node;
protected double prevAngularVelocity;
/** Packets */
protected double prevAngularVelocity;
int ticks = 0;
/** Packets */
boolean markPacketUpdate = false;
/** Simple debug external GUI */
GearDebugFrame frame = null;
@ -53,15 +53,17 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
{
ticks = 0;
}
//Make sure to update on both sides
this.node.update(0.05f);
if (!world().isRemote)
{
checkClientUpdate();
this.node.update(0.05f);
checkClientUpdate();
}
else
{
//System.out.println("Client->[" + this + "]Angle: " + node.renderAngle);
System.out.println("Client->[" + this + "]Angle: " + node.renderAngle);
}
if (frame != null)
{