Store ItemStackWrappers instead of just ItemStacks (#844)
* Store ItemStackWrappers instead of just ItemStacks Allows proper usage of getRecipeForInput() * Refactoring and helper methods
This commit is contained in:
parent
46a35ac1fb
commit
c34bd48aa5
|
@ -1,5 +1,6 @@
|
|||
package WayofTime.bloodmagic.altar;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
@ -354,7 +355,8 @@ public class BloodAltar implements IFluidHandler
|
|||
if (tileAltar.getStackInSlot(0) != null)
|
||||
{
|
||||
// Do recipes
|
||||
for (AltarRecipe recipe : AltarRecipeRegistry.getRecipes().values())
|
||||
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(tileAltar.getStackInSlot(0));
|
||||
if (recipe != null)
|
||||
{
|
||||
if (recipe.doesRequiredItemMatch(tileAltar.getStackInSlot(0), altarTier))
|
||||
{
|
||||
|
|
|
@ -8,6 +8,9 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class ItemStackWrapper
|
||||
|
@ -80,4 +83,22 @@ public class ItemStackWrapper
|
|||
result.setTagCompound(nbtTag);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<ItemStackWrapper> toWrapperList(List<ItemStack> itemStackList)
|
||||
{
|
||||
List<ItemStackWrapper> wrapperList = new ArrayList<ItemStackWrapper>();
|
||||
for (ItemStack stack : itemStackList)
|
||||
wrapperList.add(ItemStackWrapper.getHolder(stack));
|
||||
|
||||
return wrapperList;
|
||||
}
|
||||
|
||||
public static List<ItemStack> toStackList(List<ItemStackWrapper> wrapperList)
|
||||
{
|
||||
List<ItemStack> stackList = new ArrayList<ItemStack>();
|
||||
for (ItemStackWrapper wrapper : wrapperList)
|
||||
stackList.add(wrapper.toStack());
|
||||
|
||||
return stackList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package WayofTime.bloodmagic.api.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
@ -15,7 +16,7 @@ import java.util.List;
|
|||
|
||||
public class AltarRecipeRegistry
|
||||
{
|
||||
private static BiMap<List<ItemStack>, AltarRecipe> recipes = HashBiMap.create();
|
||||
private static BiMap<List<ItemStackWrapper>, AltarRecipe> recipes = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Registers an {@link AltarRecipe} for the Blood Altar. This can be a
|
||||
|
@ -50,13 +51,24 @@ public class AltarRecipeRegistry
|
|||
*/
|
||||
public static AltarRecipe getRecipeForInput(List<ItemStack> input)
|
||||
{
|
||||
if (recipes.keySet().contains(input))
|
||||
return recipes.get(input);
|
||||
List<ItemStackWrapper> wrapperList = ItemStackWrapper.toWrapperList(input);
|
||||
if (recipes.keySet().contains(wrapperList))
|
||||
return recipes.get(wrapperList);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BiMap<List<ItemStack>, AltarRecipe> getRecipes()
|
||||
public static AltarRecipe getRecipeForInput(ItemStack input)
|
||||
{
|
||||
return getRecipeForInput(Collections.singletonList(input));
|
||||
}
|
||||
|
||||
public static AltarRecipe getRecipeForInput(String input)
|
||||
{
|
||||
return getRecipeForInput(OreDictionary.getOres(input));
|
||||
}
|
||||
|
||||
public static BiMap<List<ItemStackWrapper>, AltarRecipe> getRecipes()
|
||||
{
|
||||
return HashBiMap.create(recipes);
|
||||
}
|
||||
|
@ -66,7 +78,7 @@ public class AltarRecipeRegistry
|
|||
@EqualsAndHashCode
|
||||
public static class AltarRecipe
|
||||
{
|
||||
private final List<ItemStack> input;
|
||||
private final List<ItemStackWrapper> input;
|
||||
private final ItemStack output;
|
||||
private final EnumAltarTier minTier;
|
||||
private final int syphon, consumeRate, drainRate;
|
||||
|
@ -96,7 +108,7 @@ public class AltarRecipeRegistry
|
|||
*/
|
||||
public AltarRecipe(List<ItemStack> input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable)
|
||||
{
|
||||
this.input = input;
|
||||
this.input = ItemStackWrapper.toWrapperList(input);
|
||||
this.output = output;
|
||||
this.minTier = minTier;
|
||||
this.syphon = syphon < 0 ? -syphon : syphon;
|
||||
|
@ -138,8 +150,8 @@ public class AltarRecipeRegistry
|
|||
if (tierCheck.ordinal() < minTier.ordinal())
|
||||
return false;
|
||||
|
||||
for (ItemStack stack : input)
|
||||
if (comparedStack.isItemEqual(stack))
|
||||
for (ItemStackWrapper stack : input)
|
||||
if (comparedStack.isItemEqual(stack.toStack()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package WayofTime.bloodmagic.compat.guideapi.page;
|
||||
|
||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import amerifrance.guideapi.api.impl.Book;
|
||||
|
@ -29,7 +30,7 @@ public class PageAltarRecipe extends Page
|
|||
|
||||
public PageAltarRecipe(AltarRecipeRegistry.AltarRecipe recipe)
|
||||
{
|
||||
this.input = recipe.getInput();
|
||||
this.input = ItemStackWrapper.toStackList(recipe.getInput());
|
||||
this.output = recipe.getOutput();
|
||||
this.tier = recipe.getMinTier().toInt();
|
||||
this.bloodRequired = recipe.getSyphon();
|
||||
|
|
|
@ -7,27 +7,27 @@ import java.util.Map;
|
|||
import javax.annotation.Nonnull;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import WayofTime.bloodmagic.api.orb.IBloodOrb;
|
||||
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.fluids.UniversalBucket;
|
||||
|
||||
public class AltarRecipeMaker
|
||||
{
|
||||
@Nonnull
|
||||
public static List<AltarRecipeJEI> getRecipes()
|
||||
{
|
||||
Map<List<ItemStack>, AltarRecipeRegistry.AltarRecipe> altarMap = AltarRecipeRegistry.getRecipes();
|
||||
Map<List<ItemStackWrapper>, AltarRecipeRegistry.AltarRecipe> altarMap = AltarRecipeRegistry.getRecipes();
|
||||
|
||||
ArrayList<AltarRecipeJEI> recipes = new ArrayList<AltarRecipeJEI>();
|
||||
|
||||
for (Map.Entry<List<ItemStack>, AltarRecipeRegistry.AltarRecipe> itemStackAltarRecipeEntry : altarMap.entrySet())
|
||||
for (Map.Entry<List<ItemStackWrapper>, AltarRecipeRegistry.AltarRecipe> itemStackAltarRecipeEntry : altarMap.entrySet())
|
||||
{
|
||||
// Make sure input is not a Blood Orb. If it is, the recipe is for a filling orb, and we don't want that.
|
||||
if (!(itemStackAltarRecipeEntry.getKey().get(0).getItem() instanceof IBloodOrb))
|
||||
if (!(itemStackAltarRecipeEntry.getKey().get(0).toStack().getItem() instanceof IBloodOrb))
|
||||
{
|
||||
List<ItemStack> input = itemStackAltarRecipeEntry.getValue().getInput();
|
||||
List<ItemStack> input = ItemStackWrapper.toStackList(itemStackAltarRecipeEntry.getValue().getInput());
|
||||
ItemStack output = itemStackAltarRecipeEntry.getValue().getOutput();
|
||||
int requiredTier = itemStackAltarRecipeEntry.getValue().getMinTier().toInt();
|
||||
int requiredLP = itemStackAltarRecipeEntry.getValue().getSyphon();
|
||||
|
|
Loading…
Reference in a new issue