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.
|
/** A mechanical node for mechanical energy.
|
||||||
*
|
*
|
||||||
* @author Calclavia */
|
* @author Calclavia */
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
public class MechanicalNode implements IMechanicalNode, ISaveObj
|
public class MechanicalNode implements IMechanicalNode, ISaveObj
|
||||||
{
|
{
|
||||||
|
public boolean doDebug = false;
|
||||||
public double torque = 0;
|
public double torque = 0;
|
||||||
public double prevAngularVelocity, angularVelocity = 0;
|
public double prevAngularVelocity, angularVelocity = 0;
|
||||||
public float acceleration = 2f;
|
public float acceleration = 2f;
|
||||||
|
@ -63,15 +63,21 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
||||||
return 0.5;
|
return 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void debug(String txt)
|
||||||
|
{
|
||||||
|
if (doDebug)
|
||||||
|
System.out.println("[MechMode]" + txt);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float deltaTime)
|
public void update(float deltaTime)
|
||||||
{
|
{
|
||||||
prevAngularVelocity = angularVelocity;
|
prevAngularVelocity = angularVelocity;
|
||||||
//if (world() != null && !world().isRemote)
|
if (world() != null && !world().isRemote)
|
||||||
// System.out.println("\nNode :" + toString());
|
debug("Node :" + toString());
|
||||||
//Update
|
//Update
|
||||||
//if (world() != null && !world().isRemote)
|
if (world() != null && !world().isRemote)
|
||||||
// System.out.println("AngleBefore: " + renderAngle + " Vel: " + angularVelocity);
|
debug("AngleBefore: " + renderAngle + " Vel: " + angularVelocity);
|
||||||
if (angularVelocity >= 0)
|
if (angularVelocity >= 0)
|
||||||
{
|
{
|
||||||
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
|
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
|
||||||
|
@ -80,8 +86,8 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
||||||
{
|
{
|
||||||
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
|
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
|
||||||
}
|
}
|
||||||
// if (world() != null && !world().isRemote)
|
if (world() != null && !world().isRemote)
|
||||||
// System.out.println("AngleAfter: " + renderAngle + " Vel: " + angularVelocity);
|
debug("AngleAfter: " + renderAngle + " Vel: " + angularVelocity);
|
||||||
|
|
||||||
if (renderAngle % (Math.PI * 2) != renderAngle)
|
if (renderAngle % (Math.PI * 2) != renderAngle)
|
||||||
{
|
{
|
||||||
|
@ -133,7 +139,7 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
||||||
|
|
||||||
ForgeDirection dir = entry.getValue();
|
ForgeDirection dir = entry.getValue();
|
||||||
MechanicalNode adjacentMech = entry.getKey();
|
MechanicalNode adjacentMech = entry.getKey();
|
||||||
|
debug("Connection: " + adjacentMech + " Side: " + dir);
|
||||||
/** Calculate angular velocity and torque. */
|
/** Calculate angular velocity and torque. */
|
||||||
float ratio = adjacentMech.getRatio(dir.getOpposite(), this) / getRatio(dir, adjacentMech);
|
float ratio = adjacentMech.getRatio(dir.getOpposite(), this) / getRatio(dir, adjacentMech);
|
||||||
boolean inverseRotation = inverseRotation(dir, adjacentMech) && adjacentMech.inverseRotation(dir.getOpposite(), this);
|
boolean inverseRotation = inverseRotation(dir, adjacentMech) && adjacentMech.inverseRotation(dir.getOpposite(), this);
|
||||||
|
|
|
@ -3,183 +3,209 @@ package resonantinduction.mechanical.energy.grid;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonant.api.grid.INode;
|
import resonant.api.grid.INode;
|
||||||
import resonant.api.grid.INodeProvider;
|
import resonant.api.grid.INodeProvider;
|
||||||
|
import resonant.core.ResonantEngine;
|
||||||
import codechicken.lib.data.MCDataInput;
|
import codechicken.lib.data.MCDataInput;
|
||||||
import codechicken.lib.data.MCDataOutput;
|
import codechicken.lib.data.MCDataOutput;
|
||||||
|
import codechicken.multipart.ControlKeyModifer;
|
||||||
import codechicken.multipart.JCuboidPart;
|
import codechicken.multipart.JCuboidPart;
|
||||||
import codechicken.multipart.JNormalOcclusion;
|
import codechicken.multipart.JNormalOcclusion;
|
||||||
import codechicken.multipart.TFacePart;
|
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 abstract class PartMechanical extends JCuboidPart implements JNormalOcclusion, TFacePart, INodeProvider
|
||||||
{
|
{
|
||||||
public MechanicalNode node;
|
public MechanicalNode node;
|
||||||
protected double prevAngularVelocity;
|
protected double prevAngularVelocity;
|
||||||
|
|
||||||
/**
|
/** Packets */
|
||||||
* Packets
|
int ticks = 0;
|
||||||
*/
|
boolean markPacketUpdate = false;
|
||||||
int ticks = 0;
|
|
||||||
boolean markPacketUpdate = false;
|
|
||||||
|
|
||||||
/** Side of the block this is placed on */
|
/** Side of the block this is placed on */
|
||||||
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
|
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
|
||||||
|
|
||||||
public int tier;
|
public int tier;
|
||||||
|
|
||||||
public void preparePlacement(int side, int itemDamage)
|
public void preparePlacement(int side, int itemDamage)
|
||||||
{
|
{
|
||||||
this.placementSide = ForgeDirection.getOrientation((byte) (side));
|
this.placementSide = ForgeDirection.getOrientation((byte) (side));
|
||||||
this.tier = itemDamage;
|
this.tier = itemDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
ticks++;
|
ticks++;
|
||||||
|
|
||||||
if (!world().isRemote)
|
if (!world().isRemote)
|
||||||
checkClientUpdate();
|
{
|
||||||
|
checkClientUpdate();
|
||||||
|
System.out.println("\nPart: " + this + " Node: " + this.node);
|
||||||
|
this.node.update(0.05f);
|
||||||
|
}
|
||||||
|
|
||||||
super.update();
|
super.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkClientUpdate()
|
@Override
|
||||||
{
|
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
|
||||||
if (Math.abs(prevAngularVelocity - node.angularVelocity) > 0.001f || (prevAngularVelocity != node.angularVelocity && (prevAngularVelocity == 0 || node.angularVelocity == 0)))
|
{
|
||||||
{
|
if (ResonantEngine.runningAsDev)
|
||||||
prevAngularVelocity = node.angularVelocity;
|
{
|
||||||
markPacketUpdate = true;
|
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)
|
public void checkClientUpdate()
|
||||||
{
|
{
|
||||||
sendRotationPacket();
|
if (Math.abs(prevAngularVelocity - node.angularVelocity) > 0.001f || (prevAngularVelocity != node.angularVelocity && (prevAngularVelocity == 0 || node.angularVelocity == 0)))
|
||||||
markPacketUpdate = false;
|
{
|
||||||
}
|
prevAngularVelocity = node.angularVelocity;
|
||||||
}
|
markPacketUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
if (markPacketUpdate && ticks % 10 == 0)
|
||||||
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
|
{
|
||||||
{
|
sendRotationPacket();
|
||||||
if (nodeType.isAssignableFrom(node.getClass()))
|
markPacketUpdate = false;
|
||||||
return node;
|
}
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWorldJoin()
|
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
|
||||||
{
|
{
|
||||||
node.reconstruct();
|
if (nodeType.isAssignableFrom(node.getClass()))
|
||||||
}
|
return node;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWorldSeparate()
|
public void onWorldJoin()
|
||||||
{
|
{
|
||||||
node.deconstruct();
|
node.reconstruct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Packet Code. */
|
@Override
|
||||||
public void sendRotationPacket()
|
public void onWorldSeparate()
|
||||||
{
|
{
|
||||||
if (world() != null && !world().isRemote)
|
node.deconstruct();
|
||||||
{
|
}
|
||||||
getWriteStream().writeByte(1).writeDouble(node.angularVelocity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Packet Code. */
|
/** Packet Code. */
|
||||||
@Override
|
public void sendRotationPacket()
|
||||||
public void read(MCDataInput packet)
|
{
|
||||||
{
|
if (world() != null && !world().isRemote)
|
||||||
read(packet, packet.readUByte());
|
{
|
||||||
}
|
getWriteStream().writeByte(1).writeDouble(node.angularVelocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void read(MCDataInput packet, int packetID)
|
/** Packet Code. */
|
||||||
{
|
@Override
|
||||||
switch (packetID)
|
public void read(MCDataInput packet)
|
||||||
{
|
{
|
||||||
case 0:
|
read(packet, packet.readUByte());
|
||||||
load(packet.readNBTTagCompound());
|
}
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
node.angularVelocity = packet.readDouble();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void read(MCDataInput packet, int packetID)
|
||||||
public void readDesc(MCDataInput packet)
|
{
|
||||||
{
|
switch (packetID)
|
||||||
packet.readByte();
|
{
|
||||||
load(packet.readNBTTagCompound());
|
case 0:
|
||||||
}
|
load(packet.readNBTTagCompound());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
node.angularVelocity = packet.readDouble();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeDesc(MCDataOutput packet)
|
public void readDesc(MCDataInput packet)
|
||||||
{
|
{
|
||||||
packet.writeByte(0);
|
packet.readByte();
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
load(packet.readNBTTagCompound());
|
||||||
save(nbt);
|
}
|
||||||
packet.writeNBTTagCompound(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int redstoneConductionMap()
|
public void writeDesc(MCDataOutput packet)
|
||||||
{
|
{
|
||||||
return 0;
|
packet.writeByte(0);
|
||||||
}
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
save(nbt);
|
||||||
|
packet.writeNBTTagCompound(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean solid(int arg0)
|
public int redstoneConductionMap()
|
||||||
{
|
{
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(NBTTagCompound nbt)
|
public boolean solid(int arg0)
|
||||||
{
|
{
|
||||||
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
return true;
|
||||||
tier = nbt.getByte("tier");
|
}
|
||||||
node.load(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(NBTTagCompound nbt)
|
public void load(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
nbt.setByte("side", (byte) placementSide.ordinal());
|
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
||||||
nbt.setByte("tier", (byte) tier);
|
tier = nbt.getByte("tier");
|
||||||
node.save(nbt);
|
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
|
protected abstract ItemStack getItem();
|
||||||
public Iterable<ItemStack> getDrops()
|
|
||||||
{
|
|
||||||
List<ItemStack> drops = new ArrayList<ItemStack>();
|
|
||||||
drops.add(getItem());
|
|
||||||
return drops;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack pickItem(MovingObjectPosition hit)
|
public Iterable<ItemStack> getDrops()
|
||||||
{
|
{
|
||||||
return getItem();
|
List<ItemStack> drops = new ArrayList<ItemStack>();
|
||||||
}
|
drops.add(getItem());
|
||||||
|
return drops;
|
||||||
|
}
|
||||||
|
|
||||||
public universalelectricity.api.vector.Vector3 getPosition()
|
@Override
|
||||||
{
|
public ItemStack pickItem(MovingObjectPosition hit)
|
||||||
return new universalelectricity.api.vector.Vector3(x(), y(), z());
|
{
|
||||||
}
|
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 ";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue