2011-05-31 19:04:52 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2012-10-25 05:53:23 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2011-05-31 19:04:52 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2011-07-03 08:42:26 +02:00
|
|
|
// CraftBukkit start
|
2011-07-13 07:16:59 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2011-07-03 08:42:26 +02:00
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
2011-08-13 04:47:47 +02:00
|
|
|
import org.bukkit.craftbukkit.map.CraftMapView;
|
2011-07-03 08:42:26 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-05-31 19:04:52 +02:00
|
|
|
public class WorldMap extends WorldMapBase {
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
public int centerX;
|
|
|
|
public int centerZ;
|
2011-06-27 00:25:01 +02:00
|
|
|
public byte map;
|
2011-11-30 00:17:43 +01:00
|
|
|
public byte scale;
|
|
|
|
public byte[] colors = new byte[16384];
|
2012-10-25 05:53:23 +02:00
|
|
|
public List f = new ArrayList();
|
|
|
|
private Map i = new HashMap();
|
|
|
|
public Map g = new LinkedHashMap();
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2011-07-03 08:42:26 +02:00
|
|
|
// CraftBukkit start
|
2011-08-13 04:47:47 +02:00
|
|
|
public final CraftMapView mapView;
|
2011-07-03 08:42:26 +02:00
|
|
|
private CraftServer server;
|
2011-07-13 06:06:07 +02:00
|
|
|
private UUID uniqueId = null;
|
2011-07-03 08:42:26 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-05-31 19:04:52 +02:00
|
|
|
public WorldMap(String s) {
|
|
|
|
super(s);
|
2011-08-13 04:47:47 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
mapView = new CraftMapView(this);
|
2012-07-22 08:18:00 +02:00
|
|
|
server = (CraftServer) org.bukkit.Bukkit.getServer();
|
2011-08-13 04:47:47 +02:00
|
|
|
// CraftBukkit end
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
2011-07-03 08:42:26 +02:00
|
|
|
// CraftBukkit start
|
2011-11-30 00:17:43 +01:00
|
|
|
byte dimension = nbttagcompound.getByte("dimension");
|
2011-07-03 08:42:26 +02:00
|
|
|
|
2011-07-07 21:29:57 +02:00
|
|
|
if (dimension >= 10) {
|
2011-07-13 06:06:07 +02:00
|
|
|
long least = nbttagcompound.getLong("UUIDLeast");
|
|
|
|
long most = nbttagcompound.getLong("UUIDMost");
|
|
|
|
|
|
|
|
if (least != 0L && most != 0L) {
|
|
|
|
this.uniqueId = new UUID(most, least);
|
2011-07-26 22:04:18 +02:00
|
|
|
|
|
|
|
CraftWorld world = (CraftWorld) server.getWorld(this.uniqueId);
|
|
|
|
// Check if the stored world details are correct.
|
|
|
|
if (world == null) {
|
|
|
|
/* All Maps which do not have their valid world loaded are set to a dimension which hopefully won't be reached.
|
|
|
|
This is to prevent them being corrupted with the wrong map data. */
|
|
|
|
dimension = 127;
|
|
|
|
} else {
|
|
|
|
dimension = (byte) world.getHandle().dimension;
|
|
|
|
}
|
2011-07-07 21:29:57 +02:00
|
|
|
}
|
2011-07-03 08:42:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.map = dimension;
|
|
|
|
// CraftBukkit end
|
2011-11-30 00:17:43 +01:00
|
|
|
this.centerX = nbttagcompound.getInt("xCenter");
|
|
|
|
this.centerZ = nbttagcompound.getInt("zCenter");
|
|
|
|
this.scale = nbttagcompound.getByte("scale");
|
|
|
|
if (this.scale < 0) {
|
|
|
|
this.scale = 0;
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
if (this.scale > 4) {
|
|
|
|
this.scale = 4;
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
short short1 = nbttagcompound.getShort("width");
|
|
|
|
short short2 = nbttagcompound.getShort("height");
|
2011-05-31 19:04:52 +02:00
|
|
|
|
|
|
|
if (short1 == 128 && short2 == 128) {
|
2011-11-30 00:17:43 +01:00
|
|
|
this.colors = nbttagcompound.getByteArray("colors");
|
2011-05-31 19:04:52 +02:00
|
|
|
} else {
|
2011-11-30 00:17:43 +01:00
|
|
|
byte[] abyte = nbttagcompound.getByteArray("colors");
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
this.colors = new byte[16384];
|
2011-05-31 19:04:52 +02:00
|
|
|
int i = (128 - short1) / 2;
|
|
|
|
int j = (128 - short2) / 2;
|
|
|
|
|
|
|
|
for (int k = 0; k < short2; ++k) {
|
|
|
|
int l = k + j;
|
|
|
|
|
|
|
|
if (l >= 0 || l < 128) {
|
|
|
|
for (int i1 = 0; i1 < short1; ++i1) {
|
|
|
|
int j1 = i1 + i;
|
|
|
|
|
|
|
|
if (j1 >= 0 || j1 < 128) {
|
2011-11-30 00:17:43 +01:00
|
|
|
this.colors[j1 + l * 128] = abyte[i1 + k * short1];
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
2011-07-03 08:42:26 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
if (this.map >= 10) {
|
2011-07-13 06:06:07 +02:00
|
|
|
if (this.uniqueId == null) {
|
2011-07-03 08:42:26 +02:00
|
|
|
for (org.bukkit.World world : server.getWorlds()) {
|
|
|
|
CraftWorld cWorld = (CraftWorld) world;
|
|
|
|
if (cWorld.getHandle().dimension == this.map) {
|
2011-07-13 06:06:07 +02:00
|
|
|
this.uniqueId = cWorld.getUID();
|
2011-07-03 08:42:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-26 22:04:18 +02:00
|
|
|
/* Perform a second check to see if a matching world was found, this is a necessary
|
|
|
|
change incase Maps are forcefully unlinked from a World and lack a UID.*/
|
|
|
|
if (this.uniqueId != null) {
|
|
|
|
nbttagcompound.setLong("UUIDLeast", this.uniqueId.getLeastSignificantBits());
|
|
|
|
nbttagcompound.setLong("UUIDMost", this.uniqueId.getMostSignificantBits());
|
|
|
|
}
|
2011-07-03 08:42:26 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-11-30 00:17:43 +01:00
|
|
|
nbttagcompound.setByte("dimension", this.map);
|
|
|
|
nbttagcompound.setInt("xCenter", this.centerX);
|
|
|
|
nbttagcompound.setInt("zCenter", this.centerZ);
|
|
|
|
nbttagcompound.setByte("scale", this.scale);
|
|
|
|
nbttagcompound.setShort("width", (short) 128);
|
|
|
|
nbttagcompound.setShort("height", (short) 128);
|
|
|
|
nbttagcompound.setByteArray("colors", this.colors);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityHuman entityhuman, ItemStack itemstack) {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!this.i.containsKey(entityhuman)) {
|
2011-05-31 19:04:52 +02:00
|
|
|
WorldMapHumanTracker worldmaphumantracker = new WorldMapHumanTracker(this, entityhuman);
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.i.put(entityhuman, worldmaphumantracker);
|
|
|
|
this.f.add(worldmaphumantracker);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!entityhuman.inventory.c(itemstack)) {
|
|
|
|
this.g.remove(entityhuman.getName());
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
for (int i = 0; i < this.f.size(); ++i) {
|
|
|
|
WorldMapHumanTracker worldmaphumantracker1 = (WorldMapHumanTracker) this.f.get(i);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!worldmaphumantracker1.trackee.dead && (worldmaphumantracker1.trackee.inventory.c(itemstack) || itemstack.z())) {
|
|
|
|
if (!itemstack.z() && worldmaphumantracker1.trackee.dimension == this.map) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.a(0, worldmaphumantracker1.trackee.world, worldmaphumantracker1.trackee.getName(), worldmaphumantracker1.trackee.locX, worldmaphumantracker1.trackee.locZ, (double) worldmaphumantracker1.trackee.yaw);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.i.remove(worldmaphumantracker1.trackee);
|
|
|
|
this.f.remove(worldmaphumantracker1);
|
|
|
|
}
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack.z()) {
|
|
|
|
this.a(1, entityhuman.world, "frame-" + itemstack.A().id, (double) itemstack.A().x, (double) itemstack.A().z, (double) (itemstack.A().direction * 90));
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
private void a(int i, World world, String s, double d0, double d1, double d2) {
|
|
|
|
int j = 1 << this.scale;
|
|
|
|
float f = (float) (d0 - (double) this.centerX) / (float) j;
|
|
|
|
float f1 = (float) (d1 - (double) this.centerZ) / (float) j;
|
|
|
|
byte b0 = (byte) ((int) ((double) (f * 2.0F) + 0.5D));
|
|
|
|
byte b1 = (byte) ((int) ((double) (f1 * 2.0F) + 0.5D));
|
|
|
|
byte b2 = 63;
|
|
|
|
byte b3;
|
|
|
|
|
|
|
|
if (f >= (float) (-b2) && f1 >= (float) (-b2) && f <= (float) b2 && f1 <= (float) b2) {
|
|
|
|
d2 += d2 < 0.0D ? -8.0D : 8.0D;
|
|
|
|
b3 = (byte) ((int) (d2 * 16.0D / 360.0D));
|
|
|
|
if (this.map < 0) {
|
2012-11-06 13:05:28 +01:00
|
|
|
int k = (int) (world.getWorldData().getDayTime() / 10L);
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
b3 = (byte) (k * k * 34187121 + k * 121 >> 15 & 15);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Math.abs(f) >= 320.0F || Math.abs(f1) >= 320.0F) {
|
|
|
|
this.g.remove(s);
|
|
|
|
return;
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
i = 6;
|
|
|
|
b3 = 0;
|
|
|
|
if (f <= (float) (-b2)) {
|
|
|
|
b0 = (byte) ((int) ((double) (b2 * 2) + 2.5D));
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (f1 <= (float) (-b2)) {
|
|
|
|
b1 = (byte) ((int) ((double) (b2 * 2) + 2.5D));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f >= (float) b2) {
|
|
|
|
b0 = (byte) (b2 * 2 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f1 >= (float) b2) {
|
|
|
|
b1 = (byte) (b2 * 2 + 1);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
this.g.put(s, new WorldMapDecoration(this, (byte) i, b0, b1, b3));
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
public byte[] getUpdatePacket(ItemStack itemstack, World world, EntityHuman entityhuman) {
|
2012-10-25 05:53:23 +02:00
|
|
|
WorldMapHumanTracker worldmaphumantracker = (WorldMapHumanTracker) this.i.get(entityhuman);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
return worldmaphumantracker == null ? null : worldmaphumantracker.a(itemstack);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
public void flagDirty(int i, int j, int k) {
|
2012-10-25 05:53:23 +02:00
|
|
|
super.c();
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
for (int l = 0; l < this.f.size(); ++l) {
|
|
|
|
WorldMapHumanTracker worldmaphumantracker = (WorldMapHumanTracker) this.f.get(l);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
|
|
|
if (worldmaphumantracker.b[i] < 0 || worldmaphumantracker.b[i] > j) {
|
|
|
|
worldmaphumantracker.b[i] = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (worldmaphumantracker.c[i] < 0 || worldmaphumantracker.c[i] < k) {
|
|
|
|
worldmaphumantracker.c[i] = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
public WorldMapHumanTracker a(EntityHuman entityhuman) {
|
|
|
|
WorldMapHumanTracker worldmaphumantracker = (WorldMapHumanTracker) this.i.get(entityhuman);
|
|
|
|
|
|
|
|
if (worldmaphumantracker == null) {
|
|
|
|
worldmaphumantracker = new WorldMapHumanTracker(this, entityhuman);
|
|
|
|
this.i.put(entityhuman, worldmaphumantracker);
|
|
|
|
this.f.add(worldmaphumantracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
return worldmaphumantracker;
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|