Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 247 lines 9.8 kB view raw
1package net.minecraft.server; 2 3// CraftBukkit start 4 5import org.bukkit.Bukkit; 6import org.bukkit.event.server.MapInitializeEvent; 7// CraftBukkit end 8 9public class ItemWorldMap extends ItemWorldMapBase { 10 11 protected ItemWorldMap(int i) { 12 super(i); 13 this.c(1); 14 } 15 16 public WorldMap a(ItemStack itemstack, World world) { 17 18 WorldMap worldmap = (WorldMap) world.a(WorldMap.class, "map_" + itemstack.getData()); 19 20 if (worldmap == null) { 21 itemstack.b(world.b("map")); 22 String s = "map_" + itemstack.getData(); 23 24 worldmap = new WorldMap(s); 25 worldmap.b = world.q().c(); 26 worldmap.c = world.q().e(); 27 worldmap.e = 3; 28 worldmap.map = (byte) world.worldProvider.dimension; 29 worldmap.a(); 30 world.a(s, (WorldMapBase) worldmap); 31 32 // CraftBukkit start 33 MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView); 34 Bukkit.getServer().getPluginManager().callEvent(event); 35 // CraftBukkit end 36 } 37 38 return worldmap; 39 } 40 41 public void a(World world, Entity entity, WorldMap worldmap) { 42 if (((WorldServer) world).dimension == worldmap.map) { // CraftBukkit 43 short short1 = 128; 44 short short2 = 128; 45 int i = 1 << worldmap.e; 46 int j = worldmap.b; 47 int k = worldmap.c; 48 int l = MathHelper.floor(entity.locX - (double) j) / i + short1 / 2; 49 int i1 = MathHelper.floor(entity.locZ - (double) k) / i + short2 / 2; 50 int j1 = 128 / i; 51 52 if (world.worldProvider.e) { 53 j1 /= 2; 54 } 55 56 ++worldmap.g; 57 58 for (int k1 = l - j1 + 1; k1 < l + j1; ++k1) { 59 if ((k1 & 15) == (worldmap.g & 15)) { 60 int l1 = 255; 61 int i2 = 0; 62 double d0 = 0.0D; 63 64 for (int j2 = i1 - j1 - 1; j2 < i1 + j1; ++j2) { 65 if (k1 >= 0 && j2 >= -1 && k1 < short1 && j2 < short2) { 66 int k2 = k1 - l; 67 int l2 = j2 - i1; 68 boolean flag = k2 * k2 + l2 * l2 > (j1 - 2) * (j1 - 2); 69 int i3 = (j / i + k1 - short1 / 2) * i; 70 int j3 = (k / i + j2 - short2 / 2) * i; 71 byte b0 = 0; 72 byte b1 = 0; 73 byte b2 = 0; 74 int[] aint = new int[256]; 75 Chunk chunk = world.getChunkAtWorldCoords(i3, j3); 76 if (chunk.isEmpty()) continue; // CraftBukkit 77 int k3 = i3 & 15; 78 int l3 = j3 & 15; 79 int i4 = 0; 80 double d1 = 0.0D; 81 int j4; 82 int k4; 83 int l4; 84 int i5; 85 86 if (world.worldProvider.e) { 87 l4 = i3 + j3 * 231871; 88 l4 = l4 * l4 * 31287121 + l4 * 11; 89 if ((l4 >> 20 & 1) == 0) { 90 aint[Block.DIRT.id] += 10; 91 } else { 92 aint[Block.STONE.id] += 10; 93 } 94 95 d1 = 100.0D; 96 } else { 97 for (l4 = 0; l4 < i; ++l4) { 98 for (j4 = 0; j4 < i; ++j4) { 99 k4 = chunk.b(l4 + k3, j4 + l3) + 1; 100 int j5 = 0; 101 102 if (k4 > 1) { 103 boolean flag1 = false; 104 105 do { 106 flag1 = true; 107 j5 = chunk.getTypeId(l4 + k3, k4 - 1, j4 + l3); 108 if (j5 == 0) { 109 flag1 = false; 110 } else if (k4 > 0 && j5 > 0 && Block.byId[j5].material.C == MaterialMapColor.b) { 111 flag1 = false; 112 } 113 114 if (!flag1) { 115 --k4; 116 if (k4 <= 0) break; // CraftBukkit 117 j5 = chunk.getTypeId(l4 + k3, k4 - 1, j4 + l3); 118 } 119 } while (!flag1); 120 121 if (j5 != 0 && Block.byId[j5].material.isLiquid()) { 122 i5 = k4 - 1; 123 boolean flag2 = false; 124 125 int k5; 126 127 do { 128 k5 = chunk.getTypeId(l4 + k3, i5--, j4 + l3); 129 ++i4; 130 } while (i5 > 0 && k5 != 0 && Block.byId[k5].material.isLiquid()); 131 } 132 } 133 134 d1 += (double) k4 / (double) (i * i); 135 ++aint[j5]; 136 } 137 } 138 } 139 140 i4 /= i * i; 141 int l5 = b0 / (i * i); 142 143 l5 = b1 / (i * i); 144 l5 = b2 / (i * i); 145 l4 = 0; 146 j4 = 0; 147 148 for (k4 = 0; k4 < 256; ++k4) { 149 if (aint[k4] > l4) { 150 j4 = k4; 151 l4 = aint[k4]; 152 } 153 } 154 155 double d2 = (d1 - d0) * 4.0D / (double) (i + 4) + ((double) (k1 + j2 & 1) - 0.5D) * 0.4D; 156 byte b3 = 1; 157 158 if (d2 > 0.6D) { 159 b3 = 2; 160 } 161 162 if (d2 < -0.6D) { 163 b3 = 0; 164 } 165 166 i5 = 0; 167 if (j4 > 0) { 168 MaterialMapColor materialmapcolor = Block.byId[j4].material.C; 169 170 if (materialmapcolor == MaterialMapColor.n) { 171 d2 = (double) i4 * 0.1D + (double) (k1 + j2 & 1) * 0.2D; 172 b3 = 1; 173 if (d2 < 0.5D) { 174 b3 = 2; 175 } 176 177 if (d2 > 0.9D) { 178 b3 = 0; 179 } 180 } 181 182 i5 = materialmapcolor.q; 183 } 184 185 d0 = d1; 186 if (j2 >= 0 && k2 * k2 + l2 * l2 < j1 * j1 && (!flag || (k1 + j2 & 1) != 0)) { 187 byte b4 = worldmap.f[k1 + j2 * short1]; 188 byte b5 = (byte) (i5 * 4 + b3); 189 190 if (b4 != b5) { 191 if (l1 > j2) { 192 l1 = j2; 193 } 194 195 if (i2 < j2) { 196 i2 = j2; 197 } 198 199 worldmap.f[k1 + j2 * short1] = b5; 200 } 201 } 202 } 203 } 204 205 if (l1 <= i2) { 206 worldmap.a(k1, l1, i2); 207 } 208 } 209 } 210 } 211 } 212 213 public void a(ItemStack itemstack, World world, Entity entity, int i, boolean flag) { 214 if (!world.isStatic) { 215 WorldMap worldmap = this.a(itemstack, world); 216 217 if (entity instanceof EntityHuman) { 218 EntityHuman entityhuman = (EntityHuman) entity; 219 220 worldmap.a(entityhuman, itemstack); 221 } 222 223 if (flag) { 224 this.a(world, entity, worldmap); 225 } 226 } 227 } 228 229 public void c(ItemStack itemstack, World world, EntityHuman entityhuman) { 230 itemstack.b(world.b("map")); 231 String s = "map_" + itemstack.getData(); 232 WorldMap worldmap = new WorldMap(s); 233 234 world.a(s, (WorldMapBase) worldmap); 235 worldmap.b = MathHelper.floor(entityhuman.locX); 236 worldmap.c = MathHelper.floor(entityhuman.locZ); 237 worldmap.e = 3; 238 worldmap.map = (byte) ((WorldServer) world).dimension; // CraftBukkit 239 worldmap.a(); 240 } 241 242 public Packet b(ItemStack itemstack, World world, EntityHuman entityhuman) { 243 byte[] abyte = this.a(itemstack, world).a(itemstack, world, entityhuman); 244 245 return abyte == null ? null : new Packet131((short) Item.MAP.id, (short) itemstack.getData(), abyte); 246 } 247}