2016-04-29 23:24:59 +02:00
|
|
|
package com.boydti.fawe.bukkit.v1_8;
|
|
|
|
|
|
|
|
import com.boydti.fawe.FaweCache;
|
|
|
|
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
|
|
|
|
import com.boydti.fawe.example.CharFaweChunk;
|
|
|
|
import com.boydti.fawe.object.FaweChunk;
|
2016-05-06 00:59:21 +02:00
|
|
|
import com.boydti.fawe.object.RunnableVal;
|
2016-05-19 09:41:55 +02:00
|
|
|
import com.boydti.fawe.util.MainUtil;
|
2016-05-06 00:59:21 +02:00
|
|
|
import com.boydti.fawe.util.MathMan;
|
|
|
|
import com.boydti.fawe.util.ReflectionUtils;
|
2016-05-20 10:55:26 +02:00
|
|
|
import com.boydti.fawe.util.TaskManager;
|
2016-05-06 00:59:21 +02:00
|
|
|
import com.sk89q.jnbt.CompoundTag;
|
|
|
|
import com.sk89q.jnbt.StringTag;
|
|
|
|
import com.sk89q.jnbt.Tag;
|
2016-07-15 01:53:30 +02:00
|
|
|
import java.io.File;
|
2016-04-29 23:24:59 +02:00
|
|
|
import java.lang.reflect.Field;
|
2016-07-15 01:53:30 +02:00
|
|
|
import java.util.Arrays;
|
2016-04-29 23:24:59 +02:00
|
|
|
import java.util.Collection;
|
2016-09-02 05:23:58 +02:00
|
|
|
import java.util.Collections;
|
2016-05-20 10:55:26 +02:00
|
|
|
import java.util.List;
|
2016-04-29 23:24:59 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2016-05-12 19:46:38 +02:00
|
|
|
import java.util.UUID;
|
2016-11-24 07:36:44 +01:00
|
|
|
import net.minecraft.server.v1_8_R3.*;
|
2016-04-29 23:24:59 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.World;
|
2016-07-15 01:53:30 +02:00
|
|
|
import org.bukkit.WorldCreator;
|
2016-04-29 23:24:59 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
|
2016-07-15 01:53:30 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
|
|
|
import org.bukkit.event.world.WorldInitEvent;
|
|
|
|
import org.bukkit.event.world.WorldLoadEvent;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
2016-04-29 23:24:59 +02:00
|
|
|
|
2016-07-27 00:03:51 +02:00
|
|
|
public class BukkitQueue18R3 extends BukkitQueue_0<Chunk, ChunkSection[], ChunkSection> {
|
2016-04-29 23:24:59 +02:00
|
|
|
|
2016-08-28 11:03:42 +02:00
|
|
|
public static Field isDirty;
|
|
|
|
|
2016-11-28 04:34:12 +01:00
|
|
|
protected static Field fieldTickingBlockCount;
|
|
|
|
protected static Field fieldNonEmptyBlockCount;
|
|
|
|
protected static Field fieldSection;
|
|
|
|
protected static Field fieldChunkMap;
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
fieldSection = ChunkSection.class.getDeclaredField("blockIds");
|
|
|
|
fieldTickingBlockCount = ChunkSection.class.getDeclaredField("tickingBlockCount");
|
|
|
|
fieldNonEmptyBlockCount = ChunkSection.class.getDeclaredField("nonEmptyBlockCount");
|
|
|
|
fieldChunkMap = PlayerChunkMap.class.getDeclaredField("d");
|
|
|
|
fieldSection.setAccessible(true);
|
|
|
|
fieldTickingBlockCount.setAccessible(true);
|
|
|
|
fieldNonEmptyBlockCount.setAccessible(true);
|
|
|
|
fieldChunkMap.setAccessible(true);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-12-08 15:47:50 +01:00
|
|
|
try {
|
|
|
|
isDirty = ChunkSection.class.getDeclaredField("isDirty");
|
|
|
|
isDirty.setAccessible(true);
|
|
|
|
} catch (Throwable ignore) {}
|
2016-11-28 04:34:12 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 19:41:03 +02:00
|
|
|
public BukkitQueue18R3(final com.sk89q.worldedit.world.World world) {
|
2016-04-29 23:24:59 +02:00
|
|
|
super(world);
|
2016-11-28 04:34:12 +01:00
|
|
|
getImpWorld();
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 07:43:23 +02:00
|
|
|
public BukkitQueue18R3(final String world) {
|
|
|
|
super(world);
|
2016-09-24 05:27:52 +02:00
|
|
|
getImpWorld();
|
2016-08-28 11:03:42 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 14:43:11 +02:00
|
|
|
@Override
|
2016-11-17 22:44:16 +01:00
|
|
|
public void setHeightMap(FaweChunk chunk, byte[] heightMap) {
|
2016-10-24 14:43:11 +02:00
|
|
|
CraftChunk craftChunk = (CraftChunk) chunk.getChunk();
|
|
|
|
if (craftChunk != null) {
|
|
|
|
int[] otherMap = craftChunk.getHandle().heightMap;
|
|
|
|
for (int i = 0; i < heightMap.length; i++) {
|
2016-11-29 05:20:00 +01:00
|
|
|
int newHeight = heightMap[i] & 0xFF;
|
|
|
|
int currentHeight = otherMap[i];
|
|
|
|
if (newHeight > currentHeight) {
|
|
|
|
otherMap[i] = newHeight;
|
2016-10-24 14:43:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
@Override
|
|
|
|
public boolean isChunkLoaded(int x, int z) {
|
|
|
|
return getWorld().isChunkLoaded(x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
public World getWorld(String world) {
|
|
|
|
return Bukkit.getWorld(world);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean regenerateChunk(World world, int x, int z) {
|
|
|
|
return world.regenerateChunk(x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean loadChunk(World world, int x, int z, boolean generate) {
|
2016-05-19 09:41:55 +02:00
|
|
|
return getCachedSections(world, x, z) != null;
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-15 01:53:30 +02:00
|
|
|
@Override
|
|
|
|
public void setFullbright(ChunkSection[] sections) {
|
|
|
|
for (int i = 0; i < sections.length; i++) {
|
|
|
|
ChunkSection section = sections[i];
|
|
|
|
if (section != null) {
|
|
|
|
byte[] bytes = section.getSkyLightArray().a();
|
|
|
|
Arrays.fill(bytes, Byte.MAX_VALUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
@Override
|
2016-05-19 09:41:55 +02:00
|
|
|
public ChunkSection[] getCachedSections(World world, int x, int z) {
|
2016-04-29 23:24:59 +02:00
|
|
|
Chunk chunk = world.getChunkAt(x, z);
|
|
|
|
if (chunk == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!chunk.isLoaded()) {
|
|
|
|
chunk.load(true);
|
|
|
|
}
|
|
|
|
return ((CraftChunk) chunk).getHandle().getSections();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-27 00:03:51 +02:00
|
|
|
public int getCombinedId4Data(ChunkSection section, int x, int y, int z) {
|
|
|
|
char[] ls = section.getIdArray();
|
2016-08-20 05:33:56 +02:00
|
|
|
return ls[FaweCache.CACHE_J[y][z & 15][x & 15]];
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isChunkLoaded(World world, int x, int z) {
|
|
|
|
return world.isChunkLoaded(x, z);
|
|
|
|
}
|
|
|
|
|
2016-05-02 05:06:23 +02:00
|
|
|
@Override
|
2016-07-27 00:03:51 +02:00
|
|
|
public ChunkSection getCachedSection(ChunkSection[] chunkSections, int cy) {
|
|
|
|
return chunkSections[cy];
|
2016-05-02 05:06:23 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:46:38 +02:00
|
|
|
@Override
|
|
|
|
public CharFaweChunk getPrevious(CharFaweChunk fs, ChunkSection[] sections, Map<?, ?> tilesGeneric, Collection<?>[] entitiesGeneric, Set<UUID> createdEntities, boolean all) throws Exception {
|
|
|
|
Map<BlockPosition, TileEntity> tiles = (Map<BlockPosition, TileEntity>) tilesGeneric;
|
|
|
|
Collection<Entity>[] entities = (Collection<Entity>[]) entitiesGeneric;
|
2016-05-19 09:41:55 +02:00
|
|
|
CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ());
|
2016-11-17 22:44:16 +01:00
|
|
|
char[][] idPrevious = previous.getCombinedIdArrays();
|
2016-05-12 19:46:38 +02:00
|
|
|
for (int layer = 0; layer < sections.length; layer++) {
|
|
|
|
if (fs.getCount(layer) != 0 || all) {
|
|
|
|
ChunkSection section = sections[layer];
|
|
|
|
if (section != null) {
|
|
|
|
idPrevious[layer] = section.getIdArray().clone();
|
|
|
|
short solid = 0;
|
|
|
|
for (int combined : idPrevious[layer]) {
|
|
|
|
if (combined > 1) {
|
|
|
|
solid++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
previous.count[layer] = solid;
|
|
|
|
previous.air[layer] = (short) (4096 - solid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tiles != null) {
|
|
|
|
for (Map.Entry<BlockPosition, TileEntity> entry : tiles.entrySet()) {
|
|
|
|
TileEntity tile = entry.getValue();
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
BlockPosition pos = entry.getKey();
|
2016-05-19 09:41:55 +02:00
|
|
|
CompoundTag nativeTag = getTag(tile);
|
|
|
|
previous.setTile(pos.getX() & 15, pos.getY(), pos.getZ() & 15, nativeTag);
|
2016-05-12 19:46:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (entities != null) {
|
|
|
|
for (Collection<Entity> entityList : entities) {
|
|
|
|
for (Entity ent : entityList) {
|
2016-05-19 09:41:55 +02:00
|
|
|
if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && createdEntities.contains(ent.getUniqueID()))) {
|
2016-05-12 19:46:38 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int x = ((int) Math.round(ent.locX) & 15);
|
|
|
|
int z = ((int) Math.round(ent.locZ) & 15);
|
|
|
|
int y = (int) Math.round(ent.locY);
|
2016-08-20 05:33:56 +02:00
|
|
|
int i = FaweCache.CACHE_I[y][z][x];
|
2016-05-12 19:46:38 +02:00
|
|
|
char[] array = fs.getIdArray(i);
|
|
|
|
if (array == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-20 05:33:56 +02:00
|
|
|
int j = FaweCache.CACHE_J[y][z][x];
|
2016-05-12 19:46:38 +02:00
|
|
|
if (array[j] != 0) {
|
|
|
|
String id = EntityTypes.b(ent);
|
|
|
|
if (id != null) {
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
ent.e(tag); // readEntityIntoTag
|
|
|
|
CompoundTag nativeTag = (CompoundTag) methodToNative.invoke(adapter, tag);
|
|
|
|
Map<String, Tag> map = ReflectionUtils.getMap(nativeTag.getValue());
|
|
|
|
map.put("Id", new StringTag(id));
|
|
|
|
previous.setEntity(nativeTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return previous;
|
|
|
|
}
|
|
|
|
|
2016-05-19 09:41:55 +02:00
|
|
|
public CompoundTag getTag(TileEntity tile) {
|
|
|
|
try {
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
tile.b(tag); // readTagIntoEntity
|
|
|
|
return (CompoundTag) methodToNative.invoke(adapter, tag);
|
|
|
|
} catch (Exception e) {
|
|
|
|
MainUtil.handleError(e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private BlockPosition.MutableBlockPosition pos = new BlockPosition.MutableBlockPosition(0, 0, 0);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CompoundTag getTileEntity(Chunk chunk, int x, int y, int z) {
|
|
|
|
Map<BlockPosition, TileEntity> tiles = ((CraftChunk) chunk).getHandle().getTileEntities();
|
|
|
|
pos.c(x, y, z);
|
|
|
|
TileEntity tile = tiles.get(pos);
|
|
|
|
return tile != null ? getTag(tile) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunk(World world, int x, int z) {
|
|
|
|
return world.getChunkAt(x, z);
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
public void setCount(int tickingBlockCount, int nonEmptyBlockCount, ChunkSection section) throws NoSuchFieldException, IllegalAccessException {
|
|
|
|
fieldTickingBlockCount.set(section, tickingBlockCount);
|
|
|
|
fieldNonEmptyBlockCount.set(section, nonEmptyBlockCount);
|
|
|
|
}
|
|
|
|
|
2016-11-28 04:34:12 +01:00
|
|
|
public int getNonEmptyBlockCount(ChunkSection section) throws IllegalAccessException {
|
|
|
|
return (int) fieldNonEmptyBlockCount.get(section);
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
@Override
|
2016-08-09 06:32:51 +02:00
|
|
|
public void refreshChunk(FaweChunk fc) {
|
|
|
|
BukkitChunk_1_8 fs = (BukkitChunk_1_8) fc;
|
2016-08-14 02:26:51 +02:00
|
|
|
ensureChunkLoaded(fc.getX(), fc.getZ());
|
2016-08-09 06:32:51 +02:00
|
|
|
Chunk chunk = fs.getChunk();
|
2016-04-29 23:24:59 +02:00
|
|
|
if (!chunk.isLoaded()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-20 10:55:26 +02:00
|
|
|
try {
|
|
|
|
net.minecraft.server.v1_8_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
|
|
|
|
WorldServer w = (WorldServer) nmsChunk.getWorld();
|
|
|
|
PlayerChunkMap chunkMap = w.getPlayerChunkMap();
|
2016-08-09 06:32:51 +02:00
|
|
|
int x = nmsChunk.locX;
|
|
|
|
int z = nmsChunk.locZ;
|
2016-05-20 10:55:26 +02:00
|
|
|
if (!chunkMap.isChunkInUse(x, z)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 04:34:12 +01:00
|
|
|
|
2016-05-20 10:55:26 +02:00
|
|
|
LongHashMap<Object> map = (LongHashMap<Object>) fieldChunkMap.get(chunkMap);
|
|
|
|
long pair = (long) x + 2147483647L | (long) z + 2147483647L << 32;
|
|
|
|
Object playerChunk = map.getEntry(pair);
|
|
|
|
Field fieldPlayers = playerChunk.getClass().getDeclaredField("b");
|
|
|
|
fieldPlayers.setAccessible(true);
|
2016-08-09 06:32:51 +02:00
|
|
|
Collection<EntityPlayer> players = (Collection<EntityPlayer>) fieldPlayers.get(playerChunk);
|
|
|
|
if (players.isEmpty()) {
|
2016-05-20 10:55:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-09 06:32:51 +02:00
|
|
|
// Send chunks
|
|
|
|
int mask = fc.getBitMask();
|
2016-11-17 22:44:16 +01:00
|
|
|
if (mask == 0 || mask == 65535 && hasEntities(nmsChunk)) {
|
2016-08-09 06:32:51 +02:00
|
|
|
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(nmsChunk, false, 65280);
|
|
|
|
for (EntityPlayer player : players) {
|
|
|
|
player.playerConnection.sendPacket(packet);
|
2016-05-20 10:55:26 +02:00
|
|
|
}
|
2016-08-09 06:32:51 +02:00
|
|
|
mask = 255;
|
2016-05-20 10:55:26 +02:00
|
|
|
}
|
2016-08-09 06:32:51 +02:00
|
|
|
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(nmsChunk, false, mask);
|
2016-05-20 10:55:26 +02:00
|
|
|
for (EntityPlayer player : players) {
|
|
|
|
player.playerConnection.sendPacket(packet);
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
2016-08-16 08:41:29 +02:00
|
|
|
// Send tiles
|
|
|
|
for (Map.Entry<BlockPosition, TileEntity> entry : nmsChunk.getTileEntities().entrySet()) {
|
|
|
|
TileEntity tile = entry.getValue();
|
|
|
|
Packet tilePacket = tile.getUpdatePacket();
|
|
|
|
for (EntityPlayer player : players) {
|
|
|
|
player.playerConnection.sendPacket(tilePacket);
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 07:36:44 +01:00
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
e.printStackTrace();
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 06:32:51 +02:00
|
|
|
public boolean hasEntities(net.minecraft.server.v1_8_R3.Chunk nmsChunk) {
|
|
|
|
for (int i = 0; i < nmsChunk.entitySlices.length; i++) {
|
|
|
|
List<Entity> slice = nmsChunk.entitySlices[i];
|
|
|
|
if (slice != null && !slice.isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
@Override
|
2016-07-15 01:53:30 +02:00
|
|
|
public boolean removeLighting(ChunkSection[] sections, RelightMode mode, boolean sky) {
|
|
|
|
if (mode == RelightMode.ALL) {
|
|
|
|
for (int i = 0; i < sections.length; i++) {
|
|
|
|
ChunkSection section = sections[i];
|
|
|
|
if (section != null) {
|
|
|
|
section.a(new NibbleArray());
|
|
|
|
if (sky) {
|
|
|
|
section.b(new NibbleArray());
|
2016-05-12 19:46:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-15 01:53:30 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public World createWorld(final WorldCreator creator) {
|
|
|
|
final String name = creator.name();
|
|
|
|
ChunkGenerator generator = creator.generator();
|
|
|
|
final CraftServer server = (CraftServer) Bukkit.getServer();
|
|
|
|
final MinecraftServer console = server.getServer();
|
|
|
|
final File folder = new File(server.getWorldContainer(), name);
|
|
|
|
final World world = server.getWorld(name);
|
|
|
|
final WorldType type = WorldType.getType(creator.type().getName());
|
|
|
|
final boolean generateStructures = creator.generateStructures();
|
|
|
|
if (world != null) {
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
if (folder.exists() && !folder.isDirectory()) {
|
|
|
|
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
|
|
|
|
}
|
2016-09-02 05:23:58 +02:00
|
|
|
TaskManager.IMP.sync(new RunnableVal<Object>() {
|
|
|
|
@Override
|
|
|
|
public void run(Object value) {
|
|
|
|
try {
|
|
|
|
Field field = CraftServer.class.getDeclaredField("worlds");
|
|
|
|
field.setAccessible(true);
|
|
|
|
Map<Object, Object> existing = (Map<Object, Object>) field.get(server);
|
|
|
|
if (!existing.getClass().getName().contains("SynchronizedMap")) {
|
|
|
|
field.set(server, Collections.synchronizedMap(existing));
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-07-15 01:53:30 +02:00
|
|
|
if (generator == null) {
|
|
|
|
generator = server.getGenerator(name);
|
|
|
|
}
|
|
|
|
int dimension = 10 + console.worlds.size();
|
|
|
|
boolean used = false;
|
|
|
|
do {
|
|
|
|
for (final WorldServer ws : console.worlds) {
|
|
|
|
used = (ws.dimension == dimension);
|
|
|
|
if (used) {
|
|
|
|
++dimension;
|
|
|
|
break;
|
2016-06-06 09:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-15 01:53:30 +02:00
|
|
|
} while (used);
|
|
|
|
final boolean hardcore = false;
|
|
|
|
ServerNBTManager sdm = new ServerNBTManager(server.getWorldContainer(), name, true);
|
|
|
|
WorldData worlddata = sdm.getWorldData();
|
|
|
|
final WorldSettings worldSettings;
|
|
|
|
if (worlddata == null) {
|
|
|
|
worldSettings = new WorldSettings(creator.seed(), WorldSettings.EnumGamemode.getById(server.getDefaultGameMode().getValue()), generateStructures, hardcore, type);
|
|
|
|
worldSettings.setGeneratorSettings(creator.generatorSettings());
|
|
|
|
worlddata = new WorldData(worldSettings, name);
|
|
|
|
} else {
|
|
|
|
worldSettings = null;
|
|
|
|
}
|
|
|
|
worlddata.checkName(name);
|
|
|
|
final WorldServer internal = (WorldServer)new WorldServer(console, sdm, worlddata, dimension, console.methodProfiler, creator.environment(), generator).b();
|
|
|
|
startSet(true); // Temporarily allow async chunk load since the world isn't added yet
|
2016-09-02 06:15:28 +02:00
|
|
|
if (worldSettings != null) {
|
|
|
|
internal.a(worldSettings);
|
|
|
|
}
|
2016-07-15 01:53:30 +02:00
|
|
|
endSet(true);
|
|
|
|
internal.scoreboard = server.getScoreboardManager().getMainScoreboard().getHandle();
|
|
|
|
internal.tracker = new EntityTracker(internal);
|
|
|
|
internal.addIWorldAccess(new WorldManager(console, internal));
|
|
|
|
internal.worldData.setDifficulty(EnumDifficulty.EASY);
|
|
|
|
internal.setSpawnFlags(true, true);
|
|
|
|
if (generator != null) {
|
|
|
|
internal.getWorld().getPopulators().addAll(generator.getDefaultPopulators(internal.getWorld()));
|
|
|
|
}
|
|
|
|
// Add the world
|
|
|
|
return TaskManager.IMP.sync(new RunnableVal<World>() {
|
|
|
|
@Override
|
|
|
|
public void run(World value) {
|
|
|
|
console.worlds.add(internal);
|
|
|
|
server.getPluginManager().callEvent(new WorldInitEvent(internal.getWorld()));
|
|
|
|
server.getPluginManager().callEvent(new WorldLoadEvent(internal.getWorld()));
|
|
|
|
this.value = internal.getWorld();
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
2016-07-15 01:53:30 +02:00
|
|
|
});
|
|
|
|
}
|
2016-04-29 23:24:59 +02:00
|
|
|
|
2016-07-15 01:53:30 +02:00
|
|
|
@Override
|
|
|
|
public void relight(int x, int y, int z) {
|
|
|
|
pos.c(x, y, z);
|
|
|
|
nmsWorld.x(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
private WorldServer nmsWorld;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public World getImpWorld() {
|
|
|
|
World world = super.getImpWorld();
|
2016-10-02 07:20:12 +02:00
|
|
|
if (world != null) {
|
|
|
|
this.nmsWorld = ((CraftWorld) world).getHandle();
|
|
|
|
return super.getImpWorld();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|
2016-06-21 07:53:52 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public FaweChunk getFaweChunk(int x, int z) {
|
2016-08-10 09:18:55 +02:00
|
|
|
return new BukkitChunk_1_8(this, x, z);
|
2016-06-21 07:53:52 +02:00
|
|
|
}
|
2016-07-25 00:25:07 +02:00
|
|
|
|
|
|
|
@Override
|
2016-07-27 00:03:51 +02:00
|
|
|
public void setSkyLight(ChunkSection section, int x, int y, int z, int value) {
|
|
|
|
section.a(x & 15, y & 15, z & 15, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBlockLight(ChunkSection section, int x, int y, int z, int value) {
|
|
|
|
section.b(x & 15, y & 15, z & 15, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSkyLight(ChunkSection section, int x, int y, int z) {
|
|
|
|
return section.d(x & 15, y & 15, z & 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEmmittedLight(ChunkSection section, int x, int y, int z) {
|
|
|
|
return section.e(x & 15, y & 15, z & 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOpacity(ChunkSection section, int x, int y, int z) {
|
|
|
|
int combined = getCombinedId4Data(section, x, y, z);
|
|
|
|
if (combined == 0) {
|
|
|
|
return 0;
|
2016-07-25 00:25:07 +02:00
|
|
|
}
|
2016-07-27 00:03:51 +02:00
|
|
|
Block block = Block.getById(FaweCache.getId(combined));
|
|
|
|
return block.p();
|
2016-07-25 00:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-27 00:03:51 +02:00
|
|
|
public int getBrightness(ChunkSection section, int x, int y, int z) {
|
|
|
|
int combined = getCombinedId4Data(section, x, y, z);
|
|
|
|
if (combined == 0) {
|
|
|
|
return 0;
|
2016-07-25 00:25:07 +02:00
|
|
|
}
|
2016-07-27 00:03:51 +02:00
|
|
|
Block block = Block.getById(FaweCache.getId(combined));
|
|
|
|
return block.r();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasBlock(ChunkSection section, int x, int y, int z) {
|
2016-08-20 05:33:56 +02:00
|
|
|
int i = FaweCache.CACHE_J[y & 15][z & 15][x & 15];
|
2016-07-27 00:03:51 +02:00
|
|
|
return section.getIdArray()[i] != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOpacityBrightnessPair(ChunkSection section, int x, int y, int z) {
|
|
|
|
int combined = getCombinedId4Data(section, x, y, z);
|
|
|
|
if (combined == 0) {
|
|
|
|
return 0;
|
2016-07-25 00:25:07 +02:00
|
|
|
}
|
2016-07-27 00:03:51 +02:00
|
|
|
Block block = Block.getById(FaweCache.getId(combined));
|
|
|
|
return MathMan.pair16(block.p(), block.r());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void relightBlock(int x, int y, int z) {
|
|
|
|
pos.c(x, y, z);
|
|
|
|
nmsWorld.c(EnumSkyBlock.BLOCK, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void relightSky(int x, int y, int z) {
|
|
|
|
pos.c(x, y, z);
|
|
|
|
nmsWorld.c(EnumSkyBlock.SKY, pos);
|
2016-07-25 00:25:07 +02:00
|
|
|
}
|
2016-04-29 23:24:59 +02:00
|
|
|
}
|