2018-02-06 01:04:38 +00:00
|
|
|
package WayofTime.bloodmagic.apibutnotreally.registry;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2018-02-06 01:04:38 +00:00
|
|
|
import WayofTime.bloodmagic.apibutnotreally.BloodMagicAPI;
|
|
|
|
import WayofTime.bloodmagic.apibutnotreally.ItemStackWrapper;
|
|
|
|
import WayofTime.bloodmagic.apibutnotreally.altar.EnumAltarTier;
|
2016-03-17 20:00:44 +00:00
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
import com.google.common.collect.HashBiMap;
|
2015-11-28 01:15:19 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-25 14:07:30 +00:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2017-08-15 03:53:42 +00:00
|
|
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2016-03-25 14:07:30 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2015-12-03 03:27:28 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public class AltarRecipeRegistry {
|
2016-07-08 22:13:46 +00:00
|
|
|
private static BiMap<List<ItemStackWrapper>, AltarRecipe> recipes = HashBiMap.create();
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2016-03-25 14:07:30 +00:00
|
|
|
/**
|
2016-04-05 20:16:17 +00:00
|
|
|
* Registers an {@link AltarRecipe} for the Blood Altar. This can be a
|
|
|
|
* {@code ItemStack}, {@code List<Itemstack>}, or {@code String}
|
|
|
|
* OreDictionary entry.
|
2017-08-16 04:30:48 +00:00
|
|
|
* <p>
|
2016-04-05 20:16:17 +00:00
|
|
|
* If the OreDictionary entry does not exist or is empty, it will not be
|
|
|
|
* registered.
|
2017-08-16 04:30:48 +00:00
|
|
|
*
|
|
|
|
* @param altarRecipe - The AltarRecipe to register
|
2016-03-25 14:07:30 +00:00
|
|
|
*/
|
2017-08-16 04:30:48 +00:00
|
|
|
public static void registerRecipe(AltarRecipe altarRecipe) {
|
2016-03-25 14:07:30 +00:00
|
|
|
if (!recipes.containsValue(altarRecipe) && altarRecipe.getInput().size() > 0)
|
|
|
|
recipes.put(altarRecipe.getInput(), altarRecipe);
|
2015-10-30 03:22:14 +00:00
|
|
|
else
|
2017-08-15 03:53:42 +00:00
|
|
|
BloodMagicAPI.logger.error("Error adding altar recipe for input [{}].", altarRecipe.toString());
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public static void registerFillRecipe(ItemStack orbStack, EnumAltarTier tier, int maxForOrb, int consumeRate, int drainRate) {
|
2016-01-02 03:59:10 +00:00
|
|
|
registerRecipe(new AltarRecipe(orbStack, orbStack, tier, maxForOrb, consumeRate, drainRate, true));
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public static void removeRecipe(AltarRecipe altarRecipe) {
|
2017-06-02 05:16:24 +00:00
|
|
|
recipes.remove(altarRecipe.getInput());
|
|
|
|
}
|
|
|
|
|
2016-03-25 14:07:30 +00:00
|
|
|
/**
|
|
|
|
* Gets the recipe that the provided input is registered to.
|
2017-08-16 04:30:48 +00:00
|
|
|
*
|
|
|
|
* @param input - The input ItemStack to get the recipe for
|
2016-03-25 14:07:30 +00:00
|
|
|
* @return - The recipe that the provided input is registered to.
|
|
|
|
*/
|
2017-08-16 04:30:48 +00:00
|
|
|
public static AltarRecipe getRecipeForInput(List<ItemStack> input) {
|
2016-07-08 22:13:46 +00:00
|
|
|
List<ItemStackWrapper> wrapperList = ItemStackWrapper.toWrapperList(input);
|
|
|
|
if (recipes.keySet().contains(wrapperList))
|
|
|
|
return recipes.get(wrapperList);
|
2016-03-25 14:07:30 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-07-21 01:29:04 +00:00
|
|
|
//TODO: Determine a more time-effective method
|
2017-08-16 04:30:48 +00:00
|
|
|
public static AltarRecipe getRecipeForInput(ItemStack input) {
|
|
|
|
for (AltarRecipe recipe : recipes.values()) {
|
|
|
|
if (recipe.doesRequiredItemMatch(input, recipe.getMinTier())) {
|
2016-07-21 01:29:04 +00:00
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2016-07-08 22:13:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public static AltarRecipe getRecipeForInput(String input) {
|
2016-07-08 22:13:46 +00:00
|
|
|
return getRecipeForInput(OreDictionary.getOres(input));
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public static BiMap<List<ItemStackWrapper>, AltarRecipe> getRecipes() {
|
2016-03-25 14:07:30 +00:00
|
|
|
return HashBiMap.create(recipes);
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
2015-12-03 03:27:28 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public static class AltarRecipe {
|
2016-07-08 22:13:46 +00:00
|
|
|
private final List<ItemStackWrapper> input;
|
2016-03-25 14:07:30 +00:00
|
|
|
private final ItemStack output;
|
|
|
|
private final EnumAltarTier minTier;
|
|
|
|
private final int syphon, consumeRate, drainRate;
|
|
|
|
private final boolean fillable;
|
2015-12-03 03:27:28 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-30 20:34:40 +00:00
|
|
|
* Allows creation of a recipe for the
|
|
|
|
* {@link WayofTime.bloodmagic.block.BlockAltar} /
|
|
|
|
* {@link WayofTime.bloodmagic.tile.TileAltar}. The output ItemStack is
|
|
|
|
* allowed to be null as some recipes do not contain an output. (Blood
|
|
|
|
* Orbs)
|
2017-08-16 04:30:48 +00:00
|
|
|
*
|
|
|
|
* @param input - The input ItemStack
|
|
|
|
* @param output - The ItemStack obtained from the recipe
|
|
|
|
* @param minTier - The minimum tier of Altar required
|
|
|
|
* @param syphon - The amount of LP to syphon from the Altar
|
|
|
|
* @param consumeRate - The rate at which LP is consumed during crafting
|
|
|
|
* @param drainRate - The rate at which LP is drained during crafting
|
|
|
|
* @param fillable - Whether the input item can be filled with LP. IE: Orbs
|
2015-12-03 03:27:28 +00:00
|
|
|
*/
|
2017-08-16 04:30:48 +00:00
|
|
|
public AltarRecipe(List<ItemStack> input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable) {
|
2016-07-08 22:13:46 +00:00
|
|
|
this.input = ItemStackWrapper.toWrapperList(input);
|
2015-12-03 03:27:28 +00:00
|
|
|
this.output = output;
|
|
|
|
this.minTier = minTier;
|
2015-12-23 17:41:59 +00:00
|
|
|
this.syphon = syphon < 0 ? -syphon : syphon;
|
|
|
|
this.consumeRate = consumeRate < 0 ? -consumeRate : consumeRate;
|
|
|
|
this.drainRate = drainRate < 0 ? -drainRate : drainRate;
|
2016-01-02 03:59:10 +00:00
|
|
|
this.fillable = fillable;
|
2015-12-03 03:27:28 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public AltarRecipe(List<ItemStack> input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
2015-12-03 03:27:28 +00:00
|
|
|
this(input, output, minTier, syphon, consumeRate, drainRate, false);
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public AltarRecipe(ItemStack input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable) {
|
2016-03-25 14:07:30 +00:00
|
|
|
this(Collections.singletonList(input), output, minTier, syphon, consumeRate, drainRate, fillable);
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public AltarRecipe(ItemStack input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
2016-03-25 14:07:30 +00:00
|
|
|
this(Collections.singletonList(input), output, minTier, syphon, consumeRate, drainRate, false);
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public AltarRecipe(String inputEntry, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable) {
|
2016-03-25 14:07:30 +00:00
|
|
|
this(OreDictionary.doesOreNameExist(inputEntry) && OreDictionary.getOres(inputEntry).size() > 0 ? OreDictionary.getOres(inputEntry) : Collections.<ItemStack>emptyList(), output, minTier, syphon, consumeRate, drainRate, fillable);
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public AltarRecipe(String inputEntry, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
2016-03-25 14:07:30 +00:00
|
|
|
this(OreDictionary.doesOreNameExist(inputEntry) && OreDictionary.getOres(inputEntry).size() > 0 ? OreDictionary.getOres(inputEntry) : Collections.<ItemStack>emptyList(), output, minTier, syphon, consumeRate, drainRate, false);
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean doesRequiredItemMatch(ItemStack comparedStack, EnumAltarTier tierCheck) {
|
2015-12-23 17:41:59 +00:00
|
|
|
if (comparedStack == null || this.input == null)
|
2015-12-23 02:03:00 +00:00
|
|
|
return false;
|
|
|
|
|
2016-03-25 14:07:30 +00:00
|
|
|
if (tierCheck.ordinal() < minTier.ordinal())
|
|
|
|
return false;
|
2016-02-18 17:49:12 +00:00
|
|
|
|
2016-10-22 23:06:48 +00:00
|
|
|
for (ItemStackWrapper stack : input) {
|
2016-07-08 22:13:46 +00:00
|
|
|
if (comparedStack.isItemEqual(stack.toStack()))
|
2016-03-25 14:07:30 +00:00
|
|
|
return true;
|
|
|
|
|
2016-10-22 23:06:48 +00:00
|
|
|
if (comparedStack.getItem() == stack.item && stack.meta == OreDictionary.WILDCARD_VALUE)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-25 14:07:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-08-15 03:53:42 +00:00
|
|
|
|
|
|
|
public List<ItemStackWrapper> getInput() {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getOutput() {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EnumAltarTier getMinTier() {
|
|
|
|
return minTier;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getSyphon() {
|
|
|
|
return syphon;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getConsumeRate() {
|
|
|
|
return consumeRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDrainRate() {
|
|
|
|
return drainRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFillable() {
|
|
|
|
return fillable;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (!(o instanceof AltarRecipe)) return false;
|
|
|
|
|
|
|
|
AltarRecipe that = (AltarRecipe) o;
|
|
|
|
|
|
|
|
if (syphon != that.syphon) return false;
|
|
|
|
if (consumeRate != that.consumeRate) return false;
|
|
|
|
if (drainRate != that.drainRate) return false;
|
|
|
|
if (fillable != that.fillable) return false;
|
|
|
|
if (input != null ? !input.equals(that.input) : that.input != null) return false;
|
|
|
|
if (output != null ? !output.equals(that.output) : that.output != null) return false;
|
|
|
|
return minTier == that.minTier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int result = input != null ? input.hashCode() : 0;
|
|
|
|
result = 31 * result + (output != null ? output.hashCode() : 0);
|
|
|
|
result = 31 * result + (minTier != null ? minTier.hashCode() : 0);
|
|
|
|
result = 31 * result + syphon;
|
|
|
|
result = 31 * result + consumeRate;
|
|
|
|
result = 31 * result + drainRate;
|
|
|
|
result = 31 * result + (fillable ? 1 : 0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return new ToStringBuilder(this)
|
|
|
|
.append("input", input)
|
|
|
|
.append("output", output)
|
|
|
|
.append("minTier", minTier)
|
|
|
|
.append("syphon", syphon)
|
|
|
|
.append("consumeRate", consumeRate)
|
|
|
|
.append("drainRate", drainRate)
|
|
|
|
.append("fillable", fillable)
|
|
|
|
.toString();
|
|
|
|
}
|
2016-02-18 17:49:12 +00:00
|
|
|
}
|
2016-03-25 14:07:30 +00:00
|
|
|
}
|