SnowyEgret Posted August 3, 2015 Posted August 3, 2015 How can I make my block provide drops when broken in creative mode? Quote
Draco18s Posted August 3, 2015 Posted August 3, 2015 You can, but the better question is why? (Usually people want to know how to prevent the drops) Quote 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.
SnowyEgret Posted August 3, 2015 Author Posted August 3, 2015 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 Quote
Ytt Posted August 3, 2015 Posted August 3, 2015 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 Quote
SnowyEgret Posted August 3, 2015 Author Posted August 3, 2015 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? Quote
Ytt Posted August 3, 2015 Posted August 3, 2015 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) Quote
SnowyEgret Posted August 4, 2015 Author Posted August 4, 2015 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? Quote
Choonster Posted August 4, 2015 Posted August 4, 2015 Try overriding Block#removedByPlayer to call Block#harvestBlock if the player that destroyed the block is in creative mode. 1 Quote 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.
SnowyEgret Posted August 4, 2015 Author Posted August 4, 2015 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); } 1 Quote
Choonster Posted August 4, 2015 Posted August 4, 2015 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. Quote 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.
Recommended Posts
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.