Started with ExNihilo rework

This commit is contained in:
Zixxl 2015-07-09 16:57:05 +02:00
parent 2dd8e910f4
commit df846585c4
6 changed files with 247 additions and 182 deletions

View file

@ -14,6 +14,7 @@ import modtweaker2.mods.botania.lexicon.commands.LexiconKnowledgeTypesLogger;
import modtweaker2.mods.botania.lexicon.commands.LexiconPageLogger;
import modtweaker2.mods.chisel.commands.ChiselGroupLogger;
import modtweaker2.mods.chisel.commands.ChiselVariationLogger;
import modtweaker2.mods.exnihilo.commands.ExNihiloLogger;
import modtweaker2.mods.factorization.commands.FactorizationLogger;
import modtweaker2.mods.mekanism.gas.GasLogger;
import modtweaker2.mods.railcraft.commands.RailcraftLogger;
@ -85,6 +86,10 @@ public class Commands {
if (TweakerPlugin.isLoaded("Railcraft")) {
MineTweakerAPI.server.addMineTweakerCommand("railcraft", new String[] {"/minetweaker railcraft [FILTER]", " Outputs a list of all Railcraft recipes."}, new RailcraftLogger());
}
if (TweakerPlugin.isLoaded("exnihilo")) {
MineTweakerAPI.server.addMineTweakerCommand("exnihilo", new String[] {"/minetweaker exnihilo [FILTER]", " Outputs a list of all ExNihilo recipes."}, new ExNihiloLogger());
}
}
}

View file

@ -0,0 +1,13 @@
package modtweaker2.mods.exnihilo;
import java.util.Map;
import modtweaker2.helpers.ReflectionHelper;
import exnihilo.registries.HeatRegistry;
import exnihilo.utils.ItemInfo;
public class ExNihiloHelper {
public static Map<ItemInfo, Float> getHeatMap() {
return ReflectionHelper.<Map<ItemInfo, Float>>getStaticObject(HeatRegistry.class, "heatmap");
}
}

View file

@ -0,0 +1,69 @@
package modtweaker2.mods.exnihilo.commands;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import minetweaker.MineTweakerAPI;
import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.player.IPlayer;
import minetweaker.api.server.ICommandFunction;
import modtweaker2.helpers.LogHelper;
import modtweaker2.helpers.StringHelper;
import modtweaker2.mods.exnihilo.ExNihiloHelper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import exnihilo.registries.CompostRegistry;
import exnihilo.registries.CrucibleRegistry;
import exnihilo.registries.helpers.Compostable;
import exnihilo.registries.helpers.Meltable;
import exnihilo.utils.ItemInfo;
public class ExNihiloLogger implements ICommandFunction {
private static final List<String> validArguments = new LinkedList<String>();
static {
validArguments.add("compost");
validArguments.add("crucible");
}
@Override
public void execute(String[] arguments, IPlayer player) {
List<String> args = StringHelper.toLowerCase(Arrays.asList(arguments));
if(!validArguments.containsAll(args)) {
if(player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
}
} else {
if(args.isEmpty() || args.contains("compost")) {
for(Entry<ItemInfo, Compostable> recipe : CompostRegistry.entries.entrySet()) {
MineTweakerAPI.logCommand(String.format("mods.exnihilo.Composting.addRecipe(%s, %s, \"%s\");",
LogHelper.getStackDescription(recipe.getKey().getStack()),
recipe.getValue().value,
Integer.toHexString(recipe.getValue().color.toInt()).substring(2)));
}
}
if(args.isEmpty() || args.contains("crucible")) {
for(Meltable recipe : CrucibleRegistry.entries.values()) {
MineTweakerAPI.logCommand(String.format("mods.exnihilo.Crucible.addRecipe(%s, %s);",
LogHelper.getStackDescription(new ItemStack(recipe.block, 1, recipe.meta)),
LogHelper.getStackDescription(new FluidStack(recipe.fluid, (int)recipe.fluidVolume))));
}
for(Entry<ItemInfo, Float> recipe : ExNihiloHelper.getHeatMap().entrySet()) {
MineTweakerAPI.logCommand(String.format("mods.exnihilo.Crucible.addHeatSource(%s, %s);",
LogHelper.getStackDescription(recipe.getKey().getStack()),
recipe.getValue()));
}
}
if (player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
}
}
}
}

View file

@ -1,117 +1,92 @@
package modtweaker2.mods.exnihilo.handlers;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toStack;
import minetweaker.IUndoableAction;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseMapAddition;
import modtweaker2.utils.BaseMapRemoval;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import exnihilo.registries.CompostRegistry;
import exnihilo.registries.helpers.Color;
import exnihilo.registries.helpers.Compostable;
import exnihilo.utils.ItemInfo;
@ZenClass("mods.exnihilo.Composting")
public class Compost {
//Adding a Ex Nihilo Composting recipe
public static final String name = "ExNihilo Composting";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRecipe(IItemStack input, double value, @Optional String hex) {
hex = (hex == null || hex.equals("")) ? "35A82A" : hex;
MineTweakerAPI.apply(new Add(toStack(input).getItem(), toStack(input).getItemDamage(), Math.min(1.0F, (float) value), new Color(hex)));
}
//Passes the list to the map list implementation, and adds the recipe
private static class Add implements IUndoableAction
{
private Item item;
private int meta;
private float value;
private Color color;
public Add(Item item, int meta, float value, Color color) {
this.item = item;
this.meta = meta;
this.value = value;
this.color = color;
if(input == null) {
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
return;
}
hex = (hex == null || hex.equals("")) ? "35A82A" : hex;
Map<ItemInfo, Compostable> recipes = new HashMap<ItemInfo, Compostable>();
recipes.put(
new ItemInfo(toStack(input)),
new Compostable(Math.min(1.0F, (float)value), new Color(hex)));
MineTweakerAPI.apply(new Add(recipes));
}
private static class Add extends BaseMapAddition<ItemInfo, Compostable> {
public Add(Map<ItemInfo, Compostable> recipes) {
super(Compost.name, CompostRegistry.entries, recipes);
}
@Override
protected String getRecipeInfo(Entry<ItemInfo, Compostable> recipe) {
return LogHelper.getStackDescription(recipe.getKey().getStack());
}
@Override
public void apply() {
CompostRegistry.register(item, meta, value, color);
}
@Override
public boolean canUndo() {
return false;
}
@Override
public String describe() {
return "Adding Composting Recipe using " + item.getUnlocalizedName();
}
@Override
public String describeUndo() {
return null;
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public void undo() {
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Removing a Ex Nihilo Composting recipe
@ZenMethod
public static void removeRecipe(IItemStack input) {
MineTweakerAPI.apply(new Remove(toStack(input)));
}
//Removes a recipe, will always remove the key, so all should be good
private static class Remove implements IUndoableAction
{
private ItemStack stack;
public Remove(ItemStack stack) {
this.stack = stack;
public static void removeRecipe(IIngredient input) {
Map<ItemInfo, Compostable> recipes = new HashMap<ItemInfo, Compostable>();
for(Entry<ItemInfo, Compostable> recipe : CompostRegistry.entries.entrySet()) {
if(matches(input, toIItemStack(recipe.getKey().getStack()))) {
recipes.put(recipe.getKey(), recipe.getValue());
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s recipes found for %s. Command ignored!", Compost.name, input.toString()));
}
}
private static class Remove extends BaseMapRemoval<ItemInfo, Compostable> {
public Remove(Map<ItemInfo, Compostable> recipes) {
super(Compost.name, CompostRegistry.entries, recipes);
}
@Override
protected String getRecipeInfo(Entry<ItemInfo, Compostable> recipe) {
return LogHelper.getStackDescription(recipe.getKey().getStack());
}
@Override
public void apply() {
CompostRegistry.unregister(stack.getItem(), stack.getItemDamage());
}
@Override
public boolean canUndo() {
return false;
}
@Override
public String describe() {
return "Removing Composting Recipe using " + stack.getUnlocalizedName();
}
@Override
public String describeUndo() {
return null;
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public void undo() {
}
}
}

View file

@ -2,45 +2,69 @@ package modtweaker2.mods.exnihilo.handlers;
import static modtweaker2.helpers.InputHelper.isABlock;
import static modtweaker2.helpers.InputHelper.toFluid;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toILiquidStack;
import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import modtweaker2.helpers.LogHelper;
import modtweaker2.mods.exnihilo.ExNihiloHelper;
import modtweaker2.utils.BaseMapAddition;
import modtweaker2.utils.BaseMapRemoval;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import exnihilo.registries.CrucibleRegistry;
import exnihilo.registries.HeatRegistry;
import exnihilo.registries.helpers.Meltable;
import exnihilo.utils.ItemInfo;
@ZenClass("mods.exnihilo.Crucible")
public class Crucible {
public static final String nameMelting = "ExNihilo Crucible (Melting)";
public static final String nameHeatSource = "ExNihilo Crucible (Heat source)";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/************************************************ Crucible Melting ************************************************/
//Adding a Ex Nihilo Crucible recipe
@ZenMethod
public static void addRecipe(IItemStack input, ILiquidStack fluid) {
if (isABlock(input)) {
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
int theMeta = toStack(input).getItemDamage();
MineTweakerAPI.apply(new AddRecipe(new Meltable(theBlock, theMeta, 2000, toFluid(fluid).getFluid(), toFluid(fluid).amount, theBlock)));
if(input == null || fluid == null) {
LogHelper.logError(String.format("Required parameters missing for %s recipe.", nameMelting));
return;
}
if(!isABlock(input)) {
LogHelper.logError(String.format("Input item for %s recipe must be a block.", nameMelting));
return;
}
Map<String, Meltable> recipes = new HashMap<String, Meltable>();
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
int theMeta = toStack(input).getItemDamage();
recipes.put(
theBlock + ":" + theMeta,
new Meltable(theBlock, theMeta, 2000, toFluid(fluid).getFluid(), toFluid(fluid).amount, theBlock));
MineTweakerAPI.apply(new AddRecipe(recipes));
}
//Passes the list to the map list implementation, and adds the recipe
private static class AddRecipe extends BaseMapAddition<String, Meltable> {
public AddRecipe(Meltable recipe) {
super("ExNihilo Crucible", CrucibleRegistry.entries);
recipes.put(recipe.block + ":" + recipe.meta, recipe);
public AddRecipe(Map<String, Meltable> recipes) {
super(nameMelting, CrucibleRegistry.entries, recipes);
}
@Override
@ -53,23 +77,27 @@ public class Crucible {
//Removing a Ex Nihilo Crucible recipe
@ZenMethod
public static void removeRecipe(IItemStack output) {
if (isABlock(output)) {
MineTweakerAPI.apply(new RemoveRecipe(toStack(output)));
public static void removeRecipe(IIngredient output) {
Map<String, Meltable> recipes = new HashMap<String, Meltable>();
for(Entry<String, Meltable> entry : CrucibleRegistry.entries.entrySet()) {
FluidStack fluid = new FluidStack(entry.getValue().fluid, (int)entry.getValue().fluidVolume);
if(matches(output, toILiquidStack(fluid))) {
recipes.put(entry.getKey(), entry.getValue());
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new RemoveRecipe(recipes));
} else {
LogHelper.logWarning(String.format("No %s recipe found for %s. Command ignored!", Crucible.nameMelting, output.toString()));
}
}
//Removes a recipe, will always remove the key, so all should be good
private static class RemoveRecipe extends BaseMapRemoval<String, Meltable> {
public RemoveRecipe(ItemStack stack) {
super("ExNihilo Crucible", CrucibleRegistry.entries);
String key = Block.getBlockFromItem(stack.getItem()) + ":" + stack.getItemDamage();
for(Entry<String, Meltable> entry : map.entrySet()) {
if(entry.getKey().equals(key))
recipes.put(entry.getKey(), entry.getValue());
}
public RemoveRecipe(Map<String, Meltable> recipes) {
super(nameMelting, CrucibleRegistry.entries, recipes);
}
@Override
@ -82,92 +110,67 @@ public class Crucible {
//Adding a Ex Nihilo Crucible heat source
@ZenMethod
public static void addHeatSource(IItemStack input, double value) {
if (isABlock(input)) {
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
int theMeta = toStack(input).getItemDamage();
MineTweakerAPI.apply(new AddHeatSource(theBlock, theMeta, (float) value));
if(input == null) {
LogHelper.logError(String.format("Required parameters missing for %s recipe.", nameMelting));
return;
}
if(!isABlock(input)) {
LogHelper.logError(String.format("Input item for %s recipe must be a block.", nameMelting));
return;
}
Map<ItemInfo, Float> recipes = new HashMap<ItemInfo, Float>();
recipes.put(new ItemInfo(toStack(input)), (float)value);
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new AddHeatSource(recipes));
}
}
//Passes the list to the base map implementation, and adds the recipe
private static class AddHeatSource implements IUndoableAction
private static class AddHeatSource extends BaseMapAddition<ItemInfo, Float>
{
Block source;
int sourceMeta;
float value;
public AddHeatSource(Block source, int sourceMeta, float value) {
this.source = source;
this.sourceMeta = sourceMeta;
this.value = value;
public AddHeatSource(Map<ItemInfo, Float> recipes) {
super(Crucible.nameHeatSource, ExNihiloHelper.getHeatMap(), recipes);
}
public void apply() {
HeatRegistry.register(source, sourceMeta, value);
}
public boolean canUndo() {
return false;
}
public String describe() {
return "Adding ExNihilo Heat source of " + source.getLocalizedName();
}
public String describeUndo() {
return null;
}
public Object getOverrideKey() {
return null;
}
public void undo() {
@Override
protected String getRecipeInfo(Entry<ItemInfo, Float> recipe) {
return LogHelper.getStackDescription(recipe.getKey().getStack());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Removing a Ex Nihilo Crucible heat source
@ZenMethod
public static void removeHeatSource(IItemStack output) {
if (isABlock(output)) {
Block block = Block.getBlockFromItem(toStack(output).getItem());
MineTweakerAPI.apply(new RemoveHeatSource(block));
public static void removeHeatSource(IIngredient output) {
Map<ItemInfo, Float> recipes = new HashMap<ItemInfo, Float>();
for(Entry<ItemInfo, Float> entry : ExNihiloHelper.getHeatMap().entrySet()) {
if(matches(output, toIItemStack(entry.getKey().getStack()))) {
recipes.put(entry.getKey(), entry.getValue());
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new RemoveHeatSource(recipes));
} else {
LogHelper.logWarning(String.format("No %s recipe found for %s. Command ignored!", Crucible.nameMelting, output.toString()));
}
}
//Removes a recipe, will always remove the key, so all should be good
private static class RemoveHeatSource implements IUndoableAction
private static class RemoveHeatSource extends BaseMapAddition<ItemInfo, Float>
{
Block block;
public RemoveHeatSource(Block block) {
this.block = block;
public RemoveHeatSource(Map<ItemInfo, Float> recipes) {
super(Crucible.nameHeatSource, ExNihiloHelper.getHeatMap(), recipes);
}
public void apply() {
HeatRegistry.unregister(block);
}
public boolean canUndo() {
return false;
}
public String describe() {
return "Removing ExNihilo Heat source of " + block.getLocalizedName();
}
public String describeUndo() {
return null;
}
public Object getOverrideKey() {
return null;
}
public void undo() {
}
@Override
protected String getRecipeInfo(Entry<ItemInfo, Float> recipe) {
return LogHelper.getStackDescription(recipe.getKey().getStack());
}
}
}

View file

@ -13,9 +13,9 @@ import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ToolMaterial;
public class MaterialLogger implements ICommandFunction {
private static ArrayList<String> materials = new ArrayList();
private static ArrayList<String> materials = new ArrayList<String>();
static {
materials = new ArrayList();
materials = new ArrayList<String>();
for (Map.Entry<String, ToolMaterial> entry : TConstructRegistry.toolMaterialStrings.entrySet()) {
materials.add(entry.getKey());
}