2011-01-10 02:36:19 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-02-01 18:06:17 +01:00
|
|
|
// CraftBukkit start
|
2012-03-27 17:37:00 +02:00
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2011-03-23 12:22:13 +01:00
|
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.event.block.Action;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2011-02-01 18:06:17 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
public class PlayerInteractManager {
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
public World world;
|
2012-07-29 09:33:13 +02:00
|
|
|
public EntityPlayer player;
|
|
|
|
private EnumGamemode gamemode;
|
|
|
|
private boolean d;
|
2011-06-27 00:25:01 +02:00
|
|
|
private int lastDigTick;
|
2011-03-31 22:40:00 +02:00
|
|
|
private int f;
|
2011-01-10 09:30:34 +01:00
|
|
|
private int g;
|
2011-09-15 02:23:52 +02:00
|
|
|
private int h;
|
2011-04-20 19:05:14 +02:00
|
|
|
private int currentTick;
|
2011-09-15 02:23:52 +02:00
|
|
|
private boolean j;
|
2011-03-31 22:40:00 +02:00
|
|
|
private int k;
|
2011-02-23 03:37:56 +01:00
|
|
|
private int l;
|
|
|
|
private int m;
|
2011-09-15 02:23:52 +02:00
|
|
|
private int n;
|
2012-07-29 09:33:13 +02:00
|
|
|
private int o;
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
public PlayerInteractManager(World world) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.gamemode = EnumGamemode.NONE;
|
|
|
|
this.o = -1;
|
2011-09-15 02:23:52 +02:00
|
|
|
this.world = world;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void setGameMode(EnumGamemode enumgamemode) {
|
|
|
|
this.gamemode = enumgamemode;
|
|
|
|
enumgamemode.a(this.player.abilities);
|
2012-03-22 21:39:39 +01:00
|
|
|
this.player.updateAbilities();
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public EnumGamemode getGameMode() {
|
|
|
|
return this.gamemode;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public boolean isCreative() {
|
2012-07-29 09:33:13 +02:00
|
|
|
return this.gamemode.d();
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void b(EnumGamemode enumgamemode) {
|
|
|
|
if (this.gamemode == EnumGamemode.NONE) {
|
|
|
|
this.gamemode = enumgamemode;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.setGameMode(this.gamemode);
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void a() {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
2012-07-29 09:33:13 +02:00
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
int j;
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (this.j) {
|
2012-07-29 09:33:13 +02:00
|
|
|
i = this.currentTick - this.n;
|
|
|
|
int k = this.world.getTypeId(this.k, this.l, this.m);
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (k == 0) {
|
|
|
|
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) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.f(this.player.id, this.k, this.l, this.m, j);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.o = j;
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
|
|
|
if (f >= 1.0F) {
|
2011-09-15 02:23:52 +02:00
|
|
|
this.j = false;
|
2012-01-14 21:03:48 +01:00
|
|
|
this.breakBlock(this.k, this.l, this.m);
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
} else if (this.d) {
|
|
|
|
i = this.world.getTypeId(this.f, this.g, this.h);
|
|
|
|
Block block1 = Block.byId[i];
|
|
|
|
|
|
|
|
if (block1 == null) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.f(this.player.id, this.f, this.g, this.h, -1);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.o = -1;
|
|
|
|
this.d = false;
|
2011-02-23 03:37:56 +01:00
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
int l = 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) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.f(this.player.id, this.f, this.g, this.h, j);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.o = j;
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public void dig(int i, int j, int k, int l) {
|
2011-06-27 00:25:01 +02:00
|
|
|
// this.world.douseFire((EntityHuman) null, i, j, k, l); // CraftBukkit - moved down
|
2012-01-14 21:03:48 +01:00
|
|
|
// CraftBukkit
|
2011-09-15 20:07:40 +02:00
|
|
|
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, i, j, k, l, this.player.inventory.getItemInHand());
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!this.gamemode.isAdventure() || this.player.e(i, j, k)) {
|
2012-01-14 21:03:48 +01:00
|
|
|
// CraftBukkit start
|
2011-09-15 20:07:40 +02:00
|
|
|
if (event.isCancelled()) {
|
2012-01-08 02:26:23 +01:00
|
|
|
// Let the client know the block still exists
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2012-11-16 20:46:52 +01:00
|
|
|
// Update any tile entity data for this block
|
|
|
|
TileEntity tileentity = this.world.getTileEntity(i, j, k);
|
|
|
|
if (tileentity != null) {
|
2012-12-20 05:03:52 +01:00
|
|
|
this.player.playerConnection.sendPacket(tileentity.getUpdatePacket());
|
2012-11-16 20:46:52 +01:00
|
|
|
}
|
2011-09-15 20:07:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-01-14 21:03:48 +01:00
|
|
|
// CraftBukkit end
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.isCreative()) {
|
|
|
|
if (!this.world.douseFire((EntityHuman) null, i, j, k, l)) {
|
|
|
|
this.breakBlock(i, j, k);
|
|
|
|
}
|
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.douseFire((EntityHuman) null, i, j, k, l);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.lastDigTick = this.currentTick;
|
|
|
|
float f = 1.0F;
|
|
|
|
int i1 = this.world.getTypeId(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) {
|
|
|
|
// For some reason *BOTH* the bottom/top part have to be marked updated.
|
|
|
|
boolean bottom = (this.world.getData(i, j, k) & 8) == 0;
|
2012-12-20 05:03:52 +01:00
|
|
|
((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));
|
2012-07-29 09:33:13 +02:00
|
|
|
} else if (i1 == Block.TRAP_DOOR.id) {
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2012-11-04 19:14:40 +01:00
|
|
|
} else if (i1 > 0) {
|
2012-07-29 09:33:13 +02:00
|
|
|
Block.byId[i1].attack(this.world, i, j, k, this.player);
|
|
|
|
// Allow fire punching to be blocked
|
|
|
|
this.world.douseFire((EntityHuman) null, i, j, k, l);
|
|
|
|
}
|
2011-03-23 12:22:13 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
// Handle hitting a block
|
2012-11-04 19:14:40 +01:00
|
|
|
if (i1 > 0) {
|
|
|
|
f = Block.byId[i1].getDamage(this.player, this.world, i, j, k);
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (event.useItemInHand() == Event.Result.DENY) {
|
|
|
|
// If we 'insta destroyed' then the client needs to be informed.
|
2012-11-04 19:14:40 +01:00
|
|
|
if (f > 1.0f) {
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
return;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2012-11-04 19:14:40 +01:00
|
|
|
org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, i, j, k, this.player.inventory.getItemInHand(), f >= 1.0f);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (blockEvent.isCancelled()) {
|
|
|
|
// Let the client know the block still exists
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2012-07-29 09:33:13 +02:00
|
|
|
return;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-03-23 16:38:42 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (blockEvent.getInstaBreak()) {
|
2012-11-04 19:14:40 +01:00
|
|
|
f = 2.0f;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2012-11-04 19:14:40 +01:00
|
|
|
// CraftBukkit end
|
2011-03-23 16:38:42 +01:00
|
|
|
|
2012-11-04 19:14:40 +01:00
|
|
|
if (i1 > 0 && f >= 1.0F) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.breakBlock(i, j, k);
|
|
|
|
} else {
|
|
|
|
this.d = true;
|
|
|
|
this.f = i;
|
|
|
|
this.g = j;
|
|
|
|
this.h = k;
|
|
|
|
int j1 = (int) (f * 10.0F);
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.f(this.player.id, i, j, k, j1);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.o = j1;
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public void a(int i, int j, int k) {
|
2011-09-15 02:23:52 +02:00
|
|
|
if (i == this.f && j == this.g && k == this.h) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
2011-06-27 00:25:01 +02:00
|
|
|
int l = this.currentTick - this.lastDigTick;
|
2011-04-20 19:05:14 +02:00
|
|
|
int i1 = this.world.getTypeId(i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
if (i1 != 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
Block block = Block.byId[i1];
|
2012-07-29 09:33:13 +02:00
|
|
|
float f = block.getDamage(this.player, this.player.world, i, j, k) * (float) (l + 1);
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
if (f >= 0.7F) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.d = false;
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.f(this.player.id, i, j, k, -1);
|
2012-01-14 21:03:48 +01:00
|
|
|
this.breakBlock(i, j, k);
|
2011-09-15 02:23:52 +02:00
|
|
|
} else if (!this.j) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.d = false;
|
2011-09-15 02:23:52 +02:00
|
|
|
this.j = true;
|
|
|
|
this.k = i;
|
|
|
|
this.l = j;
|
|
|
|
this.m = k;
|
|
|
|
this.n = this.lastDigTick;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Force block reset to client
|
2011-03-24 22:42:23 +01:00
|
|
|
} else {
|
2013-03-25 05:22:32 +01:00
|
|
|
this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2011-03-24 22:42:23 +01:00
|
|
|
// CraftBukkit end
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void c(int i, int j, int k) {
|
|
|
|
this.d = false;
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.f(this.player.id, this.f, this.g, this.h, -1);
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private boolean d(int i, int j, int k) {
|
2011-04-20 19:05:14 +02:00
|
|
|
Block block = Block.byId[this.world.getTypeId(i, j, k)];
|
|
|
|
int l = this.world.getData(i, j, k);
|
2012-07-29 09:33:13 +02:00
|
|
|
|
|
|
|
if (block != null) {
|
|
|
|
block.a(this.world, i, j, k, l, this.player);
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
boolean flag = this.world.setAir(i, j, k);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
|
|
|
if (block != null && flag) {
|
2011-04-20 19:05:14 +02:00
|
|
|
block.postBreak(this.world, i, j, k, l);
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-10 02:36:19 +01:00
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public boolean breakBlock(int i, int j, int k) {
|
2012-03-05 20:21:43 +01:00
|
|
|
// CraftBukkit start
|
2012-08-08 13:23:43 +02:00
|
|
|
BlockBreakEvent event = null;
|
|
|
|
|
2012-03-27 17:37:00 +02:00
|
|
|
if (this.player instanceof EntityPlayer) {
|
|
|
|
org.bukkit.block.Block block = this.world.getWorld().getBlockAt(i, j, k);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
packet.data = 0;
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) this.player).playerConnection.sendPacket(packet);
|
2012-03-27 17:37:00 +02:00
|
|
|
}
|
|
|
|
|
2012-08-08 13:23:43 +02:00
|
|
|
event = new BlockBreakEvent(block, this.player.getBukkitEntity());
|
|
|
|
|
|
|
|
// Adventure mode pre-cancel
|
2013-03-13 23:33:27 +01:00
|
|
|
event.setCancelled(this.gamemode.isAdventure() && !this.player.e(i, j, k));
|
2012-08-08 13:23:43 +02:00
|
|
|
|
|
|
|
// Calculate default block experience
|
|
|
|
Block nmsBlock = Block.byId[block.getTypeId()];
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.a(nmsBlock)) {
|
2012-08-08 13:23:43 +02:00
|
|
|
// Copied from Block.a(world, entityhuman, int, int, int, int)
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!(nmsBlock.r_() && EnchantmentManager.hasSilkTouchEnchantment(this.player))) {
|
2012-08-08 13:23:43 +02:00
|
|
|
int data = block.getData();
|
2012-10-25 05:53:23 +02:00
|
|
|
int bonusLevel = EnchantmentManager.getBonusBlockLootEnchantmentLevel(this.player);
|
2012-08-08 13:23:43 +02:00
|
|
|
|
|
|
|
event.setExpToDrop(nmsBlock.getExpDrop(this.world, data, bonusLevel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-27 17:37:00 +02:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
// Let the client know the block still exists
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) this.player).playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2012-11-15 03:03:58 +01:00
|
|
|
// Update any tile entity data for this block
|
|
|
|
TileEntity tileentity = this.world.getTileEntity(i, j, k);
|
|
|
|
if (tileentity != null) {
|
2012-12-20 05:03:52 +01:00
|
|
|
this.player.playerConnection.sendPacket(tileentity.getUpdatePacket());
|
2012-11-15 03:03:58 +01:00
|
|
|
}
|
2011-02-25 04:37:47 +01:00
|
|
|
return false;
|
2011-02-01 18:06:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (false) { // Never trigger
|
|
|
|
// CraftBukkit end
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
int l = this.world.getTypeId(i, j, k);
|
2013-03-25 05:22:32 +01:00
|
|
|
if (Block.byId[l] == null) return false; // CraftBukkit - A plugin set block to air without cancelling
|
2012-07-29 09:33:13 +02:00
|
|
|
int i1 = this.world.getData(i, j, k);
|
2012-11-15 02:52:40 +01:00
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Special case skulls, their item data comes from a tile entity
|
2012-11-15 02:52:40 +01:00
|
|
|
if (l == Block.SKULL.id && !this.isCreative()) {
|
|
|
|
Block.SKULL.dropNaturally(world, i, j, k, i1, 1.0F, 0);
|
|
|
|
return this.d(i, j, k);
|
2012-10-29 18:38:34 +01:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-03-27 17:37:00 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.world.a(this.player, 2001, i, j, k, l + (this.world.getData(i, j, k) << 12));
|
|
|
|
boolean flag = this.d(i, j, k);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.isCreative()) {
|
2012-12-20 05:03:52 +01:00
|
|
|
this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
2012-07-29 09:33:13 +02:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
ItemStack itemstack = this.player.cb();
|
|
|
|
boolean flag1 = this.player.a(Block.byId[l]);
|
2012-07-29 09:33:13 +02:00
|
|
|
|
|
|
|
if (itemstack != null) {
|
|
|
|
itemstack.a(this.world, l, i, j, k, this.player);
|
|
|
|
if (itemstack.count == 0) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.player.cc();
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (flag && flag1) {
|
|
|
|
Block.byId[l].a(this.world, this.player, i, j, k, i1);
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Drop event experience
|
2012-08-08 13:23:43 +02:00
|
|
|
if (flag && event != null) {
|
2013-03-13 23:33:27 +01:00
|
|
|
Block.byId[l].j(this.world, i, j, k, event.getExpToDrop());
|
2012-08-08 13:23:43 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
return flag;
|
|
|
|
}
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean useItem(EntityHuman entityhuman, World world, ItemStack itemstack) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i = itemstack.count;
|
2011-09-15 02:23:52 +02:00
|
|
|
int j = itemstack.getData();
|
2011-01-29 22:50:29 +01:00
|
|
|
ItemStack itemstack1 = itemstack.a(world, entityhuman);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack1 == itemstack && (itemstack1 == null || itemstack1.count == i && itemstack1.n() <= 0 && itemstack1.getData() == j)) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
entityhuman.inventory.items[entityhuman.inventory.itemInHandIndex] = itemstack1;
|
2012-01-14 21:03:48 +01:00
|
|
|
if (this.isCreative()) {
|
2011-09-15 02:23:52 +02:00
|
|
|
itemstack1.count = i;
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack1.g()) {
|
2012-10-25 05:53:23 +02:00
|
|
|
itemstack1.setData(j);
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (itemstack1.count == 0) {
|
2011-04-20 19:05:14 +02:00
|
|
|
entityhuman.inventory.items[entityhuman.inventory.itemInHandIndex] = null;
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!entityhuman.bV()) {
|
2012-10-25 05:53:23 +02:00
|
|
|
((EntityPlayer) entityhuman).updateInventory(entityhuman.defaultContainer);
|
|
|
|
}
|
|
|
|
|
2011-01-10 02:36:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public boolean interact(EntityHuman entityhuman, World world, ItemStack itemstack, int i, int j, int k, int l, float f, float f1, float f2) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i1 = world.getTypeId(i, j, k);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2011-03-23 12:22:13 +01:00
|
|
|
// CraftBukkit start - Interact
|
|
|
|
boolean result = false;
|
|
|
|
if (i1 > 0) {
|
|
|
|
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityhuman, Action.RIGHT_CLICK_BLOCK, i, j, k, l, itemstack);
|
2011-03-24 12:11:28 +01:00
|
|
|
if (event.useInteractedBlock() == Event.Result.DENY) {
|
2011-03-23 18:29:43 +01:00
|
|
|
// 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) {
|
|
|
|
boolean bottom = (world.getData(i, j, k) & 8) == 0;
|
2012-12-20 05:03:52 +01:00
|
|
|
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, world));
|
2011-03-23 18:29:43 +01:00
|
|
|
}
|
2011-06-08 23:52:10 +02:00
|
|
|
result = (event.useItemInHand() != Event.Result.ALLOW);
|
2012-12-20 05:03:52 +01:00
|
|
|
} else if (!entityhuman.isSneaking() || itemstack == null) {
|
2012-07-29 09:33:13 +02:00
|
|
|
result = Block.byId[i1].interact(world, i, j, k, entityhuman, l, f, f1, f2);
|
2011-06-08 23:52:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack != null && !result) {
|
2011-09-15 09:30:52 +02:00
|
|
|
int j1 = itemstack.getData();
|
|
|
|
int k1 = itemstack.count;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
result = itemstack.placeItem(entityhuman, world, i, j, k, l, f, f1, f2);
|
2011-09-15 09:30:52 +02:00
|
|
|
|
|
|
|
// The item count should not decrement in Creative mode.
|
2012-01-14 21:03:48 +01:00
|
|
|
if (this.isCreative()) {
|
2011-11-30 00:17:43 +01:00
|
|
|
itemstack.setData(j1);
|
2011-09-15 09:30:52 +02:00
|
|
|
itemstack.count = k1;
|
|
|
|
}
|
2011-03-23 12:22:13 +01:00
|
|
|
}
|
2011-03-25 07:35:47 +01:00
|
|
|
|
2011-03-24 12:11:28 +01:00
|
|
|
// If we have 'true' and no explicit deny *or* an explicit allow -- run the item part of the hook
|
|
|
|
if (itemstack != null && ((!result && event.useItemInHand() != Event.Result.DENY) || event.useItemInHand() == Event.Result.ALLOW)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.useItem(entityhuman, world, itemstack);
|
2011-03-23 12:22:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit end
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
|
|
|
public void a(WorldServer worldserver) {
|
|
|
|
this.world = worldserver;
|
|
|
|
}
|
2011-01-10 09:30:34 +01:00
|
|
|
}
|