protochunk

This commit is contained in:
Jesse Boyd 2019-07-11 07:52:55 +10:00
parent 18925df124
commit 280147491d
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 39 additions and 21 deletions

View File

@ -33,8 +33,10 @@ import net.minecraft.server.v1_14_R1.DataPaletteBlock;
import net.minecraft.server.v1_14_R1.DataPaletteLinear; import net.minecraft.server.v1_14_R1.DataPaletteLinear;
import net.minecraft.server.v1_14_R1.GameProfileSerializer; import net.minecraft.server.v1_14_R1.GameProfileSerializer;
import net.minecraft.server.v1_14_R1.IBlockData; import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.IChunkAccess;
import net.minecraft.server.v1_14_R1.PlayerChunk; import net.minecraft.server.v1_14_R1.PlayerChunk;
import net.minecraft.server.v1_14_R1.PlayerChunkMap; import net.minecraft.server.v1_14_R1.PlayerChunkMap;
import net.minecraft.server.v1_14_R1.ProtoChunkExtension;
import net.minecraft.server.v1_14_R1.WorldServer; import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
@ -206,11 +208,12 @@ public class BukkitQueue extends SimpleCharQueueExtent {
public static Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) { public static Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) {
ChunkProviderServer provider = (ChunkProviderServer) nmsWorld.getChunkProvider(); ChunkProviderServer provider = (ChunkProviderServer) nmsWorld.getChunkProvider();
IChunkAccess nmsChunk = provider.getChunkAt(X, Z, ChunkStatus.FEATURES, false);
Chunk nmsChunk = (Chunk) provider.getChunkAt(X, Z, ChunkStatus.FEATURES, false);;
if (nmsChunk != null) { if (nmsChunk != null) {
return nmsChunk; if (nmsChunk instanceof ProtoChunkExtension) {
return ((ProtoChunkExtension) nmsChunk).u();
}
return (Chunk) nmsChunk;
} }
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(X, Z); return nmsWorld.getChunkAt(X, Z);

View File

@ -49,6 +49,7 @@ import net.minecraft.server.v1_14_R1.PacketDataSerializer;
import net.minecraft.server.v1_14_R1.PacketPlayOutMultiBlockChange; import net.minecraft.server.v1_14_R1.PacketPlayOutMultiBlockChange;
import net.minecraft.server.v1_14_R1.PlayerChunk; import net.minecraft.server.v1_14_R1.PlayerChunk;
import net.minecraft.server.v1_14_R1.PlayerChunkMap; import net.minecraft.server.v1_14_R1.PlayerChunkMap;
import net.minecraft.server.v1_14_R1.ProtoChunkExtension;
import net.minecraft.server.v1_14_R1.RegistryID; import net.minecraft.server.v1_14_R1.RegistryID;
import net.minecraft.server.v1_14_R1.TileEntity; import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.WorldChunkManager; import net.minecraft.server.v1_14_R1.WorldChunkManager;
@ -70,7 +71,7 @@ import java.util.concurrent.atomic.LongAdder;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R1.Chunk, ChunkSection[], ChunkSection> { public class BukkitQueue_1_14 extends BukkitQueue_0<IChunkAccess, ChunkSection[], ChunkSection> {
public final static Field fieldBits; public final static Field fieldBits;
public final static Field fieldPalette; public final static Field fieldPalette;
@ -204,12 +205,12 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
} }
@Override @Override
public ChunkSection[] getSections(net.minecraft.server.v1_14_R1.Chunk chunk) { public ChunkSection[] getSections(IChunkAccess chunk) {
return chunk.getSections(); return chunk.getSections();
} }
@Override @Override
public net.minecraft.server.v1_14_R1.Chunk loadChunk(World world, int x, int z, boolean generate) { public IChunkAccess loadChunk(World world, int x, int z, boolean generate) {
ChunkProviderServer provider = ((CraftWorld) world).getHandle().getChunkProvider(); ChunkProviderServer provider = ((CraftWorld) world).getHandle().getChunkProvider();
IChunkAccess chunk; IChunkAccess chunk;
if (generate) { if (generate) {
@ -217,12 +218,20 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
} else { } else {
chunk = provider.getChunkAt(x, z, ChunkStatus.FEATURES, false); chunk = provider.getChunkAt(x, z, ChunkStatus.FEATURES, false);
} }
return (net.minecraft.server.v1_14_R1.Chunk) chunk; return cast(chunk);
}
private IChunkAccess cast(IChunkAccess chunkAccess) {
if (chunkAccess instanceof ProtoChunkExtension) {
ProtoChunkExtension proto = (ProtoChunkExtension) chunkAccess;
if (proto.u() != null) chunkAccess = proto.u();
}
return chunkAccess;
} }
@Override @Override
public ChunkSection[] getCachedSections(World world, int cx, int cz) { public ChunkSection[] getCachedSections(World world, int cx, int cz) {
net.minecraft.server.v1_14_R1.Chunk chunk = (net.minecraft.server.v1_14_R1.Chunk) ((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, ChunkStatus.FEATURES, false); IChunkAccess chunk = ((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, ChunkStatus.FEATURES, false);
if (chunk != null) { if (chunk != null) {
return chunk.getSections(); return chunk.getSections();
} }
@ -230,8 +239,8 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
} }
@Override @Override
public net.minecraft.server.v1_14_R1.Chunk getCachedChunk(World world, int cx, int cz) { public IChunkAccess getCachedChunk(World world, int cx, int cz) {
return (net.minecraft.server.v1_14_R1.Chunk) ((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, ChunkStatus.FEATURES, false); return cast(((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, ChunkStatus.FEATURES, false));
} }
@Override @Override
@ -240,10 +249,16 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
} }
@Override @Override
public void saveChunk(net.minecraft.server.v1_14_R1.Chunk nmsChunk) { public void saveChunk(IChunkAccess chunkAccess) {
chunkAccess = cast(chunkAccess);
if (chunkAccess instanceof Chunk) {
net.minecraft.server.v1_14_R1.Chunk nmsChunk = (net.minecraft.server.v1_14_R1.Chunk) chunkAccess;
nmsChunk.d(true); // Set Modified nmsChunk.d(true); // Set Modified
nmsChunk.mustNotSave = false; nmsChunk.mustNotSave = false;
nmsChunk.markDirty(); nmsChunk.markDirty();
} else {
chunkAccess.setNeedsSaving(true);
}
} }
@Override @Override
@ -520,7 +535,7 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
} }
@Override @Override
public BiomeType getBiome(net.minecraft.server.v1_14_R1.Chunk chunk, int x, int z) { public BiomeType getBiome(IChunkAccess chunk, int x, int z) {
BiomeBase base = chunk.getBiomeIndex()[((z & 15) << 4) + (x & 15)]; BiomeBase base = chunk.getBiomeIndex()[((z & 15) << 4) + (x & 15)];
return getAdapter().adapt(CraftBlock.biomeBaseToBiome(base)); return getAdapter().adapt(CraftBlock.biomeBaseToBiome(base));
} }
@ -542,9 +557,9 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
@Override @Override
public void sendChunk(int x, int z, int bitMask) { public void sendChunk(int x, int z, int bitMask) {
net.minecraft.server.v1_14_R1.Chunk chunk = getCachedChunk(getWorld(), x, z); IChunkAccess chunk = getCachedChunk(getWorld(), x, z);
if (chunk != null) { if (chunk != null) {
sendChunk(getPlayerChunk((WorldServer) chunk.getWorld(), x, z), chunk, bitMask); sendChunk(getPlayerChunk((WorldServer) nmsWorld, x, z), chunk, bitMask);
} }
} }
@ -656,7 +671,7 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
return playerChunk; return playerChunk;
} }
public boolean sendChunk(PlayerChunk playerChunk, net.minecraft.server.v1_14_R1.Chunk nmsChunk, int mask) { public boolean sendChunk(PlayerChunk playerChunk, IChunkAccess nmsChunk, int mask) {
if (playerChunk == null) { if (playerChunk == null) {
return false; return false;
} }
@ -882,8 +897,8 @@ public class BukkitQueue_1_14 extends BukkitQueue_0<net.minecraft.server.v1_14_R
protected BlockPosition.MutableBlockPosition pos = new BlockPosition.MutableBlockPosition(0, 0, 0); protected BlockPosition.MutableBlockPosition pos = new BlockPosition.MutableBlockPosition(0, 0, 0);
@Override @Override
public CompoundTag getTileEntity(net.minecraft.server.v1_14_R1.Chunk chunk, int x, int y, int z) { public CompoundTag getTileEntity(IChunkAccess chunk, int x, int y, int z) {
Map<BlockPosition, TileEntity> tiles = chunk.getTileEntities(); Map<BlockPosition, TileEntity> tiles = ((net.minecraft.server.v1_14_R1.Chunk) cast(chunk)).getTileEntities();
pos.c(x, y, z); pos.c(x, y, z);
TileEntity tile = tiles.get(pos); TileEntity tile = tiles.get(pos);
return tile != null ? getTag(tile) : null; return tile != null ? getTag(tile) : null;