2011-02-01 22:55:30 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
|
|
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.event.block.BlockInteractEvent;
|
|
|
|
|
|
|
|
public class BlockDispenser extends BlockContainer {
|
|
|
|
|
|
|
|
protected BlockDispenser(int i) {
|
2011-02-01 23:01:37 +01:00
|
|
|
super(i, Material.STONE);
|
|
|
|
this.textureId = 45;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int b() {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a(int i, Random random) {
|
2011-02-01 23:01:37 +01:00
|
|
|
return Block.DISPENSER.id;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void e(World world, int i, int j, int k) {
|
|
|
|
super.e(world, i, j, k);
|
2011-02-01 23:01:37 +01:00
|
|
|
this.g(world, i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void g(World world, int i, int j, int k) {
|
2011-02-01 23:01:37 +01:00
|
|
|
int l = world.getTypeId(i, j, k - 1);
|
|
|
|
int i1 = world.getTypeId(i, j, k + 1);
|
|
|
|
int j1 = world.getTypeId(i - 1, j, k);
|
|
|
|
int k1 = world.getTypeId(i + 1, j, k);
|
|
|
|
byte b0 = 3;
|
2011-02-01 22:55:30 +01:00
|
|
|
|
|
|
|
if (Block.o[l] && !Block.o[i1]) {
|
2011-02-01 23:01:37 +01:00
|
|
|
b0 = 3;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
if (Block.o[i1] && !Block.o[l]) {
|
2011-02-01 23:01:37 +01:00
|
|
|
b0 = 2;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
if (Block.o[j1] && !Block.o[k1]) {
|
2011-02-01 23:01:37 +01:00
|
|
|
b0 = 5;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
if (Block.o[k1] && !Block.o[j1]) {
|
2011-02-01 23:01:37 +01:00
|
|
|
b0 = 4;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
|
|
|
world.c(i, j, k, b0);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int a(int i) {
|
2011-02-01 23:01:37 +01:00
|
|
|
return i == 1 ? this.textureId + 17 : (i == 0 ? this.textureId + 17 : (i == 3 ? this.textureId + 1 : this.textureId));
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:01:37 +01:00
|
|
|
public boolean a(World world, int i, int j, int k, EntityHuman entityhuman) {
|
|
|
|
if (world.isStatic) {
|
2011-02-01 22:55:30 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// CraftBukkit start - Interact Dispenser
|
|
|
|
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
|
|
|
CraftServer server = ((WorldServer) world).getServer();
|
|
|
|
Type eventType = Type.BLOCK_INTERACT;
|
|
|
|
CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
|
2011-02-23 13:56:36 +01:00
|
|
|
LivingEntity who = (entityhuman == null) ? null : (LivingEntity) entityhuman.getBukkitEntity();
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-02 00:32:18 +01:00
|
|
|
BlockInteractEvent event = new BlockInteractEvent(eventType, block, who);
|
|
|
|
server.getPluginManager().callEvent(event);
|
2011-02-01 22:55:30 +01:00
|
|
|
|
2011-02-02 00:32:18 +01:00
|
|
|
if (event.isCancelled()) {
|
2011-02-01 22:55:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-02-01 23:01:37 +01:00
|
|
|
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
|
2011-02-01 23:01:37 +01:00
|
|
|
entityhuman.a(tileentitydispenser);
|
2011-02-01 22:55:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit - private->public
|
2011-02-02 00:16:25 +01:00
|
|
|
public void b(World world, int i, int j, int k, Random random) {
|
2011-02-01 23:01:37 +01:00
|
|
|
int l = world.getData(i, j, k);
|
2011-02-01 22:55:30 +01:00
|
|
|
float f = 0.0F;
|
|
|
|
float f1 = 0.0F;
|
|
|
|
|
|
|
|
if (l == 3) {
|
|
|
|
f1 = 1.0F;
|
|
|
|
} else if (l == 2) {
|
2011-02-01 23:01:37 +01:00
|
|
|
f1 = -1.0F;
|
2011-02-01 22:55:30 +01:00
|
|
|
} else if (l == 5) {
|
|
|
|
f = 1.0F;
|
|
|
|
} else {
|
2011-02-01 23:01:37 +01:00
|
|
|
f = -1.0F;
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
|
|
|
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);
|
2011-02-23 03:37:56 +01:00
|
|
|
ItemStack itemstack = tileentitydispenser.b();
|
2011-02-01 23:01:37 +01:00
|
|
|
double d0 = (double) i + (double) f * 0.5D + 0.5D;
|
2011-02-01 22:55:30 +01:00
|
|
|
double d1 = (double) j + 0.5D;
|
|
|
|
double d2 = (double) k + (double) f1 * 0.5D + 0.5D;
|
|
|
|
|
|
|
|
if (itemstack == null) {
|
2011-02-01 23:01:37 +01:00
|
|
|
world.a((double) i, (double) j, (double) k, "random.click", 1.0F, 1.2F);
|
2011-02-01 22:55:30 +01:00
|
|
|
} else {
|
2011-02-01 23:01:37 +01:00
|
|
|
double d3;
|
|
|
|
|
|
|
|
if (itemstack.id == Item.ARROW.id) {
|
|
|
|
EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2);
|
|
|
|
|
|
|
|
entityarrow.a((double) f, 0.10000000149011612D, (double) f1, 1.1F, 6.0F);
|
|
|
|
world.a((Entity) entityarrow);
|
|
|
|
world.a((double) i, (double) j, (double) k, "random.bow", 1.0F, 1.2F);
|
|
|
|
} else if (itemstack.id == Item.EGG.id) {
|
|
|
|
EntityEgg entityegg = new EntityEgg(world, d0, d1, d2);
|
|
|
|
|
|
|
|
entityegg.a((double) f, 0.10000000149011612D, (double) f1, 1.1F, 6.0F);
|
|
|
|
world.a((Entity) entityegg);
|
|
|
|
world.a((double) i, (double) j, (double) k, "random.bow", 1.0F, 1.2F);
|
|
|
|
} else if (itemstack.id == Item.SNOW_BALL.id) {
|
|
|
|
EntitySnowball entitysnowball = new EntitySnowball(world, d0, d1, d2);
|
|
|
|
|
|
|
|
entitysnowball.a((double) f, 0.10000000149011612D, (double) f1, 1.1F, 6.0F);
|
|
|
|
world.a((Entity) entitysnowball);
|
|
|
|
world.a((double) i, (double) j, (double) k, "random.bow", 1.0F, 1.2F);
|
2011-02-01 22:55:30 +01:00
|
|
|
} else {
|
2011-02-01 23:01:37 +01:00
|
|
|
EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack);
|
|
|
|
|
|
|
|
d3 = random.nextDouble() * 0.1D + 0.2D;
|
|
|
|
entityitem.motX = (double) f * d3;
|
|
|
|
entityitem.motY = 0.20000000298023224D;
|
|
|
|
entityitem.motZ = (double) f1 * d3;
|
|
|
|
entityitem.motX += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
|
|
|
entityitem.motY += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
|
|
|
entityitem.motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
|
|
|
world.a((Entity) entityitem);
|
|
|
|
world.a((double) i, (double) j, (double) k, "random.click", 1.0F, 1.0F);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
|
|
|
for (int i1 = 0; i1 < 10; ++i1) {
|
|
|
|
d3 = random.nextDouble() * 0.2D + 0.01D;
|
|
|
|
double d4 = d0 + (double) f * 0.01D + (random.nextDouble() - 0.5D) * (double) f1 * 0.5D;
|
|
|
|
double d5 = d1 + (random.nextDouble() - 0.5D) * 0.5D;
|
|
|
|
double d6 = d2 + (double) f1 * 0.01D + (random.nextDouble() - 0.5D) * (double) f * 0.5D;
|
|
|
|
double d7 = (double) f * d3 + random.nextGaussian() * 0.01D;
|
|
|
|
double d8 = -0.03D + random.nextGaussian() * 0.01D;
|
|
|
|
double d9 = (double) f1 * d3 + random.nextGaussian() * 0.01D;
|
|
|
|
|
|
|
|
world.a("smoke", d4, d5, d6, d7, d8, d9);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public void a(World world, int i, int j, int k, int l) {
|
2011-02-01 23:01:37 +01:00
|
|
|
if (l > 0 && Block.byId[l].c()) {
|
2011-02-01 22:55:30 +01:00
|
|
|
boolean flag = world.p(i, j, k) || world.p(i, j + 1, k);
|
|
|
|
|
|
|
|
if (flag) {
|
2011-02-23 03:37:56 +01:00
|
|
|
world.c(i, j, k, this.id, this.b());
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
|
|
|
if (world.p(i, j, k) || world.p(i, j + 1, k)) {
|
2011-02-01 23:01:37 +01:00
|
|
|
this.b(world, i, j, k, random);
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected TileEntity a_() {
|
2011-02-01 23:01:37 +01:00
|
|
|
return new TileEntityDispenser();
|
2011-02-01 22:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(World world, int i, int j, int k, EntityLiving entityliving) {
|
2011-02-01 23:01:37 +01:00
|
|
|
int l = MathHelper.b((double) (entityliving.yaw * 4.0F / 360.0F) + 0.5D) & 3;
|
2011-02-01 22:55:30 +01:00
|
|
|
|
|
|
|
if (l == 0) {
|
|
|
|
world.c(i, j, k, 2);
|
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
if (l == 1) {
|
|
|
|
world.c(i, j, k, 5);
|
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
if (l == 2) {
|
|
|
|
world.c(i, j, k, 3);
|
|
|
|
}
|
2011-02-01 23:01:37 +01:00
|
|
|
|
2011-02-01 22:55:30 +01:00
|
|
|
if (l == 3) {
|
|
|
|
world.c(i, j, k, 4);
|
|
|
|
}
|
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
}
|