Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by BenignBanana

You should override Block::breakBlock. This method is called before the tile entity is destroyed so you can still access it.

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.