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

You can, but the better question is why?

(Usually people want to know how to prevent the drops)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I have a block which replaces a selection of blocks and stores the path to a file with the saved selections on its tile entity. In survival, the player picks up the block after breaking and puts it in his inventory to place it at some other time and place and restore the original blocks from file. I would like the same behavior in creative

First, you need to check whether the player is in creative mode with an of statement. Next, you need to get the item id of the item you broke (I think there's a method called onBlockBreak for that). Finally, return the block id in the onBlockBreak method. I'm just trying to make simple solutions, so if this doesn't work, tell me and I'll spend some time thinking of a more concrete way to solve this

  • Author

Thanks for the reply :)

 

Not sure what you mean by " item id of the item you broke".

 

I am breaking a Block. My understanding is that once it is in the player's inventory it is an ItemBlock.

 

Method onBlockBreak is on which class?

I re read what you were doing, and I was completely wrong ;-; disregard all of the above. How are you getting and saving the selection of blocks? Post your code please :P

 

I made a mistake and assumed you were doing something less complicated, my bad. Just post the class. Honestly, the way I'm thinking of is really simple (if what you're trying to do is what I think)

  • Author

My mod is on GitHub, repository is mo-jo. The Block is named BlockSaved. Please have a look if you are interested.

 

But this is really a generic problem. How do you make a block, any block, drop in creative?

Try overriding

Block#removedByPlayer

to call

Block#harvestBlock

if the player that destroyed the block is in creative mode.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Thanks!

 

@Override
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
	if (willHarvest) {
		// Delay deletion of the block until after getDrops
		return true;
	}
	if (player.capabilities.isCreativeMode) {
		harvestBlock(world, player, pos, this.getDefaultState(), null);
	}
	return super.removedByPlayer(world, pos, player, willHarvest);
}

You should pass the actual state (

World#getBlockState

) rather than the default state (

Block#getDefaultState

) to

harvestBlock

. At the time of

removedByPlayer

being called, the

Block

is still in the world.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.