Did some API cleaning up

This commit is contained in:
Ellpeck 2016-08-03 01:09:11 +02:00
parent d63c7e788d
commit 12f6430778
13 changed files with 95 additions and 165 deletions

View file

@ -25,9 +25,9 @@ public class CrusherRecipe{
public int outputOneAmount; public int outputOneAmount;
public String outputTwo; public String outputTwo;
public int outputTwoAmount; public int outputTwoAmount;
private ItemStack inputStack; public ItemStack inputStack;
private ItemStack outputOneStack; public ItemStack outputOneStack;
private ItemStack outputTwoStack; public ItemStack outputTwoStack;
public CrusherRecipe(ItemStack input, String outputOne, int outputOneAmount){ public CrusherRecipe(ItemStack input, String outputOne, int outputOneAmount){
this.inputStack = input; this.inputStack = input;
@ -51,75 +51,4 @@ public class CrusherRecipe{
this.outputTwoChance = outputTwoChance; this.outputTwoChance = outputTwoChance;
} }
public List<ItemStack> getRecipeOutputOnes(){
if(this.outputOneStack != null){
return Collections.singletonList(this.outputOneStack.copy());
}
if(this.outputOne == null || this.outputOne.isEmpty()){
return null;
}
List<ItemStack> stacks = OreDictionary.getOres(this.outputOne, false);
if(stacks != null && !stacks.isEmpty()){
List<ItemStack> stacksCopy = new ArrayList<ItemStack>();
for(ItemStack stack : stacks){
if(stack != null){
ItemStack stackCopy = stack.copy();
stackCopy.stackSize = this.outputOneAmount;
stacksCopy.add(stackCopy);
}
}
return stacksCopy;
}
return null;
}
public List<ItemStack> getRecipeOutputTwos(){
if(this.outputTwoStack != null){
return Collections.singletonList(this.outputTwoStack.copy());
}
if(this.outputTwo == null || this.outputTwo.isEmpty()){
return null;
}
List<ItemStack> stacks = OreDictionary.getOres(this.outputTwo, false);
if(stacks != null && !stacks.isEmpty()){
List<ItemStack> stacksCopy = new ArrayList<ItemStack>();
for(ItemStack stack : stacks){
if(stack != null){
ItemStack stackCopy = stack.copy();
stackCopy.stackSize = this.outputTwoAmount;
stacksCopy.add(stackCopy);
}
}
return stacksCopy;
}
return null;
}
public List<ItemStack> getRecipeInputs(){
if(this.inputStack != null){
return Collections.singletonList(this.inputStack.copy());
}
if(this.input == null || this.input.isEmpty()){
return null;
}
List<ItemStack> stacks = OreDictionary.getOres(this.input, false);
if(stacks != null && !stacks.isEmpty()){
List<ItemStack> stacksCopy = new ArrayList<ItemStack>();
for(ItemStack stack : stacks){
if(stack != null){
ItemStack stackCopy = stack.copy();
stackCopy.stackSize = 1;
stacksCopy.add(stackCopy);
}
}
return stacksCopy;
}
return null;
}
} }

View file

@ -12,20 +12,15 @@ package de.ellpeck.actuallyadditions.api.recipe;
import de.ellpeck.actuallyadditions.api.lens.LensConversion; import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LensConversionRecipe{ public class LensConversionRecipe{
public final int energyUse; public final int energyUse;
public final LensConversion type; public final LensConversion type;
private String input; public String input;
private String output; public String output;
private ItemStack inputStack; public ItemStack inputStack;
private ItemStack outputStack; public ItemStack outputStack;
public LensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type){ public LensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type){
this.inputStack = input; this.inputStack = input;
@ -41,51 +36,4 @@ public class LensConversionRecipe{
this.type = type; this.type = type;
} }
public List<ItemStack> getOutputs(){
if(this.outputStack != null){
return Collections.singletonList(this.outputStack.copy());
}
if(this.output == null || this.output.isEmpty()){
return null;
}
List<ItemStack> stacks = OreDictionary.getOres(this.output, false);
if(stacks != null && !stacks.isEmpty()){
List<ItemStack> stacksCopy = new ArrayList<ItemStack>();
for(ItemStack stack : stacks){
if(stack != null){
ItemStack stackCopy = stack.copy();
stackCopy.stackSize = 1;
stacksCopy.add(stackCopy);
}
}
return stacksCopy;
}
return null;
}
public List<ItemStack> getInputs(){
if(this.inputStack != null){
return Collections.singletonList(this.inputStack.copy());
}
if(this.input == null || this.input.isEmpty()){
return null;
}
List<ItemStack> stacks = OreDictionary.getOres(this.input, false);
if(stacks != null && !stacks.isEmpty()){
List<ItemStack> stacksCopy = new ArrayList<ItemStack>();
for(ItemStack stack : stacks){
if(stack != null){
ItemStack stackCopy = stack.copy();
stackCopy.stackSize = 1;
stacksCopy.add(stackCopy);
}
}
return stacksCopy;
}
return null;
}
} }

View file

@ -83,7 +83,6 @@ public class BlockCrystal extends BlockBase{
this.setMaxDamage(0); this.setMaxDamage(0);
} }
@Override @Override
public String getUnlocalizedName(ItemStack stack){ public String getUnlocalizedName(ItemStack stack){
return stack.getItemDamage() >= ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+ALL_CRYSTALS[stack.getItemDamage()].name; return stack.getItemDamage() >= ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+ALL_CRYSTALS[stack.getItemDamage()].name;

View file

@ -14,16 +14,14 @@ import de.ellpeck.actuallyadditions.api.internal.IBookletGui;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet; import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy; import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.*;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -69,19 +67,21 @@ public class PageCrusherRecipe extends BookletPageAA{
Minecraft.getMinecraft().fontRendererObj.drawString(this.recipe.outputTwoChance+"%", gui.getGuiLeft()+37+62, gui.getGuiTop()+20+33, 0); Minecraft.getMinecraft().fontRendererObj.drawString(this.recipe.outputTwoChance+"%", gui.getGuiLeft()+37+62, gui.getGuiTop()+20+33, 0);
} }
if(this.recipe.getRecipeOutputOnes() != null){ List<ItemStack> outputOnes = RecipeUtil.getCrusherRecipeOutputOnes(this.recipe);
if(outputOnes != null){
for(int i = 0; i < 2; i++){ for(int i = 0; i < 2; i++){
for(int j = 0; j < 3; j++){ for(int j = 0; j < 3; j++){
ItemStack stack; ItemStack stack;
switch(j){ switch(j){
case 0: case 0:
stack = this.recipe.getRecipeInputs().get(Math.min(this.recipe.getRecipeInputs().size()-1, this.recipePos)); List<ItemStack> inputs = RecipeUtil.getCrusherRecipeInputs(this.recipe);
stack = inputs.get(Math.min(inputs.size()-1, this.recipePos));
break; break;
case 1: case 1:
stack = this.recipe.getRecipeOutputOnes().get(Math.min(this.recipe.getRecipeOutputOnes().size()-1, this.recipePos)); stack = outputOnes.get(Math.min(outputOnes.size()-1, this.recipePos));
break; break;
default: default:
List<ItemStack> outputTwos = this.recipe.getRecipeOutputTwos(); List<ItemStack> outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.recipe);
stack = outputTwos == null ? null : outputTwos.get(Math.min(outputTwos.size()-1, this.recipePos)); stack = outputTwos == null ? null : outputTwos.get(Math.min(outputTwos.size()-1, this.recipePos));
break; break;
} }
@ -114,8 +114,8 @@ public class PageCrusherRecipe extends BookletPageAA{
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void updateScreen(int ticksElapsed){ public void updateScreen(int ticksElapsed){
if(ticksElapsed%10 == 0){ if(ticksElapsed%10 == 0){
List<ItemStack> outputTwos = this.recipe.getRecipeOutputTwos(); List<ItemStack> outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.recipe);
if(this.recipePos+1 >= Math.max(this.recipe.getRecipeInputs().size(), Math.max(this.recipe.getRecipeOutputOnes().size(), outputTwos == null ? 0 : outputTwos.size()))){ if(this.recipePos+1 >= Math.max(RecipeUtil.getCrusherRecipeInputs(this.recipe).size(), Math.max(RecipeUtil.getCrusherRecipeOutputOnes(this.recipe).size(), outputTwos == null ? 0 : outputTwos.size()))){
this.recipePos = 0; this.recipePos = 0;
} }
else{ else{
@ -126,6 +126,7 @@ public class PageCrusherRecipe extends BookletPageAA{
@Override @Override
public ItemStack[] getItemStacksForPage(){ public ItemStack[] getItemStacksForPage(){
return this.recipe == null ? new ItemStack[0] : this.recipe.getRecipeOutputOnes().toArray(new ItemStack[this.recipe.getRecipeOutputOnes().size()]); List<ItemStack> outputOnes = RecipeUtil.getCrusherRecipeOutputOnes(this.recipe);
return this.recipe == null ? new ItemStack[0] : outputOnes.toArray(new ItemStack[outputOnes.size()]);
} }
} }

View file

@ -15,10 +15,7 @@ import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet; import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy; import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.*;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@ -73,7 +70,7 @@ public class PageReconstructor extends BookletPageAA{
AssetUtil.renderStackToGui(new ItemStack(InitBlocks.blockAtomicReconstructor), gui.getGuiLeft()+37+22, gui.getGuiTop()+20+21, 1.0F); AssetUtil.renderStackToGui(new ItemStack(InitBlocks.blockAtomicReconstructor), gui.getGuiLeft()+37+22, gui.getGuiTop()+20+21, 1.0F);
for(int i = 0; i < 2; i++){ for(int i = 0; i < 2; i++){
for(int x = 0; x < 2; x++){ for(int x = 0; x < 2; x++){
List<ItemStack> stacks = x == 0 ? recipe.getInputs() : recipe.getOutputs(); List<ItemStack> stacks = x == 0 ? RecipeUtil.getConversionLensInputs(recipe) : RecipeUtil.getConversionLensOutputs(recipe);
if(stacks != null && !stacks.isEmpty()){ if(stacks != null && !stacks.isEmpty()){
ItemStack stack = stacks.get(0); ItemStack stack = stacks.get(0);
@ -117,7 +114,7 @@ public class PageReconstructor extends BookletPageAA{
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>(); ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
for(LensConversionRecipe recipe : this.recipes){ for(LensConversionRecipe recipe : this.recipes){
if(recipe != null){ if(recipe != null){
stacks.addAll(recipe.getOutputs()); stacks.addAll(RecipeUtil.getConversionLensOutputs(recipe));
} }
} }
return stacks.toArray(new ItemStack[stacks.size()]); return stacks.toArray(new ItemStack[stacks.size()]);

View file

@ -115,7 +115,7 @@ public final class LensRecipeHandler{
public static ArrayList<LensConversionRecipe> getRecipesFor(ItemStack input){ public static ArrayList<LensConversionRecipe> getRecipesFor(ItemStack input){
ArrayList<LensConversionRecipe> possibleRecipes = new ArrayList<LensConversionRecipe>(); ArrayList<LensConversionRecipe> possibleRecipes = new ArrayList<LensConversionRecipe>();
for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES){ for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES){
if(ItemUtil.contains(recipe.getInputs(), input, true)){ if(ItemUtil.contains(RecipeUtil.getConversionLensInputs(recipe), input, true)){
possibleRecipes.add(recipe); possibleRecipes.add(recipe);
} }
} }

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.jei.crusher; package de.ellpeck.actuallyadditions.mod.jei.crusher;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import mezz.jei.api.IGuiHelper; import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable; import mezz.jei.api.gui.IDrawable;
@ -66,12 +67,12 @@ public class CrusherRecipeCategory implements IRecipeCategory{
CrusherRecipeWrapper wrapper = (CrusherRecipeWrapper)recipeWrapper; CrusherRecipeWrapper wrapper = (CrusherRecipeWrapper)recipeWrapper;
recipeLayout.getItemStacks().init(0, true, 19, 7); recipeLayout.getItemStacks().init(0, true, 19, 7);
recipeLayout.getItemStacks().set(0, wrapper.theRecipe.getRecipeInputs()); recipeLayout.getItemStacks().set(0, RecipeUtil.getCrusherRecipeInputs(wrapper.theRecipe));
recipeLayout.getItemStacks().init(1, true, 7, 55); recipeLayout.getItemStacks().init(1, true, 7, 55);
recipeLayout.getItemStacks().set(1, wrapper.theRecipe.getRecipeOutputOnes()); recipeLayout.getItemStacks().set(1, RecipeUtil.getCrusherRecipeOutputOnes(wrapper.theRecipe));
List<ItemStack> outputTwos = wrapper.theRecipe.getRecipeOutputTwos(); List<ItemStack> outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(wrapper.theRecipe);
if(outputTwos != null && !outputTwos.isEmpty()){ if(outputTwos != null && !outputTwos.isEmpty()){
recipeLayout.getItemStacks().init(2, true, 31, 55); recipeLayout.getItemStacks().init(2, true, 31, 55);
recipeLayout.getItemStacks().set(2, outputTwos); recipeLayout.getItemStacks().set(2, outputTwos);

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
import de.ellpeck.actuallyadditions.mod.jei.RecipeWrapperWithButton; import de.ellpeck.actuallyadditions.mod.jei.RecipeWrapperWithButton;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import mezz.jei.api.recipe.IRecipeWrapper; import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -35,15 +36,15 @@ public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRe
@Override @Override
public List getInputs(){ public List getInputs(){
return this.theRecipe.getRecipeInputs(); return RecipeUtil.getCrusherRecipeInputs(this.theRecipe);
} }
@Override @Override
public List getOutputs(){ public List getOutputs(){
List list = new ArrayList(); List list = new ArrayList();
list.addAll(this.theRecipe.getRecipeOutputOnes()); list.addAll(RecipeUtil.getCrusherRecipeOutputOnes(this.theRecipe));
List<ItemStack> outputTwos = this.theRecipe.getRecipeOutputTwos(); List<ItemStack> outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.theRecipe);
if(outputTwos != null && !outputTwos.isEmpty()){ if(outputTwos != null && !outputTwos.isEmpty()){
list.addAll(outputTwos); list.addAll(outputTwos);
} }
@ -65,7 +66,7 @@ public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRe
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){
this.updateButton(minecraft, mouseX, mouseY); this.updateButton(minecraft, mouseX, mouseY);
List<ItemStack> outputTwos = this.theRecipe.getRecipeOutputTwos(); List<ItemStack> outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.theRecipe);
if(outputTwos != null && !outputTwos.isEmpty()){ if(outputTwos != null && !outputTwos.isEmpty()){
minecraft.fontRendererObj.drawString(this.theRecipe.outputTwoChance+"%", 60, 60, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); minecraft.fontRendererObj.drawString(this.theRecipe.outputTwoChance+"%", 60, 60, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false);
} }

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.jei.reconstructor;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import mezz.jei.api.IGuiHelper; import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable; import mezz.jei.api.gui.IDrawable;
@ -66,10 +67,10 @@ public class ReconstructorRecipeCategory implements IRecipeCategory{
ReconstructorRecipeWrapper wrapper = (ReconstructorRecipeWrapper)recipeWrapper; ReconstructorRecipeWrapper wrapper = (ReconstructorRecipeWrapper)recipeWrapper;
recipeLayout.getItemStacks().init(0, true, 4, 18); recipeLayout.getItemStacks().init(0, true, 4, 18);
recipeLayout.getItemStacks().set(0, wrapper.theRecipe.getInputs()); recipeLayout.getItemStacks().set(0, RecipeUtil.getConversionLensInputs(wrapper.theRecipe));
recipeLayout.getItemStacks().init(1, true, 66, 18); recipeLayout.getItemStacks().init(1, true, 66, 18);
recipeLayout.getItemStacks().set(1, wrapper.theRecipe.getOutputs()); recipeLayout.getItemStacks().set(1, RecipeUtil.getConversionLensOutputs(wrapper.theRecipe));
} }
} }

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
import de.ellpeck.actuallyadditions.mod.jei.RecipeWrapperWithButton; import de.ellpeck.actuallyadditions.mod.jei.RecipeWrapperWithButton;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import mezz.jei.api.recipe.IRecipeWrapper; import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -34,12 +35,12 @@ public class ReconstructorRecipeWrapper extends RecipeWrapperWithButton implemen
@Override @Override
public List getInputs(){ public List getInputs(){
return this.theRecipe.getInputs(); return RecipeUtil.getConversionLensInputs(this.theRecipe);
} }
@Override @Override
public List getOutputs(){ public List getOutputs(){
return this.theRecipe.getOutputs(); return RecipeUtil.getConversionLensOutputs(this.theRecipe);
} }
@Override @Override

View file

@ -24,6 +24,7 @@ import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture;
import de.ellpeck.actuallyadditions.mod.booklet.page.PageTextOnly; import de.ellpeck.actuallyadditions.mod.booklet.page.PageTextOnly;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler; import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -141,7 +142,7 @@ public class MethodHandler implements IMethodHandler{
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state))); List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)));
for(LensConversionRecipe recipe : recipes){ for(LensConversionRecipe recipe : recipes){
if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){ if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){
List<ItemStack> outputs = recipe.getOutputs(); List<ItemStack> outputs = RecipeUtil.getConversionLensOutputs(recipe);
if(outputs != null && !outputs.isEmpty()){ if(outputs != null && !outputs.isEmpty()){
ItemStack output = outputs.get(0); ItemStack output = outputs.get(0);
if(output.getItem() instanceof ItemBlock){ if(output.getItem() instanceof ItemBlock){
@ -171,7 +172,7 @@ public class MethodHandler implements IMethodHandler{
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(stack); List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(stack);
for(LensConversionRecipe recipe : recipes){ for(LensConversionRecipe recipe : recipes){
if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){ if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){
List<ItemStack> outputs = recipe.getOutputs(); List<ItemStack> outputs = RecipeUtil.getConversionLensOutputs(recipe);
if(outputs != null && !outputs.isEmpty()){ if(outputs != null && !outputs.isEmpty()){
ItemStack outputCopy = outputs.get(0).copy(); ItemStack outputCopy = outputs.get(0).copy();
outputCopy.stackSize = stack.stackSize; outputCopy.stackSize = stack.stackSize;

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
@ -82,12 +83,12 @@ public final class CrusherRecipeRegistry{
public static List<ItemStack> getOutputOnes(ItemStack input){ public static List<ItemStack> getOutputOnes(ItemStack input){
CrusherRecipe recipe = getRecipeFromInput(input); CrusherRecipe recipe = getRecipeFromInput(input);
return recipe == null ? null : recipe.getRecipeOutputOnes(); return recipe == null ? null : RecipeUtil.getCrusherRecipeOutputOnes(recipe);
} }
public static CrusherRecipe getRecipeFromInput(ItemStack input){ public static CrusherRecipe getRecipeFromInput(ItemStack input){
for(CrusherRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES){ for(CrusherRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES){
if(ItemUtil.contains(recipe.getRecipeInputs(), input, true)){ if(ItemUtil.contains(RecipeUtil.getCrusherRecipeInputs(recipe), input, true)){
return recipe; return recipe;
} }
} }
@ -96,7 +97,7 @@ public final class CrusherRecipeRegistry{
public static List<ItemStack> getOutputTwos(ItemStack input){ public static List<ItemStack> getOutputTwos(ItemStack input){
CrusherRecipe recipe = getRecipeFromInput(input); CrusherRecipe recipe = getRecipeFromInput(input);
return recipe == null ? null : recipe.getRecipeOutputTwos(); return recipe == null ? null : RecipeUtil.getCrusherRecipeOutputTwos(recipe);
} }
public static int getOutputTwoChance(ItemStack input){ public static int getOutputTwoChance(ItemStack input){

View file

@ -11,11 +11,17 @@
package de.ellpeck.actuallyadditions.mod.util; package de.ellpeck.actuallyadditions.mod.util;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public final class RecipeUtil{ public final class RecipeUtil{
@ -35,4 +41,48 @@ public final class RecipeUtil{
Object recipe = list.get(list.size()-1); Object recipe = list.get(list.size()-1);
return recipe instanceof IRecipe ? (IRecipe)recipe : null; return recipe instanceof IRecipe ? (IRecipe)recipe : null;
} }
public static List<ItemStack> getCrusherRecipeOutputOnes(CrusherRecipe recipe){
return doRecipeOrWhatever(recipe.outputOneStack, recipe.outputOne, recipe.outputOneAmount);
}
public static List<ItemStack> getCrusherRecipeOutputTwos(CrusherRecipe recipe){
return doRecipeOrWhatever(recipe.outputTwoStack, recipe.outputTwo, recipe.outputTwoAmount);
}
public static List<ItemStack> getCrusherRecipeInputs(CrusherRecipe recipe){
return doRecipeOrWhatever(recipe.inputStack, recipe.input, 1);
}
public static List<ItemStack> getConversionLensInputs(LensConversionRecipe recipe){
return doRecipeOrWhatever(recipe.inputStack, recipe.input, 1);
}
public static List<ItemStack> getConversionLensOutputs(LensConversionRecipe recipe){
return doRecipeOrWhatever(recipe.outputStack, recipe.output, 1);
}
private static List<ItemStack> doRecipeOrWhatever(ItemStack stack, String oredict, int amount){
if(stack != null){
return Collections.singletonList(stack.copy());
}
if(oredict == null || oredict.isEmpty()){
return null;
}
List<ItemStack> stacks = OreDictionary.getOres(oredict, false);
if(stacks != null && !stacks.isEmpty()){
List<ItemStack> stacksCopy = new ArrayList<ItemStack>();
for(ItemStack aStack : stacks){
if(aStack != null){
ItemStack stackCopy = aStack.copy();
stackCopy.stackSize = amount;
stacksCopy.add(stackCopy);
}
}
return stacksCopy;
}
return null;
}
} }