Jump to content

[1.10.2][FIXED thank you Draco18s!] Break blocks with enchantments


Recommended Posts

Posted

World#DestroyBlock bypasses all the code that is specific to the player harvesting blocks.  If you want to harvest blocks you need to call the code responsible for harvesting blocks.

 

If you want Silk Touch to work, then use your IDE to figure out where the code already references Silk Touch.

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

Start with

Block#harvestBlock

.

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

Block#harvestBlock doesn't actually set the block to air.  You would know this if you actually looked at the method.

 

Point is, you can't call just one method, or you completely bypass the set of hooks designed to let other mods know that the block was harvested and removed, or in some cases, letting the block itself know.

 

Take a look at PlayerInterationManager#tryHarvestBlock(BlockPos)

 

The series of things to do is:

Block#canHarvestBlock (ensure you can actually harvest the block: you might be able to skip this if you're destroying same-type blocks only)

ItemStack#onBlockDestroyed (you would probably skip this because this is how your Item knows that it destroyed a block, and if that calls these methods again, you have a problem)

Block#removedByPlayer (automatically called Block#onBlockHarvested; default empty method, but used by various blocks to handle TE containers)

Block#onBlockDestroyedByPlayer

Block#harvestBlock (finally get the harvested drops to...drop)

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 now changed it to this:

if (state.getBlock().canHarvestBlock(worldIn, offset2, player)) {

state.getBlock().removedByPlayer(state, worldIn, offset2, player, true);

state.getBlock().onBlockDestroyedByPlayer(worldIn, offset2, state);

state.getBlock().harvestBlock(worldIn, player, offset2, state, null, itemStack);

} else {

worldIn.setBlockToAir(offset2);

}

 

The error:

http://pastebin.com/iyU6Z4ec

Posted

Gosh. It's almost like you're asking a block of diamond ore what type of dirt it is.

 

When you change position you need to get a NEW BLOCKSTATE or check that the two blocks ARE THE SAME FIRST

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

state.getBlock() //the block I mined out (diamond ore)

...removedByPlayer(state, worldIn, offset2, player, true); //offset2, the location of a different block (dirt), state: the diamond ore...

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

Thank you, but there are 2 problems:

1. I can't make it be able to not break unbreakeble blocks

2. Only the original block drops (all of them breakes)

 

if (worldIn.getBlockState(offset2).getBlock().canHarvestBlock(worldIn, offset2, player)) {

worldIn.getBlockState(offset2).getBlock().removedByPlayer(state, worldIn, offset2, player, true);

worldIn.getBlockState(offset2).getBlock().onBlockDestroyedByPlayer(worldIn, offset2, state);

worldIn.getBlockState(offset2).getBlock().harvestBlock(worldIn, player, offset2, state, null,

itemStack);

} else {

if (worldIn.isBlockModifiable(player, offset2)) {

worldIn.setBlockToAir(offset2);

}

}

Posted

Still doen't work, updated code:

if (worldIn.getBlockState(offset2).getBlock().canHarvestBlock(worldIn, offset2, player)) {

worldIn.getBlockState(offset2).getBlock().removedByPlayer(worldIn.getBlockState(offset2), worldIn,

offset2, player, true);

worldIn.getBlockState(offset2).getBlock().onBlockDestroyedByPlayer(worldIn, offset2,

worldIn.getBlockState(offset2));

worldIn.getBlockState(offset2).getBlock().harvestBlock(worldIn, player, offset2,

worldIn.getBlockState(offset2), null, itemStack);

} else {

if (worldIn.isBlockModifiable(player, offset2)) {

worldIn.setBlockToAir(offset2);

}

}

Posted

So, defined "doesn't work" for me here, because this worked for me just fine:

 

	public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
	if(entityLiving instanceof EntityPlayer) {
		EntityPlayer harvester = (EntityPlayer) entityLiving;
		Iterable<BlockPos> list = BlockPos.getAllInBox(pos.add(-1, -1, -1), pos.add(1,1,1));
		for(BlockPos offset2 : list) {
			IBlockState state2 = world.getBlockState(offset2);
			Block block2 = state2.getBlock();
			boolean canharvest = block2.canHarvestBlock(world, offset2, harvester);
			if (canharvest) {
				block2.removedByPlayer(state2, world, offset2, harvester, true);
				block2.onBlockDestroyedByPlayer(world, offset2, state2);
				block2.harvestBlock(world, harvester, offset2, state2, null, stack);
			}
			else {
				if (world.isBlockModifiable(harvester, offset2)) {
					world.setBlockToAir(offset2);
				}
			}
		}
	}
        return super.onBlockDestroyed(stack, world, state, pos, entityLiving);
    }

width=800 height=449http://s32.postimg.org/uemjtabol/2016_07_29_13_18_51.png[/img]

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.

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.