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

183 lines
5.6 KiB
Java
Raw Normal View History

2011-01-08 14:33:54 +01:00
package net.minecraft.server;
import java.util.List;
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.entity.LivingEntity;
2011-01-08 14:33:54 +01:00
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockInteractEvent;
2011-01-12 18:40:42 +01:00
import org.bukkit.event.block.BlockRedstoneEvent;
// CraftBukkit end
2011-01-08 14:33:54 +01:00
public class BlockPressurePlate extends Block {
private EnumMobType a;
protected BlockPressurePlate(int i, int j, EnumMobType enummobtype) {
2011-01-29 22:50:29 +01:00
super(i, j, Material.STONE);
this.a = enummobtype;
this.a(true);
2011-01-08 14:33:54 +01:00
float f = 0.0625F;
2011-01-29 22:50:29 +01:00
this.a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f);
2011-01-08 14:33:54 +01:00
}
public int b() {
return 20;
}
public AxisAlignedBB d(World world, int i, int j, int k) {
return null;
}
public boolean a() {
return false;
}
public boolean a(World world, int i, int j, int k) {
return world.d(i, j - 1, k);
}
2011-01-14 14:31:10 +01:00
public void e(World world, int i, int j, int k) {}
2011-01-08 14:33:54 +01:00
2011-02-23 03:37:56 +01:00
public void a(World world, int i, int j, int k, int l) {
2011-01-08 14:33:54 +01:00
boolean flag = false;
if (!world.d(i, j - 1, k)) {
flag = true;
}
2011-01-29 22:50:29 +01:00
2011-01-08 14:33:54 +01:00
if (flag) {
2011-02-23 03:37:56 +01:00
this.b_(world, i, j, k, world.getData(i, j, k));
2011-01-14 14:31:10 +01:00
world.e(i, j, k, 0);
2011-01-08 14:33:54 +01:00
}
}
public void a(World world, int i, int j, int k, Random random) {
2011-01-29 22:50:29 +01:00
if (!world.isStatic) {
if (world.getData(i, j, k) != 0) {
this.g(world, i, j, k);
}
2011-01-08 14:33:54 +01:00
}
}
public void a(World world, int i, int j, int k, Entity entity) {
2011-01-29 22:50:29 +01:00
if (!world.isStatic) {
if (world.getData(i, j, k) != 1) {
this.g(world, i, j, k);
}
2011-01-08 14:33:54 +01:00
}
}
private void g(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
boolean flag = world.getData(i, j, k) == 1;
2011-01-08 14:33:54 +01:00
boolean flag1 = false;
float f = 0.125F;
List list = null;
2011-01-29 22:50:29 +01:00
if (this.a == EnumMobType.EVERYTHING) {
list = world.b((Entity) null, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f)));
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
if (this.a == EnumMobType.MOBS) {
list = world.a(EntityLiving.class, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f)));
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
if (this.a == EnumMobType.PLAYERS) {
list = world.a(EntityHuman.class, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f)));
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
2011-01-08 14:33:54 +01:00
if (list.size() > 0) {
flag1 = true;
}
2011-01-14 14:31:10 +01:00
// CraftBukkit start - Interact Pressure Plate
CraftServer server = ((WorldServer) world).getServer();
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
if (flag != flag1) {
if (flag1) {
for (Object object: list) {
if (object != null && object instanceof EntityLiving) {
EntityLiving entity = (EntityLiving) object;
Type eventType = Type.BLOCK_INTERACT;
org.bukkit.entity.LivingEntity who = (LivingEntity) entity.getBukkitEntity();
BlockInteractEvent event = new BlockInteractEvent(eventType, block, who);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
}
}
}
BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, flag ? 1 : 0, flag1 ? 1 : 0);
server.getPluginManager().callEvent(eventRedstone);
flag1 = eventRedstone.getNewCurrent() > 0;
}
2011-02-23 13:56:36 +01:00
// CraftBukkit end
2011-01-08 14:33:54 +01:00
if (flag1 && !flag) {
2011-01-14 14:31:10 +01:00
world.c(i, j, k, 1);
2011-01-29 22:50:29 +01:00
world.h(i, j, k, this.id);
world.h(i, j - 1, k, this.id);
2011-01-08 14:33:54 +01:00
world.b(i, j, k, i, j, k);
2011-01-29 22:50:29 +01:00
world.a((double) i + 0.5D, (double) j + 0.1D, (double) k + 0.5D, "random.click", 0.3F, 0.6F);
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
2011-01-08 14:33:54 +01:00
if (!flag1 && flag) {
2011-01-14 14:31:10 +01:00
world.c(i, j, k, 0);
2011-01-29 22:50:29 +01:00
world.h(i, j, k, this.id);
world.h(i, j - 1, k, this.id);
2011-01-08 14:33:54 +01:00
world.b(i, j, k, i, j, k);
2011-01-29 22:50:29 +01:00
world.a((double) i + 0.5D, (double) j + 0.1D, (double) k + 0.5D, "random.click", 0.3F, 0.5F);
2011-01-08 14:33:54 +01:00
}
2011-01-29 22:50:29 +01:00
2011-01-08 14:33:54 +01:00
if (flag1) {
2011-02-23 03:37:56 +01:00
world.c(i, j, k, this.id, this.b());
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
int l = world.getData(i, j, k);
2011-01-08 14:33:54 +01:00
if (l > 0) {
2011-01-29 22:50:29 +01:00
world.h(i, j, k, this.id);
world.h(i, j - 1, k, this.id);
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);
}
public void a(IBlockAccess iblockaccess, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
boolean flag = iblockaccess.getData(i, j, k) == 1;
2011-01-08 14:33:54 +01:00
float f = 0.0625F;
if (flag) {
2011-01-29 22:50:29 +01:00
this.a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f);
2011-01-08 14:33:54 +01:00
} else {
2011-01-29 22:50:29 +01:00
this.a(f, 0.0F, f, 1.0F - f, 0.0625F, 1.0F - f);
2011-01-08 14:33:54 +01:00
}
}
public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
return iblockaccess.getData(i, j, k) > 0;
2011-01-08 14:33:54 +01:00
}
2011-02-23 03:37:56 +01:00
public boolean c(World world, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
return world.getData(i, j, k) == 0 ? false : l == 1;
2011-01-08 14:33:54 +01:00
}
public boolean c() {
return true;
}
}