diff options
author | feildmaster <admin@feildmaster.com> | 2012-08-08 06:23:43 -0500 |
---|---|---|
committer | feildmaster <admin@feildmaster.com> | 2012-08-08 19:49:10 -0500 |
commit | 27c1c85adb97073b7f048374c8a4356f8ba39c3c (patch) | |
tree | 6fa43cf5c1a06fc2c4ed5f69996ba8287fb5b42b /src/main/java/net | |
parent | 8d946b88b3b96be1f6ae6b21bca915b73909e0bb (diff) | |
download | craftbukkit-27c1c85adb97073b7f048374c8a4356f8ba39c3c.tar craftbukkit-27c1c85adb97073b7f048374c8a4356f8ba39c3c.tar.gz craftbukkit-27c1c85adb97073b7f048374c8a4356f8ba39c3c.tar.lz craftbukkit-27c1c85adb97073b7f048374c8a4356f8ba39c3c.tar.xz craftbukkit-27c1c85adb97073b7f048374c8a4356f8ba39c3c.zip |
Implement BlockBreakEvent block experience. Adds BUKKIT-2033
Diffstat (limited to 'src/main/java/net')
5 files changed, 73 insertions, 3 deletions
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index ae4ab83a..290af479 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 bff4d028..50e41b62 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 48246357..f679e3ee 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 123d8fd2..b3716bbd 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 aa63a1c4..64515d16 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; } } |