PaperMC/src/main/java/net/minecraft/server/BlockChest.java

171 lines
5.2 KiB
Java
Raw Normal View History

2011-01-08 14:33:54 +01:00
package net.minecraft.server;
import java.util.Random;
// CraftBukkit start
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.entity.CraftPlayer;
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 {
private Random a;
protected BlockChest(int i) {
super(i, Material.c);
a = new Random();
2011-01-14 14:31:10 +01:00
bh = 26;
2011-01-08 14:33:54 +01:00
}
public int a(int i) {
if (i == 1) {
2011-01-14 14:31:10 +01:00
return bh - 1;
2011-01-08 14:33:54 +01:00
}
if (i == 0) {
2011-01-14 14:31:10 +01:00
return bh - 1;
2011-01-08 14:33:54 +01:00
}
if (i == 3) {
2011-01-14 14:31:10 +01:00
return bh + 1;
2011-01-08 14:33:54 +01:00
} else {
2011-01-14 14:31:10 +01:00
return bh;
2011-01-08 14:33:54 +01:00
}
}
public boolean a(World world, int i, int j, int k) {
int l = 0;
2011-01-14 14:31:10 +01:00
if (world.a(i - 1, j, k) == bi) {
2011-01-08 14:33:54 +01:00
l++;
}
2011-01-14 14:31:10 +01:00
if (world.a(i + 1, j, k) == bi) {
2011-01-08 14:33:54 +01:00
l++;
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k - 1) == bi) {
2011-01-08 14:33:54 +01:00
l++;
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k + 1) == bi) {
2011-01-08 14:33:54 +01:00
l++;
}
if (l > 1) {
return false;
}
if (g(world, i - 1, j, k)) {
return false;
}
if (g(world, i + 1, j, k)) {
return false;
}
if (g(world, i, j, k - 1)) {
return false;
}
return !g(world, i, j, k + 1);
}
private boolean g(World world, int i, int j, int k) {
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k) != bi) {
2011-01-08 14:33:54 +01:00
return false;
}
2011-01-14 14:31:10 +01:00
if (world.a(i - 1, j, k) == bi) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i + 1, j, k) == bi) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k - 1) == bi) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
return world.a(i, j, k + 1) == bi;
2011-01-08 14:33:54 +01:00
}
public void b(World world, int i, int j, int k) {
2011-01-14 14:31:10 +01:00
TileEntityChest tileentitychest = (TileEntityChest) world.m(i, j, k);
2011-01-08 14:33:54 +01:00
label0:
2011-01-14 14:31:10 +01:00
for (int l = 0; l < ((IInventory) (tileentitychest)).h_(); l++) {
ItemStack itemstack = ((IInventory) (tileentitychest)).a(l);
2011-01-08 14:33:54 +01:00
if (itemstack == null) {
continue;
}
float f = a.nextFloat() * 0.8F + 0.1F;
float f1 = a.nextFloat() * 0.8F + 0.1F;
float f2 = a.nextFloat() * 0.8F + 0.1F;
do {
if (itemstack.a <= 0) {
continue label0;
}
int i1 = a.nextInt(21) + 10;
if (i1 > itemstack.a) {
i1 = itemstack.a;
}
itemstack.a -= i1;
2011-01-14 14:31:10 +01:00
EntityItem entityitem = new EntityItem(world, (float) i + f, (float) j + f1, (float) k + f2, new ItemStack(itemstack.c, i1, itemstack.h()));
2011-01-08 14:33:54 +01:00
float f3 = 0.05F;
entityitem.s = (float) a.nextGaussian() * f3;
entityitem.t = (float) a.nextGaussian() * f3 + 0.2F;
entityitem.u = (float) a.nextGaussian() * f3;
world.a(((Entity) (entityitem)));
2011-01-08 14:33:54 +01:00
} while (true);
}
super.b(world, i, j, k);
}
public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) {
2011-01-14 14:31:10 +01:00
Object obj = (((TileEntityChest) world.m(i, j, k)));
2011-01-08 14:33:54 +01:00
if (world.d(i, j + 1, k)) {
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i - 1, j, k) == bi && world.d(i - 1, j + 1, k)) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i + 1, j, k) == bi && world.d(i + 1, j + 1, k)) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k - 1) == bi && world.d(i, j + 1, k - 1)) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k + 1) == bi && world.d(i, j + 1, k + 1)) {
2011-01-08 14:33:54 +01:00
return true;
}
2011-01-14 14:31:10 +01:00
if (world.a(i - 1, j, k) == bi) {
obj = ((new InventoryLargeChest("Large chest", ((IInventory) ((TileEntityChest) world.m(i - 1, j, k))), ((IInventory) (obj)))));
2011-01-08 14:33:54 +01:00
}
2011-01-14 14:31:10 +01:00
if (world.a(i + 1, j, k) == bi) {
obj = ((new InventoryLargeChest("Large chest", ((IInventory) (obj)), ((IInventory) ((TileEntityChest) world.m(i + 1, j, k))))));
2011-01-08 14:33:54 +01:00
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k - 1) == bi) {
obj = ((new InventoryLargeChest("Large chest", ((IInventory) ((TileEntityChest) world.m(i, j, k - 1))), ((IInventory) (obj)))));
2011-01-08 14:33:54 +01:00
}
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k + 1) == bi) {
obj = ((new InventoryLargeChest("Large chest", ((IInventory) (obj)), ((IInventory) ((TileEntityChest) world.m(i, j, k + 1))))));
2011-01-08 14:33:54 +01:00
}
if (world.z) {
return true;
} else {
// CraftBukkit start - Interact Chest
2011-01-08 14:33:54 +01:00
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer);
BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player);
2011-01-08 14:33:54 +01:00
((WorldServer) world).getServer().getPluginManager().callEvent(bie);
if (bie.isCancelled()) return true;
// CraftBukkit end
entityplayer.a(((IInventory) (obj)));
2011-01-08 14:33:54 +01:00
return true;
}
}
protected TileEntity a_() {
return ((TileEntity) (new TileEntityChest()));
2011-01-08 14:33:54 +01:00
}
}