From f2e8633746bb211b3acb257bf9b181fa9414f25a Mon Sep 17 00:00:00 2001 From: Azanor Date: Tue, 1 Apr 2014 19:54:04 +0200 Subject: [PATCH] fix for shift clicking event triggers --- build.gradle | 2 +- src/main/java/baubles/common/Baubles.java | 3 +- .../container/ContainerPlayerExpanded.java | 99 ++++++++++++++++++- src/main/resources/changelog.txt | 4 +- 4 files changed, 102 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 2a7c08f..d448082 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.2-1.0.0.0" +version = "1.7.2-1.0.0.1" group= "com.azanor.baubles" archivesBaseName = "Baubles" diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java index 7b02445..a22c271 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -8,7 +8,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import baubles.common.event.EventHandlerEntity; -import baubles.common.lib.PlayerHandler; import baubles.common.network.EventHandlerNetwork; import baubles.common.network.PacketPipeline; import cpw.mods.fml.common.FMLCommonHandler; @@ -27,7 +26,7 @@ public class Baubles { public static final String MODID = "Baubles"; public static final String MODNAME = "Baubles"; - public static final String VERSION = "1.0.0.0"; + public static final String VERSION = "1.0.0.1"; @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") public static CommonProxy proxy; diff --git a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java index d812807..7a557fe 100644 --- a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java +++ b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java @@ -229,7 +229,7 @@ public class ContainerPlayerExpanded extends Container return null; } } - else if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false)) + else if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false, slot)) { return null; } @@ -253,6 +253,103 @@ public class ContainerPlayerExpanded extends Container return itemstack; } + + private void unequipBauble(ItemStack stack) { + if (stack.getItem() instanceof IBauble) { + ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer); + } + } + + protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4, Slot ss) + { + boolean flag1 = false; + int k = par2; + + if (par4) + { + k = par3 - 1; + } + + Slot slot; + ItemStack itemstack1; + + if (par1ItemStack.isStackable()) + { + while (par1ItemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) + { + slot = (Slot)this.inventorySlots.get(k); + itemstack1 = slot.getStack(); + + if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1)) + { + int l = itemstack1.stackSize + par1ItemStack.stackSize; + if (l <= par1ItemStack.getMaxStackSize()) + { + if (ss instanceof SlotBauble) unequipBauble(par1ItemStack); + par1ItemStack.stackSize = 0; + itemstack1.stackSize = l; + slot.onSlotChanged(); + flag1 = true; + } + else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize()) + { + if (ss instanceof SlotBauble) unequipBauble(par1ItemStack); + par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize; + itemstack1.stackSize = par1ItemStack.getMaxStackSize(); + slot.onSlotChanged(); + flag1 = true; + } + } + + if (par4) + { + --k; + } + else + { + ++k; + } + } + } + + if (par1ItemStack.stackSize > 0) + { + if (par4) + { + k = par3 - 1; + } + else + { + k = par2; + } + + while (!par4 && k < par3 || par4 && k >= par2) + { + slot = (Slot)this.inventorySlots.get(k); + itemstack1 = slot.getStack(); + + if (itemstack1 == null) + { + if (ss instanceof SlotBauble) unequipBauble(par1ItemStack); + slot.putStack(par1ItemStack.copy()); + slot.onSlotChanged(); + par1ItemStack.stackSize = 0; + flag1 = true; + break; + } + + if (par4) + { + --k; + } + else + { + ++k; + } + } + } + return flag1; + } @Override public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot) diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index 0055422..f1df3b9 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -1,2 +1,2 @@ -1.0.0.0 -- \ No newline at end of file +1.0.0.1 +- properly trigger unequip event when shift clicking out of bauble slot \ No newline at end of file