Paper/src/main/java/net/minecraft/server/ItemInWorldManager.java

144 lines
4.0 KiB
Java
Raw Normal View History

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.craftbukkit.CraftServer;
import org.bukkit.event.block.BlockBreakEvent;
// 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-01-10 09:30:34 +01:00
private float c;
2011-01-29 22:50:29 +01:00
public float d = 0.0F; // CraftBukkit private -> public
private int e = 0;
private float f = 0.0F;
2011-01-10 09:30:34 +01:00
private int g;
private int h;
private int i;
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-01-29 22:50:29 +01:00
public void a(int i, int j, int k) {
int l = this.b.getTypeId(i, j, k);
2011-01-10 02:36:19 +01:00
2011-01-29 22:50:29 +01:00
if (l > 0 && this.d == 0.0F) {
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
if (l > 0 && Block.byId[l].a(this.a) >= 1.0F) {
this.c(i, j, k);
2011-01-10 02:36:19 +01:00
}
}
public void a() {
2011-01-29 22:50:29 +01:00
this.d = 0.0F;
this.e = 0;
2011-01-10 02:36:19 +01:00
}
2011-01-29 22:50:29 +01:00
public void a(int i, int j, int k, int l) {
if (this.e > 0) {
--this.e;
2011-01-10 02:36:19 +01:00
} else {
2011-01-29 22:50:29 +01:00
if (i == this.g && j == this.h && k == this.i) {
int i1 = this.b.getTypeId(i, j, k);
if (i1 == 0) {
return;
}
Block block = Block.byId[i1];
this.d += block.a(this.a);
++this.f;
if (this.d >= 1.0F) {
this.c(i, j, k);
this.d = 0.0F;
this.c = 0.0F;
this.f = 0.0F;
this.e = 5;
}
} else {
this.d = 0.0F;
this.c = 0.0F;
this.f = 0.0F;
this.g = i;
this.h = j;
this.i = k;
}
2011-01-10 02:36:19 +01:00
}
}
2011-01-29 22:50:29 +01:00
public boolean b(int i, int j, int k) {
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-01-29 22:50:29 +01:00
block.a(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-01-29 22:50:29 +01:00
public boolean c(int i, int j, int k) {
2011-02-01 18:06:17 +01:00
//CraftBukkit start
if (this.a instanceof EntityPlayer){
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);
if (event.isCancelled()){
return true;
}
}
//CraftBukkit end
2011-01-29 22:50:29 +01:00
int l = this.b.getTypeId(i, j, k);
int i1 = this.b.getData(i, j, k);
boolean flag = this.b(i, j, k);
ItemStack itemstack = this.a.P();
2011-01-10 02:36:19 +01:00
if (itemstack != null) {
2011-01-29 22:50:29 +01:00
itemstack.a(l, i, j, k);
if (itemstack.count == 0) {
itemstack.a(this.a);
this.a.Q();
2011-01-10 02:36:19 +01:00
}
}
2011-01-29 22:50:29 +01:00
if (flag && this.a.b(Block.byId[l])) {
Block.byId[l].g(this.b, i, j, k, i1);
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-01-29 22:50:29 +01:00
return i1 > 0 && Block.byId[i1].a(world, i, j, k, entityhuman) ? true : (itemstack == null ? false : itemstack.a(entityhuman, world, i, j, k, l));
2011-01-10 02:36:19 +01:00
}
2011-01-10 09:30:34 +01:00
}