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

184 Zeilen
5.6 KiB
Java

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.block.BlockFace;import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
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;
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) {
super(i, j, Material.d);
a = enummobtype;
a(true);
float f = 0.0625F;
a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f);
}
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
public void b(World world, int i, int j, int k, int l) {
boolean flag = false;
if (!world.d(i, j - 1, k)) {
flag = true;
}
if (flag) {
a_(world, i, j, k, world.b(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) {
if (world.z) {
return;
}
if (world.b(i, j, k) == 0) {
return;
} else {
g(world, i, j, k);
return;
}
}
public void a(World world, int i, int j, int k, Entity entity) {
if (world.z) {
return;
}
if (world.b(i, j, k) == 1) {
return;
} else {
// CraftBukkit start - Interact Pressure Plate
2011-01-08 14:33:54 +01:00
if (entity instanceof EntityLiving) {
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
CraftLivingEntity craftEntity = null;
2011-01-08 14:33:54 +01:00
if (entity instanceof EntityPlayerMP) {
craftEntity = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entity);
} else {
craftEntity = new CraftLivingEntity(((WorldServer) world).getServer(), (EntityLiving) entity);
}
BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, craftEntity);
2011-01-08 14:33:54 +01:00
((WorldServer) world).getServer().getPluginManager().callEvent(bie);
2011-01-12 18:40:42 +01:00
if (bie.isCancelled()) {
return;
}
2011-01-08 14:33:54 +01:00
}
// CraftBukkit end
2011-01-08 14:33:54 +01:00
g(world, i, j, k);
return;
}
}
private void g(World world, int i, int j, int k) {
boolean flag = world.b(i, j, k) == 1;
boolean flag1 = false;
float f = 0.125F;
List list = null;
if (a == EnumMobType.a) {
list = world.b(((Entity) (null)), AxisAlignedBB.b((float) i + f, j, (float) k + f, (float) (i + 1) - f, (double) j + 0.25D, (float) (k + 1) - f));
2011-01-08 14:33:54 +01:00
}
if (a == EnumMobType.b) {
list = world.a(net.minecraft.server.EntityLiving.class, AxisAlignedBB.b((float) i + f, j, (float) k + f, (float) (i + 1) - f, (double) j + 0.25D, (float) (k + 1) - f));
}
if (a == EnumMobType.c) {
list = world.a(net.minecraft.server.EntityPlayer.class, AxisAlignedBB.b((float) i + f, j, (float) k + f, (float) (i + 1) - f, (double) j + 0.25D, (float) (k + 1) - f));
}
if (list.size() > 0) {
flag1 = true;
}
2011-01-14 14:31:10 +01:00
// Craftbukkit start
2011-01-12 18:40:42 +01:00
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.SELF, flag ? 15 : 0, flag1 ? 15 : 0);
2011-01-12 18:40:42 +01:00
((WorldServer) world).getServer().getPluginManager().callEvent(bre);
flag1 = bre.getNewCurrent() > 0;
2011-01-14 14:31:10 +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);
world.h(i, j, k, bi);
world.h(i, j - 1, k, bi);
2011-01-08 14:33:54 +01:00
world.b(i, j, k, i, j, k);
world.a((double) i + 0.5D, (double) j + 0.10000000000000001D, (double) k + 0.5D, "random.click", 0.3F, 0.6F);
}
if (!flag1 && flag) {
2011-01-14 14:31:10 +01:00
world.c(i, j, k, 0);
world.h(i, j, k, bi);
world.h(i, j - 1, k, bi);
2011-01-08 14:33:54 +01:00
world.b(i, j, k, i, j, k);
world.a((double) i + 0.5D, (double) j + 0.10000000000000001D, (double) k + 0.5D, "random.click", 0.3F, 0.5F);
}
if (flag1) {
2011-01-14 14:31:10 +01:00
world.i(i, j, k, bi);
2011-01-08 14:33:54 +01:00
}
}
public void b(World world, int i, int j, int k) {
int l = world.b(i, j, k);
if (l > 0) {
2011-01-14 14:31:10 +01:00
world.h(i, j, k, bi);
world.h(i, j - 1, k, bi);
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) {
boolean flag = iblockaccess.b(i, j, k) == 1;
float f = 0.0625F;
if (flag) {
a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f);
} else {
a(f, 0.0F, f, 1.0F - f, 0.0625F, 1.0F - f);
}
}
public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
return iblockaccess.b(i, j, k) > 0;
}
public boolean d(World world, int i, int j, int k, int l) {
if (world.b(i, j, k) == 0) {
return false;
} else {
return l == 1;
}
}
public boolean c() {
return true;
}
}