From c9979169b953816e5fe4449c4ee7cd5475577a24 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Wed, 13 Jul 2011 19:49:20 -0400 Subject: [PATCH] Possibly fixed crashes caused by tile entities under certain circumstances again. --- .../minecraft/server/TileEntityPiston.java | 130 ++++++++++++++++++ src/main/java/net/minecraft/server/World.java | 12 +- 2 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/minecraft/server/TileEntityPiston.java diff --git a/src/main/java/net/minecraft/server/TileEntityPiston.java b/src/main/java/net/minecraft/server/TileEntityPiston.java new file mode 100644 index 0000000000..15d885f3dd --- /dev/null +++ b/src/main/java/net/minecraft/server/TileEntityPiston.java @@ -0,0 +1,130 @@ +package net.minecraft.server; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class TileEntityPiston extends TileEntity { + + private int a; + private int b; + private int c; + private boolean i; + private boolean j; + private float k; + private float l; + private static List m = new ArrayList(); + + public TileEntityPiston() {} + + public TileEntityPiston(int i, int j, int k, boolean flag, boolean flag1) { + this.a = i; + this.b = j; + this.c = k; + this.i = flag; + this.j = flag1; + } + + public int a() { + return this.a; + } + + public int e() { + return this.b; + } + + public boolean c() { + return this.i; + } + + public int d() { + return this.c; + } + + public float a(float f) { + if (f > 1.0F) { + f = 1.0F; + } + + return this.l + (this.k - this.l) * f; + } + + private void a(float f, float f1) { + if (!this.i) { + --f; + } else { + f = 1.0F - f; + } + + AxisAlignedBB axisalignedbb = Block.PISTON_MOVING.a(this.world, this.x, this.y, this.z, this.a, f, this.c); + + if (axisalignedbb != null) { + List list = this.world.b((Entity) null, axisalignedbb); + + if (!list.isEmpty()) { + m.addAll(list); + Iterator iterator = m.iterator(); + + while (iterator.hasNext()) { + Entity entity = (Entity) iterator.next(); + + entity.move((double) (f1 * (float) PistonBlockTextures.b[this.c]), (double) (f1 * (float) PistonBlockTextures.c[this.c]), (double) (f1 * (float) PistonBlockTextures.d[this.c])); + } + + m.clear(); + } + } + } + + public void k() { + if (this.l < 1.0F) { + this.l = this.k = 1.0F; + this.world.o(this.x, this.y, this.z); + this.h(); + if (this.world.getTypeId(this.x, this.y, this.z) == Block.PISTON_MOVING.id) { + this.world.setTypeIdAndData(this.x, this.y, this.z, this.a, this.b); + } + } + } + + public void g_() { + // CraftBukkit + if (this.world == null) return; + this.l = this.k; + if (this.l >= 1.0F) { + this.a(1.0F, 0.25F); + this.world.o(this.x, this.y, this.z); + this.h(); + if (this.world.getTypeId(this.x, this.y, this.z) == Block.PISTON_MOVING.id) { + this.world.setTypeIdAndData(this.x, this.y, this.z, this.a, this.b); + } + } else { + this.k += 0.5F; + if (this.k >= 1.0F) { + this.k = 1.0F; + } + + if (this.i) { + this.a(this.k, this.k - this.l + 0.0625F); + } + } + } + + public void a(NBTTagCompound nbttagcompound) { + super.a(nbttagcompound); + this.a = nbttagcompound.e("blockId"); + this.b = nbttagcompound.e("blockData"); + this.c = nbttagcompound.e("facing"); + this.l = this.k = nbttagcompound.g("progress"); + this.i = nbttagcompound.m("extending"); + } + + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + nbttagcompound.a("blockId", this.a); + nbttagcompound.a("blockData", this.b); + nbttagcompound.a("facing", this.c); + nbttagcompound.a("progress", this.l); + nbttagcompound.a("extending", this.i); + } +} diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index 77bffbebf0..736ae38c05 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -1144,14 +1144,20 @@ public class World implements IBlockAccess { TileEntity tileentity1 = (TileEntity) iterator1.next(); if (!tileentity1.g()) { - if (!this.c.contains(tileentity1)) { + // CraftBukkit - order matters, moved down + /* if (!this.c.contains(tileentity1)) { this.c.add(tileentity1); - } + } */ Chunk chunk1 = this.getChunkAt(tileentity1.x >> 4, tileentity1.z >> 4); if (chunk1 != null) { chunk1.a(tileentity1.x & 15, tileentity1.y, tileentity1.z & 15, tileentity1); + // CraftBukkit start - moved in from above + if (!this.c.contains(tileentity1)) { + this.c.add(tileentity1); + } + // CraftBukkit end } this.notify(tileentity1.x, tileentity1.y, tileentity1.z); @@ -1539,8 +1545,8 @@ public class World implements IBlockAccess { if (chunk != null) { chunk.a(i & 15, j, k & 15, tileentity); + this.c.add(tileentity); // CraftBukkit - moved in from above } - this.c.add(tileentity); } } }