Added TE IDismantleable support

This commit is contained in:
bdew committed 2013-12-31 20:21:49 +02:00
1 parent 1d22316626
commit e540a45e20
1 file changed
+26 -1
@@ -14,9 +14,34 @@ import net.minecraft.entity.player.EntityPlayer
import buildcraft.api.tools.IToolWrench
import net.bdew.gendustry.Gendustry
import net.minecraft.block.Block
import cpw.mods.fml.common.Optional
import net.bdew.gendustry.compat.PowerProxy
import cofh.api.block.IDismantleable
import net.minecraft.item.ItemStack
import net.bdew.lib.tile.inventory.BreakableInventoryTile
import net.bdew.lib.items.ItemUtils
trait BlockGuiWrenchable extends Block {
@Optional.Interface(modid = PowerProxy.TE_MOD_ID, iface = "cofh.api.block.IDismantleable")
trait BlockGuiWrenchable extends Block with IDismantleable {
val guiId: Int
def dismantleBlock(player: EntityPlayer, world: World, x: Int, y: Int, z: Int, returnBlock: Boolean): ItemStack = {
val item = new ItemStack(this)
val te = world.getBlockTileEntity(x, y, z)
if (te != null && te.isInstanceOf[BreakableInventoryTile])
te.asInstanceOf[BreakableInventoryTile].dropItems()
world.setBlockToAir(x, y, z)
if (!returnBlock)
ItemUtils.throwItemAt(world, x, y, z, item)
return item
}
def canDismantle(player: EntityPlayer, world: World, x: Int, y: Int, z: Int): Boolean = true
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
if (player.isSneaking) {
val equipped = if (player.getCurrentEquippedItem != null) player.getCurrentEquippedItem.getItem else null