diff options
Diffstat (limited to 'src/main/java/net/minecraft/server/PlayerInteractManager.java')
-rw-r--r-- | src/main/java/net/minecraft/server/PlayerInteractManager.java | 177 |
1 files changed, 89 insertions, 88 deletions
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java index 16420e46..3028404a 100644 --- a/src/main/java/net/minecraft/server/PlayerInteractManager.java +++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java @@ -56,24 +56,21 @@ public class PlayerInteractManager { public void a() { this.currentTick = MinecraftServer.currentTick; // CraftBukkit - int i; float f; - int j; + int i; if (this.j) { - i = this.currentTick - this.n; - int k = this.world.getTypeId(this.k, this.l, this.m); + int j = this.currentTick - this.n; + Block block = this.world.getType(this.k, this.l, this.m); - if (k == 0) { + if (block.getMaterial() == Material.AIR) { this.j = false; } else { - Block block = Block.byId[k]; - - f = block.getDamage(this.player, this.player.world, this.k, this.l, this.m) * (float) (i + 1); - j = (int) (f * 10.0F); - if (j != this.o) { - this.world.f(this.player.id, this.k, this.l, this.m, j); - this.o = j; + f = block.getDamage(this.player, this.player.world, this.k, this.l, this.m) * (float) (j + 1); + i = (int) (f * 10.0F); + if (i != this.o) { + this.world.d(this.player.getId(), this.k, this.l, this.m, i); + this.o = i; } if (f >= 1.0F) { @@ -82,36 +79,32 @@ public class PlayerInteractManager { } } } else if (this.d) { - i = this.world.getTypeId(this.f, this.g, this.h); - Block block1 = Block.byId[i]; + Block block1 = this.world.getType(this.f, this.g, this.h); - if (block1 == null) { - this.world.f(this.player.id, this.f, this.g, this.h, -1); + if (block1.getMaterial() == Material.AIR) { + this.world.d(this.player.getId(), this.f, this.g, this.h, -1); this.o = -1; this.d = false; } else { - int l = this.currentTick - this.lastDigTick; + int k = this.currentTick - this.lastDigTick; - f = block1.getDamage(this.player, this.player.world, this.f, this.g, this.h) * (float) (l + 1); - j = (int) (f * 10.0F); - if (j != this.o) { - this.world.f(this.player.id, this.f, this.g, this.h, j); - this.o = j; + f = block1.getDamage(this.player, this.player.world, this.f, this.g, this.h) * (float) (k + 1); + i = (int) (f * 10.0F); + if (i != this.o) { + this.world.d(this.player.getId(), this.f, this.g, this.h, i); + this.o = i; } } } } public void dig(int i, int j, int k, int l) { - // this.world.douseFire((EntityHuman) null, i, j, k, l); // CraftBukkit - moved down - // CraftBukkit + // CraftBukkit start PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, i, j, k, l, this.player.inventory.getItemInHand()); - if (!this.gamemode.isAdventure() || this.player.d(i, j, k)) { - // CraftBukkit start if (event.isCancelled()) { // Let the client know the block still exists - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); // Update any tile entity data for this block TileEntity tileentity = this.world.getTileEntity(i, j, k); if (tileentity != null) { @@ -125,36 +118,32 @@ public class PlayerInteractManager { this.breakBlock(i, j, k); } } else { - this.world.douseFire((EntityHuman) null, i, j, k, l); + // this.world.douseFire((EntityHuman) null, i, j, k, l); // CraftBukkit - Moved down this.lastDigTick = this.currentTick; float f = 1.0F; - int i1 = this.world.getTypeId(i, j, k); + Block block = this.world.getType(i, j, k); // CraftBukkit start - Swings at air do *NOT* exist. if (event.useInteractedBlock() == Event.Result.DENY) { // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. - if (i1 == Block.WOODEN_DOOR.id) { + if (block == Blocks.WOODEN_DOOR) { // For some reason *BOTH* the bottom/top part have to be marked updated. boolean bottom = (this.world.getData(i, j, k) & 8) == 0; - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, this.world)); - } else if (i1 == Block.TRAP_DOOR.id) { - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j + (bottom ? 1 : -1), k, this.world)); + } else if (block == Blocks.TRAP_DOOR) { + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); } - } else if (i1 > 0) { - Block.byId[i1].attack(this.world, i, j, k, this.player); + } else if (block.getMaterial() != Material.AIR) { + block.attack(this.world, i, j, k, this.player); + f = block.getDamage(this.player, this.player.world, i, j, k); // Allow fire punching to be blocked this.world.douseFire((EntityHuman) null, i, j, k, l); } - // Handle hitting a block - if (i1 > 0) { - f = Block.byId[i1].getDamage(this.player, this.world, i, j, k); - } - if (event.useItemInHand() == Event.Result.DENY) { // If we 'insta destroyed' then the client needs to be informed. if (f > 1.0f) { - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); } return; } @@ -162,7 +151,7 @@ public class PlayerInteractManager { if (blockEvent.isCancelled()) { // Let the client know the block still exists - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); return; } @@ -171,17 +160,17 @@ public class PlayerInteractManager { } // CraftBukkit end - if (i1 > 0 && f >= 1.0F) { + if (block.getMaterial() != Material.AIR && f >= 1.0F) { this.breakBlock(i, j, k); } else { this.d = true; this.f = i; this.g = j; this.h = k; - int j1 = (int) (f * 10.0F); + int i1 = (int) (f * 10.0F); - this.world.f(this.player.id, i, j, k, j1); - this.o = j1; + this.world.d(this.player.getId(), i, j, k, i1); + this.o = i1; } } } @@ -191,15 +180,14 @@ public class PlayerInteractManager { if (i == this.f && j == this.g && k == this.h) { this.currentTick = MinecraftServer.currentTick; // CraftBukkit int l = this.currentTick - this.lastDigTick; - int i1 = this.world.getTypeId(i, j, k); + Block block = this.world.getType(i, j, k); - if (i1 != 0) { - Block block = Block.byId[i1]; + if (block.getMaterial() != Material.AIR) { float f = block.getDamage(this.player, this.player.world, i, j, k) * (float) (l + 1); if (f >= 0.7F) { this.d = false; - this.world.f(this.player.id, i, j, k, -1); + this.world.d(this.player.getId(), i, j, k, -1); this.breakBlock(i, j, k); } else if (!this.j) { this.d = false; @@ -212,27 +200,24 @@ public class PlayerInteractManager { } // CraftBukkit start - Force block reset to client } else { - this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); // CraftBukkit end } } public void c(int i, int j, int k) { this.d = false; - this.world.f(this.player.id, this.f, this.g, this.h, -1); + this.world.d(this.player.getId(), this.f, this.g, this.h, -1); } private boolean d(int i, int j, int k) { - Block block = Block.byId[this.world.getTypeId(i, j, k)]; + Block block = this.world.getType(i, j, k); int l = this.world.getData(i, j, k); - if (block != null) { - block.a(this.world, i, j, k, l, this.player); - } - + block.a(this.world, i, j, k, l, this.player); boolean flag = this.world.setAir(i, j, k); - if (block != null && flag) { + if (flag) { block.postBreak(this.world, i, j, k, l); } @@ -248,9 +233,8 @@ public class PlayerInteractManager { // Tell client the block is gone immediately then process events if (world.getTileEntity(i, j, k) == null) { - Packet53BlockChange packet = new Packet53BlockChange(i, j, k, this.world); - - packet.material = 0; + PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(i, j, k, this.world); + packet.block = Blocks.AIR; packet.data = 0; ((EntityPlayer) this.player).playerConnection.sendPacket(packet); } @@ -261,14 +245,14 @@ public class PlayerInteractManager { event.setCancelled(this.gamemode.isAdventure() && !this.player.d(i, j, k)); // Sword + Creative mode pre-cancel - event.setCancelled(event.isCancelled() || (this.gamemode.d() && this.player.aZ() != null && this.player.aZ().getItem() instanceof ItemSword)); + event.setCancelled(event.isCancelled() || (this.gamemode.d() && this.player.be() != null && this.player.be().getItem() instanceof ItemSword)); // Calculate default block experience - Block nmsBlock = Block.byId[block.getTypeId()]; + Block nmsBlock = this.world.getType(i, j, k); if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.a(nmsBlock)) { - // Copied from Block.a(world, entityhuman, int, int, int, int) - if (!(nmsBlock.r_() && EnchantmentManager.hasSilkTouchEnchantment(this.player))) { + // Copied from block.a(world, entityhuman, int, int, int, int) + if (!(nmsBlock.E() && EnchantmentManager.hasSilkTouchEnchantment(this.player))) { int data = block.getData(); int bonusLevel = EnchantmentManager.getBonusBlockLootEnchantmentLevel(this.player); @@ -280,7 +264,7 @@ public class PlayerInteractManager { if (event.isCancelled()) { // Let the client know the block still exists - ((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); // Update any tile entity data for this block TileEntity tileentity = this.world.getTileEntity(i, j, k); if (tileentity != null) { @@ -290,45 +274,47 @@ public class PlayerInteractManager { } } - if (false) { // Never trigger + if (false && this.gamemode.isAdventure() && !this.player.d(i, j, k)) { // Never trigger // CraftBukkit end return false; + } else if (false && this.gamemode.d() && this.player.be() != null && this.player.be().getItem() instanceof ItemSword) { // CraftBukkit - never trigger + return false; } else { - int l = this.world.getTypeId(i, j, k); - if (Block.byId[l] == null) return false; // CraftBukkit - A plugin set block to air without cancelling - int i1 = this.world.getData(i, j, k); + Block block = this.world.getType(i, j, k); + if (block == Blocks.AIR) return false; // CraftBukkit - A plugin set block to air without cancelling + int l = this.world.getData(i, j, k); // CraftBukkit start - Special case skulls, their item data comes from a tile entity - if (l == Block.SKULL.id && !this.isCreative()) { - Block.SKULL.dropNaturally(world, i, j, k, i1, 1.0F, 0); + if (block == Blocks.SKULL && !this.isCreative()) { + block.dropNaturally(world, i, j, k, l, 1.0F, 0); return this.d(i, j, k); } // CraftBukkit end - this.world.a(this.player, 2001, i, j, k, l + (this.world.getData(i, j, k) << 12)); + this.world.a(this.player, 2001, i, j, k, Block.b(block) + (this.world.getData(i, j, k) << 12)); boolean flag = this.d(i, j, k); if (this.isCreative()) { - this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world)); + this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, this.world)); } else { - ItemStack itemstack = this.player.by(); - boolean flag1 = this.player.a(Block.byId[l]); + ItemStack itemstack = this.player.bD(); + boolean flag1 = this.player.a(block); if (itemstack != null) { - itemstack.a(this.world, l, i, j, k, this.player); + itemstack.a(this.world, block, i, j, k, this.player); if (itemstack.count == 0) { - this.player.bz(); + this.player.bE(); } } if (flag && flag1) { - Block.byId[l].a(this.world, this.player, i, j, k, i1); + block.a(this.world, this.player, i, j, k, l); } } // CraftBukkit start - Drop event experience if (flag && event != null) { - Block.byId[l].j(this.world, i, j, k, event.getExpToDrop()); + block.c(this.world, i, j, k, event.getExpToDrop()); } // CraftBukkit end @@ -356,7 +342,7 @@ public class PlayerInteractManager { entityhuman.inventory.items[entityhuman.inventory.itemInHandIndex] = null; } - if (!entityhuman.br()) { + if (!entityhuman.bw()) { ((EntityPlayer) entityhuman).updateInventory(entityhuman.defaultContainer); } @@ -365,21 +351,36 @@ public class PlayerInteractManager { } public boolean interact(EntityHuman entityhuman, World world, ItemStack itemstack, int i, int j, int k, int l, float f, float f1, float f2) { - int i1 = world.getTypeId(i, j, k); + /* CraftBukkit start - whole method + if ((!entityhuman.isSneaking() || entityhuman.be() == null) && world.getType(i, j, k).interact(world, i, j, k, entityhuman, l, f, f1, f2)) { + return true; + } else if (itemstack == null) { + return false; + } else if (this.isCreative()) { + int i1 = itemstack.getData(); + int j1 = itemstack.count; + boolean flag = itemstack.placeItem(entityhuman, world, i, j, k, l, f, f1, f2); - // CraftBukkit start - Interact + itemstack.setData(i1); + itemstack.count = j1; + return flag; + } else { + return itemstack.placeItem(entityhuman, world, i, j, k, l, f, f1, f2); + } + // Interract event */ + Block block = world.getType(i, j, k); boolean result = false; - if (i1 > 0) { + if (block != Blocks.AIR) { PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityhuman, Action.RIGHT_CLICK_BLOCK, i, j, k, l, itemstack); if (event.useInteractedBlock() == Event.Result.DENY) { // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. - if (i1 == Block.WOODEN_DOOR.id) { + if (block == Blocks.WOODEN_DOOR) { boolean bottom = (world.getData(i, j, k) & 8) == 0; - ((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, world)); + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j + (bottom ? 1 : -1), k, world)); } result = (event.useItemInHand() != Event.Result.ALLOW); } else if (!entityhuman.isSneaking() || itemstack == null) { - result = Block.byId[i1].interact(world, i, j, k, entityhuman, l, f, f1, f2); + result = block.interact(world, i, j, k, entityhuman, l, f, f1, f2); } if (itemstack != null && !result) { |