Use a wrapper instead of ItemStacks for Altar recipes
This commit is contained in:
parent
e12c78877e
commit
798d4b926c
5 changed files with 66 additions and 17 deletions
53
src/main/java/WayofTime/bloodmagic/api/ItemStackWrapper.java
Normal file
53
src/main/java/WayofTime/bloodmagic/api/ItemStackWrapper.java
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package WayofTime.bloodmagic.api;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class ItemStackWrapper {
|
||||||
|
|
||||||
|
public final Item item;
|
||||||
|
public final int stackSize;
|
||||||
|
public final int meta;
|
||||||
|
|
||||||
|
public ItemStackWrapper(Item item, int stackSize) {
|
||||||
|
this(item, stackSize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackWrapper(Item item) {
|
||||||
|
this(item, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackWrapper(Block block, int stackSize, int meta) {
|
||||||
|
this(Item.getItemFromBlock(block), stackSize, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackWrapper(Block block, int stackSize) {
|
||||||
|
this(block, stackSize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackWrapper(Block block) {
|
||||||
|
this(block, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack toStack() {
|
||||||
|
return new ItemStack(item, stackSize, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return toStack().getDisplayName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return stackSize + "x" + item.getUnlocalizedName() + "@" + this.meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStackWrapper getHolder(ItemStack stack) {
|
||||||
|
return new ItemStackWrapper(stack.getItem(), stack.stackSize, stack.getItemDamage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package WayofTime.bloodmagic.api.altar;
|
package WayofTime.bloodmagic.api.altar;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ public class AltarRecipe {
|
||||||
|
|
||||||
public final int syphon, consumeRate, drainRate;
|
public final int syphon, consumeRate, drainRate;
|
||||||
public final boolean useTag;
|
public final boolean useTag;
|
||||||
public final ItemStack input, output;
|
public final ItemStackWrapper input, output;
|
||||||
public final EnumAltarTier minTier;
|
public final EnumAltarTier minTier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,7 +25,7 @@ public class AltarRecipe {
|
||||||
* @param drainRate - The rate at which LP is drained during crafting
|
* @param drainRate - The rate at which LP is drained during crafting
|
||||||
* @param useTag -
|
* @param useTag -
|
||||||
*/
|
*/
|
||||||
public AltarRecipe(ItemStack input, @Nullable ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
|
public AltarRecipe(ItemStackWrapper input, @Nullable ItemStackWrapper output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.minTier = minTier;
|
this.minTier = minTier;
|
||||||
|
@ -35,11 +35,11 @@ public class AltarRecipe {
|
||||||
this.useTag = useTag;
|
this.useTag = useTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AltarRecipe(ItemStack input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
public AltarRecipe(ItemStackWrapper input, ItemStackWrapper output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
||||||
this(input, output, minTier, syphon, consumeRate, drainRate, false);
|
this(input, output, minTier, syphon, consumeRate, drainRate, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AltarRecipe (ItemStack input, EnumAltarTier minTier, int consumeRate, int drainRate) {
|
public AltarRecipe (ItemStackWrapper input, EnumAltarTier minTier, int consumeRate, int drainRate) {
|
||||||
this(input, null, minTier, 0, consumeRate, drainRate);
|
this(input, null, minTier, 0, consumeRate, drainRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package WayofTime.bloodmagic.api.registry;
|
package WayofTime.bloodmagic.api.registry;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||||
|
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||||
import WayofTime.bloodmagic.api.altar.AltarRecipe;
|
import WayofTime.bloodmagic.api.altar.AltarRecipe;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public class AltarRecipeRegistry {
|
public class AltarRecipeRegistry {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static BiMap<ItemStack, AltarRecipe> recipes = HashBiMap.create();
|
private static BiMap<ItemStackWrapper, AltarRecipe> recipes = HashBiMap.create();
|
||||||
|
|
||||||
public static void registerRecipe(AltarRecipe recipe) {
|
public static void registerRecipe(AltarRecipe recipe) {
|
||||||
if (!recipes.containsValue(recipe))
|
if (!recipes.containsValue(recipe))
|
||||||
|
@ -19,11 +19,7 @@ public class AltarRecipeRegistry {
|
||||||
BloodMagicAPI.getLogger().error("Error adding recipe for " + recipe.input.getDisplayName() + (recipe.output == null ? "" : " -> " + recipe.output.getDisplayName()) + ". Recipe already exists.");
|
BloodMagicAPI.getLogger().error("Error adding recipe for " + recipe.input.getDisplayName() + (recipe.output == null ? "" : " -> " + recipe.output.getDisplayName()) + ". Recipe already exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AltarRecipe getRecipeForInput(ItemStack input) {
|
public static AltarRecipe getRecipeForInput(ItemStackWrapper input) {
|
||||||
for (ItemStack stack : recipes.keySet())
|
return recipes.get(input);
|
||||||
if (stack.getIsItemStackEqual(input))
|
|
||||||
return recipes.get(stack);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package WayofTime.bloodmagic.tile;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.altar.BloodAltar;
|
import WayofTime.bloodmagic.altar.BloodAltar;
|
||||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||||
|
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||||
import WayofTime.bloodmagic.api.NBTHolder;
|
import WayofTime.bloodmagic.api.NBTHolder;
|
||||||
import WayofTime.bloodmagic.api.altar.AltarRecipe;
|
import WayofTime.bloodmagic.api.altar.AltarRecipe;
|
||||||
import WayofTime.bloodmagic.api.altar.AltarUpgrade;
|
import WayofTime.bloodmagic.api.altar.AltarUpgrade;
|
||||||
|
@ -71,7 +72,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
|
||||||
setInputFluid(fluidIn);
|
setInputFluid(fluidIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
altarTier = Enums.getIfPresent(EnumAltarTier.class, tagCompound.getString(NBTHolder.NBT_ALTAR_TIER)).get();
|
altarTier = Enums.getIfPresent(EnumAltarTier.class, tagCompound.getString(NBTHolder.NBT_ALTAR_TIER)).or(EnumAltarTier.ONE);
|
||||||
isActive = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_ACTIVE);
|
isActive = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_ACTIVE);
|
||||||
liquidRequired = tagCompound.getInteger(NBTHolder.NBT_ALTAR_LIQUID_REQ);
|
liquidRequired = tagCompound.getInteger(NBTHolder.NBT_ALTAR_LIQUID_REQ);
|
||||||
canBeFilled = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_FILLABLE);
|
canBeFilled = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_FILLABLE);
|
||||||
|
@ -164,8 +165,8 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
|
||||||
|
|
||||||
if (getStackInSlot(0) != null) {
|
if (getStackInSlot(0) != null) {
|
||||||
// Do recipes
|
// Do recipes
|
||||||
if (AltarRecipeRegistry.getRecipes().containsKey(getStackInSlot(0))) {
|
if (AltarRecipeRegistry.getRecipes().containsKey(ItemStackWrapper.getHolder(getStackInSlot(0)))) {
|
||||||
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(getStackInSlot(0));
|
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(ItemStackWrapper.getHolder(getStackInSlot(0)));
|
||||||
|
|
||||||
if (altarTier.ordinal() >= recipe.getMinTier().ordinal()) {
|
if (altarTier.ordinal() >= recipe.getMinTier().ordinal()) {
|
||||||
this.liquidRequired = recipe.getSyphon();
|
this.liquidRequired = recipe.getSyphon();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package WayofTime.bloodmagic.tile;
|
package WayofTime.bloodmagic.tile;
|
||||||
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue