Toyed with MechanicalNode in attempts to fix issues
This commit is contained in:
parent
3404a103c0
commit
f98782541a
|
@ -9,7 +9,7 @@ import resonant.api.grid.INode;
|
|||
import resonant.api.grid.INodeProvider;
|
||||
import resonant.lib.grid.NodeRegistry;
|
||||
import resonant.lib.prefab.tile.TileElectrical;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import universalelectricity.api.energy.EnergyStorageHandler;
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,9 +17,9 @@ import resonant.lib.utility.WrenchUtility;
|
|||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.core.grid.fluid.FluidPressureNode;
|
||||
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.core.prefab.part.PartFace;
|
||||
import resonantinduction.electrical.Electrical;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import universalelectricity.api.CompatibilityModule;
|
||||
import universalelectricity.api.electricity.IElectricalNetwork;
|
||||
import universalelectricity.api.energy.IConductor;
|
||||
|
|
|
@ -17,6 +17,7 @@ import resonantinduction.core.Reference;
|
|||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.core.Settings;
|
||||
import resonantinduction.core.TabRI;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.mechanical.belt.BlockConveyorBelt;
|
||||
import resonantinduction.mechanical.belt.TileConveyorBelt;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
|
@ -31,7 +32,6 @@ import resonantinduction.mechanical.fluid.pipe.ItemPipe;
|
|||
import resonantinduction.mechanical.fluid.transport.TilePump;
|
||||
import resonantinduction.mechanical.gear.ItemGear;
|
||||
import resonantinduction.mechanical.gearshaft.ItemGearShaft;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import resonantinduction.mechanical.logistic.belt.BlockDetector;
|
||||
import resonantinduction.mechanical.logistic.belt.BlockManipulator;
|
||||
import resonantinduction.mechanical.logistic.belt.TileDetector;
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package resonantinduction.mechanical.energy.grid;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonant.api.grid.INodeProvider;
|
||||
import resonant.lib.grid.Node;
|
||||
import resonant.lib.grid.TickingGrid;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import resonant.lib.utility.nbt.ISaveObj;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
||||
|
@ -19,7 +19,7 @@ import codechicken.multipart.TMultiPart;
|
|||
*
|
||||
* @author Calclavia */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalNode> implements IMechanicalNode
|
||||
public class MechanicalNode implements IMechanicalNode, ISaveObj
|
||||
{
|
||||
public double torque = 0;
|
||||
public double prevAngularVelocity, angularVelocity = 0;
|
||||
|
@ -35,10 +35,13 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
|
|||
protected byte connectionMap = Byte.parseByte("111111", 2);
|
||||
|
||||
private double power = 0;
|
||||
private INodeProvider parent;
|
||||
|
||||
protected final AbstractMap<MechanicalNode, ForgeDirection> connections = new WeakHashMap<MechanicalNode, ForgeDirection>();
|
||||
|
||||
public MechanicalNode(INodeProvider parent)
|
||||
{
|
||||
super(parent);
|
||||
this.setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,11 +67,11 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
|
|||
public void update(float deltaTime)
|
||||
{
|
||||
prevAngularVelocity = angularVelocity;
|
||||
if (world() != null && !world().isRemote)
|
||||
System.out.println("\nNode :" + toString());
|
||||
//if (world() != null && !world().isRemote)
|
||||
// System.out.println("\nNode :" + toString());
|
||||
//Update
|
||||
if (world() != null && !world().isRemote)
|
||||
System.out.println("AngleBefore: " + renderAngle + " Vel: " + angularVelocity);
|
||||
//if (world() != null && !world().isRemote)
|
||||
// System.out.println("AngleBefore: " + renderAngle + " Vel: " + angularVelocity);
|
||||
if (angularVelocity >= 0)
|
||||
{
|
||||
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
|
||||
|
@ -77,8 +80,8 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
|
|||
{
|
||||
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
|
||||
}
|
||||
if (world() != null && !world().isRemote)
|
||||
System.out.println("AngleAfter: " + renderAngle + " Vel: " + angularVelocity);
|
||||
// if (world() != null && !world().isRemote)
|
||||
// System.out.println("AngleAfter: " + renderAngle + " Vel: " + angularVelocity);
|
||||
|
||||
if (renderAngle % (Math.PI * 2) != renderAngle)
|
||||
{
|
||||
|
@ -224,9 +227,65 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
|
|||
return load;
|
||||
}
|
||||
|
||||
/** Recache the connections. This is the default connection implementation. */
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
return (source instanceof MechanicalNode) && (connectionMap & (1 << from.ordinal())) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRecache()
|
||||
public double getEnergy()
|
||||
{
|
||||
return getTorque() * getAngularSpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPower()
|
||||
{
|
||||
return power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
torque = nbt.getDouble("torque");
|
||||
angularVelocity = nbt.getDouble("angularVelocity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setDouble("torque", torque);
|
||||
nbt.setDouble("angularVelocity", angularVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
recache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deconstruct()
|
||||
{
|
||||
for (Entry<MechanicalNode, ForgeDirection> entry : connections.entrySet())
|
||||
{
|
||||
entry.getKey().recache();
|
||||
}
|
||||
connections.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recache()
|
||||
{
|
||||
connections.clear();
|
||||
|
||||
|
@ -246,54 +305,14 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
|
|||
}
|
||||
}
|
||||
|
||||
public World world()
|
||||
public INodeProvider getParent()
|
||||
{
|
||||
return parent instanceof TMultiPart ? ((TMultiPart) parent).world() : parent instanceof TileEntity ? ((TileEntity) parent).getWorldObj() : null;
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Vector3 position()
|
||||
public void setParent(INodeProvider parent)
|
||||
{
|
||||
return parent instanceof TMultiPart ? new Vector3(((TMultiPart) parent).x(), ((TMultiPart) parent).y(), ((TMultiPart) parent).z()) : parent instanceof TileEntity ? new Vector3((TileEntity) parent) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
return (source instanceof MechanicalNode) && (connectionMap & (1 << from.ordinal())) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy()
|
||||
{
|
||||
return getTorque() * getAngularSpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPower()
|
||||
{
|
||||
return power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingGrid newGrid()
|
||||
{
|
||||
return new TickingGrid<MechanicalNode>(this, MechanicalNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.load(nbt);
|
||||
torque = nbt.getDouble("torque");
|
||||
angularVelocity = nbt.getDouble("angularVelocity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.save(nbt);
|
||||
nbt.setDouble("torque", torque);
|
||||
nbt.setDouble("angularVelocity", angularVelocity);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import resonant.api.grid.INodeProvider;
|
|||
import resonant.lib.network.Synced;
|
||||
import resonant.lib.network.Synced.SyncedInput;
|
||||
import resonant.lib.network.Synced.SyncedOutput;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
|
||||
//TODO: MC 1.7, merge turbines in.
|
||||
public class TileMechanicalTurbine extends TileTurbineBase implements INodeProvider
|
||||
|
|
|
@ -3,8 +3,8 @@ package resonantinduction.mechanical.gear;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonant.api.grid.INodeProvider;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
|
@ -21,7 +21,7 @@ public class GearNode extends MechanicalNode
|
|||
|
||||
protected PartGear gear()
|
||||
{
|
||||
return (PartGear) this.parent;
|
||||
return (PartGear) this.getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,8 +78,9 @@ public class GearNode extends MechanicalNode
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRecache()
|
||||
public void recache()
|
||||
{
|
||||
System.out.println("doRecache: " + this);
|
||||
connections.clear();
|
||||
|
||||
/** Only call refresh if this is the main block of a multiblock gear or a single gear block. */
|
||||
|
@ -95,7 +96,7 @@ public class GearNode extends MechanicalNode
|
|||
{
|
||||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) tileBehind).getNode(MechanicalNode.class, gear().placementSide.getOpposite());
|
||||
|
||||
if (instance != null && instance != this && !(instance.parent instanceof PartGearShaft) && instance.canConnect(gear().placementSide.getOpposite(), this))
|
||||
if (instance != null && instance != this && !(instance.getParent() instanceof PartGearShaft) && instance.canConnect(gear().placementSide.getOpposite(), this))
|
||||
{
|
||||
connections.put(instance, gear().placementSide);
|
||||
}
|
||||
|
@ -144,7 +145,7 @@ public class GearNode extends MechanicalNode
|
|||
{
|
||||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) checkTile).getNode(MechanicalNode.class, gear().placementSide);
|
||||
|
||||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && !(instance.parent instanceof PartGearShaft))
|
||||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && !(instance.getParent() instanceof PartGearShaft))
|
||||
{
|
||||
connections.put(instance, checkDir);
|
||||
}
|
||||
|
@ -167,7 +168,7 @@ public class GearNode extends MechanicalNode
|
|||
|
||||
if (with instanceof MechanicalNode)
|
||||
{
|
||||
INodeProvider parent = ((MechanicalNode) with).parent;
|
||||
INodeProvider parent = ((MechanicalNode) with).getParent();
|
||||
|
||||
/** Check for flat connections (gear face on gear face) to make sure it's actually on
|
||||
* this gear block. */
|
||||
|
|
|
@ -17,11 +17,11 @@ import resonant.lib.multiblock.IMultiBlockStructure;
|
|||
import resonant.lib.multiblock.MultiBlockHandler;
|
||||
import resonant.lib.utility.WrenchUtility;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.core.resource.ItemHandCrank;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import resonantinduction.mechanical.energy.grid.PartMechanical;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Transformation;
|
||||
|
@ -70,15 +70,14 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
|
|||
|
||||
if (!this.world().isRemote)
|
||||
{
|
||||
System.out.println(this + ">>>" + this.node);
|
||||
//System.out.println(this + ">>>" + this.node);
|
||||
this.node.update(0.05f);
|
||||
if (manualCrankTime > 0)
|
||||
{
|
||||
node.apply(this, isClockwiseCrank ? 15 : -15, isClockwiseCrank ? 0.025f : -0.025f);
|
||||
manualCrankTime--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getMultiBlock().update();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ import java.util.List;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonant.api.grid.INodeProvider;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import resonantinduction.mechanical.gear.PartGear;
|
||||
import resonantinduction.mechanical.gear.PartGearShaft;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
|
||||
public class GearShaftNode extends MechanicalNode
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ public class GearShaftNode extends MechanicalNode
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRecache()
|
||||
public void recache()
|
||||
{
|
||||
connections.clear();
|
||||
List<ForgeDirection> dirs = new ArrayList<ForgeDirection>();
|
||||
|
@ -80,7 +80,7 @@ public class GearShaftNode extends MechanicalNode
|
|||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) checkTile).getNode(MechanicalNode.class, checkDir.getOpposite());
|
||||
|
||||
// Only connect to shafts outside of this block space.
|
||||
if (instance != null && instance != this && instance.parent instanceof PartGearShaft && instance.canConnect(checkDir.getOpposite(), this))
|
||||
if (instance != null && instance != this && instance.getParent() instanceof PartGearShaft && instance.canConnect(checkDir.getOpposite(), this))
|
||||
{
|
||||
connections.put(instance, checkDir);
|
||||
}
|
||||
|
@ -94,9 +94,9 @@ public class GearShaftNode extends MechanicalNode
|
|||
{
|
||||
if (source instanceof MechanicalNode)
|
||||
{
|
||||
if (((MechanicalNode) source).parent instanceof PartGear)
|
||||
if (((MechanicalNode) source).getParent() instanceof PartGear)
|
||||
{
|
||||
PartGear gear = (PartGear) ((MechanicalNode) source).parent;
|
||||
PartGear gear = (PartGear) ((MechanicalNode) source).getParent();
|
||||
|
||||
if (!(Math.abs(gear.placementSide.offsetX) == Math.abs(shaft().placementSide.offsetX) && Math.abs(gear.placementSide.offsetY) == Math.abs(shaft().placementSide.offsetY) && Math.abs(gear.placementSide.offsetZ) == Math.abs(shaft().placementSide.offsetZ)))
|
||||
{
|
||||
|
@ -121,6 +121,6 @@ public class GearShaftNode extends MechanicalNode
|
|||
|
||||
public PartGearShaft shaft()
|
||||
{
|
||||
return (PartGearShaft) this.parent;
|
||||
return (PartGearShaft) this.getParent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import resonant.lib.prefab.vector.Cuboid;
|
|||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.core.ResonantInduction.RecipeType;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.core.Timer;
|
||||
import resonantinduction.mechanical.energy.grid.TileMechanical;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,10 +20,10 @@ import resonant.lib.utility.inventory.InventoryUtility;
|
|||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.ResonantInduction.RecipeType;
|
||||
import resonantinduction.core.Timer;
|
||||
import resonantinduction.core.interfaces.IMechanicalNode;
|
||||
import resonantinduction.core.resource.ResourceGenerator;
|
||||
import resonantinduction.core.resource.fluid.BlockFluidMixture;
|
||||
import resonantinduction.mechanical.energy.grid.TileMechanical;
|
||||
import resonantinduction.mechanical.interfaces.IMechanicalNode;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue