Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted

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

Posted

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?

Posted

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)

Posted

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?

Posted

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.

Posted

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
Posted

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

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

Announcements



×
×
  • Create New...

Important Information

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