From 7b8646659a5adb5fe29e84fbd65d16206deaeb32 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Fri, 8 Jan 2016 09:12:31 -0500 Subject: [PATCH] Added SoulForgeRecipe (basically a modified ShapelessOreRecipe, so is compatible with the oredictionary), and worked on the shift-clicking into the inventory. --- .../api/recipe/SoulForgeRecipe.java | 142 ++++++++++++++++++ .../api/registry/SoulForgeRecipeRegistry.java | 37 +++++ .../bloodmagic/client/gui/GuiSoulForge.java | 1 - .../bloodmagic/tile/TileSoulForge.java | 102 +++++++++++++ .../tile/container/ContainerSoulForge.java | 85 +++++++---- .../textures/items/BaseMonsterSoul.png | Bin 474 -> 841 bytes .../bloodmagic/textures/items/MonsterSoul.png | Bin 841 -> 0 bytes 7 files changed, 338 insertions(+), 29 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/api/recipe/SoulForgeRecipe.java create mode 100644 src/main/java/WayofTime/bloodmagic/api/registry/SoulForgeRecipeRegistry.java delete mode 100644 src/main/resources/assets/bloodmagic/textures/items/MonsterSoul.png diff --git a/src/main/java/WayofTime/bloodmagic/api/recipe/SoulForgeRecipe.java b/src/main/java/WayofTime/bloodmagic/api/recipe/SoulForgeRecipe.java new file mode 100644 index 00000000..bc14e49b --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/api/recipe/SoulForgeRecipe.java @@ -0,0 +1,142 @@ +package WayofTime.bloodmagic.api.recipe; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import lombok.Getter; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +public class SoulForgeRecipe +{ + protected ItemStack output = null; + protected ArrayList input = new ArrayList(); + @Getter + protected double minimumSouls; + @Getter + protected double soulsDrained; + + public SoulForgeRecipe(Block result, double minSouls, double drain, Object... recipe) + { + this(new ItemStack(result), minSouls, drain, recipe); + } + + public SoulForgeRecipe(Item result, double minSouls, double drain, Object... recipe) + { + this(new ItemStack(result), minSouls, drain, recipe); + } + + public SoulForgeRecipe(ItemStack result, double minSouls, double drain, Object... recipe) + { + output = result.copy(); + for (Object in : recipe) + { + if (in instanceof ItemStack) + { + input.add(((ItemStack) in).copy()); + } else if (in instanceof Item) + { + input.add(new ItemStack((Item) in)); + } else if (in instanceof Block) + { + input.add(new ItemStack((Block) in)); + } else if (in instanceof String) + { + input.add(OreDictionary.getOres((String) in)); + } else + { + String ret = "Invalid soul forge recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } + } + } + + /** + * Returns the size of the recipe area + */ + public int getRecipeSize() + { + return input.size(); + } + + public ItemStack getRecipeOutput() + { + return output; + } + + /** + * Used to check if a recipe matches current crafting inventory. World and + * BlockPos are for future-proofing + */ + @SuppressWarnings("unchecked") + public boolean matches(List checkedList, World world, BlockPos pos) + { + ArrayList required = new ArrayList(input); + + for (int x = 0; x < checkedList.size(); x++) + { + ItemStack slot = checkedList.get(x); + + if (slot != null) + { + boolean inRecipe = false; + Iterator req = required.iterator(); + + while (req.hasNext()) + { + boolean match = false; + + Object next = req.next(); + + if (next instanceof ItemStack) + { + match = OreDictionary.itemMatches((ItemStack) next, slot, false); + } else if (next instanceof List) + { + Iterator itr = ((List) next).iterator(); + while (itr.hasNext() && !match) + { + match = OreDictionary.itemMatches(itr.next(), slot, false); + } + } + + if (match) + { + inRecipe = true; + required.remove(next); + break; + } + } + + if (!inRecipe) + { + return false; + } + } + } + + return required.isEmpty(); + } + + /** + * Returns the input for this recipe, any mod accessing this value should + * never manipulate the values in this array as it will effect the recipe + * itself. + * + * @return The recipes input vales. + */ + public ArrayList getInput() + { + return this.input; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/api/registry/SoulForgeRecipeRegistry.java b/src/main/java/WayofTime/bloodmagic/api/registry/SoulForgeRecipeRegistry.java new file mode 100644 index 00000000..5360d740 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/api/registry/SoulForgeRecipeRegistry.java @@ -0,0 +1,37 @@ +package WayofTime.bloodmagic.api.registry; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; +import WayofTime.bloodmagic.api.recipe.SoulForgeRecipe; + +public class SoulForgeRecipeRegistry +{ + public static List recipeList = new ArrayList(); + + public static void registerRecipe(SoulForgeRecipe recipe) + { + recipeList.add(recipe); + } + + public static void registerRecipe(ItemStack outputStack, double minimulSouls, double drain, Object... objects) + { + registerRecipe(new SoulForgeRecipe(outputStack, minimulSouls, drain, objects)); + } + + public static SoulForgeRecipe getMatchingRecipe(List itemList, World world, BlockPos pos) + { + for (SoulForgeRecipe recipe : recipeList) + { + if (recipe.matches(itemList, world, pos)) + { + return recipe; + } + } + + return null; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/client/gui/GuiSoulForge.java b/src/main/java/WayofTime/bloodmagic/client/gui/GuiSoulForge.java index 9d5c3dbc..4d651dfa 100644 --- a/src/main/java/WayofTime/bloodmagic/client/gui/GuiSoulForge.java +++ b/src/main/java/WayofTime/bloodmagic/client/gui/GuiSoulForge.java @@ -5,7 +5,6 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import WayofTime.bloodmagic.api.Constants; diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java b/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java index cace5af1..605e8d4c 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java @@ -1,10 +1,23 @@ package WayofTime.bloodmagic.tile; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; +import WayofTime.bloodmagic.api.recipe.SoulForgeRecipe; +import WayofTime.bloodmagic.api.registry.SoulForgeRecipeRegistry; +import WayofTime.bloodmagic.api.soul.ISoul; +import WayofTime.bloodmagic.api.soul.ISoulGem; public class TileSoulForge extends TileInventory implements ITickable { + public static final int soulSlot = 4; + public static final int outputSlot = 5; + + //Input slots are from 0 to 3. + public TileSoulForge() { super(6, "soulForge"); @@ -25,6 +38,95 @@ public class TileSoulForge extends TileInventory implements ITickable @Override public void update() { + if (!hasSoulGemOrSoul()) + { + return; + } + double soulsInGem = getSouls(); + + List inputList = new ArrayList(); + + for (int i = 0; i < 4; i++) + { + if (getStackInSlot(i) != null) + { + inputList.add(getStackInSlot(i)); + } + } + + SoulForgeRecipe recipe = SoulForgeRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos()); + if (recipe != null && recipe.getMinimumSouls() <= soulsInGem) + { + ItemStack outputStack = recipe.getRecipeOutput(); + if (getStackInSlot(outputSlot) == null) + { + setInventorySlotContents(outputSlot, outputStack); + consumeInventory(); + } else + { + + } + } + } + + public boolean hasSoulGemOrSoul() + { + ItemStack soulStack = getStackInSlot(soulSlot); + + if (soulStack != null) + { + if (soulStack.getItem() instanceof ISoul || soulStack.getItem() instanceof ISoulGem) + { + return true; + } + } + + return false; + } + + public double getSouls() + { + ItemStack soulStack = getStackInSlot(soulSlot); + + if (soulStack != null) + { + if (soulStack.getItem() instanceof ISoul) + { + ISoul soul = (ISoul) soulStack.getItem(); + return soul.getSouls(soulStack); + } + + if (soulStack.getItem() instanceof ISoulGem) + { + ISoulGem soul = (ISoulGem) soulStack.getItem(); + return soul.getSouls(soulStack); + } + } + + return 0; + } + + public void consumeInventory() + { + for (int i = 0; i < 4; i++) + { + ItemStack inputStack = getStackInSlot(i); + if (inputStack != null) + { + if (inputStack.getItem().hasContainerItem(inputStack)) + { + setInventorySlotContents(i, inputStack.getItem().getContainerItem(inputStack)); + continue; + } + + inputStack.stackSize--; + if (inputStack.stackSize <= 0) + { + setInventorySlotContents(i, null); + continue; + } + } + } } } diff --git a/src/main/java/WayofTime/bloodmagic/tile/container/ContainerSoulForge.java b/src/main/java/WayofTime/bloodmagic/tile/container/ContainerSoulForge.java index 24022121..9ba7e8a9 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/container/ContainerSoulForge.java +++ b/src/main/java/WayofTime/bloodmagic/tile/container/ContainerSoulForge.java @@ -8,7 +8,7 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import WayofTime.bloodmagic.api.soul.ISoul; import WayofTime.bloodmagic.api.soul.ISoulGem; -import WayofTime.bloodmagic.item.ItemTelepositionFocus; +import WayofTime.bloodmagic.tile.TileSoulForge; public class ContainerSoulForge extends Container { @@ -17,7 +17,12 @@ public class ContainerSoulForge extends Container public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge) { this.tileForge = tileForge; - this.addSlotToContainer(new SlotSoul(tileForge, 0, 152, 51)); + this.addSlotToContainer(new Slot(tileForge, 0, 8, 15)); + this.addSlotToContainer(new Slot(tileForge, 1, 80, 15)); + this.addSlotToContainer(new Slot(tileForge, 2, 80, 87)); + this.addSlotToContainer(new Slot(tileForge, 3, 8, 87)); + this.addSlotToContainer(new SlotSoul(tileForge, TileSoulForge.soulSlot, 152, 51)); + this.addSlotToContainer(new SlotOutput(tileForge, TileSoulForge.outputSlot, 44, 51)); for (int i = 0; i < 3; i++) { @@ -34,48 +39,58 @@ public class ContainerSoulForge extends Container } @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slot) + public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - ItemStack stack = null; - Slot slotObject = inventorySlots.get(slot); - int slots = inventorySlots.size(); + ItemStack itemstack = null; + Slot slot = (Slot) this.inventorySlots.get(index); - if (slotObject != null && slotObject.getHasStack()) + if (slot != null && slot.getHasStack()) { - ItemStack stackInSlot = slotObject.getStack(); - stack = stackInSlot.copy(); + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); - if (stack.getItem() instanceof ItemTelepositionFocus) + if (index == 5) { - if (slot <= slots) - { - if (!this.mergeItemStack(stackInSlot, 0, slots, false)) - { - return null; - } - } else if (!this.mergeItemStack(stackInSlot, slots, 36 + slots, false)) + if (!this.mergeItemStack(itemstack1, 6, 6 + 36, true)) { return null; } - } - if (stackInSlot.stackSize == 0) + slot.onSlotChange(itemstack1, itemstack); + } else if (index > 5) { - slotObject.putStack(null); - } else - { - slotObject.onSlotChanged(); - } - - if (stackInSlot.stackSize == stack.stackSize) + if (itemstack1.getItem() instanceof ISoul || itemstack1.getItem() instanceof ISoulGem) + { + if (!this.mergeItemStack(itemstack1, 4, 5, false)) + { + return null; + } + } else if (!this.mergeItemStack(itemstack1, 0, 4, false)) + { + return null; + } + } else if (!this.mergeItemStack(itemstack1, 6, 42, false)) { return null; } - slotObject.onPickupFromSlot(player, stackInSlot); + if (itemstack1.stackSize == 0) + { + slot.putStack((ItemStack) null); + } else + { + slot.onSlotChanged(); + } + + if (itemstack1.stackSize == itemstack.stackSize) + { + return null; + } + + slot.onPickupFromSlot(playerIn, itemstack1); } - return stack; + return itemstack; } @Override @@ -97,4 +112,18 @@ public class ContainerSoulForge extends Container return itemStack.getItem() instanceof ISoulGem || itemStack.getItem() instanceof ISoul; } } + + private class SlotOutput extends Slot + { + public SlotOutput(IInventory inventory, int slotIndex, int x, int y) + { + super(inventory, slotIndex, x, y); + } + + @Override + public boolean isItemValid(ItemStack stack) + { + return false; + } + } } diff --git a/src/main/resources/assets/bloodmagic/textures/items/BaseMonsterSoul.png b/src/main/resources/assets/bloodmagic/textures/items/BaseMonsterSoul.png index 4305497c5185970289042c2ec138cc1fdd7f1ff8..369129915c279b5b4a234a7a2c01b6e4591b2e83 100644 GIT binary patch delta 812 zcmV+{1JnH41IY%EDu3qy>Hyo;!~U88000SaNLh0L01FcU01FcV0GgZ_00007bV*G` z2jBq%4ip`-bD{bG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