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

300 Zeilen
8.5 KiB
Java

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
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
public class BlockFlowing extends BlockFluids {
2013-07-01 13:03:00 +02:00
int a;
2011-01-29 22:50:29 +01:00
boolean[] b = new boolean[4];
2013-11-04 14:07:38 +01:00
int[] M = new int[4];
2011-01-29 22:50:29 +01:00
2013-11-04 14:07:38 +01:00
protected BlockFlowing(Material material) {
super(material);
2011-01-01 08:05:05 +01:00
}
2013-11-04 14:07:38 +01:00
private void n(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
int l = world.getData(i, j, k);
2013-11-04 14:07:38 +01:00
world.setTypeAndData(i, j, k, Block.e(Block.b((Block) this) + 1), l, 2);
2012-03-01 11:49:23 +01:00
}
2013-03-13 23:33:27 +01:00
public void a(World world, int i, int j, int k, Random random) {
2011-03-02 21:24:19 +01:00
// CraftBukkit start
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
2013-11-04 14:07:38 +01:00
int l = this.e(world, i, j, k);
2011-01-29 22:50:29 +01:00
byte b0 = 1;
2013-07-01 13:03:00 +02:00
if (this.material == Material.LAVA && !world.worldProvider.f) {
2011-01-29 22:50:29 +01:00
b0 = 2;
}
2011-01-29 22:50:29 +01:00
2011-01-01 08:05:05 +01:00
boolean flag = true;
2013-07-01 13:03:00 +02:00
int i1 = this.a(world);
int j1;
2011-01-29 22:50:29 +01:00
if (l > 0) {
byte b1 = -100;
2011-01-29 22:50:29 +01:00
this.a = 0;
2013-11-04 14:07:38 +01:00
int k1 = this.a(world, i - 1, j, k, b1);
2013-07-01 13:03:00 +02:00
2013-11-04 14:07:38 +01:00
k1 = this.a(world, i + 1, j, k, k1);
k1 = this.a(world, i, j, k - 1, k1);
k1 = this.a(world, i, j, k + 1, k1);
2013-07-01 13:03:00 +02:00
j1 = k1 + b0;
if (j1 >= 8 || k1 < 0) {
j1 = -1;
}
2013-11-04 14:07:38 +01:00
if (this.e(world, i, j + 1, k) >= 0) {
int l1 = this.e(world, i, j + 1, k);
2011-01-29 22:50:29 +01:00
2013-07-01 13:03:00 +02:00
if (l1 >= 8) {
j1 = l1;
} else {
2013-07-01 13:03:00 +02:00
j1 = l1 + 8;
}
2011-01-01 08:05:05 +01:00
}
2011-01-29 22:50:29 +01:00
if (this.a >= 2 && this.material == Material.WATER) {
2013-11-04 14:07:38 +01:00
if (world.getType(i, j - 1, k).getMaterial().isBuildable()) {
2013-07-01 13:03:00 +02:00
j1 = 0;
2013-11-04 14:07:38 +01:00
} else if (world.getType(i, j - 1, k).getMaterial() == this.material && world.getData(i, j - 1, k) == 0) {
2013-07-01 13:03:00 +02:00
j1 = 0;
}
}
2011-01-29 22:50:29 +01:00
2013-07-01 13:03:00 +02:00
if (this.material == Material.LAVA && l < 8 && j1 < 8 && j1 > l && random.nextInt(4) != 0) {
i1 *= 4;
2011-01-01 08:05:05 +01:00
}
2011-01-29 22:50:29 +01:00
2013-07-01 13:03:00 +02:00
if (j1 == l) {
2012-07-29 09:33:13 +02:00
if (flag) {
2013-11-04 14:07:38 +01:00
this.n(world, i, j, k);
2012-07-29 09:33:13 +02:00
}
} else {
2013-07-01 13:03:00 +02:00
l = j1;
if (j1 < 0) {
2013-03-13 23:33:27 +01:00
world.setAir(i, j, k);
} else {
2013-07-01 13:03:00 +02:00
world.setData(i, j, k, j1, 2);
2013-11-04 14:07:38 +01:00
world.a(i, j, k, this, i1);
world.applyPhysics(i, j, k, this);
2011-01-01 08:05:05 +01:00
}
}
} else {
2013-11-04 14:07:38 +01:00
this.n(world, i, j, k);
2011-01-01 08:05:05 +01:00
}
2011-01-29 22:50:29 +01:00
2013-11-04 14:07:38 +01:00
if (this.q(world, i, j - 1, k)) {
2013-03-25 05:22:32 +01:00
// CraftBukkit start - Send "down" to the server
BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN);
2011-03-02 21:24:19 +01:00
if (server != null) {
server.getPluginManager().callEvent(event);
}
2011-01-29 22:50:29 +01:00
if (!event.isCancelled()) {
2013-11-04 14:07:38 +01:00
if (this.material == Material.LAVA && world.getType(i, j - 1, k).getMaterial() == Material.WATER) {
world.setTypeUpdate(i, j - 1, k, Blocks.STONE);
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);
} else {
2012-07-29 09:33:13 +02:00
this.flow(world, i, j - 1, k, l + 8);
}
}
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2013-11-04 14:07:38 +01:00
} else if (l >= 0 && (l == 0 || this.p(world, i, j - 1, k))) {
boolean[] aboolean = this.o(world, i, j, k);
2013-07-01 13:03:00 +02:00
j1 = l + b0;
2011-01-29 22:50:29 +01:00
if (l >= 8) {
2013-07-01 13:03:00 +02:00
j1 = 1;
}
2011-01-29 22:50:29 +01:00
2013-07-01 13:03:00 +02:00
if (j1 >= 8) {
return;
}
2011-01-29 22:50:29 +01:00
2013-03-25 05:22:32 +01:00
// CraftBukkit start - All four cardinal directions. Do not change the order!
BlockFace[] faces = new BlockFace[] { BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH };
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]) {
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()) {
2013-07-01 13:03:00 +02:00
this.flow(world, i + currentFace.getModX(), j, k + currentFace.getModZ(), j1);
2011-01-05 14:16:44 +01:00
}
}
index++;
2011-01-01 08:05:05 +01:00
}
// CraftBukkit end
}
2011-01-01 08:05:05 +01:00
}
private void flow(World world, int i, int j, int k, int l) {
2013-11-04 14:07:38 +01:00
if (this.q(world, i, j, k)) {
Block block = world.getType(i, j, k);
2013-11-04 14:07:38 +01:00
if (this.material == Material.LAVA) {
this.fizz(world, i, j, k);
} else {
block.b(world, i, j, k, world.getData(i, j, k), 0);
}
2011-01-29 22:50:29 +01:00
2013-11-04 14:07:38 +01:00
world.setTypeAndData(i, j, k, this, l, 3);
2011-01-01 08:05:05 +01:00
}
}
2013-11-04 14:07:38 +01:00
private int c(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-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-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;
}
2013-11-04 14:07:38 +01:00
if (!this.p(world, l1, j, i2) && (world.getType(l1, j, i2).getMaterial() != this.material || world.getData(l1, j, i2) != 0)) {
if (!this.p(world, l1, j - 1, i2)) {
2011-01-29 22:50:29 +01:00
return l;
}
if (l < 4) {
2013-11-04 14:07:38 +01:00
int j2 = this.c(world, l1, j, i2, l + 1, k1);
2011-01-29 22:50:29 +01:00
if (j2 < j1) {
j1 = j2;
}
}
}
}
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
}
2013-11-04 14:07:38 +01:00
private boolean[] o(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
int l;
int i1;
2011-01-29 22:50:29 +01:00
for (l = 0; l < 4; ++l) {
2013-11-04 14:07:38 +01:00
this.M[l] = 1000;
2011-01-29 22:50:29 +01:00
i1 = i;
int j1 = k;
if (l == 0) {
i1 = i - 1;
}
2011-01-29 22:50:29 +01:00
if (l == 1) {
++i1;
}
2011-01-29 22:50:29 +01:00
if (l == 2) {
j1 = k - 1;
}
2011-01-29 22:50:29 +01:00
if (l == 3) {
++j1;
}
2011-01-29 22:50:29 +01:00
2013-11-04 14:07:38 +01:00
if (!this.p(world, i1, j, j1) && (world.getType(i1, j, j1).getMaterial() != this.material || world.getData(i1, j, j1) != 0)) {
if (this.p(world, i1, j - 1, j1)) {
this.M[l] = this.c(world, i1, j, j1, 1, l);
2011-01-29 22:50:29 +01:00
} else {
2013-11-04 14:07:38 +01:00
this.M[l] = 0;
2011-01-29 22:50:29 +01:00
}
}
2011-01-01 08:05:05 +01:00
}
2013-11-04 14:07:38 +01:00
l = this.M[0];
2011-01-29 22:50:29 +01:00
for (i1 = 1; i1 < 4; ++i1) {
2013-11-04 14:07:38 +01:00
if (this.M[i1] < l) {
l = this.M[i1];
}
}
2011-01-01 08:05:05 +01:00
2011-01-29 22:50:29 +01:00
for (i1 = 0; i1 < 4; ++i1) {
2013-11-04 14:07:38 +01:00
this.b[i1] = this.M[i1] == l;
}
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
}
2013-11-04 14:07:38 +01:00
private boolean p(World world, int i, int j, int k) {
Block block = world.getType(i, j, k);
2011-01-29 22:50:29 +01:00
2013-11-04 14:07:38 +01:00
return block != Blocks.WOODEN_DOOR && block != Blocks.IRON_DOOR_BLOCK && block != Blocks.SIGN_POST && block != Blocks.LADDER && block != Blocks.SUGAR_CANE_BLOCK ? (block.material == Material.PORTAL ? true : block.material.isSolid()) : true;
2011-01-01 08:05:05 +01:00
}
2013-11-04 14:07:38 +01:00
protected int a(World world, int i, int j, int k, int l) {
int i1 = this.e(world, i, j, k);
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-01 08:05:05 +01:00
}
2013-11-04 14:07:38 +01:00
private boolean q(World world, int i, int j, int k) {
Material material = world.getType(i, j, k).getMaterial();
2013-11-04 14:07:38 +01:00
return material == this.material ? false : (material == Material.LAVA ? false : !this.p(world, i, j, k));
2011-01-01 08:05:05 +01:00
}
public void onPlace(World world, int i, int j, int k) {
super.onPlace(world, i, j, k);
2013-11-04 14:07:38 +01:00
if (world.getType(i, j, k) == this) {
world.a(i, j, k, this, this.a(world));
}
2011-01-01 08:05:05 +01:00
}
2013-11-04 14:07:38 +01:00
public boolean L() {
2013-07-01 13:03:00 +02:00
return true;
}
}