2011-01-01 08:05:05 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-01-15 22:36:57 +01:00
|
|
|
import org.bukkit.block.BlockFace;
|
2011-01-15 22:40:18 +01:00
|
|
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
2011-01-01 08:05:05 +01:00
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.event.block.BlockFromToEvent;
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-01 08:05:05 +01:00
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
public class BlockFlowing extends BlockFluids {
|
|
|
|
|
|
|
|
int a;
|
|
|
|
boolean b[];
|
|
|
|
int c[];
|
2011-01-01 08:05:05 +01:00
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
protected BlockFlowing(int i1, Material material) {
|
2011-01-01 08:05:05 +01:00
|
|
|
super(i1, material);
|
|
|
|
a = 0;
|
|
|
|
b = new boolean[4];
|
|
|
|
c = new int[4];
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
private void i(World world, int i1, int j1, int k1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int l1 = world.b(i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
world.a(i1, j1, k1, bi + 1, l1);
|
2011-01-01 08:05:05 +01:00
|
|
|
world.b(i1, j1, k1, i1, j1, k1);
|
|
|
|
world.g(i1, j1, k1);
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
public void a(World world, int i1, int j1, int k1, Random random) {
|
2011-01-16 06:11:26 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
// skedit: Moved up to make sure that it is accurate
|
|
|
|
CraftBlock source = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i1, j1, k1);
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-01-01 08:05:05 +01:00
|
|
|
int l1 = g(world, i1, j1, k1);
|
|
|
|
byte byte0 = 1;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (bt == Material.g && !world.q.d) {
|
2011-01-01 08:05:05 +01:00
|
|
|
byte0 = 2;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
boolean flag = true;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (l1 > 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int i2 = -100;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-01 08:05:05 +01:00
|
|
|
a = 0;
|
|
|
|
i2 = e(world, i1 - 1, j1, k1, i2);
|
|
|
|
i2 = e(world, i1 + 1, j1, k1, i2);
|
|
|
|
i2 = e(world, i1, j1, k1 - 1, i2);
|
|
|
|
i2 = e(world, i1, j1, k1 + 1, i2);
|
|
|
|
int j2 = i2 + byte0;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (j2 >= 8 || i2 < 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2 = -1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (g(world, i1, j1 + 1, k1) >= 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int l2 = g(world, i1, j1 + 1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (l2 >= 8) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2 = l2;
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2 = l2 + 8;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
if (a >= 2 && bt == Material.f) {
|
2011-01-02 00:14:26 +01:00
|
|
|
if (world.d(i1, j1 - 1, k1)) {
|
|
|
|
j2 = 0;
|
2011-01-14 14:31:10 +01:00
|
|
|
} else if (world.c(i1, j1 - 1, k1) == bt && world.b(i1, j1, k1) == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2 = 0;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
if (bt == Material.g && l1 < 8 && j2 < 8 && j2 > l1 && random.nextInt(4) != 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2 = l1;
|
|
|
|
flag = false;
|
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
if (j2 != l1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
l1 = j2;
|
2011-01-02 00:14:26 +01:00
|
|
|
if (l1 < 0) {
|
2011-01-14 14:31:10 +01:00
|
|
|
world.e(i1, j1, k1, 0);
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-14 14:31:10 +01:00
|
|
|
world.c(i1, j1, k1, l1);
|
|
|
|
world.i(i1, j1, k1, bi);
|
|
|
|
world.h(i1, j1, k1, bi);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
} else if (flag) {
|
|
|
|
i(world, i1, j1, k1);
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-01 08:05:05 +01:00
|
|
|
i(world, i1, j1, k1);
|
|
|
|
}
|
2011-01-16 06:11:26 +01:00
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
if (l(world, i1, j1 - 1, k1)) {
|
2011-01-16 06:11:26 +01:00
|
|
|
// CraftBukkit start
|
2011-01-01 14:06:04 +01:00
|
|
|
// Craftbucket send "down" to the server
|
2011-01-15 21:16:30 +01:00
|
|
|
BlockFromToEvent blockFlow = new BlockFromToEvent(Type.BLOCK_FLOW, source, BlockFace.DOWN);
|
2011-01-01 08:05:05 +01:00
|
|
|
((WorldServer) world).getServer().getPluginManager().callEvent(blockFlow);
|
2011-01-01 14:06:04 +01:00
|
|
|
|
|
|
|
if (!blockFlow.isCancelled()) {
|
2011-01-02 00:14:26 +01:00
|
|
|
if (l1 >= 8) {
|
2011-01-14 14:31:10 +01:00
|
|
|
world.b(i1, j1 - 1, k1, bi, l1);
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-14 14:31:10 +01:00
|
|
|
world.b(i1, j1 - 1, k1, bi, l1 + 8);
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 14:06:04 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-02 00:14:26 +01:00
|
|
|
} else if (l1 >= 0 && (l1 == 0 || k(world, i1, j1 - 1, k1))) {
|
|
|
|
boolean aflag[] = j(world, i1, j1, k1);
|
|
|
|
int k2 = l1 + byte0;
|
|
|
|
|
|
|
|
if (l1 >= 8) {
|
|
|
|
k2 = 1;
|
|
|
|
}
|
|
|
|
if (k2 >= 8) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start - all four cardinal directions. Do not change the order!
|
2011-01-15 21:16:30 +01: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-01-11 09:25:13 +01:00
|
|
|
for (BlockFace currentFace: faces) {
|
2011-01-02 00:14:26 +01:00
|
|
|
if (aflag[index]) {
|
|
|
|
BlockFromToEvent event = new BlockFromToEvent(Type.BLOCK_FLOW, source, currentFace);
|
|
|
|
((WorldServer) world).getServer().getPluginManager().callEvent(event);
|
2011-01-05 14:16:44 +01:00
|
|
|
if (!event.isCancelled()) {
|
2011-01-02 00:14:26 +01:00
|
|
|
f(world, i1 + currentFace.getModX(), j1, k1 + currentFace.getModZ(), k2);
|
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-01-02 00:14:26 +01:00
|
|
|
private void f(World world, int i1, int j1, int k1, int l1) {
|
|
|
|
if (l(world, i1, j1, k1)) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int i2 = world.a(i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (i2 > 0) {
|
2011-01-14 14:31:10 +01:00
|
|
|
if (bt == Material.g) {
|
2011-01-01 08:05:05 +01:00
|
|
|
h(world, i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-01 08:05:05 +01:00
|
|
|
Block.m[i2].a_(world, i1, j1, k1, world.b(i1, j1, k1));
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
world.b(i1, j1, k1, bi, l1);
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
private int b(World world, int i1, int j1, int k1, int l1, int i2) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int j2 = 1000;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
for (int k2 = 0; k2 < 4; k2++) {
|
|
|
|
if (k2 == 0 && i2 == 1 || k2 == 1 && i2 == 0 || k2 == 2 && i2 == 3 || k2 == 3 && i2 == 2) {
|
2011-01-01 08:05:05 +01:00
|
|
|
continue;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
int l2 = i1;
|
|
|
|
int i3 = j1;
|
|
|
|
int j3 = k1;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (k2 == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
l2--;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (k2 == 1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
l2++;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (k2 == 2) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j3--;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (k2 == 3) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j3++;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
if (k(world, l2, i3, j3) || world.c(l2, i3, j3) == bt && world.b(l2, i3, j3) == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
continue;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (!k(world, l2, i3 - 1, j3)) {
|
2011-01-01 08:05:05 +01:00
|
|
|
return l1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (l1 >= 4) {
|
2011-01-01 08:05:05 +01:00
|
|
|
continue;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
int k3 = b(world, l2, i3, j3, l1 + 1, k2);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (k3 < j2) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2 = k3;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return j2;
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
private boolean[] j(World world, int i1, int j1, int k1) {
|
|
|
|
for (int l1 = 0; l1 < 4; l1++) {
|
2011-01-01 08:05:05 +01:00
|
|
|
c[l1] = 1000;
|
|
|
|
int j2 = i1;
|
|
|
|
int i3 = j1;
|
|
|
|
int j3 = k1;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (l1 == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2--;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (l1 == 1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j2++;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (l1 == 2) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j3--;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (l1 == 3) {
|
2011-01-01 08:05:05 +01:00
|
|
|
j3++;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
if (k(world, j2, i3, j3) || world.c(j2, i3, j3) == bt && world.b(j2, i3, j3) == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
continue;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (!k(world, j2, i3 - 1, j3)) {
|
2011-01-01 08:05:05 +01:00
|
|
|
c[l1] = 0;
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-14 14:31:10 +01:00
|
|
|
c[l1] = b(world, j2, i3, j3, 1, l1);
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int i2 = c[0];
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
for (int k2 = 1; k2 < 4; k2++) {
|
|
|
|
if (c[k2] < i2) {
|
2011-01-01 08:05:05 +01:00
|
|
|
i2 = c[k2];
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
for (int l2 = 0; l2 < 4; l2++) {
|
2011-01-01 08:05:05 +01:00
|
|
|
b[l2] = c[l2] == i2;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
private boolean k(World world, int i1, int j1, int k1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int l1 = world.a(i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (l1 == Block.aE.bi || l1 == Block.aL.bi || l1 == Block.aD.bi || l1 == Block.aF.bi || l1 == Block.aX.bi) {
|
2011-01-01 08:05:05 +01:00
|
|
|
return true;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (l1 == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
return false;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
Material material = Block.m[l1].bt;
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-01 08:05:05 +01:00
|
|
|
return material.a();
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
protected int e(World world, int i1, int j1, int k1, int l1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
int i2 = g(world, i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
|
|
|
if (i2 < 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
return l1;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (i2 == 0) {
|
2011-01-01 08:05:05 +01:00
|
|
|
a++;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (i2 >= 8) {
|
2011-01-01 08:05:05 +01:00
|
|
|
i2 = 0;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
return l1 >= 0 && i2 >= l1 ? l1 : i2;
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
private boolean l(World world, int i1, int j1, int k1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
Material material = world.c(i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (material == bt) {
|
2011-01-01 08:05:05 +01:00
|
|
|
return false;
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
|
|
|
if (material == Material.g) {
|
2011-01-01 08:05:05 +01:00
|
|
|
return false;
|
2011-01-02 00:14:26 +01:00
|
|
|
} else {
|
2011-01-01 08:05:05 +01:00
|
|
|
return !k(world, i1, j1, k1);
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 00:14:26 +01:00
|
|
|
public void e(World world, int i1, int j1, int k1) {
|
2011-01-01 08:05:05 +01:00
|
|
|
super.e(world, i1, j1, k1);
|
2011-01-14 14:31:10 +01:00
|
|
|
if (world.a(i1, j1, k1) == bi) {
|
|
|
|
world.i(i1, j1, k1, bi);
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|
2011-01-01 08:05:05 +01:00
|
|
|
}
|
2011-01-02 00:14:26 +01:00
|
|
|
}
|