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:
Robert S 2014-06-05 00:56:10 -04:00
parent 6c42ba4342
commit 7196ee31e4
2 changed files with 179 additions and 147 deletions

View file

@ -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);

View file

@ -3,183 +3,209 @@ 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;
public MechanicalNode node;
protected double prevAngularVelocity;
/**
* Packets
*/
int ticks = 0;
boolean markPacketUpdate = false;
/** Packets */
int ticks = 0;
boolean markPacketUpdate = false;
/** Side of the block this is placed on */
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
/** Side of the block this is placed on */
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
public int tier;
public int tier;
public void preparePlacement(int side, int itemDamage)
{
this.placementSide = ForgeDirection.getOrientation((byte) (side));
this.tier = itemDamage;
}
public void preparePlacement(int side, int itemDamage)
{
this.placementSide = ForgeDirection.getOrientation((byte) (side));
this.tier = itemDamage;
}
@Override
public void update()
{
ticks++;
@Override
public void update()
{
ticks++;
if (!world().isRemote)
checkClientUpdate();
if (!world().isRemote)
{
checkClientUpdate();
System.out.println("\nPart: " + this + " Node: " + this.node);
this.node.update(0.05f);
}
super.update();
}
super.update();
}
public void checkClientUpdate()
{
if (Math.abs(prevAngularVelocity - node.angularVelocity) > 0.001f || (prevAngularVelocity != node.angularVelocity && (prevAngularVelocity == 0 || node.angularVelocity == 0)))
{
prevAngularVelocity = node.angularVelocity;
markPacketUpdate = true;
}
@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);
}
if (markPacketUpdate && ticks % 10 == 0)
{
sendRotationPacket();
markPacketUpdate = false;
}
}
public void checkClientUpdate()
{
if (Math.abs(prevAngularVelocity - node.angularVelocity) > 0.001f || (prevAngularVelocity != node.angularVelocity && (prevAngularVelocity == 0 || node.angularVelocity == 0)))
{
prevAngularVelocity = node.angularVelocity;
markPacketUpdate = true;
}
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
if (nodeType.isAssignableFrom(node.getClass()))
return node;
return null;
}
if (markPacketUpdate && ticks % 10 == 0)
{
sendRotationPacket();
markPacketUpdate = false;
}
}
@Override
public void onWorldJoin()
{
node.reconstruct();
}
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
if (nodeType.isAssignableFrom(node.getClass()))
return node;
return null;
}
@Override
public void onWorldSeparate()
{
node.deconstruct();
}
@Override
public void onWorldJoin()
{
node.reconstruct();
}
/** Packet Code. */
public void sendRotationPacket()
{
if (world() != null && !world().isRemote)
{
getWriteStream().writeByte(1).writeDouble(node.angularVelocity);
}
}
@Override
public void onWorldSeparate()
{
node.deconstruct();
}
/** Packet Code. */
@Override
public void read(MCDataInput packet)
{
read(packet, packet.readUByte());
}
/** Packet Code. */
public void sendRotationPacket()
{
if (world() != null && !world().isRemote)
{
getWriteStream().writeByte(1).writeDouble(node.angularVelocity);
}
}
public void read(MCDataInput packet, int packetID)
{
switch (packetID)
{
case 0:
load(packet.readNBTTagCompound());
break;
case 1:
node.angularVelocity = packet.readDouble();
break;
}
}
/** Packet Code. */
@Override
public void read(MCDataInput packet)
{
read(packet, packet.readUByte());
}
@Override
public void readDesc(MCDataInput packet)
{
packet.readByte();
load(packet.readNBTTagCompound());
}
public void read(MCDataInput packet, int packetID)
{
switch (packetID)
{
case 0:
load(packet.readNBTTagCompound());
break;
case 1:
node.angularVelocity = packet.readDouble();
break;
}
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte(0);
NBTTagCompound nbt = new NBTTagCompound();
save(nbt);
packet.writeNBTTagCompound(nbt);
}
@Override
public void readDesc(MCDataInput packet)
{
packet.readByte();
load(packet.readNBTTagCompound());
}
@Override
public int redstoneConductionMap()
{
return 0;
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte(0);
NBTTagCompound nbt = new NBTTagCompound();
save(nbt);
packet.writeNBTTagCompound(nbt);
}
@Override
public boolean solid(int arg0)
{
return true;
}
@Override
public int redstoneConductionMap()
{
return 0;
}
@Override
public void load(NBTTagCompound nbt)
{
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
tier = nbt.getByte("tier");
node.load(nbt);
}
@Override
public boolean solid(int arg0)
{
return true;
}
@Override
public void save(NBTTagCompound nbt)
{
nbt.setByte("side", (byte) placementSide.ordinal());
nbt.setByte("tier", (byte) tier);
node.save(nbt);
}
@Override
public void load(NBTTagCompound nbt)
{
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
tier = nbt.getByte("tier");
node.load(nbt);
}
protected abstract ItemStack getItem();
@Override
public void save(NBTTagCompound nbt)
{
nbt.setByte("side", (byte) placementSide.ordinal());
nbt.setByte("tier", (byte) tier);
node.save(nbt);
}
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem());
return drops;
}
protected abstract ItemStack getItem();
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return getItem();
}
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem());
return drops;
}
public universalelectricity.api.vector.Vector3 getPosition()
{
return new universalelectricity.api.vector.Vector3(x(), y(), z());
}
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return getItem();
}
public universalelectricity.api.vector.Vector3 getPosition()
{
return new universalelectricity.api.vector.Vector3(x(), y(), z());
}
@Override
public String toString()
{
return "[PartMech]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s ";
}
}