2011-01-10 02:36:19 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-02-01 18:06:17 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2011-03-23 16:38:42 +01:00
|
|
|
import org.bukkit.event.block.BlockDamageEvent;
|
2011-03-23 12:22:13 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
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
|
|
|
|
|
2011-01-10 02:36:19 +01:00
|
|
|
public class ItemInWorldManager {
|
|
|
|
|
2011-01-10 09:30:34 +01:00
|
|
|
private World b;
|
2011-01-29 22:50:29 +01:00
|
|
|
public EntityHuman a;
|
2011-03-23 16:39:25 +01:00
|
|
|
private float c = 0.0F;
|
2011-02-23 03:37:56 +01:00
|
|
|
private int d;
|
2011-03-31 22:40:00 +02:00
|
|
|
private int e;
|
|
|
|
private int f;
|
2011-01-10 09:30:34 +01:00
|
|
|
private int g;
|
|
|
|
private int h;
|
2011-03-31 22:40:00 +02:00
|
|
|
private boolean i;
|
2011-02-23 03:37:56 +01:00
|
|
|
private int 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-01-10 02:36:19 +01:00
|
|
|
|
|
|
|
public ItemInWorldManager(World world) {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.b = world;
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public void a() {
|
2011-04-03 11:06:12 +02:00
|
|
|
this.h = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
2011-03-31 22:40:00 +02:00
|
|
|
if (this.i) {
|
|
|
|
int i = this.h - this.m;
|
|
|
|
int j = this.b.getTypeId(this.j, this.k, this.l);
|
2011-02-23 03:37:56 +01:00
|
|
|
|
|
|
|
if (j != 0) {
|
|
|
|
Block block = Block.byId[j];
|
|
|
|
float f = block.a(this.a) * (float) (i + 1);
|
|
|
|
|
|
|
|
if (f >= 1.0F) {
|
2011-03-31 22:40:00 +02:00
|
|
|
this.i = false;
|
|
|
|
this.d(this.j, this.k, this.l);
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-31 22:40:00 +02:00
|
|
|
this.i = false;
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-26 09:56:16 +01:00
|
|
|
// CraftBukkit added face
|
|
|
|
public void a(int i, int j, int k, int face) {
|
2011-04-03 11:06:12 +02:00
|
|
|
this.d = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
2011-01-29 22:50:29 +01:00
|
|
|
int l = this.b.getTypeId(i, j, k);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2011-03-23 12:22:13 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
// Swings at air do *NOT* exist.
|
|
|
|
if (l <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-26 09:56:16 +01:00
|
|
|
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.a, Action.LEFT_CLICK_BLOCK , i, j, k, face, this.a.inventory.b());
|
2011-03-23 12:22:13 +01:00
|
|
|
|
2011-03-23 18:29:43 +01:00
|
|
|
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 (l == Block.WOODEN_DOOR.id) {
|
|
|
|
// For some reason *BOTH* the bottom/top part have to be marked updated.
|
|
|
|
boolean bottom = (this.b.getData(i, j, k) & 8) == 0;
|
2011-03-27 21:57:46 +02:00
|
|
|
((EntityPlayer) this.a).a.b((Packet) (new Packet53BlockChange(i, j, k, this.b)));
|
2011-03-23 18:29:43 +01:00
|
|
|
((EntityPlayer) this.a).a.b((Packet) (new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, this.b)));
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
Block.byId[l].b(this.b, i, j, k, this.a);
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-03-23 16:38:42 +01:00
|
|
|
// Handle hitting a block
|
|
|
|
float toolDamage = Block.byId[l].a(this.a);
|
2011-03-24 22:42:23 +01:00
|
|
|
if (event.useItemInHand() == Event.Result.DENY) {
|
|
|
|
// If we 'insta destroyed' then the client needs to be informed.
|
|
|
|
if (toolDamage > 1.0f) {
|
|
|
|
((EntityPlayer) this.a).a.b((Packet) (new Packet53BlockChange(i, j, k, this.b)));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2011-03-23 16:38:42 +01:00
|
|
|
BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.a, i, j, k, this.a.inventory.b(), toolDamage >= 1.0f);
|
|
|
|
|
|
|
|
if (blockEvent.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blockEvent.getInstaBreak()) {
|
|
|
|
toolDamage = 2.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toolDamage >= 1.0F) {
|
|
|
|
// CraftBukkit end
|
2011-02-23 03:37:56 +01:00
|
|
|
this.d(i, j, k);
|
|
|
|
} else {
|
2011-03-31 22:40:00 +02:00
|
|
|
this.e = i;
|
|
|
|
this.f = j;
|
|
|
|
this.g = k;
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public void b(int i, int j, int k) {
|
2011-03-31 22:40:00 +02:00
|
|
|
if (i == this.e && j == this.f && k == this.g) {
|
2011-04-03 11:06:12 +02:00
|
|
|
this.h = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
2011-03-31 22:40:00 +02:00
|
|
|
int l = this.h - this.d;
|
2011-02-23 03:37:56 +01:00
|
|
|
int i1 = this.b.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];
|
2011-02-23 03:37:56 +01:00
|
|
|
float f = block.a(this.a) * (float) (l + 1);
|
|
|
|
|
|
|
|
if (f >= 1.0F) {
|
|
|
|
this.d(i, j, k);
|
2011-03-31 22:40:00 +02:00
|
|
|
} else if (!this.i) {
|
|
|
|
this.i = true;
|
|
|
|
this.j = i;
|
|
|
|
this.k = j;
|
|
|
|
this.l = k;
|
|
|
|
this.m = this.d;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-24 22:42:23 +01:00
|
|
|
// CraftBukkit start -- force blockreset to client
|
|
|
|
} else {
|
|
|
|
((EntityPlayer) this.a).a.b((Packet) (new Packet53BlockChange(i, j, k, this.b)));
|
|
|
|
// CraftBukkit end
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
|
|
|
this.c = 0.0F;
|
|
|
|
this.e = 0;
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public boolean c(int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
Block block = Block.byId[this.b.getTypeId(i, j, k)];
|
|
|
|
int l = this.b.getData(i, j, k);
|
|
|
|
boolean flag = this.b.e(i, j, k, 0);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
|
|
|
if (block != null && flag) {
|
2011-02-23 03:37:56 +01:00
|
|
|
block.b(this.b, 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;
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public boolean d(int i, int j, int k) {
|
|
|
|
// CraftBukkit start
|
2011-02-23 13:56:36 +01:00
|
|
|
if (this.a instanceof EntityPlayer) {
|
2011-02-01 18:06:17 +01:00
|
|
|
CraftServer server = ((WorldServer) this.b).getServer();
|
|
|
|
org.bukkit.block.Block block = ((WorldServer) this.b).getWorld().getBlockAt(i, j, k);
|
|
|
|
org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.a.getBukkitEntity();
|
|
|
|
|
|
|
|
BlockBreakEvent event = new BlockBreakEvent(block,player);
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
if (event.isCancelled()) {
|
2011-02-25 04:37:47 +01:00
|
|
|
return false;
|
2011-02-01 18:06:17 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
// CraftBukkit end
|
2011-02-01 18:06:17 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
int l = this.b.getTypeId(i, j, k);
|
|
|
|
int i1 = this.b.getData(i, j, k);
|
2011-02-23 03:37:56 +01:00
|
|
|
boolean flag = this.c(i, j, k);
|
2011-03-31 22:40:00 +02:00
|
|
|
ItemStack itemstack = this.a.A();
|
2011-01-10 02:36:19 +01:00
|
|
|
|
|
|
|
if (itemstack != null) {
|
2011-03-31 22:40:00 +02:00
|
|
|
itemstack.a(l, i, j, k, this.a);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (itemstack.count == 0) {
|
|
|
|
itemstack.a(this.a);
|
2011-03-31 22:40:00 +02:00
|
|
|
this.a.B();
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (flag && this.a.b(Block.byId[l])) {
|
2011-03-31 22:40:00 +02:00
|
|
|
Block.byId[l].a(this.b, this.a, i, j, k, i1);
|
2011-02-23 03:37:56 +01:00
|
|
|
((EntityPlayer) this.a).a.b((Packet) (new Packet53BlockChange(i, j, k, this.b)));
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public boolean a(EntityHuman entityhuman, World world, ItemStack itemstack) {
|
|
|
|
int i = itemstack.count;
|
|
|
|
ItemStack itemstack1 = itemstack.a(world, entityhuman);
|
2011-01-10 02:36:19 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (itemstack1 == itemstack && (itemstack1 == null || itemstack1.count == i)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
entityhuman.inventory.a[entityhuman.inventory.c] = itemstack1;
|
|
|
|
if (itemstack1.count == 0) {
|
|
|
|
entityhuman.inventory.a[entityhuman.inventory.c] = null;
|
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 true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public boolean a(EntityHuman entityhuman, World world, ItemStack itemstack, int i, int j, int k, int l) {
|
|
|
|
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;
|
2011-03-24 12:11:28 +01:00
|
|
|
((EntityPlayer) entityhuman).a.b((Packet) (new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, world)));
|
2011-03-23 18:29:43 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-23 12:22:13 +01:00
|
|
|
result = Block.byId[i1].a(world, i, j, k, entityhuman);
|
2011-03-25 07:35:47 +01:00
|
|
|
if (itemstack != null && !result) {
|
|
|
|
result = itemstack.a(entityhuman, world, i, j, k, l);
|
|
|
|
}
|
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-03-25 07:35:47 +01:00
|
|
|
this.a(entityhuman, world, itemstack);
|
2011-03-23 12:22:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2011-01-10 02:36:19 +01:00
|
|
|
}
|
2011-03-23 12:22:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-10 09:30:34 +01:00
|
|
|
}
|