Added a way to debug gears one at a time using a stick, only works with mod set in dev mode
This commit is contained in:
parent
6c42ba4342
commit
7196ee31e4
2 changed files with 179 additions and 147 deletions
|
@ -18,9 +18,9 @@ import codechicken.multipart.TMultiPart;
|
|||
/** A mechanical node for mechanical energy.
|
||||
*
|
||||
* @author Calclavia */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class MechanicalNode implements IMechanicalNode, ISaveObj
|
||||
{
|
||||
public boolean doDebug = false;
|
||||
public double torque = 0;
|
||||
public double prevAngularVelocity, angularVelocity = 0;
|
||||
public float acceleration = 2f;
|
||||
|
@ -63,15 +63,21 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
public void debug(String txt)
|
||||
{
|
||||
if (doDebug)
|
||||
System.out.println("[MechMode]" + txt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float deltaTime)
|
||||
{
|
||||
prevAngularVelocity = angularVelocity;
|
||||
//if (world() != null && !world().isRemote)
|
||||
// System.out.println("\nNode :" + toString());
|
||||
if (world() != null && !world().isRemote)
|
||||
debug("Node :" + toString());
|
||||
//Update
|
||||
//if (world() != null && !world().isRemote)
|
||||
// System.out.println("AngleBefore: " + renderAngle + " Vel: " + angularVelocity);
|
||||
if (world() != null && !world().isRemote)
|
||||
debug("AngleBefore: " + renderAngle + " Vel: " + angularVelocity);
|
||||
if (angularVelocity >= 0)
|
||||
{
|
||||
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
|
||||
|
@ -80,8 +86,8 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
{
|
||||
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
|
||||
}
|
||||
// if (world() != null && !world().isRemote)
|
||||
// System.out.println("AngleAfter: " + renderAngle + " Vel: " + angularVelocity);
|
||||
if (world() != null && !world().isRemote)
|
||||
debug("AngleAfter: " + renderAngle + " Vel: " + angularVelocity);
|
||||
|
||||
if (renderAngle % (Math.PI * 2) != renderAngle)
|
||||
{
|
||||
|
@ -133,7 +139,7 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
|
||||
ForgeDirection dir = entry.getValue();
|
||||
MechanicalNode adjacentMech = entry.getKey();
|
||||
|
||||
debug("Connection: " + adjacentMech + " Side: " + dir);
|
||||
/** Calculate angular velocity and torque. */
|
||||
float ratio = adjacentMech.getRatio(dir.getOpposite(), this) / getRatio(dir, adjacentMech);
|
||||
boolean inverseRotation = inverseRotation(dir, adjacentMech) && adjacentMech.inverseRotation(dir.getOpposite(), this);
|
||||
|
|
|
@ -3,32 +3,31 @@ package resonantinduction.mechanical.energy.grid;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonant.api.grid.INode;
|
||||
import resonant.api.grid.INodeProvider;
|
||||
import resonant.core.ResonantEngine;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
import codechicken.multipart.JCuboidPart;
|
||||
import codechicken.multipart.JNormalOcclusion;
|
||||
import codechicken.multipart.TFacePart;
|
||||
|
||||
/**
|
||||
* We assume all the force acting on the gear is 90 degrees.
|
||||
/** We assume all the force acting on the gear is 90 degrees.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
* @author Calclavia */
|
||||
public abstract class PartMechanical extends JCuboidPart implements JNormalOcclusion, TFacePart, INodeProvider
|
||||
{
|
||||
public MechanicalNode node;
|
||||
protected double prevAngularVelocity;
|
||||
|
||||
/**
|
||||
* Packets
|
||||
*/
|
||||
/** Packets */
|
||||
int ticks = 0;
|
||||
boolean markPacketUpdate = false;
|
||||
|
||||
|
@ -49,11 +48,32 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
ticks++;
|
||||
|
||||
if (!world().isRemote)
|
||||
{
|
||||
checkClientUpdate();
|
||||
System.out.println("\nPart: " + this + " Node: " + this.node);
|
||||
this.node.update(0.05f);
|
||||
}
|
||||
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
|
||||
{
|
||||
if (ResonantEngine.runningAsDev)
|
||||
{
|
||||
if (itemStack != null && itemStack.getItem().itemID == Item.stick.itemID)
|
||||
{
|
||||
if (!world().isRemote && ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
this.node.doDebug = !this.node.doDebug;
|
||||
player.addChatMessage("[Debug] PartMechanical debug mode is now " + (this.node.doDebug ? "on" : "off"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.activate(player, hit, itemStack);
|
||||
}
|
||||
|
||||
public void checkClientUpdate()
|
||||
{
|
||||
if (Math.abs(prevAngularVelocity - node.angularVelocity) > 0.001f || (prevAngularVelocity != node.angularVelocity && (prevAngularVelocity == 0 || node.angularVelocity == 0)))
|
||||
|
@ -182,4 +202,10 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
{
|
||||
return new universalelectricity.api.vector.Vector3(x(), y(), z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[PartMech]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s ";
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue