From 174d56b8ffffb9584bf32b3d9063c758212d5c14 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Thu, 20 Nov 2014 10:19:45 -0500 Subject: [PATCH] Finishing up Compression sigil --- .gitignore | 1 + .../AlchemicalWizardry.java | 4 +- .../alchemicalWizardry/ModItems.java | 4 + .../api/compress/CompressionHandler.java | 11 +- .../api/compress/CompressionRegistry.java | 5 +- .../compress/AdvancedCompressionHandler.java | 175 ++++++++++++++++++ .../compress/BaseCompressionHandler.java | 5 +- .../compress/DumbyInventoryCrafting.java | 17 ++ .../common/items/sigil/ItemPackRatSigil.java | 45 ++--- .../items/CompressionSigil_activated.png | Bin 0 -> 592 bytes .../items/CompressionSigil_deactivated.png | Bin 0 -> 616 bytes 11 files changed, 228 insertions(+), 39 deletions(-) create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/compress/DumbyInventoryCrafting.java create mode 100644 src/main/resources/assets/alchemicalwizardry/textures/items/CompressionSigil_activated.png create mode 100644 src/main/resources/assets/alchemicalwizardry/textures/items/CompressionSigil_deactivated.png diff --git a/.gitignore b/.gitignore index 91cc5856..da2d8747 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ crash-reports/ /resourcepacks/ /logs/ /mods/ +/screenshots/ # File Extensions *.psd diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 678509dd..120dbd38 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -66,6 +66,7 @@ import WayofTime.alchemicalWizardry.common.alchemy.CombinedPotionRegistry; import WayofTime.alchemicalWizardry.common.block.ArmourForge; import WayofTime.alchemicalWizardry.common.bloodAltarUpgrade.UpgradedAltars; import WayofTime.alchemicalWizardry.common.book.BUEntries; +import WayofTime.alchemicalWizardry.common.compress.AdvancedCompressionHandler; import WayofTime.alchemicalWizardry.common.compress.BaseCompressionHandler; import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketAngel; import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketRegistry; @@ -1302,6 +1303,7 @@ public class AlchemicalWizardry public void initCompressionHandlers() { - CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust), new ItemStack(Blocks.glowstone), 0)); + CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 0)); + CompressionRegistry.registerHandler(new AdvancedCompressionHandler()); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/ModItems.java b/src/main/java/WayofTime/alchemicalWizardry/ModItems.java index bfe506fe..3965fb93 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/ModItems.java +++ b/src/main/java/WayofTime/alchemicalWizardry/ModItems.java @@ -67,6 +67,7 @@ import WayofTime.alchemicalWizardry.common.items.sigil.DivinationSigil; import WayofTime.alchemicalWizardry.common.items.sigil.ItemBloodLightSigil; import WayofTime.alchemicalWizardry.common.items.sigil.ItemFluidSigil; import WayofTime.alchemicalWizardry.common.items.sigil.ItemHarvestSigil; +import WayofTime.alchemicalWizardry.common.items.sigil.ItemPackRatSigil; import WayofTime.alchemicalWizardry.common.items.sigil.ItemSeerSigil; import WayofTime.alchemicalWizardry.common.items.sigil.ItemSigilOfEnderSeverance; import WayofTime.alchemicalWizardry.common.items.sigil.ItemSigilOfSupression; @@ -195,6 +196,7 @@ public class ModItems public static Item itemBloodMagicBook; public static Item itemHarvestSigil; + public static Item itemCompressionSigil; public static Item bucketLife; @@ -299,6 +301,7 @@ public class ModItems itemBloodPack = new ItemBloodLetterPack().setUnlocalizedName("itemBloodPack"); itemHarvestSigil = new ItemHarvestSigil().setUnlocalizedName("itemHarvestSigil"); + itemCompressionSigil = new ItemPackRatSigil().setUnlocalizedName("itemCompressionSigil"); } public static void registerItems() @@ -404,6 +407,7 @@ public class ModItems GameRegistry.registerItem(ModItems.itemBloodPack, "itemBloodPack"); GameRegistry.registerItem(ModItems.itemHarvestSigil, "itemHarvestSigil"); + GameRegistry.registerItem(ModItems.itemCompressionSigil, "itemCompressionSigil"); //GameRegistry.registerItem(ModItems.itemBloodFrame, "itemBloodFrame"); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java b/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java index 7c8e1019..a05c7003 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java @@ -1,17 +1,14 @@ package WayofTime.alchemicalWizardry.api.compress; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public abstract class CompressionHandler -{ - public abstract ItemStack getResultStack(); - - public abstract ItemStack getRequiredStack(); - +{ /** - * Called to look at the inventory and syphons the required stack. Returns getResultStack if successful, and null if not. + * Called to look at the inventory and syphons the required stack. Returns resultant stack if successful, and null if not. * @param inv The inventory iterated through * @return The result of the compression */ - public abstract ItemStack compressInventory(ItemStack[] inv); + public abstract ItemStack compressInventory(ItemStack[] inv, World world); } diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java b/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java index 4ddfe342..f1e05742 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; /** * A registry aimed to help compress items in an inventory into its compressible form. @@ -18,11 +19,11 @@ public class CompressionRegistry compressionRegistry.add(handler); } - public static ItemStack compressInventory(ItemStack[] inv) + public static ItemStack compressInventory(ItemStack[] inv, World world) { for(CompressionHandler handler : compressionRegistry) { - ItemStack stack = handler.compressInventory(inv); + ItemStack stack = handler.compressInventory(inv, world); if(stack != null) { return stack; diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java new file mode 100644 index 00000000..118211b1 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/AdvancedCompressionHandler.java @@ -0,0 +1,175 @@ +package WayofTime.alchemicalWizardry.common.compress; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.compress.CompressionHandler; + +public class AdvancedCompressionHandler extends CompressionHandler +{ + public AdvancedCompressionHandler() + { + super(); + } + + @Override + public ItemStack compressInventory(ItemStack[] inv, World world) + { + return test(inv, true, world); + } + + public ItemStack test(ItemStack[] inv, boolean doDrain, World world) + { + for(ItemStack invStack : inv) + { + if(invStack == null) + { + continue; + } + + for(int i=2; i<=3; i++) + { + ItemStack stacky = getRecipe(invStack, world, i); + if(isResultStackReversible(stacky, i, world)) + { + int needed = i*i; + int neededLeft = iterateThroughInventory(invStack, 0, inv, needed, false); + if(neededLeft <= 0) + { + iterateThroughInventory(invStack, 0, inv, needed, true); + return stacky; + } + } + } + } + + return null; + } + + public int iterateThroughInventory(ItemStack required, int kept, ItemStack[] inv, int needed, boolean doDrain) + { + int i = -1; + + for(ItemStack invStack : inv) + { + i++; + + if(invStack == null) + { + continue; + } + + if(invStack.isItemEqual(required) && (invStack.getTagCompound() == null ? required.getTagCompound() == null : invStack.getTagCompound().equals(required.getTagCompound()))) + { + int stackSize = invStack.stackSize; + int used = 0; + if(kept > 0) + { + int remainingFromStack = Math.max(stackSize - kept, 0); + used += stackSize - remainingFromStack; + } + + kept -= used; + + if(kept <= 0 && needed > 0) + { + int remainingFromStack = Math.max(stackSize - used - needed, 0); + needed -= (stackSize - used - remainingFromStack); + if(doDrain) + { + invStack.stackSize = remainingFromStack; + if(invStack.stackSize <= 0) + { + inv[i] = null; + } + } + } + + if(needed <= 0) + { + return 0; + } + } + } + + return needed; + } + + public boolean isResultStackReversible(ItemStack stack, int gridSize, World world) + { + InventoryCrafting inventory = new InventoryCrafting(new Container() + { + public boolean canInteractWith(EntityPlayer player) + { + return false; + } + }, 2, 2); + + inventory.setInventorySlotContents(0, stack); + + ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world); + if(returnStack == null) + { + return false; + } + + ItemStack compressedStack = null; + switch(gridSize) + { + case 2: + compressedStack = get22Recipe(returnStack, world); + break; + case 3: + compressedStack = get33Recipe(returnStack, world); + break; + } + + if(compressedStack == null) + { + return false; + }else + { + return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound())); + } + } + + public ItemStack getRecipe(ItemStack stack, World world, int gridSize) + { + InventoryCrafting inventory = new InventoryCrafting(new Container() + { + public boolean canInteractWith(EntityPlayer player) + { + return false; + } + }, gridSize, gridSize); + for(int i=0; iWFU8GbZ8()Nlj2>E@cM*00Fc~L_t(I%bk>)z*Zlcft6?gE+zkoXEN6cPjl5pTE(Zp2sd4T2C%pGoZLY5VrO z=$TALV!#v>)Zv`^`0J;Rkp#f^-6?e;?(VGfKVcRCzK+GL?(4`cUswwR5BCnu#en?{ z;Vo1Z)CTGfMiy}3BWOE_4MZO51~xMTU{6uM8#p?FA2Y(k0&E4p3Ye8}Fk$jw0tW%6 z4Rl&ckkseLHH8ReW}ddsutGQf4J$}WJSp`*tI$$k^riFM&`ob`IT$8+VU<}x$$*X|K!eCyvIhdGiYl;Bp zA#Ar81IeeQ2X+Nel<>2^43AofJH~qsYa#h?9R$f+3-^!B`G9Fj*y+pk{X$8H0ce{3 z+znP*?B64#Pv><9j7A(k5y>+HQ9nLydjTL#;LhBjcmv9st^;mg1#b{QxeD-S_rVwl zTfI?)6DHe`z69zVa`mbr`;S%ra!sewBL`&;l^_CIAaB8n!_Caxyp^5<0OH{g=Nx%a eT;exgGX4No=;0r&Vjm6w0000|^eq-FpB03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E@cM*00GQNL_t(I%bk-?OO#O* z#((GDcm8POG=|oqU8{C|jy6JjMVMR^ts;U9+_);Dh$1YK$;zNW+Js-F&rk+7I^+Ak zzJKo1Vn&An74m@#XK|k2eK_Y{lLWxeR|n*=xbdjL|HzI2{J12Nd{9^XsKYs^MsRb- z&IW8XMdTpMAUDVZ)Q9F;1wsHb@E-C4=5`Ih9i#FR4tnq_W&M5vE`ub2GKJq=J}h-% z?=KYPDG9zdw7HVd`!fjQE5iIRbpR?r0d4{opIxA_P+C8ZLDJ}K&q$xD+PvN=Ke(EKia_T2Q1wa}pGwR^#?_9cVBxdEwT7!21(4X8row;4Rd}aCs05DOj;k~CH$LIKs=hQ#;IO8>-y8I3R0000frV literal 0 HcmV?d00001