Archiviert
13
0

Added MinecartTrackLogic.java and BlockMinecartTrack.java for diff visibility

Dieser Commit ist enthalten in:
Nathan Adams 2012-01-15 19:03:41 +00:00
Ursprung d3b4375d31
Commit 864397d6c8
2 geänderte Dateien mit 624 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,265 @@
package net.minecraft.server;
import java.util.Random;
public class BlockMinecartTrack extends Block {
private final boolean a;
public static final boolean g(World world, int i, int j, int k) {
int l = world.getTypeId(i, j, k);
return l == Block.RAILS.id || l == Block.GOLDEN_RAIL.id || l == Block.DETECTOR_RAIL.id;
}
public static final boolean d(int i) {
return i == Block.RAILS.id || i == Block.GOLDEN_RAIL.id || i == Block.DETECTOR_RAIL.id;
}
protected BlockMinecartTrack(int i, int j, boolean flag) {
super(i, j, Material.ORIENTABLE);
this.a = flag;
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
}
public boolean h() {
return this.a;
}
public AxisAlignedBB e(World world, int i, int j, int k) {
return null;
}
public boolean a() {
return false;
}
public MovingObjectPosition a(World world, int i, int j, int k, Vec3D vec3d, Vec3D vec3d1) {
this.updateShape(world, i, j, k);
return super.a(world, i, j, k, vec3d, vec3d1);
}
public void updateShape(IBlockAccess iblockaccess, int i, int j, int k) {
int l = iblockaccess.getData(i, j, k);
if (l >= 2 && l <= 5) {
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F);
} else {
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
}
}
public int a(int i, int j) {
if (this.a) {
if (this.id == Block.GOLDEN_RAIL.id && (j & 8) == 0) {
return this.textureId - 16;
}
} else if (j >= 6) {
return this.textureId - 16;
}
return this.textureId;
}
public boolean b() {
return false;
}
public int c() {
return 9;
}
public int a(Random random) {
return 1;
}
public boolean canPlace(World world, int i, int j, int k) {
return world.e(i, j - 1, k);
}
public void onPlace(World world, int i, int j, int k) {
if (!world.isStatic) {
this.a(world, i, j, k, true);
if (this.id == Block.GOLDEN_RAIL.id) {
this.doPhysics(world, i, j, k, this.id);
}
}
}
public void doPhysics(World world, int i, int j, int k, int l) {
if (!world.isStatic) {
int i1 = world.getData(i, j, k);
int j1 = i1;
if (this.a) {
j1 = i1 & 7;
}
boolean flag = false;
if (!world.e(i, j - 1, k)) {
flag = true;
}
if (j1 == 2 && !world.e(i + 1, j, k)) {
flag = true;
}
if (j1 == 3 && !world.e(i - 1, j, k)) {
flag = true;
}
if (j1 == 4 && !world.e(i, j, k - 1)) {
flag = true;
}
if (j1 == 5 && !world.e(i, j, k + 1)) {
flag = true;
}
if (flag) {
this.b(world, i, j, k, world.getData(i, j, k), 0);
world.setTypeId(i, j, k, 0);
} else if (this.id == Block.GOLDEN_RAIL.id) {
boolean flag1 = world.isBlockIndirectlyPowered(i, j, k) || world.isBlockIndirectlyPowered(i, j + 1, k);
flag1 = flag1 || this.a(world, i, j, k, i1, true, 0) || this.a(world, i, j, k, i1, false, 0);
boolean flag2 = false;
if (flag1 && (i1 & 8) == 0) {
world.setData(i, j, k, j1 | 8);
flag2 = true;
} else if (!flag1 && (i1 & 8) != 0) {
world.setData(i, j, k, j1);
flag2 = true;
}
if (flag2) {
world.applyPhysics(i, j - 1, k, this.id);
if (j1 == 2 || j1 == 3 || j1 == 4 || j1 == 5) {
world.applyPhysics(i, j + 1, k, this.id);
}
}
} else if (l > 0 && Block.byId[l].isPowerSource() && !this.a && MinecartTrackLogic.a(new MinecartTrackLogic(this, world, i, j, k)) == 3) {
this.a(world, i, j, k, false);
}
}
}
private void a(World world, int i, int j, int k, boolean flag) {
if (!world.isStatic) {
(new MinecartTrackLogic(this, world, i, j, k)).a(world.isBlockIndirectlyPowered(i, j, k), flag);
}
}
private boolean a(World world, int i, int j, int k, int l, boolean flag, int i1) {
if (i1 >= 8) {
return false;
} else {
int j1 = l & 7;
boolean flag1 = true;
switch (j1) {
case 0:
if (flag) {
++k;
} else {
--k;
}
break;
case 1:
if (flag) {
--i;
} else {
++i;
}
break;
case 2:
if (flag) {
--i;
} else {
++i;
++j;
flag1 = false;
}
j1 = 1;
break;
case 3:
if (flag) {
--i;
++j;
flag1 = false;
} else {
++i;
}
j1 = 1;
break;
case 4:
if (flag) {
++k;
} else {
--k;
++j;
flag1 = false;
}
j1 = 0;
break;
case 5:
if (flag) {
++k;
++j;
flag1 = false;
} else {
--k;
}
j1 = 0;
}
return this.a(world, i, j, k, flag, i1, j1) ? true : flag1 && this.a(world, i, j - 1, k, flag, i1, j1);
}
}
private boolean a(World world, int i, int j, int k, boolean flag, int l, int i1) {
int j1 = world.getTypeId(i, j, k);
if (j1 == Block.GOLDEN_RAIL.id) {
int k1 = world.getData(i, j, k);
int l1 = k1 & 7;
if (i1 == 1 && (l1 == 0 || l1 == 4 || l1 == 5)) {
return false;
}
if (i1 == 0 && (l1 == 1 || l1 == 2 || l1 == 3)) {
return false;
}
if ((k1 & 8) != 0) {
if (!world.isBlockIndirectlyPowered(i, j, k) && !world.isBlockIndirectlyPowered(i, j + 1, k)) {
return this.a(world, i, j, k, k1, flag, l + 1);
}
return true;
}
}
return false;
}
public int g() {
return 0;
}
static boolean a(BlockMinecartTrack blockminecarttrack) {
return blockminecarttrack.a;
}
}

Datei anzeigen

@ -0,0 +1,359 @@
package net.minecraft.server;
import java.util.ArrayList;
import java.util.List;
class MinecartTrackLogic {
private World b;
private int c;
private int d;
private int e;
private final boolean f;
private List g;
final BlockMinecartTrack a;
public MinecartTrackLogic(BlockMinecartTrack blockminecarttrack, World world, int i, int j, int k) {
this.a = blockminecarttrack;
this.g = new ArrayList();
this.b = world;
this.c = i;
this.d = j;
this.e = k;
int l = world.getTypeId(i, j, k);
int i1 = world.getData(i, j, k);
if (BlockMinecartTrack.a((BlockMinecartTrack) Block.byId[l])) {
this.f = true;
i1 &= -9;
} else {
this.f = false;
}
this.a(i1);
}
private void a(int i) {
this.g.clear();
if (i == 0) {
this.g.add(new ChunkPosition(this.c, this.d, this.e - 1));
this.g.add(new ChunkPosition(this.c, this.d, this.e + 1));
} else if (i == 1) {
this.g.add(new ChunkPosition(this.c - 1, this.d, this.e));
this.g.add(new ChunkPosition(this.c + 1, this.d, this.e));
} else if (i == 2) {
this.g.add(new ChunkPosition(this.c - 1, this.d, this.e));
this.g.add(new ChunkPosition(this.c + 1, this.d + 1, this.e));
} else if (i == 3) {
this.g.add(new ChunkPosition(this.c - 1, this.d + 1, this.e));
this.g.add(new ChunkPosition(this.c + 1, this.d, this.e));
} else if (i == 4) {
this.g.add(new ChunkPosition(this.c, this.d + 1, this.e - 1));
this.g.add(new ChunkPosition(this.c, this.d, this.e + 1));
} else if (i == 5) {
this.g.add(new ChunkPosition(this.c, this.d, this.e - 1));
this.g.add(new ChunkPosition(this.c, this.d + 1, this.e + 1));
} else if (i == 6) {
this.g.add(new ChunkPosition(this.c + 1, this.d, this.e));
this.g.add(new ChunkPosition(this.c, this.d, this.e + 1));
} else if (i == 7) {
this.g.add(new ChunkPosition(this.c - 1, this.d, this.e));
this.g.add(new ChunkPosition(this.c, this.d, this.e + 1));
} else if (i == 8) {
this.g.add(new ChunkPosition(this.c - 1, this.d, this.e));
this.g.add(new ChunkPosition(this.c, this.d, this.e - 1));
} else if (i == 9) {
this.g.add(new ChunkPosition(this.c + 1, this.d, this.e));
this.g.add(new ChunkPosition(this.c, this.d, this.e - 1));
}
}
private void a() {
for (int i = 0; i < this.g.size(); ++i) {
MinecartTrackLogic minecarttracklogic = this.a((ChunkPosition) this.g.get(i));
if (minecarttracklogic != null && minecarttracklogic.b(this)) {
this.g.set(i, new ChunkPosition(minecarttracklogic.c, minecarttracklogic.d, minecarttracklogic.e));
} else {
this.g.remove(i--);
}
}
}
private boolean a(int i, int j, int k) {
return BlockMinecartTrack.g(this.b, i, j, k) ? true : (BlockMinecartTrack.g(this.b, i, j + 1, k) ? true : BlockMinecartTrack.g(this.b, i, j - 1, k));
}
private MinecartTrackLogic a(ChunkPosition chunkposition) {
return BlockMinecartTrack.g(this.b, chunkposition.x, chunkposition.y, chunkposition.z) ? new MinecartTrackLogic(this.a, this.b, chunkposition.x, chunkposition.y, chunkposition.z) : (BlockMinecartTrack.g(this.b, chunkposition.x, chunkposition.y + 1, chunkposition.z) ? new MinecartTrackLogic(this.a, this.b, chunkposition.x, chunkposition.y + 1, chunkposition.z) : (BlockMinecartTrack.g(this.b, chunkposition.x, chunkposition.y - 1, chunkposition.z) ? new MinecartTrackLogic(this.a, this.b, chunkposition.x, chunkposition.y - 1, chunkposition.z) : null));
}
private boolean b(MinecartTrackLogic minecarttracklogic) {
for (int i = 0; i < this.g.size(); ++i) {
ChunkPosition chunkposition = (ChunkPosition) this.g.get(i);
if (chunkposition.x == minecarttracklogic.c && chunkposition.z == minecarttracklogic.e) {
return true;
}
}
return false;
}
private boolean b(int i, int j, int k) {
for (int l = 0; l < this.g.size(); ++l) {
ChunkPosition chunkposition = (ChunkPosition) this.g.get(l);
if (chunkposition.x == i && chunkposition.z == k) {
return true;
}
}
return false;
}
private int b() {
int i = 0;
if (this.a(this.c, this.d, this.e - 1)) {
++i;
}
if (this.a(this.c, this.d, this.e + 1)) {
++i;
}
if (this.a(this.c - 1, this.d, this.e)) {
++i;
}
if (this.a(this.c + 1, this.d, this.e)) {
++i;
}
return i;
}
private boolean c(MinecartTrackLogic minecarttracklogic) {
if (this.b(minecarttracklogic)) {
return true;
} else if (this.g.size() == 2) {
return false;
} else if (this.g.size() == 0) {
return true;
} else {
ChunkPosition chunkposition = (ChunkPosition) this.g.get(0);
return minecarttracklogic.d == this.d && chunkposition.y == this.d ? true : true;
}
}
private void d(MinecartTrackLogic minecarttracklogic) {
this.g.add(new ChunkPosition(minecarttracklogic.c, minecarttracklogic.d, minecarttracklogic.e));
boolean flag = this.b(this.c, this.d, this.e - 1);
boolean flag1 = this.b(this.c, this.d, this.e + 1);
boolean flag2 = this.b(this.c - 1, this.d, this.e);
boolean flag3 = this.b(this.c + 1, this.d, this.e);
byte b0 = -1;
if (flag || flag1) {
b0 = 0;
}
if (flag2 || flag3) {
b0 = 1;
}
if (!this.f) {
if (flag1 && flag3 && !flag && !flag2) {
b0 = 6;
}
if (flag1 && flag2 && !flag && !flag3) {
b0 = 7;
}
if (flag && flag2 && !flag1 && !flag3) {
b0 = 8;
}
if (flag && flag3 && !flag1 && !flag2) {
b0 = 9;
}
}
if (b0 == 0) {
if (BlockMinecartTrack.g(this.b, this.c, this.d + 1, this.e - 1)) {
b0 = 4;
}
if (BlockMinecartTrack.g(this.b, this.c, this.d + 1, this.e + 1)) {
b0 = 5;
}
}
if (b0 == 1) {
if (BlockMinecartTrack.g(this.b, this.c + 1, this.d + 1, this.e)) {
b0 = 2;
}
if (BlockMinecartTrack.g(this.b, this.c - 1, this.d + 1, this.e)) {
b0 = 3;
}
}
if (b0 < 0) {
b0 = 0;
}
int i = b0;
if (this.f) {
i = this.b.getData(this.c, this.d, this.e) & 8 | b0;
}
this.b.setData(this.c, this.d, this.e, i);
}
private boolean c(int i, int j, int k) {
MinecartTrackLogic minecarttracklogic = this.a(new ChunkPosition(i, j, k));
if (minecarttracklogic == null) {
return false;
} else {
minecarttracklogic.a();
return minecarttracklogic.c(this);
}
}
public void a(boolean flag, boolean flag1) {
boolean flag2 = this.c(this.c, this.d, this.e - 1);
boolean flag3 = this.c(this.c, this.d, this.e + 1);
boolean flag4 = this.c(this.c - 1, this.d, this.e);
boolean flag5 = this.c(this.c + 1, this.d, this.e);
byte b0 = -1;
if ((flag2 || flag3) && !flag4 && !flag5) {
b0 = 0;
}
if ((flag4 || flag5) && !flag2 && !flag3) {
b0 = 1;
}
if (!this.f) {
if (flag3 && flag5 && !flag2 && !flag4) {
b0 = 6;
}
if (flag3 && flag4 && !flag2 && !flag5) {
b0 = 7;
}
if (flag2 && flag4 && !flag3 && !flag5) {
b0 = 8;
}
if (flag2 && flag5 && !flag3 && !flag4) {
b0 = 9;
}
}
if (b0 == -1) {
if (flag2 || flag3) {
b0 = 0;
}
if (flag4 || flag5) {
b0 = 1;
}
if (!this.f) {
if (flag) {
if (flag3 && flag5) {
b0 = 6;
}
if (flag4 && flag3) {
b0 = 7;
}
if (flag5 && flag2) {
b0 = 9;
}
if (flag2 && flag4) {
b0 = 8;
}
} else {
if (flag2 && flag4) {
b0 = 8;
}
if (flag5 && flag2) {
b0 = 9;
}
if (flag4 && flag3) {
b0 = 7;
}
if (flag3 && flag5) {
b0 = 6;
}
}
}
}
if (b0 == 0) {
if (BlockMinecartTrack.g(this.b, this.c, this.d + 1, this.e - 1)) {
b0 = 4;
}
if (BlockMinecartTrack.g(this.b, this.c, this.d + 1, this.e + 1)) {
b0 = 5;
}
}
if (b0 == 1) {
if (BlockMinecartTrack.g(this.b, this.c + 1, this.d + 1, this.e)) {
b0 = 2;
}
if (BlockMinecartTrack.g(this.b, this.c - 1, this.d + 1, this.e)) {
b0 = 3;
}
}
if (b0 < 0) {
b0 = 0;
}
this.a(b0);
int i = b0;
if (this.f) {
i = this.b.getData(this.c, this.d, this.e) & 8 | b0;
}
if (flag1 || this.b.getData(this.c, this.d, this.e) != i) {
this.b.setData(this.c, this.d, this.e, i);
for (int j = 0; j < this.g.size(); ++j) {
MinecartTrackLogic minecarttracklogic = this.a((ChunkPosition) this.g.get(j));
if (minecarttracklogic != null) {
minecarttracklogic.a();
if (minecarttracklogic.c(this)) {
minecarttracklogic.d(this);
}
}
}
}
}
static int a(MinecartTrackLogic minecarttracklogic) {
return minecarttracklogic.b();
}
}