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;
|
||||||
|
|
|
@ -16,114 +16,110 @@ import resonantinduction.api.recipe.RecipeResource.OreDictResource;
|
||||||
|
|
||||||
public final class MachineRecipes
|
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[]>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeResource getResourceFromObject(Object obj)
|
public RecipeResource getResourceFromObject(Object obj)
|
||||||
{
|
{
|
||||||
if (obj instanceof String)
|
if (obj instanceof String)
|
||||||
return new OreDictResource((String) obj);
|
return new OreDictResource((String) obj);
|
||||||
|
|
||||||
if (obj instanceof Block)
|
if (obj instanceof Block)
|
||||||
return new ItemStackResource(new ItemStack((Block) obj));
|
return new ItemStackResource(new ItemStack((Block) obj));
|
||||||
|
|
||||||
if (obj instanceof Item)
|
if (obj instanceof Item)
|
||||||
return new ItemStackResource(new ItemStack((Item) obj));
|
return new ItemStackResource(new ItemStack((Item) obj));
|
||||||
|
|
||||||
if (obj instanceof ItemStack)
|
if (obj instanceof ItemStack)
|
||||||
return new ItemStackResource((ItemStack) obj);
|
return new ItemStackResource((ItemStack) obj);
|
||||||
|
|
||||||
if (obj instanceof FluidStack)
|
if (obj instanceof FluidStack)
|
||||||
return new FluidStackResource((FluidStack) obj);
|
return new FluidStackResource((FluidStack) obj);
|
||||||
|
|
||||||
if (obj instanceof RecipeResource)
|
if (obj instanceof RecipeResource)
|
||||||
return (RecipeResource) obj;
|
return (RecipeResource) obj;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output)
|
public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output)
|
||||||
{
|
{
|
||||||
this.recipes.get(machine).put(input, output);
|
this.recipes.get(machine).put(input, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
|
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
|
||||||
{
|
{
|
||||||
RecipeResource input = getResourceFromObject(inputObj);
|
RecipeResource input = getResourceFromObject(inputObj);
|
||||||
RecipeResource[] outputs = new RecipeResource[outputObj.length];
|
RecipeResource[] outputs = new RecipeResource[outputObj.length];
|
||||||
|
|
||||||
for (int i = 0; i < outputs.length; i++)
|
for (int i = 0; i < outputs.length; i++)
|
||||||
{
|
{
|
||||||
RecipeResource output = getResourceFromObject(outputObj[i]);
|
RecipeResource output = getResourceFromObject(outputObj[i]);
|
||||||
|
|
||||||
if (input == null || output == null)
|
if (input == null || output == null)
|
||||||
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
|
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
|
||||||
|
|
||||||
outputs[i] = output;
|
outputs[i] = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
addRecipe(machine, new RecipeResource[] { input }, outputs);
|
addRecipe(machine, new RecipeResource[] { input }, outputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRecipe(RecipeType machine, RecipeResource[] input)
|
public void removeRecipe(RecipeType machine, RecipeResource[] input)
|
||||||
{
|
{
|
||||||
this.recipes.get(machine).remove(input);
|
this.recipes.get(machine).remove(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
|
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
|
||||||
{
|
{
|
||||||
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
|
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
|
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
|
||||||
{
|
{
|
||||||
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
|
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
|
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
|
||||||
{
|
{
|
||||||
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
|
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
|
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
|
||||||
|
|
||||||
if (Arrays.equals(entry.getKey(), input))
|
if (Arrays.equals(entry.getKey(), input))
|
||||||
{
|
{
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RecipeResource[] {};
|
return new RecipeResource[] {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeResource[] getOutput(RecipeType machine, Object... inputs)
|
public RecipeResource[] getOutput(RecipeType machine, Object... inputs)
|
||||||
{
|
{
|
||||||
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
|
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
|
||||||
|
|
||||||
for (int i = 0; i < inputs.length; i++)
|
for (int i = 0; i < inputs.length; i++)
|
||||||
{
|
{
|
||||||
resourceInputs[i] = getResourceFromObject(inputs[i]);
|
resourceInputs[i] = getResourceFromObject(inputs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getOutput(machine, resourceInputs);
|
return getOutput(machine, resourceInputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
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…
Reference in a new issue