diff --git a/src/main/java/baubles/common/container/SlotBauble.java b/src/main/java/baubles/common/container/SlotBauble.java index fa44ec43..8b1736d9 100644 --- a/src/main/java/baubles/common/container/SlotBauble.java +++ b/src/main/java/baubles/common/container/SlotBauble.java @@ -3,8 +3,11 @@ import baubles.api.IBauble; import baubles.api.cap.BaublesCapabilities; import baubles.api.cap.IBaublesItemHandler; +import baubles.common.event.BaubleEquipmentChangeEvent; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.EventBus; import net.minecraftforge.items.SlotItemHandler; public class SlotBauble extends SlotItemHandler @@ -45,6 +48,7 @@ public ItemStack onTake(EntityPlayer playerIn, ItemStack stack) { stack.getCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null).onUnequipped(stack, playerIn); } super.onTake(playerIn, stack); + MinecraftForge.EVENT_BUS.post(new BaubleEquipmentChangeEvent(playerIn, baubleSlot, stack, ItemStack.EMPTY)); return stack; } @@ -58,12 +62,15 @@ public void putStack(ItemStack stack) { ItemStack oldstack = getStack().copy(); super.putStack(stack); - if (getHasStack() && !ItemStack.areItemStacksEqual(oldstack,getStack()) && !((IBaublesItemHandler)getItemHandler()).isEventBlocked() && getStack().hasCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null)) { getStack().getCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null).onEquipped(getStack(), player); } + if (!ItemStack.areItemStacksEqual(oldstack,getStack())){ + MinecraftForge.EVENT_BUS.post(new BaubleEquipmentChangeEvent(player, baubleSlot, oldstack, getStack())); + } + } @Override diff --git a/src/main/java/baubles/common/event/BaubleEquipmentChangeEvent.java b/src/main/java/baubles/common/event/BaubleEquipmentChangeEvent.java new file mode 100644 index 00000000..01100511 --- /dev/null +++ b/src/main/java/baubles/common/event/BaubleEquipmentChangeEvent.java @@ -0,0 +1,34 @@ +package baubles.common.event; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.living.LivingEvent; + +import javax.annotation.Nonnull; + +public class BaubleEquipmentChangeEvent extends LivingEvent { + private final int slot; + private final ItemStack from; + private final ItemStack to; + + public BaubleEquipmentChangeEvent(EntityLivingBase entity, int slot, @Nonnull ItemStack from, @Nonnull ItemStack to) { + super(entity); + this.slot = slot; + this.from = from; + this.to = to; + } + + public int getSlot() { + return this.slot; + } + + @Nonnull + public ItemStack getFrom() { + return this.from; + } + + @Nonnull + public ItemStack getTo() { + return this.to; + } +}