diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index ae4ab83aeb..290af4796a 100644 --- a/src/main/java/net/minecraft/server/Block.java +++ b/src/main/java/net/minecraft/server/Block.java @@ -698,5 +698,9 @@ public class Block { public static int getDropData(Block block, int data) { return block.getDropData(data); } + + public int getExpDrop(World world, int data, int enchantmentLevel) { + return 0; + } // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/BlockMobSpawner.java b/src/main/java/net/minecraft/server/BlockMobSpawner.java index bff4d0286a..50e41b62b4 100644 --- a/src/main/java/net/minecraft/server/BlockMobSpawner.java +++ b/src/main/java/net/minecraft/server/BlockMobSpawner.java @@ -22,9 +22,17 @@ public class BlockMobSpawner extends BlockContainer { public void dropNaturally(World world, int i, int j, int k, int l, float f, int i1) { super.dropNaturally(world, i, j, k, l, f, i1); + /* CraftBukkit start - delegate to getExpDrop int j1 = 15 + world.random.nextInt(15) + world.random.nextInt(15); - this.g(world, i, j, k, j1); + this.g(world, i, j, k, j1); */ + } + + public int getExpDrop(World world, int data, int enchantmentLevel) { + int j1 = 15 + world.random.nextInt(15) + world.random.nextInt(15); + + return j1; + // CraftBukkit end } public boolean d() { diff --git a/src/main/java/net/minecraft/server/BlockOre.java b/src/main/java/net/minecraft/server/BlockOre.java index 4824635752..f679e3eed4 100644 --- a/src/main/java/net/minecraft/server/BlockOre.java +++ b/src/main/java/net/minecraft/server/BlockOre.java @@ -33,6 +33,7 @@ public class BlockOre extends Block { public void dropNaturally(World world, int i, int j, int k, int l, float f, int i1) { super.dropNaturally(world, i, j, k, l, f, i1); + /* CraftBukkit start - delegated getExpDrop if (this.getDropType(l, world.random, i1) != this.id) { int j1 = 0; @@ -47,7 +48,28 @@ public class BlockOre extends Block { } this.g(world, i, j, k, j1); + } */ + } + + public int getExpDrop(World world, int l, int i1) { + if (this.getDropType(l, world.random, i1) != this.id) { + int j1 = 0; + + if (this.id == Block.COAL_ORE.id) { + j1 = MathHelper.a(world.random, 0, 2); + } else if (this.id == Block.DIAMOND_ORE.id) { + j1 = MathHelper.a(world.random, 3, 7); + } else if (this.id == Block.EMERALD_ORE.id) { + j1 = MathHelper.a(world.random, 3, 7); + } else if (this.id == Block.LAPIS_ORE.id) { + j1 = MathHelper.a(world.random, 2, 5); + } + + return j1; } + + return 0; + // CraftBukkit end } protected int getDropData(int i) { diff --git a/src/main/java/net/minecraft/server/BlockRedstoneOre.java b/src/main/java/net/minecraft/server/BlockRedstoneOre.java index 123d8fd23b..b3716bbdb6 100644 --- a/src/main/java/net/minecraft/server/BlockRedstoneOre.java +++ b/src/main/java/net/minecraft/server/BlockRedstoneOre.java @@ -77,11 +77,23 @@ public class BlockRedstoneOre extends Block { public void dropNaturally(World world, int i, int j, int k, int l, float f, int i1) { super.dropNaturally(world, i, j, k, l, f, i1); + /* CraftBukkit start - delegate to getExpDrop if (this.getDropType(l, world.random, i1) != this.id) { int j1 = 1 + world.random.nextInt(5); this.g(world, i, j, k, j1); + } */ + } + + public int getExpDrop(World world, int l, int i1) { + if (this.getDropType(l, world.random, i1) != this.id) { + int j1 = 1 + world.random.nextInt(5); + + return j1; } + + return 0; + // CraftBukkit end } private void n(World world, int i, int j, int k) { diff --git a/src/main/java/net/minecraft/server/ItemInWorldManager.java b/src/main/java/net/minecraft/server/ItemInWorldManager.java index aa63a1c4cf..64515d1603 100644 --- a/src/main/java/net/minecraft/server/ItemInWorldManager.java +++ b/src/main/java/net/minecraft/server/ItemInWorldManager.java @@ -243,6 +243,8 @@ public class ItemInWorldManager { public boolean breakBlock(int i, int j, int k) { // CraftBukkit start + BlockBreakEvent event = null; + if (this.player instanceof EntityPlayer) { org.bukkit.block.Block block = this.world.getWorld().getBlockAt(i, j, k); @@ -255,8 +257,24 @@ public class ItemInWorldManager { ((EntityPlayer) this.player).netServerHandler.sendPacket(packet); } - BlockBreakEvent event = new BlockBreakEvent(block, (org.bukkit.entity.Player) this.player.getBukkitEntity()); - event.setCancelled(this.gamemode.isAdventure()); // Adventure mode pre-cancel + event = new BlockBreakEvent(block, this.player.getBukkitEntity()); + + // Adventure mode pre-cancel + event.setCancelled(this.gamemode.isAdventure()); + + // Calculate default block experience + Block nmsBlock = Block.byId[block.getTypeId()]; + + if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.b(nmsBlock)) { + // Copied from Block.a(world, entityhuman, int, int, int, int) + if (!(nmsBlock.q_() && EnchantmentManager.hasSilkTouchEnchantment(this.player.inventory))) { + int data = block.getData(); + int bonusLevel = EnchantmentManager.getBonusBlockLootEnchantmentLevel(this.player.inventory); + + event.setExpToDrop(nmsBlock.getExpDrop(this.world, data, bonusLevel)); + } + } + this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -295,6 +313,12 @@ public class ItemInWorldManager { } } + // CraftBukkit start - drop event experience + if (flag && event != null) { + Block.byId[l].g(this.world, i, j, k, event.getExpToDrop()); + } + // CraftBukkit end + return flag; } }