August 3, 201510 yr 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.
August 3, 201510 yr 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
August 3, 201510 yr 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
August 3, 201510 yr 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?
August 3, 201510 yr 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 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)
August 4, 201510 yr 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?
August 4, 201510 yr 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.
August 4, 201510 yr 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); }
August 4, 201510 yr 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.