Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 202 lines 7.1 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.Bukkit; 4import org.bukkit.craftbukkit.CraftServer; 5import org.bukkit.craftbukkit.CraftWorld; 6import org.bukkit.craftbukkit.map.CraftMapView; 7 8import java.util.*; 9 10// CraftBukkit start 11// CraftBukkit end 12 13public class WorldMap extends WorldMapBase { 14 15 public int b; 16 public int c; 17 public byte map; 18 public byte e; 19 public byte[] f = new byte[16384]; 20 public int g; 21 public List h = new ArrayList(); 22 private Map j = new HashMap(); 23 public List i = new ArrayList(); 24 25 // CraftBukkit start 26 public final CraftMapView mapView; 27 private CraftServer server; 28 private UUID uniqueId = null; 29 // CraftBukkit end 30 31 public WorldMap(String s) { 32 super(s); 33 // CraftBukkit start 34 mapView = new CraftMapView(this); 35 server = (CraftServer) Bukkit.getServer(); 36 // CraftBukkit end 37 } 38 39 public void a(NBTTagCompound nbttagcompound) { 40 // CraftBukkit start 41 byte dimension = nbttagcompound.c("dimension"); 42 43 if (dimension >= 10) { 44 long least = nbttagcompound.getLong("UUIDLeast"); 45 long most = nbttagcompound.getLong("UUIDMost"); 46 47 if (least != 0L && most != 0L) { 48 this.uniqueId = new UUID(most, least); 49 50 CraftWorld world = (CraftWorld) server.getWorld(this.uniqueId); 51 // Check if the stored world details are correct. 52 if (world == null) { 53 /* All Maps which do not have their valid world loaded are set to a dimension which hopefully won't be reached. 54 This is to prevent them being corrupted with the wrong map data. */ 55 dimension = 127; 56 } else { 57 dimension = (byte) world.getHandle().dimension; 58 } 59 } 60 } 61 62 this.map = dimension; 63 // CraftBukkit end 64 this.b = nbttagcompound.e("xCenter"); 65 this.c = nbttagcompound.e("zCenter"); 66 this.e = nbttagcompound.c("scale"); 67 if (this.e < 0) { 68 this.e = 0; 69 } 70 71 if (this.e > 4) { 72 this.e = 4; 73 } 74 75 short short1 = nbttagcompound.d("width"); 76 short short2 = nbttagcompound.d("height"); 77 78 if (short1 == 128 && short2 == 128) { 79 this.f = nbttagcompound.j("colors"); 80 } else { 81 byte[] abyte = nbttagcompound.j("colors"); 82 83 this.f = new byte[16384]; 84 int i = (128 - short1) / 2; 85 int j = (128 - short2) / 2; 86 87 for (int k = 0; k < short2; ++k) { 88 int l = k + j; 89 90 if (l >= 0 || l < 128) { 91 for (int i1 = 0; i1 < short1; ++i1) { 92 int j1 = i1 + i; 93 94 if (j1 >= 0 || j1 < 128) { 95 this.f[j1 + l * 128] = abyte[i1 + k * short1]; 96 } 97 } 98 } 99 } 100 } 101 } 102 103 public void b(NBTTagCompound nbttagcompound) { 104 // CraftBukkit start 105 if (this.map >= 10) { 106 if (this.uniqueId == null) { 107 for (org.bukkit.World world : server.getWorlds()) { 108 CraftWorld cWorld = (CraftWorld) world; 109 if (cWorld.getHandle().dimension == this.map) { 110 this.uniqueId = cWorld.getUID(); 111 break; 112 } 113 } 114 } 115 /* Perform a second check to see if a matching world was found, this is a necessary 116 change incase Maps are forcefully unlinked from a World and lack a UID.*/ 117 if (this.uniqueId != null) { 118 nbttagcompound.setLong("UUIDLeast", this.uniqueId.getLeastSignificantBits()); 119 nbttagcompound.setLong("UUIDMost", this.uniqueId.getMostSignificantBits()); 120 } 121 } 122 // CraftBukkit end 123 nbttagcompound.a("dimension", this.map); 124 nbttagcompound.a("xCenter", this.b); 125 nbttagcompound.a("zCenter", this.c); 126 nbttagcompound.a("scale", this.e); 127 nbttagcompound.a("width", (short) 128); 128 nbttagcompound.a("height", (short) 128); 129 nbttagcompound.a("colors", this.f); 130 } 131 132 public void a(EntityHuman entityhuman, ItemStack itemstack) { 133 if (!this.j.containsKey(entityhuman)) { 134 WorldMapHumanTracker worldmaphumantracker = new WorldMapHumanTracker(this, entityhuman); 135 136 this.j.put(entityhuman, worldmaphumantracker); 137 this.h.add(worldmaphumantracker); 138 } 139 140 this.i.clear(); 141 142 for (int i = 0; i < this.h.size(); ++i) { 143 WorldMapHumanTracker worldmaphumantracker1 = (WorldMapHumanTracker) this.h.get(i); 144 145 if (!worldmaphumantracker1.trackee.dead && worldmaphumantracker1.trackee.inventory.c(itemstack)) { 146 float f = (float) (worldmaphumantracker1.trackee.locX - (double) this.b) / (float) (1 << this.e); 147 float f1 = (float) (worldmaphumantracker1.trackee.locZ - (double) this.c) / (float) (1 << this.e); 148 byte b0 = 64; 149 byte b1 = 64; 150 151 if (f >= (float) (-b0) && f1 >= (float) (-b1) && f <= (float) b0 && f1 <= (float) b1) { 152 byte b2 = 0; 153 byte b3 = (byte) ((int) ((double) (f * 2.0F) + 0.5D)); 154 byte b4 = (byte) ((int) ((double) (f1 * 2.0F) + 0.5D)); 155 // CraftBukkit 156 byte b5 = (byte) ((int) ((double) (worldmaphumantracker1.trackee.yaw * 16.0F / 360.0F) + 0.5D)); 157 158 if (this.map < 0) { 159 int j = this.g / 10; 160 161 b5 = (byte) (j * j * 34187121 + j * 121 >> 15 & 15); 162 } 163 164 if (worldmaphumantracker1.trackee.dimension == this.map) { 165 this.i.add(new WorldMapOrienter(this, b2, b3, b4, b5)); 166 } 167 } 168 } else { 169 this.j.remove(worldmaphumantracker1.trackee); 170 this.h.remove(worldmaphumantracker1); 171 } 172 } 173 } 174 175 public byte[] a(ItemStack itemstack, World world, EntityHuman entityhuman) { 176 WorldMapHumanTracker worldmaphumantracker = (WorldMapHumanTracker) this.j.get(entityhuman); 177 178 if (worldmaphumantracker == null) { 179 return null; 180 } else { 181 byte[] abyte = worldmaphumantracker.a(itemstack); 182 183 return abyte; 184 } 185 } 186 187 public void a(int i, int j, int k) { 188 super.a(); 189 190 for (int l = 0; l < this.h.size(); ++l) { 191 WorldMapHumanTracker worldmaphumantracker = (WorldMapHumanTracker) this.h.get(l); 192 193 if (worldmaphumantracker.b[i] < 0 || worldmaphumantracker.b[i] > j) { 194 worldmaphumantracker.b[i] = j; 195 } 196 197 if (worldmaphumantracker.c[i] < 0 || worldmaphumantracker.c[i] < k) { 198 worldmaphumantracker.c[i] = k; 199 } 200 } 201 } 202}