Posted July 1, 20178 yr Hey everyone, I ran into a bit of a snag when I tried to do multiblock cleanup on block break. If I try to get the TileEntity of my block inside the onBlockDestroyedByPlayer/Explosion methods it always returns null, preventing me from calling the cleanup method on it. Why is it always returning null and/or is there any other event I can use that still has the TileEntity active? The code is a bit obtuse because of the large framework I've built and the fact that it's kotlin, but I hope these snippets are enough to understand it. Inside my framework base block class: override fun onBlockDestroyedByPlayer(worldIn: World, pos: BlockPos, state: IBlockState) { breakEvent.fire(BlockBrokenEvent(worldIn, pos)) super.onBlockDestroyedByPlayer(worldIn, pos, state) } override fun onBlockDestroyedByExplosion(worldIn: World, pos: BlockPos, explosionIn: Explosion) { breakEvent.fire(BlockBrokenEvent(worldIn, pos)) super.onBlockDestroyedByExplosion(worldIn, pos, explosionIn) } And inside the multiblock part block base class: init { placeEvent += { if(!it.world.isRemote) { val te = it.world.getTileEntity(it.pos) as TileEntityMultiblockPart te.rebuild(it.pos) } } breakEvent += { if(!it.world.isRemote) { val te = it.world.getTileEntity(it.pos) as? TileEntityMultiblockPart //This is always null if(te != null && te.multiblockId.value != -1) (it.world.getEntityByID(te.multiblockId.value) as? EntityMultiblock)?.destroy() } } } Cheers Edited July 1, 20178 yr by BenignBanana
July 1, 20178 yr You should override Block::breakBlock. This method is called before the tile entity is destroyed so you can still access it.
July 1, 20178 yr Author 2 minutes ago, Franckyi said: You should override Block::breakBlock. This method is called before the tile entity is destroyed so you can still access it. Right. I was looking for an onSomething method, so I didn't see that one. Cheers for the help
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.