Toyed with new gear network, moved IMechanicalNode into RI from RE

This commit is contained in:
Robert S 2014-06-04 01:53:20 -04:00
parent 7b94737915
commit 6e5b1c9a04
13 changed files with 224 additions and 24 deletions

View file

@ -4,12 +4,12 @@ import java.util.EnumSet;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
import resonant.api.IRotatable;
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 universalelectricity.api.energy.EnergyStorageHandler;
/**

View file

@ -11,7 +11,6 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonant.api.IMechanicalNode;
import resonant.api.grid.INodeProvider;
import resonant.lib.network.IPacketReceiver;
import resonant.lib.utility.WrenchUtility;
@ -20,6 +19,7 @@ import resonantinduction.core.grid.fluid.FluidPressureNode;
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
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;

View file

@ -6,7 +6,6 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import resonant.api.IMechanicalNode;
import resonant.core.content.debug.BlockCreativeBuilder;
import resonant.lib.content.ContentRegistry;
import resonant.lib.grid.NodeRegistry;
@ -32,6 +31,7 @@ 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;

View file

@ -7,11 +7,11 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
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 universalelectricity.api.vector.Vector3;
import codechicken.multipart.TMultiPart;
@ -36,6 +36,7 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
/** The current rotation of the mechanical node. */
public double angle = 0;
public double prev_angle = 0;
/** Limits the max distance an object can rotate in a single update */
protected double maxDeltaAngle = Math.toRadians(180);
protected double load = 2;
@ -65,18 +66,17 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
public void update(float deltaTime)
{
prevAngularVelocity = angularVelocity;
if (!ResonantInduction.proxy.isPaused())
//Update
if (angularVelocity >= 0)
{
if (angularVelocity >= 0)
{
angle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
}
else
{
angle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
}
angle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
}
else
{
angle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
}
System.out.println("Angle: " + angle);
if (angle % (Math.PI * 2) != angle)
{

View file

@ -3,13 +3,13 @@ package resonantinduction.mechanical.energy.turbine;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonant.lib.network.Synced;
import resonant.lib.network.Synced.SyncedInput;
import resonant.lib.network.Synced.SyncedOutput;
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

View file

@ -2,9 +2,9 @@ package resonantinduction.mechanical.gear;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
import resonant.api.grid.INodeProvider;
import resonantinduction.mechanical.energy.grid.MechanicalNode;
import resonantinduction.mechanical.interfaces.IMechanicalNode;
import codechicken.lib.vec.Rotation;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;

View file

@ -11,7 +11,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonant.lib.multiblock.IMultiBlockStructure;
@ -22,6 +21,7 @@ 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;

View file

@ -1,12 +1,14 @@
package resonantinduction.mechanical.gear.dev;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.net.IUpdate;
import universalelectricity.api.vector.Vector3;
import universalelectricity.core.net.ConnectionPathfinder;
/** Network type only used by gear related mechanical machines. Any node that uses this network needs
@ -87,6 +89,9 @@ public class GearNetwork implements IUpdate
if (doRemap)
{
doRemap = false;
//Rebuilds the network using a set of path finders
LinkedHashSet<Vector3> nodes = new LinkedHashSet<Vector3>();
}
}
@ -171,7 +176,7 @@ public class GearNetwork implements IUpdate
onRemoved(node, false);
}
}
newNetwork.reconstruct();
newNetwork.doRemap = true;
}
catch (Exception e)
{
@ -183,14 +188,19 @@ public class GearNetwork implements IUpdate
}
}
}
reconstruct();
}
/** Called to rebuild the network */
protected void reconstruct()
{
//TODO path find from each generator to each gear
for(NodeGear gear : nodes)
{
gear.reconstruct();
}
for(NodeGenerator gen : generators)
{
gen.reconstruct();
}
}
/** Called to destroy or rather clean up the network. Make sure to do your cleanup in this
@ -200,6 +210,14 @@ public class GearNetwork implements IUpdate
this.nodes.clear();
this.generators.clear();
this.isDead = true;
for(NodeGear gear : nodes)
{
gear.deconstruct();
}
for(NodeGenerator gen : generators)
{
gen.deconstruct();
}
}
}

View file

@ -0,0 +1,142 @@
package resonantinduction.mechanical.gear.dev;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import codechicken.multipart.TileMultipart;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorWorld;
/** @author robert */
public class GearPathFinder
{
/** A list of nodes that the pathfinder already went through. */
public final Set<Vector3> closedSet = new LinkedHashSet<Vector3>();
/** The resulted path found by the pathfinder. Could be null if no path was found. */
public final Set<Vector3> results = new LinkedHashSet<Vector3>();
protected final List<Object> ignoreConnector;
protected final Vector3 target;
public GearPathFinder(VectorWorld target, Object... ignoreConnector)
{
this.target = target;
if (ignoreConnector != null)
{
this.ignoreConnector = Arrays.asList(ignoreConnector);
}
else
{
this.ignoreConnector = new ArrayList<Object>();
}
}
public GearPathFinder(Object... ignoreConnector)
{
this(null, ignoreConnector);
}
/** A recursive function to find all connectors.
*
* @return True on success finding, false on failure. */
public boolean findNodes(VectorWorld currentNode)
{
this.closedSet.add(currentNode);
//Have we found our target
if (this.onSearch(currentNode))
{
return true;
}
//Search threw connected nodes
for (VectorWorld node : this.getConnectedNodes(currentNode))
{
//If we have not pathed this node look for nodes connected to it
if (!this.closedSet.contains(node))
{
//If we are done return true to stop the pathfinder
if (this.findNodes(node))
{
return true;
}
}
}
return false;
}
/** Finds all the nodes connected to this node */
public Set<VectorWorld> getConnectedNodes(VectorWorld currentNode)
{
Set<VectorWorld> connectedNodes = new HashSet<VectorWorld>();
if (currentNode != null)
{
TileEntity currentTile = currentNode.getTileEntity();
if (currentTile != null)
{
if (currentTile instanceof TileMultipart)
{
}
else
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
VectorWorld pos = (VectorWorld) currentNode.clone().translate(direction);
TileEntity tile = pos.getTileEntity();
if (isValid(pos) && isValid(tile))
{
connectedNodes.add(pos);
}
}
}
}
}
return connectedNodes;
}
/** Checks if its a valid node to path threw */
public boolean isValid(VectorWorld node)
{
return node != null && !this.ignoreConnector.contains(node);
}
/** Checks if its a valid tile to path threw */
public boolean isValid(TileEntity tile)
{
if (tile != null)
{
return !this.ignoreConnector.contains(tile);
}
return false;
}
/** Called each node that is searched */
protected boolean onSearch(Vector3 node)
{
if (node == target)
{
this.results.add(node);
return true;
}
return false;
}
public void reset()
{
this.results.clear();
this.closedSet.clear();
}
}

View file

@ -6,11 +6,11 @@ import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
import resonant.api.grid.INodeProvider;
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
{

View file

@ -0,0 +1,40 @@
package resonantinduction.mechanical.interfaces;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.grid.INode;
import universalelectricity.api.vector.Vector3;
/** Applied to any node that will act as a mechanical object in the network
*
* @author Darkguardsman */
public interface IMechanicalNode extends INode
{
/** The Rotational force */
public double getTorque();
/** TODO remove */
@Deprecated
public double getEnergy();
/** TODO remove */
@Deprecated
public double getPower();
/** The Rotational velocity */
public double getAngularVelocity();
/** Applies rotational force and velocity to the mechanical object */
public void apply(Object source, double torque, double angularVelocity);
public float getRatio(ForgeDirection dir, IMechanicalNode with);
@Deprecated
public boolean inverseRotation(ForgeDirection dir, IMechanicalNode with);
@Deprecated
public IMechanicalNode setLoad(double load);
@Deprecated
public Vector3 position();
}

View file

@ -7,7 +7,6 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.IMechanicalNode;
import resonant.api.IRotatable;
import resonant.api.recipe.MachineRecipes;
import resonant.api.recipe.RecipeResource;
@ -17,6 +16,7 @@ import resonantinduction.core.ResonantInduction;
import resonantinduction.core.ResonantInduction.RecipeType;
import resonantinduction.core.Timer;
import resonantinduction.mechanical.energy.grid.TileMechanical;
import resonantinduction.mechanical.interfaces.IMechanicalNode;
import universalelectricity.api.vector.Vector3;
/**

View file

@ -15,7 +15,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock;
import resonant.api.IMechanicalNode;
import resonant.api.recipe.MachineRecipes;
import resonant.lib.utility.inventory.InventoryUtility;
import resonantinduction.core.Reference;
@ -24,6 +23,7 @@ import resonantinduction.core.Timer;
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;
/**