Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] Make block drop in creative mode


SnowyEgret
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Try overriding

Block#removedByPlayer

to call

Block#harvestBlock

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

  • Like 1

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.

Link to comment
Share on other sites

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);
}

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.