diff --git a/src/net/bdew/gendustry/gui/BlockGuiWrenchable.scala b/src/net/bdew/gendustry/gui/BlockGuiWrenchable.scala index e452c7b..5feb1ce 100644 --- a/src/net/bdew/gendustry/gui/BlockGuiWrenchable.scala +++ b/src/net/bdew/gendustry/gui/BlockGuiWrenchable.scala @@ -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