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

131 lines
3.4 KiB
Java
Raw Normal View History

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;
2011-09-15 02:23:52 +02:00
private boolean d;
private boolean e;
private float f;
private float g;
private static List h = 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;
2011-09-15 02:23:52 +02:00
this.d = flag;
this.e = flag1;
}
public int a() {
return this.a;
}
2011-09-15 02:23:52 +02:00
public int j() {
return this.b;
}
public boolean c() {
2011-09-15 02:23:52 +02:00
return this.d;
}
public int d() {
return this.c;
}
public float a(float f) {
if (f > 1.0F) {
f = 1.0F;
}
2011-09-15 02:23:52 +02:00
return this.g + (this.f - this.g) * f;
}
private void a(float f, float f1) {
2011-09-15 02:23:52 +02:00
if (!this.d) {
--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()) {
2011-09-15 02:23:52 +02:00
h.addAll(list);
Iterator iterator = h.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]));
}
2011-09-15 02:23:52 +02:00
h.clear();
}
}
}
2011-09-15 02:23:52 +02:00
public void e() {
if (this.g < 1.0F) {
this.g = this.f = 1.0F;
this.world.n(this.x, this.y, this.z);
this.i();
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);
}
}
}
2011-09-15 02:23:52 +02:00
public void h_() {
if (this.world == null) return; // CraftBukkit
this.g = this.f;
if (this.g >= 1.0F) {
this.a(1.0F, 0.25F);
2011-09-15 02:23:52 +02:00
this.world.n(this.x, this.y, this.z);
this.i();
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 {
2011-09-15 02:23:52 +02:00
this.f += 0.5F;
if (this.f >= 1.0F) {
this.f = 1.0F;
}
2011-09-15 02:23:52 +02:00
if (this.d) {
this.a(this.f, this.f - this.g + 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");
2011-09-15 02:23:52 +02:00
this.g = this.f = nbttagcompound.g("progress");
this.d = 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);
2011-09-15 02:23:52 +02:00
nbttagcompound.a("progress", this.g);
nbttagcompound.a("extending", this.d);
}
}