geforkt von Mirrors/Paper
Implement BlockBreakEvent block experience. Adds BUKKIT-2033
Dieser Commit ist enthalten in:
Ursprung
8d946b88b3
Commit
27c1c85adb
@ -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
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren