Added a slot trait that intercepts clicks

This commit is contained in:
bdew committed 2013-12-31 12:35:34 +02:00
1 parent 041f570109
commit 3b31e285d2
3 files changed
+28 -1

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ buildscript {
apply plugin: 'forge'
apply plugin: 'scala'
version = "0.9.4"
version = "0.9.5"
if (project.hasProperty('buildnum')) {
project.version = project.version + '.' + project.buildnum
+9
View File
@@ -29,6 +29,15 @@ abstract class BaseContainer(te: IInventory) extends Container {
addSlotToContainer(new Slot(inv, i, xOffs + i * 18, yOffsHotbar))
}
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
if (inventorySlots.isDefinedAt(slotnum)) {
val slot = getSlot(slotnum)
if (slot != null && slot.isInstanceOf[SlotClickable])
return slot.asInstanceOf[SlotClickable].onClick(button, modifiers, player)
}
return super.slotClick(slotnum, button, modifiers, player)
}
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = {
var stack = getSlot(slot).getStack
if (getSlot(slot).inventory == player.inventory) {
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright (c) bdew, 2013
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
*/
package net.bdew.lib.gui
import net.minecraft.item.ItemStack
import net.minecraft.inventory.Slot
import net.minecraft.entity.player.EntityPlayer
trait SlotClickable extends Slot {
def onClick(button: Int, mods: Int, player: EntityPlayer): ItemStack
}