2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.api.registry;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
2015-12-03 03:27:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
|
2015-10-30 03:22:14 +00:00
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
import com.google.common.collect.HashBiMap;
|
2015-12-03 03:27:28 +00:00
|
|
|
import lombok.EqualsAndHashCode;
|
2015-10-30 03:22:14 +00:00
|
|
|
import lombok.Getter;
|
2015-12-03 03:27:28 +00:00
|
|
|
import lombok.ToString;
|
2015-11-28 01:15:19 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-12-03 03:27:28 +00:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class AltarRecipeRegistry
|
|
|
|
{
|
2015-11-28 01:15:19 +00:00
|
|
|
private static BiMap<ItemStack, AltarRecipe> recipes = HashBiMap.create();
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static void registerRecipe(AltarRecipe recipe)
|
|
|
|
{
|
2015-10-30 03:22:14 +00:00
|
|
|
if (!recipes.containsValue(recipe))
|
|
|
|
recipes.put(recipe.input, recipe);
|
|
|
|
else
|
2015-12-30 20:34:40 +00:00
|
|
|
BloodMagicAPI.getLogger().error("Error adding altar recipe for %s. Recipe already exists.", recipe.input.getDisplayName(), recipe.output == null ? "" : " -> ");
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 22:56:37 +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));
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public static AltarRecipe getRecipeForInput(ItemStack input)
|
|
|
|
{
|
2015-11-03 18:00:40 +00:00
|
|
|
return recipes.get(input);
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
2015-12-03 03:27:28 +00:00
|
|
|
|
|
|
|
@Getter
|
|
|
|
@ToString
|
|
|
|
@EqualsAndHashCode
|
2015-12-30 20:34:40 +00:00
|
|
|
public static class AltarRecipe
|
|
|
|
{
|
2015-12-03 03:27:28 +00:00
|
|
|
|
|
|
|
public final int syphon, consumeRate, drainRate;
|
2016-01-02 03:59:10 +00:00
|
|
|
public final boolean fillable;
|
2015-12-03 03:27:28 +00:00
|
|
|
public final ItemStack input, output;
|
|
|
|
public final EnumAltarTier minTier;
|
|
|
|
|
|
|
|
/**
|
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)
|
|
|
|
*
|
|
|
|
* @param input
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The input ItemStack
|
2015-12-30 20:34:40 +00:00
|
|
|
* @param output
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The ItemStack obtained from the recipe
|
2015-12-30 20:34:40 +00:00
|
|
|
* @param minTier
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The minimum tier of Altar required
|
2015-12-30 20:34:40 +00:00
|
|
|
* @param syphon
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The amount of LP to syphon from the Altar
|
2015-12-30 20:34:40 +00:00
|
|
|
* @param consumeRate
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The rate at which LP is consumed during crafting
|
2015-12-30 20:34:40 +00:00
|
|
|
* @param drainRate
|
2016-01-02 22:56:37 +00:00
|
|
|
* - The rate at which LP is drained during crafting
|
2016-01-02 03:59:10 +00:00
|
|
|
* @param fillable
|
2016-01-02 22:56:37 +00:00
|
|
|
* - Whether the input item can be filled with LP. IE: Orbs
|
2015-12-03 03:27:28 +00:00
|
|
|
*/
|
2016-01-02 03:59:10 +00:00
|
|
|
public AltarRecipe(ItemStack input, @Nullable ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-12-03 03:27:28 +00:00
|
|
|
this.input = input;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public AltarRecipe(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);
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +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;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
return tierCheck.ordinal() >= minTier.ordinal() && this.input.isItemEqual(comparedStack);// &&
|
2016-01-02 03:59:10 +00:00
|
|
|
// (this.fillable this.areRequiredTagsEqual(comparedStack) : true);
|
2015-12-23 02:03:00 +00:00
|
|
|
}
|
2015-12-03 03:27:28 +00:00
|
|
|
}
|
2016-02-18 17:49:12 +00:00
|
|
|
|
|
|
|
public static BiMap<ItemStack, AltarRecipe> getRecipes() {
|
|
|
|
return HashBiMap.create(recipes);
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|