3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-18 05:50:04 +01:00
Paper/src/main/java/net/minecraft/server/BlockRedstoneWire.java

347 Zeilen
9.8 KiB
Java

2011-01-12 18:40:42 +01:00
package net.minecraft.server;
2011-01-14 14:31:10 +01:00
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
2011-01-12 18:40:42 +01:00
import java.util.Random;
2011-01-14 14:31:10 +01:00
import java.util.Set;
import org.bukkit.block.BlockFace;
2011-01-12 18:40:42 +01:00
import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.plugin.PluginLoader;
public class BlockRedstoneWire extends Block {
private boolean a;
2011-01-14 14:31:10 +01:00
private Set b;
2011-01-12 18:40:42 +01:00
public BlockRedstoneWire(int i, int j) {
super(i, j, Material.n);
a = true;
2011-01-14 14:31:10 +01:00
b = ((Set) (new HashSet()));
2011-01-12 18:40:42 +01:00
a(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
}
public AxisAlignedBB d(World world, int i, int j, int k) {
return null;
}
public boolean a() {
return false;
}
public boolean a(World world, int i, int j, int k) {
return world.d(i, j - 1, k);
}
private void g(World world, int i, int j, int k) {
2011-01-14 14:31:10 +01:00
a(world, i, j, k, i, j, k);
ArrayList arraylist = new ArrayList(((java.util.Collection) (b)));
b.clear();
for (int l = 0; l < ((List) (arraylist)).size(); l++) {
ChunkPosition chunkposition = (ChunkPosition) ((List) (arraylist)).get(l);
world.h(chunkposition.a, chunkposition.b, chunkposition.c, bi);
}
}
private void a(World world, int i, int j, int k, int l, int i1, int j1) {
int k1 = world.b(i, j, k);
int l1 = 0;
2011-01-12 18:40:42 +01:00
a = false;
2011-01-14 14:31:10 +01:00
boolean flag = world.p(i, j, k);
2011-01-12 18:40:42 +01:00
a = true;
if (flag) {
2011-01-14 14:31:10 +01:00
l1 = 15;
2011-01-12 18:40:42 +01:00
} else {
2011-01-14 14:31:10 +01:00
for (int i2 = 0; i2 < 4; i2++) {
int k2 = i;
int i3 = k;
2011-01-12 18:40:42 +01:00
2011-01-14 14:31:10 +01:00
if (i2 == 0) {
k2--;
}
if (i2 == 1) {
k2++;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (i2 == 2) {
i3--;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (i2 == 3) {
i3++;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (k2 != l || j != i1 || i3 != j1) {
l1 = f(world, k2, j, i3, l1);
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (world.d(k2, j, i3) && !world.d(i, j + 1, k)) {
if (k2 != l || j + 1 != i1 || i3 != j1) {
l1 = f(world, k2, j + 1, i3, l1);
}
2011-01-12 18:40:42 +01:00
continue;
}
2011-01-14 14:31:10 +01:00
if (!world.d(k2, j, i3) && (k2 != l || j - 1 != i1 || i3 != j1)) {
l1 = f(world, k2, j - 1, i3, l1);
2011-01-12 18:40:42 +01:00
}
}
2011-01-14 14:31:10 +01:00
if (l1 > 0) {
l1--;
2011-01-12 18:40:42 +01:00
} else {
2011-01-14 14:31:10 +01:00
l1 = 0;
2011-01-12 18:40:42 +01:00
}
}
2011-01-14 14:31:10 +01:00
// Craftbukkit start
if (k1 != l1) {
2011-01-12 18:40:42 +01:00
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.SELF, k1, l1);
2011-01-12 18:40:42 +01:00
((WorldServer) world).getServer().getPluginManager().callEvent(bre);
2011-01-14 14:31:10 +01:00
l1 = bre.getNewCurrent();
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
// Craftbukkit end
if (k1 != l1) {
world.i = true;
world.c(i, j, k, l1);
2011-01-12 18:40:42 +01:00
world.b(i, j, k, i, j, k);
2011-01-14 14:31:10 +01:00
world.i = false;
for (int j2 = 0; j2 < 4; j2++) {
int l2 = i;
int j3 = k;
int k3 = j - 1;
2011-01-12 18:40:42 +01:00
2011-01-14 14:31:10 +01:00
if (j2 == 0) {
l2--;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (j2 == 1) {
l2++;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (j2 == 2) {
j3--;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (j2 == 3) {
j3++;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (world.d(l2, j, j3)) {
k3 += 2;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
int l3 = 0;
2011-01-12 18:40:42 +01:00
2011-01-14 14:31:10 +01:00
l3 = f(world, l2, j, j3, -1);
l1 = world.b(i, j, k);
if (l1 > 0) {
l1--;
}
if (l3 >= 0 && l3 != l1) {
a(world, l2, j, j3, i, j, k);
}
l3 = f(world, l2, k3, j3, -1);
l1 = world.b(i, j, k);
if (l1 > 0) {
l1--;
2011-01-12 18:40:42 +01:00
}
2011-01-14 14:31:10 +01:00
if (l3 >= 0 && l3 != l1) {
a(world, l2, k3, j3, i, j, k);
2011-01-12 18:40:42 +01:00
}
}
2011-01-14 14:31:10 +01:00
if (k1 == 0 || l1 == 0) {
b.add(((new ChunkPosition(i, j, k))));
b.add(((new ChunkPosition(i - 1, j, k))));
b.add(((new ChunkPosition(i + 1, j, k))));
b.add(((new ChunkPosition(i, j - 1, k))));
b.add(((new ChunkPosition(i, j + 1, k))));
b.add(((new ChunkPosition(i, j, k - 1))));
b.add(((new ChunkPosition(i, j, k + 1))));
2011-01-12 18:40:42 +01:00
}
}
}
private void h(World world, int i, int j, int k) {
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k) != bi) {
2011-01-12 18:40:42 +01:00
return;
} else {
2011-01-14 14:31:10 +01:00
world.h(i, j, k, bi);
world.h(i - 1, j, k, bi);
world.h(i + 1, j, k, bi);
world.h(i, j, k - 1, bi);
world.h(i, j, k + 1, bi);
world.h(i, j - 1, k, bi);
world.h(i, j + 1, k, bi);
2011-01-12 18:40:42 +01:00
return;
}
}
public void e(World world, int i, int j, int k) {
super.e(world, i, j, k);
if (world.z) {
return;
}
g(world, i, j, k);
2011-01-14 14:31:10 +01:00
world.h(i, j + 1, k, bi);
world.h(i, j - 1, k, bi);
2011-01-12 18:40:42 +01:00
h(world, i - 1, j, k);
h(world, i + 1, j, k);
h(world, i, j, k - 1);
h(world, i, j, k + 1);
if (world.d(i - 1, j, k)) {
h(world, i - 1, j + 1, k);
} else {
h(world, i - 1, j - 1, k);
}
if (world.d(i + 1, j, k)) {
h(world, i + 1, j + 1, k);
} else {
h(world, i + 1, j - 1, k);
}
if (world.d(i, j, k - 1)) {
h(world, i, j + 1, k - 1);
} else {
h(world, i, j - 1, k - 1);
}
if (world.d(i, j, k + 1)) {
h(world, i, j + 1, k + 1);
} else {
h(world, i, j - 1, k + 1);
}
}
public void b(World world, int i, int j, int k) {
super.b(world, i, j, k);
if (world.z) {
return;
}
2011-01-14 14:31:10 +01:00
world.h(i, j + 1, k, bi);
world.h(i, j - 1, k, bi);
2011-01-12 18:40:42 +01:00
g(world, i, j, k);
h(world, i - 1, j, k);
h(world, i + 1, j, k);
h(world, i, j, k - 1);
h(world, i, j, k + 1);
if (world.d(i - 1, j, k)) {
h(world, i - 1, j + 1, k);
} else {
h(world, i - 1, j - 1, k);
}
if (world.d(i + 1, j, k)) {
h(world, i + 1, j + 1, k);
} else {
h(world, i + 1, j - 1, k);
}
if (world.d(i, j, k - 1)) {
h(world, i, j + 1, k - 1);
} else {
h(world, i, j - 1, k - 1);
}
if (world.d(i, j, k + 1)) {
h(world, i, j + 1, k + 1);
} else {
h(world, i, j - 1, k + 1);
}
}
private int f(World world, int i, int j, int k, int l) {
2011-01-14 14:31:10 +01:00
if (world.a(i, j, k) != bi) {
2011-01-12 18:40:42 +01:00
return l;
}
int i1 = world.b(i, j, k);
if (i1 > l) {
return i1;
} else {
return l;
}
}
public void b(World world, int i, int j, int k, int l) {
if (world.z) {
return;
}
int i1 = world.b(i, j, k);
boolean flag = a(world, i, j, k);
if (!flag) {
a_(world, i, j, k, i1);
2011-01-14 14:31:10 +01:00
world.e(i, j, k, 0);
2011-01-12 18:40:42 +01:00
} else {
g(world, i, j, k);
}
super.b(world, i, j, k, l);
}
public int a(int i, Random random) {
2011-01-14 14:31:10 +01:00
return Item.aA.ba;
2011-01-12 18:40:42 +01:00
}
public boolean d(World world, int i, int j, int k, int l) {
if (!a) {
return false;
} else {
return b(((IBlockAccess) (world)), i, j, k, l);
}
}
public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
if (!a) {
return false;
}
if (iblockaccess.b(i, j, k) == 0) {
return false;
}
if (l == 1) {
return true;
}
boolean flag = b(iblockaccess, i - 1, j, k) || !iblockaccess.d(i - 1, j, k) && b(iblockaccess, i - 1, j - 1, k);
boolean flag1 = b(iblockaccess, i + 1, j, k) || !iblockaccess.d(i + 1, j, k) && b(iblockaccess, i + 1, j - 1, k);
boolean flag2 = b(iblockaccess, i, j, k - 1) || !iblockaccess.d(i, j, k - 1) && b(iblockaccess, i, j - 1, k - 1);
boolean flag3 = b(iblockaccess, i, j, k + 1) || !iblockaccess.d(i, j, k + 1) && b(iblockaccess, i, j - 1, k + 1);
if (!iblockaccess.d(i, j + 1, k)) {
if (iblockaccess.d(i - 1, j, k) && b(iblockaccess, i - 1, j + 1, k)) {
flag = true;
}
if (iblockaccess.d(i + 1, j, k) && b(iblockaccess, i + 1, j + 1, k)) {
flag1 = true;
}
if (iblockaccess.d(i, j, k - 1) && b(iblockaccess, i, j + 1, k - 1)) {
flag2 = true;
}
if (iblockaccess.d(i, j, k + 1) && b(iblockaccess, i, j + 1, k + 1)) {
flag3 = true;
}
}
if (!flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5) {
return true;
}
if (l == 2 && flag2 && !flag && !flag1) {
return true;
}
if (l == 3 && flag3 && !flag && !flag1) {
return true;
}
if (l == 4 && flag && !flag2 && !flag3) {
return true;
}
return l == 5 && flag1 && !flag2 && !flag3;
}
public boolean c() {
return a;
}
public static boolean b(IBlockAccess iblockaccess, int i, int j, int k) {
int l = iblockaccess.a(i, j, k);
2011-01-14 14:31:10 +01:00
if (l == Block.av.bi) {
2011-01-12 18:40:42 +01:00
return true;
}
if (l == 0) {
return false;
}
return Block.m[l].c();
}
}