Added NodeRegistry
This commit is contained in:
parent
0bc9aab4ca
commit
34c6b75057
8 changed files with 164 additions and 115 deletions
|
@ -1,23 +0,0 @@
|
||||||
package resonantinduction.mechanical.energy.grid;
|
|
||||||
|
|
||||||
import resonantinduction.core.grid.Grid;
|
|
||||||
import resonantinduction.core.grid.INodeProvider;
|
|
||||||
import resonantinduction.core.grid.Node;
|
|
||||||
|
|
||||||
public abstract class EnergyNode<P extends INodeProvider, G extends Grid, N> extends Node<P, G, N>
|
|
||||||
{
|
|
||||||
public EnergyNode(P parent)
|
|
||||||
{
|
|
||||||
super(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Gets the power of this node. Note that power by definition is energy per second.
|
|
||||||
*/
|
|
||||||
public abstract double getPower();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Gets the energy buffered in this node at this instance.
|
|
||||||
*/
|
|
||||||
public abstract double getEnergy();
|
|
||||||
}
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package resonantinduction.mechanical.energy.grid;
|
||||||
|
|
||||||
|
public interface IEnergyNode
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return Gets the power of this node. Note that power by definition is energy per second.
|
||||||
|
*/
|
||||||
|
public double getPower();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Gets the energy buffered in this node at this instance.
|
||||||
|
*/
|
||||||
|
public double getEnergy();
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package resonantinduction.mechanical.energy.grid;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
|
public interface IMechanicalNode extends IEnergyNode
|
||||||
|
{
|
||||||
|
public double getTorque();
|
||||||
|
|
||||||
|
public double getAngularVelocity();
|
||||||
|
|
||||||
|
public void apply(double torque, double angularVelocity);
|
||||||
|
|
||||||
|
public float getRatio(ForgeDirection dir, MechanicalNode with);
|
||||||
|
|
||||||
|
public boolean inverseRotation(ForgeDirection dir, MechanicalNode with);
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.core.ResonantInduction;
|
import resonantinduction.core.ResonantInduction;
|
||||||
import resonantinduction.core.grid.INodeProvider;
|
import resonantinduction.core.grid.INodeProvider;
|
||||||
|
import resonantinduction.core.grid.Node;
|
||||||
import resonantinduction.core.grid.TickingGrid;
|
import resonantinduction.core.grid.TickingGrid;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
|
@ -29,7 +30,7 @@ import codechicken.multipart.TMultiPart;
|
||||||
*
|
*
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*/
|
*/
|
||||||
public class MechanicalNode extends EnergyNode<INodeProvider, TickingGrid, MechanicalNode>
|
public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalNode> implements IMechanicalNode
|
||||||
{
|
{
|
||||||
public double torque = 0;
|
public double torque = 0;
|
||||||
public double prevAngularVelocity, angularVelocity = 0;
|
public double prevAngularVelocity, angularVelocity = 0;
|
||||||
|
@ -148,27 +149,32 @@ public class MechanicalNode extends EnergyNode<INodeProvider, TickingGrid, Mecha
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void apply(double torque, double angularVelocity)
|
public void apply(double torque, double angularVelocity)
|
||||||
{
|
{
|
||||||
this.torque += torque;
|
this.torque += torque;
|
||||||
this.angularVelocity += angularVelocity;
|
this.angularVelocity += angularVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getTorque()
|
public double getTorque()
|
||||||
{
|
{
|
||||||
return angularVelocity != 0 ? torque : 0;
|
return angularVelocity != 0 ? torque : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getAngularVelocity()
|
public double getAngularVelocity()
|
||||||
{
|
{
|
||||||
return torque != 0 ? angularVelocity : 0;
|
return torque != 0 ? angularVelocity : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public float getRatio(ForgeDirection dir, MechanicalNode with)
|
public float getRatio(ForgeDirection dir, MechanicalNode with)
|
||||||
{
|
{
|
||||||
return 0.5f;
|
return 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inverseRotation(ForgeDirection dir, MechanicalNode with)
|
public boolean inverseRotation(ForgeDirection dir, MechanicalNode with)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -223,6 +229,7 @@ public class MechanicalNode extends EnergyNode<INodeProvider, TickingGrid, Mecha
|
||||||
return parent instanceof TMultiPart ? new Vector3(((TMultiPart) parent).x(), ((TMultiPart) parent).y(), ((TMultiPart) parent).z()) : parent instanceof TileEntity ? new Vector3((TileEntity) parent) : null;
|
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)
|
public boolean canConnect(ForgeDirection from, Object source)
|
||||||
{
|
{
|
||||||
return (source instanceof MechanicalNode) && (connectionMap & (1 << from.ordinal())) != 0;
|
return (source instanceof MechanicalNode) && (connectionMap & (1 << from.ordinal())) != 0;
|
||||||
|
|
|
@ -18,22 +18,18 @@ public final class MachineRecipes
|
||||||
{
|
{
|
||||||
public static enum RecipeType
|
public static enum RecipeType
|
||||||
{
|
{
|
||||||
CRUSHER,
|
CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL;
|
||||||
GRINDER,
|
|
||||||
MIXER,
|
|
||||||
SMELTER,
|
|
||||||
SAWMILL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> recipes = new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>();
|
private final Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> recipes = new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>();
|
||||||
|
|
||||||
public static final MachineRecipes INSTANCE = new MachineRecipes();
|
public static MachineRecipes INSTANCE = new MachineRecipes();
|
||||||
|
|
||||||
private MachineRecipes()
|
public MachineRecipes()
|
||||||
{
|
{
|
||||||
for (RecipeType machine : RecipeType.values())
|
for (RecipeType machine : RecipeType.values())
|
||||||
{
|
{
|
||||||
this.recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
|
recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
src/main/java/resonantinduction/core/grid/NodeRegistry.java
Normal file
35
src/main/java/resonantinduction/core/grid/NodeRegistry.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package resonantinduction.core.grid;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A dynamic node loader for registering different nodes for different node interfaces.
|
||||||
|
*
|
||||||
|
* @author Calclavia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeRegistry
|
||||||
|
{
|
||||||
|
private static final HashMap<Class, Class> INTERFACE_NODE_MAP = new HashMap<Class, Class>();
|
||||||
|
|
||||||
|
public static void register(Class nodeInterface, Class nodeClass)
|
||||||
|
{
|
||||||
|
INTERFACE_NODE_MAP.put(nodeInterface, nodeClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <N> Class<? extends N> get(INodeProvider parent, Class<N> nodeInterface)
|
||||||
|
{
|
||||||
|
Class nodeClass = INTERFACE_NODE_MAP.get(nodeInterface);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (Class<? extends N>) nodeClass.getConstructor(INodeProvider.class).newInstance(parent);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,18 +48,18 @@ public class ItemOreResource extends Item
|
||||||
@Override
|
@Override
|
||||||
public String getItemDisplayName(ItemStack is)
|
public String getItemDisplayName(ItemStack is)
|
||||||
{
|
{
|
||||||
String dustName = getMaterialFromStack(is);
|
String material = getMaterialFromStack(is);
|
||||||
|
|
||||||
if (dustName != null)
|
if (material != null)
|
||||||
{
|
{
|
||||||
List<ItemStack> list = OreDictionary.getOres("ingot" + dustName.substring(0, 1).toUpperCase() + dustName.substring(1));
|
List<ItemStack> list = OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1));
|
||||||
|
|
||||||
if (list.size() > 0)
|
if (list.size() > 0)
|
||||||
{
|
{
|
||||||
ItemStack type = list.get(0);
|
ItemStack type = list.get(0);
|
||||||
|
|
||||||
String name = type.getDisplayName().replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "");
|
String name = type.getDisplayName().replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "");
|
||||||
return (LanguageUtility.getLocal(this.getUnlocalizedName() + ".name")).replace("%v", name).replace(" ", " ");
|
return (LanguageUtility.getLocal(getUnlocalizedName() + ".name")).replace("%v", name).replace(" ", " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,11 @@ public class ResourceGenerator implements IVirtualObject
|
||||||
OreDictionary.registerOre("oreGold", Block.oreGold);
|
OreDictionary.registerOre("oreGold", Block.oreGold);
|
||||||
OreDictionary.registerOre("oreIron", Block.oreIron);
|
OreDictionary.registerOre("oreIron", Block.oreIron);
|
||||||
OreDictionary.registerOre("oreLapis", Block.oreLapis);
|
OreDictionary.registerOre("oreLapis", Block.oreLapis);
|
||||||
|
regenerateOreResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void regenerateOreResources()
|
||||||
|
{
|
||||||
// Vanilla fluid recipes
|
// Vanilla fluid recipes
|
||||||
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone));
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue