Added command to reload oreDicRecipes

This commit is contained in:
modmuss50 2015-05-09 13:42:47 +01:00
parent 333ba855fe
commit c37858de79
4 changed files with 123 additions and 53 deletions

View file

@ -6,13 +6,16 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import erogenousbeef.coreTR.multiblock.MultiblockEventHandler; import erogenousbeef.coreTR.multiblock.MultiblockEventHandler;
import erogenousbeef.coreTR.multiblock.MultiblockServerTickHandler; import erogenousbeef.coreTR.multiblock.MultiblockServerTickHandler;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import techreborn.achievement.TRAchievements; import techreborn.achievement.TRAchievements;
import techreborn.api.recipe.RecipeHanderer;
import techreborn.client.GuiHandler; import techreborn.client.GuiHandler;
import techreborn.command.TechRebornDevCommand;
import techreborn.compat.CompatManager; import techreborn.compat.CompatManager;
import techreborn.compat.recipes.RecipeManager; import techreborn.compat.recipes.RecipeManager;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
@ -86,6 +89,13 @@ public class Core {
{ {
// Has to be done here as Buildcraft registers there recipes late // Has to be done here as Buildcraft registers there recipes late
RecipeManager.init(); RecipeManager.init();
//RecipeHanderer.addOreDicRecipes();
LogHelper.info(RecipeHanderer.recipeList.size() + " recipes loaded");
}
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event){
event.registerServerCommand(new TechRebornDevCommand());
} }
} }

View file

@ -1,9 +1,12 @@
package techreborn.api.recipe; package techreborn.api.recipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
@ -14,6 +17,11 @@ public class RecipeHanderer {
*/ */
public static ArrayList<IBaseRecipeType> recipeList = new ArrayList<IBaseRecipeType>(); public static ArrayList<IBaseRecipeType> recipeList = new ArrayList<IBaseRecipeType>();
/**
* This is a backedup clone of the master recipeList
*/
public static ArrayList<IBaseRecipeType> recipeListBackup = new ArrayList<IBaseRecipeType>();
/** /**
* Use this to get all of the recipes form a recipe name * Use this to get all of the recipes form a recipe name
* @param name the name that the recipe was resisted as. * @param name the name that the recipe was resisted as.
@ -45,68 +53,69 @@ public class RecipeHanderer {
public static void addOreDicRecipes(){ public static void addOreDicRecipes(){
recipeListBackup.clear();
recipeListBackup.addAll(recipeList);
ArrayList<IBaseRecipeType> newRecipes = new ArrayList<IBaseRecipeType>(); ArrayList<IBaseRecipeType> newRecipes = new ArrayList<IBaseRecipeType>();
for(IBaseRecipeType baseRecipe : recipeList){ for(IBaseRecipeType baseRecipe : recipeList){
if(baseRecipe instanceof BaseRecipe){ if(baseRecipe instanceof BaseRecipe){
int i = 0; for (int i = 0; i < baseRecipe.getInputs().size(); i++) {
for(ItemStack stack : baseRecipe.getInputs()){ BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
for(int oreId : OreDictionary.getOreIDs(stack)){ for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).inputs.get(i))){
for(ItemStack itemStack : OreDictionary.getOres(oreId)){ for(ItemStack itemStack : getInputs(OreDictionary.getOreName(oreId))){
OreDicRecipe recipe = new OreDicRecipe(baseRecipe.getRecipeName(), ((BaseRecipe) baseRecipe).tickTime, ((BaseRecipe) baseRecipe).tickTime); System.out.println(itemStack.getDisplayName());
recipe.inputs.add(itemStack); newRecipe.inputs.set(i, itemStack);
newRecipes.add(recipe);
} }
} }
newRecipes.add(newRecipe);
}
for (int i = 0; i < baseRecipe.getOutputs().size(); i++) {
BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).outputs.get(i))){
for(ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreName(oreId))){
newRecipe.outputs.set(i, itemStack);
}
}
newRecipes.add(newRecipe);
}
}
}
recipeList.addAll(newRecipes);
}
public static List<ItemStack> getInputs(String name) {
List ores = getOres(name);
boolean hasInvalidEntries = false;
Iterator ret = ores.iterator();
while(ret.hasNext()) {
ItemStack i$ = (ItemStack)ret.next();
if(i$.getItem() == null) {
hasInvalidEntries = true;
break;
}
}
if(!hasInvalidEntries) {
return ores;
} else {
ArrayList ret1 = new ArrayList(ores.size());
Iterator i$1 = ores.iterator();
while(i$1.hasNext()) {
ItemStack stack = (ItemStack)i$1.next();
if(stack.getItem() != null) {
ret1.add(stack);
} }
} }
return Collections.unmodifiableList(ret1);
} }
} }
public static class OreDicRecipe implements IBaseRecipeType{ private static List<ItemStack> getOres(String name) {
ArrayList ret = OreDictionary.getOres(name);
public ArrayList<ItemStack> inputs; return ret;
public ArrayList<ItemStack> outputs;
public String name;
public int tickTime;
public int euPerTick;
public OreDicRecipe(String name, int tickTime, int euPerTick) {
inputs = new ArrayList<ItemStack>();
outputs = new ArrayList<ItemStack>();
this.name = name;
//This adds all new recipes
this.tickTime = tickTime;
this.euPerTick = euPerTick;
}
@Override
public List<ItemStack> getOutputs() {
return outputs;
}
@Override
public List<ItemStack> getInputs() {
return inputs;
}
@Override
public String getRecipeName() {
return name;
}
@Override
public int tickTime() {
return tickTime;
}
@Override
public int euPerTick() {
return euPerTick;
}
} }
} }

View file

@ -0,0 +1,51 @@
package techreborn.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.server.ForgeTimeTracker;
import techreborn.api.recipe.RecipeHanderer;
import techreborn.init.ModRecipes;
public class TechRebornDevCommand extends CommandBase {
@Override
public String getCommandName() {
return "trdev";
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "commands.forge.usage";
}
@Override
public int getRequiredPermissionLevel() {
return 2;
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if (args.length == 0) {
sender.addChatMessage(new ChatComponentText("You need to use arguments"));
} else if ("help".equals(args[0])) {
sender.addChatMessage(new ChatComponentText("recipes - Reloads all of the machine recipes"));
} else if ("recipes".equals(args[0])) {
long startTime = System.currentTimeMillis();
RecipeHanderer.recipeList.clear();
RecipeHanderer.recipeList.addAll(RecipeHanderer.recipeListBackup);
RecipeHanderer.addOreDicRecipes();
long endTime = System.currentTimeMillis();
sender.addChatMessage(new ChatComponentText("Reloaded oreDictionary Recipes in" + (endTime - startTime) + " milliseconds"));
sender.addChatMessage(new ChatComponentText(RecipeHanderer.recipeList.size() + " recipes loaded"));
}
}
}

View file

@ -198,7 +198,7 @@ public class ModRecipes {
Blocks.cobblestone); Blocks.cobblestone);
TechRebornAPI.registerBlastFurnaceRecipe(new BlastFurnaceRecipe(new ItemStack(Items.apple), new ItemStack(Items.ender_pearl), new ItemStack(Items.golden_apple), new ItemStack(Items.diamond), 120, 1000)); TechRebornAPI.registerBlastFurnaceRecipe(new BlastFurnaceRecipe(new ItemStack(Items.apple), new ItemStack(Items.ender_pearl), new ItemStack(Items.golden_apple), new ItemStack(Items.diamond), 120, 1000));
RecipeHanderer.addRecipe(new ImplosionCompressorRecipe(new ItemStack(Items.record_11), new ItemStack(Items.golden_apple), new ItemStack(Items.brewing_stand), new ItemStack(Items.carrot), 120, 5)); RecipeHanderer.addRecipe(new ImplosionCompressorRecipe(new ItemStack(Blocks.planks), new ItemStack(Blocks.wool), new ItemStack(Items.brewing_stand), new ItemStack(Items.carrot), 120, 5));
RecipeHanderer.addRecipe(new AlloySmelterRecipe(new ItemStack(Items.coal), new ItemStack(Blocks.sand), new ItemStack(Items.diamond), 120, 5)); RecipeHanderer.addRecipe(new AlloySmelterRecipe(new ItemStack(Items.coal), new ItemStack(Blocks.sand), new ItemStack(Items.diamond), 120, 5));
RecipeHanderer.addRecipe(new AssemblingMachineRecipe(new ItemStack(Items.coal), new ItemStack(Blocks.sand), new ItemStack(Items.diamond), 120, 5)); RecipeHanderer.addRecipe(new AssemblingMachineRecipe(new ItemStack(Items.coal), new ItemStack(Blocks.sand), new ItemStack(Items.diamond), 120, 5));