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

102 Zeilen
3.3 KiB
Java

2011-01-03 10:41:43 +01:00
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
// CraftBukkit end
2011-01-03 10:41:43 +01:00
import java.util.Random;
public class BlockCactus extends Block {
protected BlockCactus(int i, int j) {
2011-01-29 22:50:29 +01:00
super(i, j, Material.CACTUS);
this.a(true);
2011-01-03 10:41:43 +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.isEmpty(i, j + 1, k)) {
2011-01-03 10:41:43 +01:00
int l;
2011-01-29 22:50:29 +01:00
for (l = 1; world.getTypeId(i, j - l, k) == this.id; ++l) {
2011-01-03 10:41:43 +01:00
;
}
2011-01-29 22:50:29 +01:00
2011-01-03 10:41:43 +01:00
if (l < 3) {
2011-01-29 22:50:29 +01:00
int i1 = world.getData(i, j, k);
2011-01-03 10:41:43 +01:00
if (i1 == 15) {
world.setTypeId(i, j + 1, k, this.id);
world.setData(i, j, k, 0);
2011-01-03 10:41:43 +01:00
} else {
world.setData(i, j, k, i1 + 1);
2011-01-03 10:41:43 +01:00
}
}
}
}
public AxisAlignedBB d(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
float f = 0.0625F;
2011-01-03 10:41:43 +01:00
2011-01-29 22:50:29 +01:00
return AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) ((float) (j + 1) - f), (double) ((float) (k + 1) - f));
2011-01-03 10:41:43 +01:00
}
public int a(int i) {
2011-01-29 22:50:29 +01:00
return i == 1 ? this.textureId - 1 : (i == 0 ? this.textureId + 1 : this.textureId);
2011-01-03 10:41:43 +01:00
}
public boolean a() {
return false;
}
public boolean canPlace(World world, int i, int j, int k) {
return !super.canPlace(world, i, j, k) ? false : this.f(world, i, j, k);
2011-01-03 10:41:43 +01:00
}
public void doPhysics(World world, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
if (!this.f(world, i, j, k)) {
2011-03-31 22:40:00 +02:00
this.a_(world, i, j, k, world.getData(i, j, k));
world.setTypeId(i, j, k, 0);
2011-01-03 10:41:43 +01:00
}
}
public boolean f(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
if (world.getMaterial(i - 1, j, k).isBuildable()) {
2011-01-03 10:41:43 +01:00
return false;
2011-01-29 22:50:29 +01:00
} else if (world.getMaterial(i + 1, j, k).isBuildable()) {
2011-01-03 10:41:43 +01:00
return false;
2011-01-29 22:50:29 +01:00
} else if (world.getMaterial(i, j, k - 1).isBuildable()) {
2011-01-03 10:41:43 +01:00
return false;
2011-01-29 22:50:29 +01:00
} else if (world.getMaterial(i, j, k + 1).isBuildable()) {
2011-01-03 10:41:43 +01:00
return false;
} else {
2011-01-29 22:50:29 +01:00
int l = world.getTypeId(i, j - 1, k);
2011-01-03 10:41:43 +01:00
2011-01-29 22:50:29 +01:00
return l == Block.CACTUS.id || l == Block.SAND.id;
2011-01-03 10:41:43 +01:00
}
}
public void a(World world, int i, int j, int k, Entity entity) {
// CraftBukkit start - ENTITY_DAMAGEBY_BLOCK event
2011-02-23 13:56:36 +01:00
if (entity instanceof EntityLiving) {
CraftServer server = ((WorldServer) world).getServer();
org.bukkit.block.Block damager = ((WorldServer) world).getWorld().getBlockAt(i, j, k);
2011-02-23 13:56:36 +01:00
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
DamageCause damageType = EntityDamageEvent.DamageCause.CONTACT;
int damageDone = 1;
2011-01-29 22:50:29 +01:00
EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, damageType, damageDone);
server.getPluginManager().callEvent(event);
2011-02-23 13:56:36 +01:00
if (!event.isCancelled()) {
entity.damageEntity((Entity) null, event.getDamage());
}
return;
2011-01-03 10:41:43 +01:00
}
2011-01-29 22:50:29 +01:00
// CraftBukkit end
entity.damageEntity((Entity) null, 1);
2011-01-03 10:41:43 +01:00
}
}