JEI support for Binding/Alchemy Array recipes

Needs pretty-fying
This commit is contained in:
Nick 2015-12-29 16:11:34 -08:00
parent 7b69251713
commit e16017bd56
10 changed files with 76 additions and 83 deletions

View file

@ -1,5 +1,7 @@
package WayofTime.bloodmagic.alchemyArray;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import lombok.Getter;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
@ -9,10 +11,13 @@ import net.minecraft.world.World;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffectCrafting;
import WayofTime.bloodmagic.client.render.alchemyArray.BindingAlchemyCircleRenderer;
public class CraftingArrayEffectBinding extends AlchemyArrayEffectCrafting{
public class AlchemyArrayEffectBinding extends AlchemyArrayEffect {
public CraftingArrayEffectBinding(ItemStack outputStack) {
super(outputStack, 300);
@Getter
public final ItemStack outputStack;
public AlchemyArrayEffectBinding(ItemStack outputStack) {
this.outputStack = outputStack;
}
@Override
@ -26,7 +31,7 @@ public class CraftingArrayEffectBinding extends AlchemyArrayEffectCrafting{
return false;
}
if(ticksActive >= tickLimit){
if(ticksActive >= 300){
BlockPos pos = tile.getPos();
ItemStack output = outputStack.copy();

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic.api.registry;
import java.util.Map.Entry;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@ -21,7 +22,7 @@ public class AlchemyArrayRecipeRegistry {
public static final AlchemyCircleRenderer defaultRenderer = new AlchemyCircleRenderer(new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/SightSigil.png"));
@Getter
private static BiMap<ItemStack, AlchemyArrayRecipe> recipes = HashBiMap.create();
private static BiMap<ItemStackWrapper, AlchemyArrayRecipe> recipes = HashBiMap.create();
/**
* General case for creating an AlchemyArrayEffect for a given input.
@ -40,14 +41,14 @@ public class AlchemyArrayRecipeRegistry {
* substituted for a special renderer
*/
public static void registerRecipe(ItemStack inputStack, @Nullable ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
for (Entry<ItemStack, AlchemyArrayRecipe> entry : recipes.entrySet()) {
for (Entry<ItemStackWrapper, AlchemyArrayRecipe> entry : recipes.entrySet()) {
AlchemyArrayRecipe arrayRecipe = entry.getValue();
if (arrayRecipe.doesInputMatchRecipe(inputStack)) {
AlchemyArrayEffect eff = arrayRecipe.getAlchemyArrayEffectForCatalyst(catalystStack);
if (eff != null) {
return; // Recipe already exists!
} else {
arrayRecipe.catalystMap.put(catalystStack, arrayEffect);
arrayRecipe.catalystMap.put(ItemStackWrapper.getHolder(catalystStack), arrayEffect);
if (circleRenderer != null) {
arrayRecipe.circleRenderer = circleRenderer;
}
@ -57,12 +58,12 @@ public class AlchemyArrayRecipeRegistry {
}
if (circleRenderer == null) {
recipes.put(inputStack, new AlchemyArrayRecipe(inputStack, catalystStack, arrayEffect, defaultRenderer));
recipes.put(ItemStackWrapper.getHolder(inputStack), new AlchemyArrayRecipe(inputStack, catalystStack, arrayEffect, defaultRenderer));
} else {
recipes.put(inputStack, new AlchemyArrayRecipe(inputStack, catalystStack, arrayEffect, circleRenderer));
recipes.put(ItemStackWrapper.getHolder(inputStack), new AlchemyArrayRecipe(inputStack, catalystStack, arrayEffect, circleRenderer));
}
recipes.put(inputStack, new AlchemyArrayRecipe(inputStack, catalystStack, arrayEffect, circleRenderer));
recipes.put(ItemStackWrapper.getHolder(inputStack), new AlchemyArrayRecipe(inputStack, catalystStack, arrayEffect, circleRenderer));
}
public static void registerCraftingRecipe(ItemStack inputStack, ItemStack catalystStack, ItemStack outputStack, AlchemyCircleRenderer circleRenderer) {
@ -96,7 +97,7 @@ public class AlchemyArrayRecipeRegistry {
if (circleRenderer == null) {
return;
}
for (Entry<ItemStack, AlchemyArrayRecipe> entry : recipes.entrySet()) {
for (Entry<ItemStackWrapper, AlchemyArrayRecipe> entry : recipes.entrySet()) {
AlchemyArrayRecipe arrayRecipe = entry.getValue();
if (arrayRecipe.doesInputMatchRecipe(inputStack)) {
arrayRecipe.circleRenderer = circleRenderer;
@ -109,9 +110,9 @@ public class AlchemyArrayRecipeRegistry {
}
public static AlchemyArrayEffect getAlchemyArrayEffect(ItemStack inputStack, @Nullable ItemStack catalystStack) {
for (Entry<ItemStack, AlchemyArrayRecipe> entry : recipes.entrySet()) {
for (Entry<ItemStackWrapper, AlchemyArrayRecipe> entry : recipes.entrySet()) {
AlchemyArrayRecipe arrayRecipe = entry.getValue();
if (arrayRecipe.doesInputMatchRecipe(inputStack)) {
if (ItemStackWrapper.getHolder(arrayRecipe.getInputStack()).equals(ItemStackWrapper.getHolder(inputStack))) {
AlchemyArrayEffect effect = arrayRecipe.getAlchemyArrayEffectForCatalyst(catalystStack);
return effect; // TODO: Decide if a copy should be returned.
@ -122,7 +123,7 @@ public class AlchemyArrayRecipeRegistry {
}
public static AlchemyCircleRenderer getAlchemyCircleRenderer(ItemStack inputStack) {
for (Entry<ItemStack, AlchemyArrayRecipe> entry : recipes.entrySet()) {
for (Entry<ItemStackWrapper, AlchemyArrayRecipe> entry : recipes.entrySet()) {
AlchemyArrayRecipe arrayRecipe = entry.getValue();
if (arrayRecipe.doesInputMatchRecipe(inputStack)) {
return arrayRecipe.circleRenderer;
@ -139,12 +140,12 @@ public class AlchemyArrayRecipeRegistry {
public AlchemyCircleRenderer circleRenderer;
public final ItemStack inputStack;
public final BiMap<ItemStack, AlchemyArrayEffect> catalystMap = HashBiMap.create();
public final BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = HashBiMap.create();
public AlchemyArrayRecipe(ItemStack inputStack, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
this.inputStack = inputStack;
catalystMap.put(catalystStack, arrayEffect);
catalystMap.put(ItemStackWrapper.getHolder(catalystStack), arrayEffect);
this.circleRenderer = circleRenderer;
}
@ -171,8 +172,8 @@ public class AlchemyArrayRecipeRegistry {
* @return
*/
public AlchemyArrayEffect getAlchemyArrayEffectForCatalyst(@Nullable ItemStack comparedStack) {
for (Entry<ItemStack, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
ItemStack catalystStack = entry.getKey();
for (Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
ItemStack catalystStack = entry.getKey().toStack();
if (comparedStack == null && catalystStack == null) {
return entry.getValue();
}

View file

@ -1,37 +0,0 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import net.minecraft.item.ItemStack;
public class BindingRecipeRegistry {
@Getter
private static BiMap<ItemStack, BindingRecipe> recipes = HashBiMap.create();
public static void registerRecipe(BindingRecipe recipe) {
if (!recipes.containsValue(recipe))
recipes.put(recipe.getInput(), recipe);
else
BloodMagicAPI.getLogger().error("Error adding binding recipe for %s %s. Recipe already exists.", recipe.input.getDisplayName(), recipe.output == null ? "" : " -> " + recipe.output.getDisplayName());
}
public static BindingRecipe getRecipeForInput(ItemStack input) {
return recipes.get(input);
}
@Getter
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor
public static class BindingRecipe {
private final ItemStack input;
private final ItemStack output;
}
}

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.compat.jei;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffectCrafting;
import WayofTime.bloodmagic.compat.jei.alchemyArray.AlchemyArrayCraftingCategory;
import WayofTime.bloodmagic.compat.jei.alchemyArray.AlchemyArrayCraftingRecipeHandler;
import WayofTime.bloodmagic.compat.jei.alchemyArray.AlchemyArrayCraftingRecipeMaker;

View file

@ -1,7 +1,10 @@
package WayofTime.bloodmagic.compat.jei.alchemyArray;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffectCrafting;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import com.google.common.collect.BiMap;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
@ -13,19 +16,22 @@ public class AlchemyArrayCraftingRecipeMaker {
@Nonnull
public static List<AlchemyArrayCraftingRecipeJEI> getRecipes() {
Map<ItemStack, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> altarMap = AlchemyArrayRecipeRegistry.getRecipes();
Map<ItemStackWrapper, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> alchemyArrayRecipeMap = AlchemyArrayRecipeRegistry.getRecipes();
ArrayList<AlchemyArrayCraftingRecipeJEI> recipes = new ArrayList<AlchemyArrayCraftingRecipeJEI>();
for (Map.Entry<ItemStack, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> itemStackAlchemyArrayRecipeEntry : altarMap.entrySet()) {
for (Map.Entry<ItemStackWrapper, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> itemStackAlchemyArrayRecipeEntry : alchemyArrayRecipeMap.entrySet()) {
ItemStack input = itemStackAlchemyArrayRecipeEntry.getValue().getInputStack();
ItemStack catalyst = itemStackAlchemyArrayRecipeEntry.getKey();
BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = itemStackAlchemyArrayRecipeEntry.getValue().catalystMap;
if (itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst) instanceof AlchemyArrayEffectCrafting) {
ItemStack output =((AlchemyArrayEffectCrafting) itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst)).getOutputStack();
for(Map.Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
ItemStack catalyst = entry.getKey().toStack();
if (AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(input, catalyst) instanceof AlchemyArrayEffectCrafting) {
ItemStack output = ((AlchemyArrayEffectCrafting) itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst)).getOutputStack();
AlchemyArrayCraftingRecipeJEI recipe = new AlchemyArrayCraftingRecipeJEI(input, catalyst, output);
recipes.add(recipe);
AlchemyArrayCraftingRecipeJEI recipe = new AlchemyArrayCraftingRecipeJEI(input, catalyst, output);
recipes.add(recipe);
}
}
}

View file

@ -3,12 +3,12 @@ package WayofTime.bloodmagic.compat.jei.binding;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.compat.jei.BloodMagicPlugin;
import WayofTime.bloodmagic.util.helper.TextHelper;
import mezz.jei.api.JEIManager;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
@ -16,7 +16,8 @@ import javax.annotation.Nonnull;
public class BindingRecipeCategory implements IRecipeCategory {
private static final int INPUT_SLOT = 0;
private static final int OUTPUT_SLOT = 1;
private static final int CATALYST_SLOT = 1;
private static final int OUTPUT_SLOT = 2;
@Nonnull
private final IDrawable background = BloodMagicPlugin.jeiHelper.getGuiHelper().createDrawable(new ResourceLocation(Constants.Mod.DOMAIN + "gui/jei/binding.png"), 0, 0, 100, 30);
@ -56,12 +57,14 @@ public class BindingRecipeCategory implements IRecipeCategory {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapper recipeWrapper) {
recipeLayout.getItemStacks().init(INPUT_SLOT, true, 0, 5);
recipeLayout.getItemStacks().init(CATALYST_SLOT, true, 50, 5);
recipeLayout.getItemStacks().init(OUTPUT_SLOT, false, 73, 5);
if (recipeWrapper instanceof BindingRecipeJEI) {
BindingRecipeJEI bindingRecipeWrapper = (BindingRecipeJEI) recipeWrapper;
recipeLayout.getItemStacks().set(INPUT_SLOT, bindingRecipeWrapper.getInputs());
recipeLayout.getItemStacks().set(OUTPUT_SLOT, bindingRecipeWrapper.getOutputs());
BindingRecipeJEI bindingRecipe = (BindingRecipeJEI) recipeWrapper;
recipeLayout.getItemStacks().set(INPUT_SLOT, (ItemStack) bindingRecipe.getInputs().get(0));
recipeLayout.getItemStacks().set(CATALYST_SLOT, (ItemStack) bindingRecipe.getInputs().get(1));
recipeLayout.getItemStacks().set(OUTPUT_SLOT, bindingRecipe.getOutputs());
}
}
}

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.compat.jei.binding;
import WayofTime.bloodmagic.compat.jei.BloodMagicRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import scala.actors.threadpool.Arrays;
import javax.annotation.Nonnull;
import java.util.Collections;
@ -11,19 +12,20 @@ import java.util.List;
public class BindingRecipeJEI extends BloodMagicRecipeWrapper {
@Nonnull
private final ItemStack input;
private final List<ItemStack> inputs;
@Nonnull
private final ItemStack output;
public BindingRecipeJEI(@Nonnull ItemStack input, @Nonnull ItemStack output) {
this.input = input;
@SuppressWarnings("unchecked")
public BindingRecipeJEI(@Nonnull ItemStack input, @Nonnull ItemStack catalyst, @Nonnull ItemStack output) {
this.inputs = Arrays.asList(new ItemStack[] {input, catalyst});
this.output = output;
}
@Override
public List getInputs() {
return Collections.singletonList(input);
return inputs;
}
@Override

View file

@ -1,6 +1,10 @@
package WayofTime.bloodmagic.compat.jei.binding;
import WayofTime.bloodmagic.api.registry.BindingRecipeRegistry;
import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import com.google.common.collect.BiMap;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
@ -12,16 +16,23 @@ public class BindingRecipeMaker {
@Nonnull
public static List<BindingRecipeJEI> getRecipes() {
Map<ItemStack, BindingRecipeRegistry.BindingRecipe> altarMap = BindingRecipeRegistry.getRecipes();
Map<ItemStackWrapper, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> alchemyArrayRecipeMap = AlchemyArrayRecipeRegistry.getRecipes();
ArrayList<BindingRecipeJEI> recipes = new ArrayList<BindingRecipeJEI>();
for (Map.Entry<ItemStack, BindingRecipeRegistry.BindingRecipe> itemStackBindingRecipeEntry : altarMap.entrySet()) {
ItemStack input = itemStackBindingRecipeEntry.getKey();
ItemStack output = itemStackBindingRecipeEntry.getValue().getOutput();
for (Map.Entry<ItemStackWrapper, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> itemStackAlchemyArrayRecipeEntry : alchemyArrayRecipeMap.entrySet()) {
ItemStack input = itemStackAlchemyArrayRecipeEntry.getValue().getInputStack();
BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = itemStackAlchemyArrayRecipeEntry.getValue().catalystMap;
BindingRecipeJEI recipe = new BindingRecipeJEI(input, output);
recipes.add(recipe);
for(Map.Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
ItemStack catalyst = entry.getKey().toStack();
if (AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(input, catalyst) instanceof AlchemyArrayEffectBinding) {
ItemStack output = ((AlchemyArrayEffectBinding) itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst)).getOutputStack();
BindingRecipeJEI recipe = new BindingRecipeJEI(input, catalyst, output);
recipes.add(recipe);
}
}
}
return recipes;

View file

@ -5,7 +5,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry;
import WayofTime.bloodmagic.alchemyArray.CraftingArrayEffectBinding;
import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.compress.CompressionRegistry;
import WayofTime.bloodmagic.api.recipe.ShapedBloodOrbRecipe;
@ -66,10 +66,10 @@ public class ModRecipes {
}
public static void addAlchemyArrayRecipes() {
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_sword), new CraftingArrayEffectBinding(new ItemStack(ModItems.boundSword)), new BindingAlchemyCircleRenderer());
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_axe), new CraftingArrayEffectBinding(new ItemStack(ModItems.boundAxe)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_pickaxe), new CraftingArrayEffectBinding(new ItemStack(ModItems.boundPickaxe)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_shovel), new CraftingArrayEffectBinding(new ItemStack(ModItems.boundShovel)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_sword), new AlchemyArrayEffectBinding(new ItemStack(ModItems.boundSword)), new BindingAlchemyCircleRenderer());
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_axe), new AlchemyArrayEffectBinding(new ItemStack(ModItems.boundAxe)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_pickaxe), new AlchemyArrayEffectBinding(new ItemStack(ModItems.boundPickaxe)));
AlchemyArrayRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.REAGENT_BINDING), new ItemStack(Items.diamond_shovel), new AlchemyArrayEffectBinding(new ItemStack(ModItems.boundShovel)));
AlchemyArrayRecipeRegistry.registerCraftingRecipe(ItemComponent.getStack(ItemComponent.REAGENT_WATER), new ItemStack(ModItems.slate), new ItemStack(ModItems.sigilWater), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/WaterSigil.png"));
AlchemyArrayRecipeRegistry.registerCraftingRecipe(ItemComponent.getStack(ItemComponent.REAGENT_LAVA), new ItemStack(ModItems.slate), new ItemStack(ModItems.sigilLava), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/LavaSigil.png"));
AlchemyArrayRecipeRegistry.registerCraftingRecipe(ItemComponent.getStack(ItemComponent.REAGENT_AIR), new ItemStack(ModItems.slate, 1, 1), new ItemStack(ModItems.sigilAir), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/AirSigil.png"));

View file

@ -191,6 +191,7 @@ chat.BloodMagic.damageSource=%s's soul became too weak
# JustEnoughItems
jei.BloodMagic.recipe.altar=Blood Altar
jei.BloodMagic.recipe.binding=Binding Ritual
jei.BloodMagic.recipe.alchemyArrayCrafting=Alchemy Array
jei.BloodMagic.recipe.requiredLP=LP: %d
jei.BloodMagic.recipe.requiredTier=Tier: %d