Skip to content

Commit

Permalink
Implement IDismanleable from COFH
Browse files Browse the repository at this point in the history
This allows breaking the kuarry by shift-clicking it with a crescent hammer
  • Loading branch information
vaartis committed Dec 9, 2019
1 parent f7d39c5 commit 2c4405d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
29 changes: 25 additions & 4 deletions src/main/kotlin/org/kotobank/kuarry/block/KuarryBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ import net.minecraft.util.NonNullList
import net.minecraft.util.math.BlockPos
import net.minecraft.world.IBlockAccess
import net.minecraft.world.World
import org.kotobank.kuarry.KuarryMod
import org.kotobank.kuarry.KuarryModGUIHandler
import org.kotobank.kuarry.tile_entity.KuarryTileEntity
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.text.TextFormatting
import net.minecraftforge.fml.common.Optional
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import net.minecraftforge.items.ItemStackHandler
import org.kotobank.kuarry.helper.TranslationHelper
import org.kotobank.kuarry.KuarryMod
import org.kotobank.kuarry.KuarryModGUIHandler
import org.kotobank.kuarry.tile_entity.KuarryTileEntity
import cofh.api.block.IDismantleable

class KuarryBlock(material: Material, registryName: String) : Block(material) {
@Optional.Interface(iface = "cofh.api.block.IDismantleable", modid = "cofhcore")
class KuarryBlock(material: Material, registryName: String) : Block(material), IDismantleable {
companion object {
val FACING: PropertyDirection =
PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL)
Expand Down Expand Up @@ -152,4 +155,22 @@ class KuarryBlock(material: Material, registryName: String) : Block(material) {
))
}
}

// region IDismantleable implementation

@Optional.Method(modid = "cofhcore")
override fun canDismantle(world: World?, pos: BlockPos?, state: IBlockState?, player: EntityPlayer?) = true

@Optional.Method(modid = "cofhcore")
override fun dismantleBlock(world: World, pos: BlockPos, state: IBlockState, player: EntityPlayer, returnDrops: Boolean): ArrayList<ItemStack> {
val res = ItemStack.EMPTY
val te = world.getTileEntity(pos)
if (te != null) {
harvestBlock(world, player, pos, state, te, res)
}

return arrayListOf(res)
}

// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,6 @@ class KuarryTileEntity : TileEntity(), ITickable {
return originalBB
}

// Overriden to make it not reset the TE on block rotation
override fun shouldRefresh(world: World, pos: BlockPos, oldState: IBlockState, newSate: IBlockState) = false
// Overriden to make it not reset the TE on block rotation, but update when the block actually changes
override fun shouldRefresh(world: World, pos: BlockPos, oldState: IBlockState, newSate: IBlockState) = oldState.block != newSate.block
}

0 comments on commit 2c4405d

Please sign in to comment.