2012-02-26 05:56:31 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
import org.bukkit.inventory.InventoryHolder; // CraftBukkit
|
2012-02-29 19:56:35 +01:00
|
|
|
|
2012-02-26 05:56:31 +01:00
|
|
|
public class TileEntity {
|
|
|
|
|
|
|
|
private static Map a = new HashMap();
|
|
|
|
private static Map b = new HashMap();
|
2012-07-29 09:33:13 +02:00
|
|
|
protected World world;
|
2012-02-26 05:56:31 +01:00
|
|
|
public int x;
|
|
|
|
public int y;
|
|
|
|
public int z;
|
|
|
|
protected boolean o;
|
|
|
|
public int p = -1;
|
|
|
|
public Block q;
|
|
|
|
|
|
|
|
public TileEntity() {}
|
|
|
|
|
|
|
|
private static void a(Class oclass, String s) {
|
2012-07-29 09:33:13 +02:00
|
|
|
if (a.containsKey(s)) {
|
2012-02-26 05:56:31 +01:00
|
|
|
throw new IllegalArgumentException("Duplicate id: " + s);
|
|
|
|
} else {
|
|
|
|
a.put(s, oclass);
|
|
|
|
b.put(oclass, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void b(World world) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.world = world;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean o() {
|
2012-07-29 09:33:13 +02:00
|
|
|
return this.world != null;
|
|
|
|
}
|
|
|
|
|
2012-02-26 05:56:31 +01:00
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
this.x = nbttagcompound.getInt("x");
|
|
|
|
this.y = nbttagcompound.getInt("y");
|
|
|
|
this.z = nbttagcompound.getInt("z");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
String s = (String) b.get(this.getClass());
|
|
|
|
|
|
|
|
if (s == null) {
|
|
|
|
throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!");
|
|
|
|
} else {
|
|
|
|
nbttagcompound.setString("id", s);
|
|
|
|
nbttagcompound.setInt("x", this.x);
|
|
|
|
nbttagcompound.setInt("y", this.y);
|
|
|
|
nbttagcompound.setInt("z", this.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void g() {}
|
2012-02-26 05:56:31 +01:00
|
|
|
|
|
|
|
public static TileEntity c(NBTTagCompound nbttagcompound) {
|
|
|
|
TileEntity tileentity = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Class oclass = (Class) a.get(nbttagcompound.getString("id"));
|
|
|
|
|
|
|
|
if (oclass != null) {
|
|
|
|
tileentity = (TileEntity) oclass.newInstance();
|
|
|
|
}
|
|
|
|
} catch (Exception exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tileentity != null) {
|
|
|
|
tileentity.a(nbttagcompound);
|
|
|
|
} else {
|
|
|
|
System.out.println("Skipping TileEntity with id " + nbttagcompound.getString("id"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return tileentity;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public int p() {
|
2012-02-26 05:56:31 +01:00
|
|
|
if (this.p == -1) {
|
|
|
|
this.p = this.world.getData(this.x, this.y, this.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.p;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void update() {
|
|
|
|
if (this.world != null) {
|
|
|
|
this.p = this.world.getData(this.x, this.y, this.z);
|
|
|
|
this.world.b(this.x, this.y, this.z, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public Block q() {
|
|
|
|
if (this.q == null) {
|
|
|
|
this.q = Block.byId[this.world.getTypeId(this.x, this.y, this.z)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.q;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Packet l() {
|
2012-02-26 05:56:31 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean r() {
|
2012-02-26 05:56:31 +01:00
|
|
|
return this.o;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void w_() {
|
2012-02-26 05:56:31 +01:00
|
|
|
this.o = true;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void s() {
|
2012-02-26 05:56:31 +01:00
|
|
|
this.o = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(int i, int j) {}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
public void h() {
|
2012-02-26 05:56:31 +01:00
|
|
|
this.q = null;
|
|
|
|
this.p = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
|
|
|
a(TileEntityFurnace.class, "Furnace");
|
|
|
|
a(TileEntityChest.class, "Chest");
|
2012-07-29 09:33:13 +02:00
|
|
|
a(TileEntityEnderChest.class, "EnderChest");
|
2012-02-26 05:56:31 +01:00
|
|
|
a(TileEntityRecordPlayer.class, "RecordPlayer");
|
|
|
|
a(TileEntityDispenser.class, "Trap");
|
|
|
|
a(TileEntitySign.class, "Sign");
|
|
|
|
a(TileEntityMobSpawner.class, "MobSpawner");
|
|
|
|
a(TileEntityNote.class, "Music");
|
|
|
|
a(TileEntityPiston.class, "Piston");
|
|
|
|
a(TileEntityBrewingStand.class, "Cauldron");
|
|
|
|
a(TileEntityEnchantTable.class, "EnchantTable");
|
|
|
|
a(TileEntityEnderPortal.class, "Airportal");
|
2012-10-25 05:53:23 +02:00
|
|
|
a(TileEntityCommand.class, "Control");
|
|
|
|
a(TileEntityBeacon.class, "Beacon");
|
|
|
|
a(TileEntitySkull.class, "Skull");
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2012-02-29 19:56:35 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
public InventoryHolder getOwner() {
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.block.BlockState state = world.getWorld().getBlockAt(x, y, z).getState();
|
2012-07-29 09:33:13 +02:00
|
|
|
if (state instanceof InventoryHolder) return (InventoryHolder) state;
|
2012-02-29 19:56:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|