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

119 Zeilen
3.8 KiB
Java

2011-04-04 06:48:40 +02:00
package net.minecraft.server;
import java.util.Random;
// CraftBukkit start
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.craftbukkit.event.CraftEventFactory;
// CraftBukkit end
2011-04-04 06:48:40 +02:00
public class BlockSoil extends Block {
2013-11-04 14:07:38 +01:00
protected BlockSoil() {
super(Material.EARTH);
this.a(true);
2011-04-04 06:48:40 +02:00
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);
2013-11-04 14:07:38 +01:00
this.g(255);
2011-04-04 06:48:40 +02:00
}
2013-11-04 14:07:38 +01:00
public AxisAlignedBB a(World world, int i, int j, int k) {
2012-07-29 09:33:13 +02:00
return AxisAlignedBB.a().a((double) (i + 0), (double) (j + 0), (double) (k + 0), (double) (i + 1), (double) (j + 1), (double) (k + 1));
2011-04-04 06:48:40 +02:00
}
public boolean c() {
2011-04-04 06:48:40 +02:00
return false;
}
2013-11-04 14:07:38 +01:00
public boolean d() {
2011-05-26 14:48:22 +02:00
return false;
}
2013-03-13 23:33:27 +01:00
public void a(World world, int i, int j, int k, Random random) {
2013-09-19 20:25:08 +02:00
if (!this.m(world, i, j, k) && !world.isRainingAt(i, j + 1, k)) {
2011-11-20 09:01:14 +01:00
int l = world.getData(i, j, k);
if (l > 0) {
2013-03-13 23:33:27 +01:00
world.setData(i, j, k, l - 1, 2);
2013-11-04 14:07:38 +01:00
} else if (!this.e(world, i, j, k)) {
// CraftBukkit start
org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k);
2013-11-04 14:07:38 +01:00
if (CraftEventFactory.callBlockFadeEvent(block, Blocks.DIRT).isCancelled()) {
return;
}
// CraftBukkit end
2013-11-04 14:07:38 +01:00
world.setTypeUpdate(i, j, k, Blocks.DIRT);
2011-04-04 06:48:40 +02:00
}
2011-11-20 09:01:14 +01:00
} else {
2013-03-13 23:33:27 +01:00
world.setData(i, j, k, 7, 2);
2011-04-04 06:48:40 +02:00
}
}
2012-01-12 23:10:13 +01:00
public void a(World world, int i, int j, int k, Entity entity, float f) {
2012-07-29 09:33:13 +02:00
if (!world.isStatic && world.random.nextFloat() < f - 0.5F) {
2012-12-20 05:03:52 +01:00
if (!(entity instanceof EntityHuman) && !world.getGameRules().getBoolean("mobGriefing")) {
return;
}
2013-03-25 05:22:32 +01:00
// CraftBukkit start - Interact soil
org.bukkit.event.Cancellable cancellable;
if (entity instanceof EntityHuman) {
cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, i, j, k, -1, null);
} else {
cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(i, j, k));
world.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
2013-11-04 14:07:38 +01:00
world.setTypeUpdate(i, j, k, Blocks.DIRT);
2011-04-04 06:48:40 +02:00
}
}
2013-11-04 14:07:38 +01:00
private boolean e(World world, int i, int j, int k) {
2011-04-04 06:48:40 +02:00
byte b0 = 0;
for (int l = i - b0; l <= i + b0; ++l) {
for (int i1 = k - b0; i1 <= k + b0; ++i1) {
2013-11-04 14:07:38 +01:00
Block block = world.getType(l, j + 1, i1);
2011-09-15 02:23:52 +02:00
2013-11-04 14:07:38 +01:00
if (block == Blocks.CROPS || block == Blocks.MELON_STEM || block == Blocks.PUMPKIN_STEM || block == Blocks.POTATOES || block == Blocks.CARROTS) {
2011-04-04 06:48:40 +02:00
return true;
}
}
}
return false;
}
2013-03-13 23:33:27 +01:00
private boolean m(World world, int i, int j, int k) {
2011-04-04 06:48:40 +02:00
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) {
2013-11-04 14:07:38 +01:00
if (world.getType(l, i1, j1).getMaterial() == Material.WATER) {
2011-04-04 06:48:40 +02:00
return true;
}
}
}
}
return false;
}
2013-11-04 14:07:38 +01:00
public void doPhysics(World world, int i, int j, int k, Block block) {
super.doPhysics(world, i, j, k, block);
Material material = world.getType(i, j + 1, k).getMaterial();
2011-04-04 06:48:40 +02:00
if (material.isBuildable()) {
2013-11-04 14:07:38 +01:00
world.setTypeUpdate(i, j, k, Blocks.DIRT);
2011-04-04 06:48:40 +02:00
}
}
2013-11-04 14:07:38 +01:00
public Item getDropType(int i, Random random, int j) {
return Blocks.DIRT.getDropType(0, random, j);
2011-04-04 06:48:40 +02:00
}
}