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

72 Zeilen
2.3 KiB
Java

2011-01-08 14:33:54 +01:00
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
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 BlockJukeBox extends Block {
protected BlockJukeBox(int i, int j) {
2011-01-29 22:50:29 +01:00
super(i, j, Material.WOOD);
2011-01-08 14:33:54 +01:00
}
public int a(int i) {
2011-01-29 22:50:29 +01:00
return this.textureId + (i == 1 ? 1 : 0);
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
public boolean a(World world, int i, int j, int k, EntityHuman entityhuman) {
int l = world.getData(i, j, k);
2011-01-08 14:33:54 +01:00
if (l > 0) {
// CraftBukkit start - Interact Jukebox
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer server = ((WorldServer) world).getServer();
Type eventType = Type.BLOCK_INTERACT;
CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
2011-01-29 22:50:29 +01:00
LivingEntity who = (entityhuman == null) ? null : (LivingEntity) entityhuman.getBukkitEntity();
2011-01-29 22:50:29 +01:00
BlockInteractEvent event = new BlockInteractEvent(eventType, block, who);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
this.f(world, i, j, k, l);
2011-01-08 14:33:54 +01:00
return true;
} else {
return false;
}
}
public void f(World world, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
world.a((String) null, i, j, k);
2011-01-14 14:31:10 +01:00
world.c(i, j, k, 0);
2011-01-29 22:50:29 +01:00
int i1 = Item.GOLD_RECORD.id + l - 1;
float f = 0.7F;
double d0 = (double) (world.l.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (world.l.nextFloat() * f) + (double) (1.0F - f) * 0.2D + 0.6D;
double d2 = (double) (world.l.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(world, (double) i + d0, (double) j + d1, (double) k + d2, new ItemStack(i1, 1, 0));
2011-01-08 14:33:54 +01:00
entityitem.c = 10;
2011-01-29 22:50:29 +01:00
world.a((Entity) entityitem);
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
public void a(World world, int i, int j, int k, int l, float f) {
if (!world.isStatic) {
if (l > 0) {
this.f(world, i, j, k, l);
}
super.a(world, i, j, k, l, f);
2011-01-08 14:33:54 +01:00
}
}
}