2011-01-01 08:05:05 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit start
|
2011-01-15 22:36:57 +01:00
|
|
|
import org.bukkit.block.BlockFace;
|
2011-01-01 08:05:05 +01:00
|
|
|
import org.bukkit.event.block.BlockFromToEvent;
|
2011-03-31 22:40:00 +02:00
|
|
|
// CraftBukkit end
|
2011-01-01 08:05:05 +01:00
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
public class BlockFlowing extends BlockFluids {
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
int a = 0;
|
|
|
|
boolean[] b = new boolean[4];
|
|
|
|
int[] c = new int[4];
|
|
|
|
|
|
|
|
protected BlockFlowing(int i, Material material) {
|
|
|
|
super(i, material);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private void l(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-02 00:14:26 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setRawTypeIdAndData(i, j, k, this.id + 1, l);
|
2012-07-29 09:33:13 +02:00
|
|
|
world.d(i, j, k, i, j, k);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public boolean c(IBlockAccess iblockaccess, int i, int j, int k) {
|
2012-03-01 11:49:23 +01:00
|
|
|
return this.material != Material.LAVA;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void b(World world, int i, int j, int k, Random random) {
|
2011-03-02 21:24:19 +01:00
|
|
|
// CraftBukkit start
|
2011-06-27 00:25:01 +02:00
|
|
|
org.bukkit.World bworld = world.getWorld();
|
|
|
|
org.bukkit.Server server = world.getServer();
|
|
|
|
org.bukkit.block.Block source = bworld == null ? null : bworld.getBlockAt(i, j, k);
|
2011-03-02 21:24:19 +01:00
|
|
|
// CraftBukkit end
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
int l = this.f_(world, i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
byte b0 = 1;
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (this.material == Material.LAVA && !world.worldProvider.d) {
|
2011-01-29 22:50:29 +01:00
|
|
|
b0 = 2;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-01 08:05:05 +01:00
|
|
|
boolean flag = true;
|
2011-01-29 22:50:29 +01:00
|
|
|
int i1;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (l > 0) {
|
|
|
|
byte b1 = -100;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a = 0;
|
2012-07-29 09:33:13 +02:00
|
|
|
int j1 = this.e(world, i - 1, j, k, b1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
j1 = this.e(world, i + 1, j, k, j1);
|
|
|
|
j1 = this.e(world, i, j, k - 1, j1);
|
|
|
|
j1 = this.e(world, i, j, k + 1, j1);
|
2011-01-29 22:50:29 +01:00
|
|
|
i1 = j1 + b0;
|
|
|
|
if (i1 >= 8 || j1 < 0) {
|
|
|
|
i1 = -1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.f_(world, i, j + 1, k) >= 0) {
|
|
|
|
int k1 = this.f_(world, i, j + 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (k1 >= 8) {
|
|
|
|
i1 = k1;
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
i1 = k1 + 8;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (this.a >= 2 && this.material == Material.WATER) {
|
2011-05-26 14:48:22 +02:00
|
|
|
if (world.getMaterial(i, j - 1, k).isBuildable()) {
|
2011-01-29 22:50:29 +01:00
|
|
|
i1 = 0;
|
|
|
|
} else if (world.getMaterial(i, j - 1, k) == this.material && world.getData(i, j, k) == 0) {
|
|
|
|
i1 = 0;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (this.material == Material.LAVA && l < 8 && i1 < 8 && i1 > l && random.nextInt(4) != 0) {
|
|
|
|
i1 = l;
|
2011-01-01 08:05:05 +01:00
|
|
|
flag = false;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (i1 == l) {
|
|
|
|
if (flag) {
|
|
|
|
this.l(world, i, j, k);
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
l = i1;
|
|
|
|
if (i1 < 0) {
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setTypeId(i, j, k, 0);
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setData(i, j, k, i1);
|
2012-07-29 09:33:13 +02:00
|
|
|
world.a(i, j, k, this.id, this.p_());
|
2011-04-20 19:05:14 +02:00
|
|
|
world.applyPhysics(i, j, k, this.id);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.l(world, i, j, k);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.p(world, i, j - 1, k)) {
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit start - send "down" to the server
|
2011-03-26 22:32:56 +01:00
|
|
|
BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN);
|
2011-03-02 21:24:19 +01:00
|
|
|
if (server != null) {
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
}
|
2011-01-01 14:06:04 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!event.isCancelled()) {
|
2011-11-20 09:01:14 +01:00
|
|
|
if (this.material == Material.LAVA && world.getMaterial(i, j - 1, k) == Material.WATER) {
|
|
|
|
world.setTypeId(i, j - 1, k, Block.STONE.id);
|
2012-01-14 21:03:48 +01:00
|
|
|
this.fizz(world, i, j - 1, k);
|
2011-11-20 09:01:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (l >= 8) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.flow(world, i, j - 1, k, l);
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.flow(world, i, j - 1, k, l + 8);
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 14:06:04 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit end
|
2012-07-29 09:33:13 +02:00
|
|
|
} else if (l >= 0 && (l == 0 || this.o(world, i, j - 1, k))) {
|
|
|
|
boolean[] aboolean = this.n(world, i, j, k);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
i1 = l + b0;
|
|
|
|
if (l >= 8) {
|
|
|
|
i1 = 1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i1 >= 8) {
|
2011-01-02 00:14:26 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start - all four cardinal directions. Do not change the order!
|
2011-06-12 00:02:58 +02:00
|
|
|
BlockFace[] faces = new BlockFace[] { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST };
|
2011-01-05 14:16:44 +01:00
|
|
|
int index = 0;
|
2011-06-12 00:02:58 +02:00
|
|
|
|
2012-01-14 23:02:10 +01:00
|
|
|
for (BlockFace currentFace : faces) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (aboolean[index]) {
|
2011-03-26 22:32:56 +01:00
|
|
|
BlockFromToEvent event = new BlockFromToEvent(source, currentFace);
|
2011-03-02 21:24:19 +01:00
|
|
|
|
|
|
|
if (server != null) {
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-01-05 14:16:44 +01:00
|
|
|
if (!event.isCancelled()) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.flow(world, i + currentFace.getModX(), j, k + currentFace.getModZ(), i1);
|
2011-01-05 14:16:44 +01:00
|
|
|
}
|
2011-01-01 14:06:04 +01:00
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
index++;
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
private void flow(World world, int i, int j, int k, int l) {
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.p(world, i, j, k)) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i1 = world.getTypeId(i, j, k);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (i1 > 0) {
|
|
|
|
if (this.material == Material.LAVA) {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.fizz(world, i, j, k);
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
Block.byId[i1].c(world, i, j, k, world.getData(i, j, k), 0);
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setTypeIdAndData(i, j, k, this.id, l);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private int d(World world, int i, int j, int k, int l, int i1) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int j1 = 1000;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (int k1 = 0; k1 < 4; ++k1) {
|
|
|
|
if ((k1 != 0 || i1 != 1) && (k1 != 1 || i1 != 0) && (k1 != 2 || i1 != 3) && (k1 != 3 || i1 != 2)) {
|
|
|
|
int l1 = i;
|
|
|
|
int i2 = k;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (k1 == 0) {
|
|
|
|
l1 = i - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k1 == 1) {
|
|
|
|
++l1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k1 == 2) {
|
|
|
|
i2 = k - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k1 == 3) {
|
|
|
|
++i2;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!this.o(world, l1, j, i2) && (world.getMaterial(l1, j, i2) != this.material || world.getData(l1, j, i2) != 0)) {
|
|
|
|
if (!this.o(world, l1, j - 1, i2)) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l < 4) {
|
2012-07-29 09:33:13 +02:00
|
|
|
int j2 = this.d(world, l1, j, i2, l + 1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (j2 < j1) {
|
|
|
|
j1 = j2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
return j1;
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private boolean[] n(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int l;
|
|
|
|
int i1;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (l = 0; l < 4; ++l) {
|
|
|
|
this.c[l] = 1000;
|
|
|
|
i1 = i;
|
|
|
|
int j1 = k;
|
|
|
|
|
|
|
|
if (l == 0) {
|
|
|
|
i1 = i - 1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (l == 1) {
|
|
|
|
++i1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (l == 2) {
|
|
|
|
j1 = k - 1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (l == 3) {
|
|
|
|
++j1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!this.o(world, i1, j, j1) && (world.getMaterial(i1, j, j1) != this.material || world.getData(i1, j, j1) != 0)) {
|
|
|
|
if (this.o(world, i1, j - 1, j1)) {
|
|
|
|
this.c[l] = this.d(world, i1, j, j1, 1, l);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.c[l] = 0;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
l = this.c[0];
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (i1 = 1; i1 < 4; ++i1) {
|
|
|
|
if (this.c[i1] < l) {
|
|
|
|
l = this.c[i1];
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (i1 = 0; i1 < 4; ++i1) {
|
|
|
|
this.b[i1] = this.c[i1] == l;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
return this.b;
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private boolean o(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int l = world.getTypeId(i, j, k);
|
|
|
|
|
|
|
|
if (l != Block.WOODEN_DOOR.id && l != Block.IRON_DOOR_BLOCK.id && l != Block.SIGN_POST.id && l != Block.LADDER.id && l != Block.SUGAR_CANE_BLOCK.id) {
|
|
|
|
if (l == 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
Material material = Block.byId[l].material;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
return material == Material.PORTAL ? true : material.isSolid();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-01-01 08:05:05 +01:00
|
|
|
return true;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
protected int e(World world, int i, int j, int k, int l) {
|
|
|
|
int i1 = this.f_(world, i, j, k);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (i1 < 0) {
|
|
|
|
return l;
|
|
|
|
} else {
|
|
|
|
if (i1 == 0) {
|
|
|
|
++this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i1 >= 8) {
|
|
|
|
i1 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l >= 0 && i1 >= l ? l : i1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private boolean p(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
Material material = world.getMaterial(i, j, k);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
return material == this.material ? false : (material == Material.LAVA ? false : !this.o(world, i, j, k));
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
public void onPlace(World world, int i, int j, int k) {
|
|
|
|
super.onPlace(world, i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.getTypeId(i, j, k) == this.id) {
|
2012-07-29 09:33:13 +02:00
|
|
|
world.a(i, j, k, this.id, this.p_());
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|