2011-05-31 19:04:52 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-08-13 04:47:47 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.event.server.MapInitializeEvent;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-05-31 19:04:52 +02:00
|
|
|
public class ItemWorldMap extends ItemWorldMapBase {
|
|
|
|
|
|
|
|
protected ItemWorldMap(int i) {
|
|
|
|
super(i);
|
2012-10-25 05:53:23 +02:00
|
|
|
this.a(true);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:27:39 +01:00
|
|
|
public WorldMap getSavedMap(ItemStack itemstack, World world) {
|
2012-10-25 05:53:23 +02:00
|
|
|
String s = "map_" + itemstack.getData();
|
|
|
|
WorldMap worldmap = (WorldMap) world.a(WorldMap.class, s);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (worldmap == null && !world.isStatic) {
|
2011-11-30 00:17:43 +01:00
|
|
|
itemstack.setData(world.b("map"));
|
2012-10-25 05:53:23 +02:00
|
|
|
s = "map_" + itemstack.getData();
|
2011-05-31 19:04:52 +02:00
|
|
|
worldmap = new WorldMap(s);
|
2011-11-30 00:17:43 +01:00
|
|
|
worldmap.scale = 3;
|
2012-10-25 05:53:23 +02:00
|
|
|
int i = 128 * (1 << worldmap.scale);
|
|
|
|
|
|
|
|
worldmap.centerX = Math.round((float) world.getWorldData().c() / (float) i) * i;
|
|
|
|
worldmap.centerZ = Math.round((float) (world.getWorldData().e() / i)) * i;
|
|
|
|
worldmap.map = (byte) ((WorldServer) world).dimension; // CraftBukkit - fixes Bukkit multiworld maps
|
|
|
|
worldmap.c();
|
2011-05-31 19:04:52 +02:00
|
|
|
world.a(s, (WorldMapBase) worldmap);
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2011-08-13 04:47:47 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
// CraftBukkit end
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return worldmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(World world, Entity entity, WorldMap worldmap) {
|
2012-10-25 05:53:23 +02:00
|
|
|
// CraftBukkit
|
|
|
|
if (((WorldServer) world).dimension == worldmap.map && entity instanceof EntityHuman) {
|
2011-05-31 19:04:52 +02:00
|
|
|
short short1 = 128;
|
|
|
|
short short2 = 128;
|
2011-11-30 00:17:43 +01:00
|
|
|
int i = 1 << worldmap.scale;
|
|
|
|
int j = worldmap.centerX;
|
|
|
|
int k = worldmap.centerZ;
|
2011-05-31 19:04:52 +02:00
|
|
|
int l = MathHelper.floor(entity.locX - (double) j) / i + short1 / 2;
|
|
|
|
int i1 = MathHelper.floor(entity.locZ - (double) k) / i + short2 / 2;
|
|
|
|
int j1 = 128 / i;
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (world.worldProvider.g) {
|
2011-05-31 19:04:52 +02:00
|
|
|
j1 /= 2;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
WorldMapHumanTracker worldmaphumantracker = worldmap.a((EntityHuman) entity);
|
|
|
|
|
|
|
|
++worldmaphumantracker.d;
|
2011-05-31 19:04:52 +02:00
|
|
|
|
|
|
|
for (int k1 = l - j1 + 1; k1 < l + j1; ++k1) {
|
2012-10-25 05:53:23 +02:00
|
|
|
if ((k1 & 15) == (worldmaphumantracker.d & 15)) {
|
2011-05-31 19:04:52 +02:00
|
|
|
int l1 = 255;
|
|
|
|
int i2 = 0;
|
|
|
|
double d0 = 0.0D;
|
|
|
|
|
|
|
|
for (int j2 = i1 - j1 - 1; j2 < i1 + j1; ++j2) {
|
|
|
|
if (k1 >= 0 && j2 >= -1 && k1 < short1 && j2 < short2) {
|
|
|
|
int k2 = k1 - l;
|
|
|
|
int l2 = j2 - i1;
|
|
|
|
boolean flag = k2 * k2 + l2 * l2 > (j1 - 2) * (j1 - 2);
|
|
|
|
int i3 = (j / i + k1 - short1 / 2) * i;
|
|
|
|
int j3 = (k / i + j2 - short2 / 2) * i;
|
|
|
|
int[] aint = new int[256];
|
2011-06-27 00:25:01 +02:00
|
|
|
Chunk chunk = world.getChunkAtWorldCoords(i3, j3);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!chunk.isEmpty()) {
|
|
|
|
int k3 = i3 & 15;
|
|
|
|
int l3 = j3 & 15;
|
|
|
|
int i4 = 0;
|
|
|
|
double d1 = 0.0D;
|
|
|
|
int j4;
|
|
|
|
int k4;
|
|
|
|
int l4;
|
|
|
|
int i5;
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (world.worldProvider.g) {
|
2012-10-25 05:53:23 +02:00
|
|
|
j4 = i3 + j3 * 231871;
|
|
|
|
j4 = j4 * j4 * 31287121 + j4 * 11;
|
|
|
|
if ((j4 >> 20 & 1) == 0) {
|
2012-07-29 09:33:13 +02:00
|
|
|
aint[Block.DIRT.id] += 10;
|
|
|
|
} else {
|
|
|
|
aint[Block.STONE.id] += 10;
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
d1 = 100.0D;
|
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
for (j4 = 0; j4 < i; ++j4) {
|
|
|
|
for (k4 = 0; k4 < i; ++k4) {
|
|
|
|
l4 = chunk.b(j4 + k3, k4 + l3) + 1;
|
2012-07-29 09:33:13 +02:00
|
|
|
int j5 = 0;
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (l4 > 1) {
|
|
|
|
boolean flag1;
|
2011-05-31 19:04:52 +02:00
|
|
|
|
|
|
|
do {
|
2012-07-29 09:33:13 +02:00
|
|
|
flag1 = true;
|
2012-10-25 05:53:23 +02:00
|
|
|
j5 = chunk.getTypeId(j4 + k3, l4 - 1, k4 + l3);
|
2012-07-29 09:33:13 +02:00
|
|
|
if (j5 == 0) {
|
|
|
|
flag1 = false;
|
2013-07-01 13:03:00 +02:00
|
|
|
} else if (l4 > 0 && j5 > 0 && Block.byId[j5].material.H == MaterialMapColor.b) {
|
2012-07-29 09:33:13 +02:00
|
|
|
flag1 = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag1) {
|
2012-10-25 05:53:23 +02:00
|
|
|
--l4;
|
|
|
|
if (l4 <= 0) {
|
2012-07-29 09:33:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
j5 = chunk.getTypeId(j4 + k3, l4 - 1, k4 + l3);
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
} while (l4 > 0 && !flag1);
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (l4 > 0 && j5 != 0 && Block.byId[j5].material.isLiquid()) {
|
|
|
|
i5 = l4 - 1;
|
2012-07-29 09:33:13 +02:00
|
|
|
boolean flag2 = false;
|
|
|
|
|
|
|
|
int k5;
|
|
|
|
|
|
|
|
do {
|
2012-10-25 05:53:23 +02:00
|
|
|
k5 = chunk.getTypeId(j4 + k3, i5--, k4 + l3);
|
2012-07-29 09:33:13 +02:00
|
|
|
++i4;
|
|
|
|
} while (i5 > 0 && k5 != 0 && Block.byId[k5].material.isLiquid());
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
d1 += (double) l4 / (double) (i * i);
|
2012-07-29 09:33:13 +02:00
|
|
|
++aint[j5];
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
i4 /= i * i;
|
|
|
|
j4 = 0;
|
2012-10-25 05:53:23 +02:00
|
|
|
k4 = 0;
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
for (l4 = 0; l4 < 256; ++l4) {
|
|
|
|
if (aint[l4] > j4) {
|
|
|
|
k4 = l4;
|
|
|
|
j4 = aint[l4];
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
double d2 = (d1 - d0) * 4.0D / (double) (i + 4) + ((double) (k1 + j2 & 1) - 0.5D) * 0.4D;
|
2012-10-25 05:53:23 +02:00
|
|
|
byte b0 = 1;
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (d2 > 0.6D) {
|
2012-10-25 05:53:23 +02:00
|
|
|
b0 = 2;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (d2 < -0.6D) {
|
2012-10-25 05:53:23 +02:00
|
|
|
b0 = 0;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
i5 = 0;
|
2012-10-25 05:53:23 +02:00
|
|
|
if (k4 > 0) {
|
2013-07-01 13:03:00 +02:00
|
|
|
MaterialMapColor materialmapcolor = Block.byId[k4].material.H;
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (materialmapcolor == MaterialMapColor.n) {
|
|
|
|
d2 = (double) i4 * 0.1D + (double) (k1 + j2 & 1) * 0.2D;
|
2012-10-25 05:53:23 +02:00
|
|
|
b0 = 1;
|
2012-07-29 09:33:13 +02:00
|
|
|
if (d2 < 0.5D) {
|
2012-10-25 05:53:23 +02:00
|
|
|
b0 = 2;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (d2 > 0.9D) {
|
2012-10-25 05:53:23 +02:00
|
|
|
b0 = 0;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
|
|
|
i5 = materialmapcolor.q;
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
d0 = d1;
|
|
|
|
if (j2 >= 0 && k2 * k2 + l2 * l2 < j1 * j1 && (!flag || (k1 + j2 & 1) != 0)) {
|
2012-10-25 05:53:23 +02:00
|
|
|
byte b1 = worldmap.colors[k1 + j2 * short1];
|
|
|
|
byte b2 = (byte) (i5 * 4 + b0);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (b1 != b2) {
|
2012-07-29 09:33:13 +02:00
|
|
|
if (l1 > j2) {
|
|
|
|
l1 = j2;
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (i2 < j2) {
|
|
|
|
i2 = j2;
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
worldmap.colors[k1 + j2 * short1] = b2;
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l1 <= i2) {
|
2011-11-30 00:17:43 +01:00
|
|
|
worldmap.flagDirty(k1, l1, i2);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
|
|
|
|
if (!world.isStatic) {
|
2012-01-12 16:27:39 +01:00
|
|
|
WorldMap worldmap = this.getSavedMap(itemstack, world);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
|
|
|
if (entity instanceof EntityHuman) {
|
|
|
|
EntityHuman entityhuman = (EntityHuman) entity;
|
|
|
|
|
|
|
|
worldmap.a(entityhuman, itemstack);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
this.a(world, entity, worldmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
public Packet c(ItemStack itemstack, World world, EntityHuman entityhuman) {
|
2012-01-12 16:27:39 +01:00
|
|
|
byte[] abyte = this.getSavedMap(itemstack, world).getUpdatePacket(itemstack, world, entityhuman);
|
2011-05-31 19:04:52 +02:00
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
return abyte == null ? null : new Packet131ItemData((short) Item.MAP.id, (short) itemstack.getData(), abyte);
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
public void d(ItemStack itemstack, World world, EntityHuman entityhuman) {
|
|
|
|
if (itemstack.hasTag() && itemstack.getTag().getBoolean("map_is_scaling")) {
|
|
|
|
WorldMap worldmap = Item.MAP.getSavedMap(itemstack, world);
|
|
|
|
|
|
|
|
itemstack.setData(world.b("map"));
|
|
|
|
WorldMap worldmap1 = new WorldMap("map_" + itemstack.getData());
|
|
|
|
|
|
|
|
worldmap1.scale = (byte) (worldmap.scale + 1);
|
|
|
|
if (worldmap1.scale > 4) {
|
|
|
|
worldmap1.scale = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
worldmap1.centerX = worldmap.centerX;
|
|
|
|
worldmap1.centerZ = worldmap.centerZ;
|
|
|
|
worldmap1.map = worldmap.map;
|
|
|
|
worldmap1.c();
|
|
|
|
world.a("map_" + itemstack.getData(), (WorldMapBase) worldmap1);
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
MapInitializeEvent event = new MapInitializeEvent(worldmap1.mapView);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
2011-05-31 19:04:52 +02:00
|
|
|
}
|