Fix biome sending

This commit is contained in:
Jesse Boyd 2019-11-14 19:21:28 +00:00
parent b38ff03ca6
commit 601890fe64
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
8 changed files with 80 additions and 26 deletions

View File

@ -1,27 +1,39 @@
package com.boydti.fawe.bukkit.adapter.mc1_14;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweOutputStream;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.ChunkSection;
import net.minecraft.server.v1_14_R1.IRegistry;
import net.minecraft.server.v1_14_R1.NBTBase;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
public class MapChunkUtil_1_14 {
@ -63,15 +75,38 @@ public class MapChunkUtil_1_14 {
}
}
public static PacketPlayOutMapChunk create(BukkitImplAdapter<NBTBase> adapter, ChunkPacket packet) {
PacketPlayOutMapChunk nmsPacket = new PacketPlayOutMapChunk();
public static PacketPlayOutMapChunk create(WorldServer world, BukkitImplAdapter<NBTBase> adapter, ChunkPacket packet) {
IBlocks chunk = packet.getChunk();
try {
PacketPlayOutMapChunk nmsPacket;
int bitMask = packet.getChunk().getBitMask();
if (bitMask == 0) {
nmsPacket = Fawe.get().getQueueHandler().sync((Callable<PacketPlayOutMapChunk>) () -> {
Chunk nmsChunk = world.getChunkAt(packet.getChunkX(), packet.getChunkZ());
PacketPlayOutMapChunk nmsPacket1 = new PacketPlayOutMapChunk(nmsChunk, 65535);
byte[] data = (byte[]) fieldChunkData.get(nmsPacket1);
int len = data.length;
ByteBuffer buffer = ByteBuffer.wrap(data, len - 256 * 4, 256 * 4);
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
BiomeType biome = chunk.getBiomeType(x, z);
if (biome != null) {
buffer.putInt(biome.getLegacyId());
} else {
buffer.getInt();
}
}
}
return nmsPacket1;
}).get();
} else {
nmsPacket = new PacketPlayOutMapChunk();
fieldX.setInt(nmsPacket, packet.getChunkX());
fieldZ.setInt(nmsPacket, packet.getChunkZ());
fieldBitMask.set(nmsPacket, packet.getChunk().getBitMask());
NBTBase heightMap = adapter.fromNative(packet.getHeightMap());
NBTBase heightMap = adapter.fromNative(/* packet.getHeightMap() */ new CompoundTag(new HashMap<>()));
fieldHeightMap.set(nmsPacket, heightMap);
fieldChunkData.set(nmsPacket, packet.getSectionBytes());
@ -84,11 +119,11 @@ public class MapChunkUtil_1_14 {
}
fieldBlockEntities.set(nmsPacket, nmsTiles);
fieldFull.set(nmsPacket, packet.isFull());
} catch (IllegalAccessException e) {
}
return nmsPacket;
} catch (Exception e) {
e.printStackTrace();
return null;
}
return nmsPacket;
}
}

View File

@ -676,7 +676,7 @@ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements Bukkit
synchronized (packet) {
PacketPlayOutMapChunk nmsPacket = (PacketPlayOutMapChunk) packet.getNativePacket();
if (nmsPacket == null) {
nmsPacket = MapChunkUtil_1_14.create(this, packet);
nmsPacket = MapChunkUtil_1_14.create(nmsWorld, this, packet);
packet.setNativePacket(nmsPacket);
}
try {

View File

@ -57,6 +57,9 @@ public interface IBlocks extends Trimable {
BlockRegistry registry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry();
FastByteArrayOutputStream sectionByteArray = new FastByteArrayOutputStream(buffer);
FaweOutputStream sectionWriter = new FaweOutputStream(sectionByteArray);
System.out.println("Bitmask " + getBitMask());
try {
for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) {
if (!this.hasSection(layer)) continue;
@ -136,11 +139,17 @@ public interface IBlocks extends Trimable {
// }
// }
if (writeBiomes) {
for (int i = 0; i < 256; i++) {
// TODO biomes
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
BiomeType biome = getBiomeType(x, z);
if (biome != null) {
sectionWriter.writeInt(biome.getLegacyId());
} else {
sectionWriter.writeInt(0);
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -38,6 +38,10 @@ public interface IChunkSet extends IBlocks, OutputExtent {
BiomeType[] getBiomes();
default boolean hasBiomes() {
return getBiomes() != null;
}
@Override
BiomeType getBiomeType(int x, int z);

View File

@ -170,6 +170,11 @@ public interface IDelegateChunk<U extends IQueueChunk> extends IQueueChunk {
return getParent().getBiomes();
}
@Override
default boolean hasBiomes() {
return getParent().hasBiomes();
}
default <T extends IChunk> T findParent(Class<T> clazz) {
IChunk root = getParent();
if (clazz.isAssignableFrom(root.getClass())) {

View File

@ -46,6 +46,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
@Override
public BiomeType getBiomeType(int x, int z) {
if (biomes == null) return null;
return biomes[(z << 4) | x];
}

View File

@ -26,7 +26,7 @@ public class ChunkSendProcessor implements IBatchProcessor {
public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
int chunkX = chunk.getX();
int chunkZ = chunk.getZ();
boolean replaceAll = set.getBiomeType(0, 0) != null;
boolean replaceAll = set.hasBiomes();
ChunkPacket packet = new ChunkPacket(chunkX, chunkZ, () -> set, replaceAll);
Stream<Player> stream = this.players.get();
if (stream == null) {

View File

@ -219,7 +219,7 @@ public final class BiomeTypes {
ERODED_BADLANDS.setLegacyId(165);
MODIFIED_WOODED_BADLANDS_PLATEAU.setLegacyId(166);
MODIFIED_BADLANDS_PLATEAU.setLegacyId(167);
// BAMBOO_JUNGLE.setLegacyId(168);
// BAMBOO_JUNGLE_HILLS.setLegacyId(169);
BAMBOO_JUNGLE.setLegacyId(168);
BAMBOO_JUNGLE_HILLS.setLegacyId(169);
}
}