Paper/src/main/java/net/minecraft/server/ItemWorldMap.java

258 Zeilen
11 KiB
Java

2011-05-31 19:04:52 +02:00
package net.minecraft.server;
// 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-07-29 09:33:13 +02:00
this.d(1);
this.a(CreativeModeTab.f);
2011-05-31 19:04:52 +02:00
}
2012-01-12 16:27:39 +01:00
public WorldMap getSavedMap(ItemStack itemstack, World world) {
2011-05-31 19:04:52 +02:00
WorldMap worldmap = (WorldMap) world.a(WorldMap.class, "map_" + itemstack.getData());
if (worldmap == null) {
itemstack.setData(world.b("map"));
2011-05-31 19:04:52 +02:00
String s = "map_" + itemstack.getData();
worldmap = new WorldMap(s);
worldmap.centerX = world.getWorldData().c();
worldmap.centerZ = world.getWorldData().e();
worldmap.scale = 3;
worldmap.map = (byte) ((WorldServer) world).dimension; // CraftBukkit - fixes Bukkit multiworld maps.
2011-05-31 19:04:52 +02:00
worldmap.a();
world.a(s, (WorldMapBase) worldmap);
2011-09-15 02:23:52 +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) {
if (((WorldServer) world).dimension == worldmap.map) { // CraftBukkit
2011-05-31 19:04:52 +02:00
short short1 = 128;
short short2 = 128;
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;
2012-03-01 11:49:23 +01:00
if (world.worldProvider.e) {
2011-05-31 19:04:52 +02:00
j1 /= 2;
}
2012-07-29 09:33:13 +02:00
++worldmap.f;
2011-05-31 19:04:52 +02:00
for (int k1 = l - j1 + 1; k1 < l + j1; ++k1) {
2012-07-29 09:33:13 +02:00
if ((k1 & 15) == (worldmap.f & 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;
byte b0 = 0;
byte b1 = 0;
byte b2 = 0;
int[] aint = new int[256];
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;
if (world.worldProvider.e) {
l4 = i3 + j3 * 231871;
l4 = l4 * l4 * 31287121 + l4 * 11;
if ((l4 >> 20 & 1) == 0) {
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 {
for (l4 = 0; l4 < i; ++l4) {
for (j4 = 0; j4 < i; ++j4) {
k4 = chunk.b(l4 + k3, j4 + l3) + 1;
int j5 = 0;
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
if (k4 > 1) {
boolean flag1 = false;
2011-05-31 19:04:52 +02:00
do {
2012-07-29 09:33:13 +02:00
flag1 = true;
j5 = chunk.getTypeId(l4 + k3, k4 - 1, j4 + l3);
if (j5 == 0) {
flag1 = false;
} else if (k4 > 0 && j5 > 0 && Block.byId[j5].material.F == MaterialMapColor.b) {
flag1 = false;
}
if (!flag1) {
--k4;
if (k4 <= 0) {
break;
}
j5 = chunk.getTypeId(l4 + k3, k4 - 1, j4 + l3);
}
} while (k4 > 0 && !flag1);
if (k4 > 0 && j5 != 0 && Block.byId[j5].material.isLiquid()) {
i5 = k4 - 1;
boolean flag2 = false;
int k5;
do {
k5 = chunk.getTypeId(l4 + k3, i5--, j4 + l3);
++i4;
} while (i5 > 0 && k5 != 0 && Block.byId[k5].material.isLiquid());
}
2011-05-31 19:04:52 +02:00
}
2012-07-29 09:33:13 +02:00
d1 += (double) k4 / (double) (i * i);
++aint[j5];
}
2011-05-31 19:04:52 +02:00
}
}
2012-07-29 09:33:13 +02:00
i4 /= i * i;
int l5 = b0 / (i * i);
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
l5 = b1 / (i * i);
l5 = b2 / (i * i);
l4 = 0;
j4 = 0;
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
for (k4 = 0; k4 < 256; ++k4) {
if (aint[k4] > l4) {
j4 = k4;
l4 = aint[k4];
}
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;
byte b3 = 1;
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
if (d2 > 0.6D) {
b3 = 2;
}
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
if (d2 < -0.6D) {
b3 = 0;
}
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
i5 = 0;
if (j4 > 0) {
MaterialMapColor materialmapcolor = Block.byId[j4].material.F;
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;
b3 = 1;
if (d2 < 0.5D) {
b3 = 2;
}
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
if (d2 > 0.9D) {
b3 = 0;
}
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)) {
byte b4 = worldmap.colors[k1 + j2 * short1];
byte b5 = (byte) (i5 * 4 + b3);
2011-05-31 19:04:52 +02:00
2012-07-29 09:33:13 +02:00
if (b4 != b5) {
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-07-29 09:33:13 +02:00
worldmap.colors[k1 + j2 * short1] = b5;
2011-05-31 19:04:52 +02:00
}
}
}
}
}
if (l1 <= i2) {
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 void d(ItemStack itemstack, World world, EntityHuman entityhuman) {
itemstack.setData(world.b("map"));
2011-05-31 19:04:52 +02:00
String s = "map_" + itemstack.getData();
WorldMap worldmap = new WorldMap(s);
world.a(s, (WorldMapBase) worldmap);
worldmap.centerX = MathHelper.floor(entityhuman.locX);
worldmap.centerZ = MathHelper.floor(entityhuman.locZ);
worldmap.scale = 3;
worldmap.map = (byte) ((WorldServer) world).dimension; // CraftBukkit - fixes Bukkit multiworld maps.
2011-05-31 19:04:52 +02:00
worldmap.a();
// CraftBukkit start
MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
Bukkit.getServer().getPluginManager().callEvent(event);
// CraftBukkit end
2011-05-31 19:04:52 +02:00
}
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
return abyte == null ? null : new Packet131ItemData((short) Item.MAP.id, (short) itemstack.getData(), abyte);
2011-05-31 19:04:52 +02:00
}
}