13
0
geforkt von Mirrors/Paper
Paper/src/main/java/net/minecraft/server/BlockSoil.java

117 Zeilen
3.5 KiB
Java

2011-04-04 06:48:40 +02:00
package net.minecraft.server;
import java.util.Random;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftServer;
2011-04-04 06:48:40 +02:00
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.Cancellable;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityInteractEvent;
// CraftBukkit end
2011-04-04 06:48:40 +02:00
public class BlockSoil extends Block {
protected BlockSoil(int i) {
super(i, Material.EARTH);
this.textureId = 87;
this.a(true);
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);
2011-04-20 22:47:26 +02:00
this.f(255);
2011-04-04 06:48:40 +02:00
}
public AxisAlignedBB d(World world, int i, int j, int k) {
return AxisAlignedBB.b((double) (i + 0), (double) (j + 0), (double) (k + 0), (double) (i + 1), (double) (j + 1), (double) (k + 1));
}
public boolean a() {
return false;
}
2011-05-26 14:48:22 +02:00
public boolean b() {
return false;
}
2011-04-04 06:48:40 +02:00
public int a(int i, int j) {
return i == 1 && j > 0 ? this.textureId - 1 : (i == 1 ? this.textureId : 2);
}
public void a(World world, int i, int j, int k, Random random) {
if (random.nextInt(5) == 0) {
2011-05-26 14:48:22 +02:00
if (!this.h(world, i, j, k) && !world.s(i, j + 1, k)) {
2011-04-04 06:48:40 +02:00
int l = world.getData(i, j, k);
if (l > 0) {
world.setData(i, j, k, l - 1);
2011-04-04 06:48:40 +02:00
} else if (!this.g(world, i, j, k)) {
world.setTypeId(i, j, k, Block.DIRT.id);
2011-04-04 06:48:40 +02:00
}
2011-04-20 22:47:26 +02:00
} else {
world.setData(i, j, k, 7);
2011-04-04 06:48:40 +02:00
}
}
}
public void b(World world, int i, int j, int k, Entity entity) {
if (world.random.nextInt(4) == 0) {
// CraftBukkit start - Interact Soil
Cancellable cancellable;
if (entity instanceof EntityHuman) {
cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, Action.PHYSICAL, i, j, k, -1, null);
} else {
cancellable = new EntityInteractEvent(entity.getBukkitEntity(), ((WorldServer) world).getWorld().getBlockAt(i, j, k));
2011-06-12 00:02:58 +02:00
((CraftServer) Bukkit.getServer()).getPluginManager().callEvent((EntityInteractEvent) cancellable);
}
2011-05-14 16:29:42 +02:00
if (cancellable.isCancelled()) {
return;
2011-04-04 06:48:40 +02:00
}
2011-05-14 16:29:42 +02:00
// CraftBukkit end
world.setTypeId(i, j, k, Block.DIRT.id);
2011-04-04 06:48:40 +02:00
}
}
private boolean g(World world, int i, int j, int k) {
byte b0 = 0;
for (int l = i - b0; l <= i + b0; ++l) {
for (int i1 = k - b0; i1 <= k + b0; ++i1) {
if (world.getTypeId(l, j + 1, i1) == Block.CROPS.id) {
return true;
}
}
}
return false;
}
private boolean h(World world, int i, int j, int k) {
for (int l = i - 4; l <= i + 4; ++l) {
for (int i1 = j; i1 <= j + 1; ++i1) {
for (int j1 = k - 4; j1 <= k + 4; ++j1) {
if (world.getMaterial(l, i1, j1) == Material.WATER) {
return true;
}
}
}
}
return false;
}
public void doPhysics(World world, int i, int j, int k, int l) {
super.doPhysics(world, i, j, k, l);
2011-04-04 06:48:40 +02:00
Material material = world.getMaterial(i, j + 1, k);
if (material.isBuildable()) {
world.setTypeId(i, j, k, Block.DIRT.id);
2011-04-04 06:48:40 +02:00
}
}
public int a(int i, Random random) {
return Block.DIRT.a(0, random);
}
}