13
0
geforkt von Mirrors/Paper
Paper/src/main/java/net/minecraft/server/BlockChest.java

143 Zeilen
5.4 KiB
Java

2011-01-08 14:33:54 +01:00
package net.minecraft.server;
import java.util.Random;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.LivingEntity;
2011-01-08 14:33:54 +01:00
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockInteractEvent;
// CraftBukkit end
2011-01-08 14:33:54 +01:00
public class BlockChest extends BlockContainer {
2011-01-29 22:50:29 +01:00
private Random a = new Random();
2011-01-08 14:33:54 +01:00
protected BlockChest(int i) {
2011-01-29 22:50:29 +01:00
super(i, Material.WOOD);
this.textureId = 26;
2011-01-08 14:33:54 +01:00
}
public int a(int i) {
2011-01-29 22:50:29 +01:00
return i == 1 ? this.textureId - 1 : (i == 0 ? this.textureId - 1 : (i == 3 ? this.textureId + 1 : this.textureId));
2011-01-08 14:33:54 +01:00
}
public boolean a(World world, int i, int j, int k) {
int l = 0;
2011-01-29 22:50:29 +01:00
if (world.getTypeId(i - 1, j, k) == this.id) {
++l;
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
if (world.getTypeId(i + 1, j, k) == this.id) {
++l;
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
if (world.getTypeId(i, j, k - 1) == this.id) {
++l;
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
if (world.getTypeId(i, j, k + 1) == this.id) {
++l;
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
return l > 1 ? false : (this.g(world, i - 1, j, k) ? false : (this.g(world, i + 1, j, k) ? false : (this.g(world, i, j, k - 1) ? false : !this.g(world, i, j, k + 1))));
2011-01-08 14:33:54 +01:00
}
private boolean g(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
return world.getTypeId(i, j, k) != this.id ? false : (world.getTypeId(i - 1, j, k) == this.id ? true : (world.getTypeId(i + 1, j, k) == this.id ? true : (world.getTypeId(i, j, k - 1) == this.id ? true : world.getTypeId(i, j, k + 1) == this.id)));
2011-01-08 14:33:54 +01:00
}
public void b(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
TileEntityChest tileentitychest = (TileEntityChest) world.getTileEntity(i, j, k);
2011-01-08 14:33:54 +01:00
2011-01-29 22:50:29 +01:00
for (int l = 0; l < tileentitychest.h_(); ++l) {
ItemStack itemstack = tileentitychest.a(l);
2011-01-08 14:33:54 +01:00
2011-01-29 22:50:29 +01:00
if (itemstack != null) {
float f = this.a.nextFloat() * 0.8F + 0.1F;
float f1 = this.a.nextFloat() * 0.8F + 0.1F;
float f2 = this.a.nextFloat() * 0.8F + 0.1F;
2011-01-08 14:33:54 +01:00
2011-01-29 22:50:29 +01:00
while (itemstack.count > 0) {
int i1 = this.a.nextInt(21) + 10;
2011-01-08 14:33:54 +01:00
2011-01-29 22:50:29 +01:00
if (i1 > itemstack.count) {
i1 = itemstack.count;
}
itemstack.count -= i1;
EntityItem entityitem = new EntityItem(world, (double) ((float) i + f), (double) ((float) j + f1), (double) ((float) k + f2), new ItemStack(itemstack.id, i1, itemstack.h()));
float f3 = 0.05F;
entityitem.motX = (double) ((float) this.a.nextGaussian() * f3);
entityitem.motY = (double) ((float) this.a.nextGaussian() * f3 + 0.2F);
entityitem.motZ = (double) ((float) this.a.nextGaussian() * f3);
world.a((Entity) entityitem);
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
}
2011-01-08 14:33:54 +01:00
}
super.b(world, i, j, k);
}
2011-01-29 22:50:29 +01:00
public boolean a(World world, int i, int j, int k, EntityHuman entityhuman) {
Object object = (TileEntityChest) world.getTileEntity(i, j, k);
2011-01-08 14:33:54 +01:00
if (world.d(i, j + 1, k)) {
return true;
2011-01-29 22:50:29 +01:00
} else if (world.getTypeId(i - 1, j, k) == this.id && world.d(i - 1, j + 1, k)) {
2011-01-08 14:33:54 +01:00
return true;
2011-01-29 22:50:29 +01:00
} else if (world.getTypeId(i + 1, j, k) == this.id && world.d(i + 1, j + 1, k)) {
2011-01-08 14:33:54 +01:00
return true;
2011-01-29 22:50:29 +01:00
} else if (world.getTypeId(i, j, k - 1) == this.id && world.d(i, j + 1, k - 1)) {
2011-01-08 14:33:54 +01:00
return true;
2011-01-29 22:50:29 +01:00
} else if (world.getTypeId(i, j, k + 1) == this.id && world.d(i, j + 1, k + 1)) {
2011-01-08 14:33:54 +01:00
return true;
} else {
2011-01-29 22:50:29 +01:00
if (world.getTypeId(i - 1, j, k) == this.id) {
object = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(i - 1, j, k), (IInventory) object);
}
if (world.getTypeId(i + 1, j, k) == this.id) {
object = new InventoryLargeChest("Large chest", (IInventory) object, (TileEntityChest) world.getTileEntity(i + 1, j, k));
}
if (world.getTypeId(i, j, k - 1) == this.id) {
object = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(i, j, k - 1), (IInventory) object);
}
if (world.getTypeId(i, j, k + 1) == this.id) {
object = new InventoryLargeChest("Large chest", (IInventory) object, (TileEntityChest) world.getTileEntity(i, j, k + 1));
}
if (world.isStatic) {
return true;
} else {
// CraftBukkit start - Interact Chest
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer server = ((WorldServer) world).getServer();
Type eventType = Type.BLOCK_INTERACT;
CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
LivingEntity who = (entityhuman == null) ? null : (LivingEntity) entityhuman.getBukkitEntity();
BlockInteractEvent event = new BlockInteractEvent(eventType, block, who);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
// CraftBukkit end
entityhuman.a((IInventory) object);
return true;
}
2011-01-08 14:33:54 +01:00
}
}
protected TileEntity a_() {
2011-01-29 22:50:29 +01:00
return new TileEntityChest();
2011-01-08 14:33:54 +01:00
}
}