How to make the player pick up the block they break

Started by oiivu on

Topic category: Help with Minecraft modding (Java Edition)

Joined Sep 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make the player pick up the block they break

Im trying to make a enchantment that automatically picks the block you break

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
this works but it might be a…
Mon, 09/01/2025 - 19:08

this works but it might be a bit jank

!((Player)entity).hasCorrectToolForDrops(blockstate, (ServerLevel)world, BlockPos.containing(x, y, z))


		
		if (entity instanceof Player _player) {
			List<ItemStack> items = Block.getDrops(blockstate, (ServerLevel)world, BlockPos.containing(x, y, z), world
					.getBlockEntity(BlockPos.containing(x, y, z)), _player, _player.getMainHandItem());

			for(ItemStack item: items) {
				_player.addItem(item);
			}
		}