Added command to reload oreDicRecipes
This commit is contained in:
parent
333ba855fe
commit
c37858de79
4 changed files with 123 additions and 53 deletions
|
@ -6,13 +6,16 @@ import cpw.mods.fml.common.SidedProxy;
|
|||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
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.registry.GameRegistry;
|
||||
import erogenousbeef.coreTR.multiblock.MultiblockEventHandler;
|
||||
import erogenousbeef.coreTR.multiblock.MultiblockServerTickHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import techreborn.achievement.TRAchievements;
|
||||
import techreborn.api.recipe.RecipeHanderer;
|
||||
import techreborn.client.GuiHandler;
|
||||
import techreborn.command.TechRebornDevCommand;
|
||||
import techreborn.compat.CompatManager;
|
||||
import techreborn.compat.recipes.RecipeManager;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
|
@ -86,6 +89,13 @@ public class Core {
|
|||
{
|
||||
// Has to be done here as Buildcraft registers there recipes late
|
||||
RecipeManager.init();
|
||||
//RecipeHanderer.addOreDicRecipes();
|
||||
LogHelper.info(RecipeHanderer.recipeList.size() + " recipes loaded");
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent event){
|
||||
event.registerServerCommand(new TechRebornDevCommand());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package techreborn.api.recipe;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -14,6 +17,11 @@ public class RecipeHanderer {
|
|||
*/
|
||||
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
|
||||
* @param name the name that the recipe was resisted as.
|
||||
|
@ -45,68 +53,69 @@ public class RecipeHanderer {
|
|||
|
||||
|
||||
public static void addOreDicRecipes(){
|
||||
recipeListBackup.clear();
|
||||
recipeListBackup.addAll(recipeList);
|
||||
ArrayList<IBaseRecipeType> newRecipes = new ArrayList<IBaseRecipeType>();
|
||||
for(IBaseRecipeType baseRecipe : recipeList){
|
||||
if(baseRecipe instanceof BaseRecipe){
|
||||
int i = 0;
|
||||
for(ItemStack stack : baseRecipe.getInputs()){
|
||||
for(int oreId : OreDictionary.getOreIDs(stack)){
|
||||
for(ItemStack itemStack : OreDictionary.getOres(oreId)){
|
||||
OreDicRecipe recipe = new OreDicRecipe(baseRecipe.getRecipeName(), ((BaseRecipe) baseRecipe).tickTime, ((BaseRecipe) baseRecipe).tickTime);
|
||||
recipe.inputs.add(itemStack);
|
||||
newRecipes.add(recipe);
|
||||
for (int i = 0; i < baseRecipe.getInputs().size(); i++) {
|
||||
BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
|
||||
for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).inputs.get(i))){
|
||||
for(ItemStack itemStack : getInputs(OreDictionary.getOreName(oreId))){
|
||||
System.out.println(itemStack.getDisplayName());
|
||||
newRecipe.inputs.set(i, itemStack);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public static class OreDicRecipe implements IBaseRecipeType{
|
||||
if(!hasInvalidEntries) {
|
||||
return ores;
|
||||
} else {
|
||||
ArrayList ret1 = new ArrayList(ores.size());
|
||||
Iterator i$1 = ores.iterator();
|
||||
|
||||
public ArrayList<ItemStack> inputs;
|
||||
|
||||
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;
|
||||
while(i$1.hasNext()) {
|
||||
ItemStack stack = (ItemStack)i$1.next();
|
||||
if(stack.getItem() != null) {
|
||||
ret1.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getOutputs() {
|
||||
return outputs;
|
||||
return Collections.unmodifiableList(ret1);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
private static List<ItemStack> getOres(String name) {
|
||||
ArrayList ret = OreDictionary.getOres(name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
51
src/main/java/techreborn/command/TechRebornDevCommand.java
Normal file
51
src/main/java/techreborn/command/TechRebornDevCommand.java
Normal 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"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ public class ModRecipes {
|
|||
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));
|
||||
|
||||
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 AssemblingMachineRecipe(new ItemStack(Items.coal), new ItemStack(Blocks.sand), new ItemStack(Items.diamond), 120, 5));
|
||||
|
|
Loading…
Reference in a new issue