From 601890fe6455edbacee29302e17bb328d9677d8d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 14 Nov 2019 19:21:28 +0000 Subject: [PATCH] Fix biome sending --- .../adapter/mc1_14/MapChunkUtil_1_14.java | 73 ++++++++++++++----- .../adapter/mc1_14/Spigot_v1_14_R4.java | 2 +- .../java/com/boydti/fawe/beta/IBlocks.java | 15 +++- .../java/com/boydti/fawe/beta/IChunkSet.java | 4 + .../com/boydti/fawe/beta/IDelegateChunk.java | 5 ++ .../implementation/blocks/CharSetBlocks.java | 1 + .../processors/ChunkSendProcessor.java | 2 +- .../worldedit/world/biome/BiomeTypes.java | 4 +- 8 files changed, 80 insertions(+), 26 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/MapChunkUtil_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/MapChunkUtil_1_14.java index cdd03c251..783fc2824 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/MapChunkUtil_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/MapChunkUtil_1_14.java @@ -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,32 +75,55 @@ public class MapChunkUtil_1_14 { } } - public static PacketPlayOutMapChunk create(BukkitImplAdapter adapter, ChunkPacket packet) { - PacketPlayOutMapChunk nmsPacket = new PacketPlayOutMapChunk(); - + public static PacketPlayOutMapChunk create(WorldServer world, BukkitImplAdapter adapter, ChunkPacket packet) { + IBlocks chunk = packet.getChunk(); try { - fieldX.setInt(nmsPacket, packet.getChunkX()); - fieldZ.setInt(nmsPacket, packet.getChunkZ()); + PacketPlayOutMapChunk nmsPacket; + int bitMask = packet.getChunk().getBitMask(); + if (bitMask == 0) { + nmsPacket = Fawe.get().getQueueHandler().sync((Callable) () -> { + Chunk nmsChunk = world.getChunkAt(packet.getChunkX(), packet.getChunkZ()); + PacketPlayOutMapChunk nmsPacket1 = new PacketPlayOutMapChunk(nmsChunk, 65535); + byte[] data = (byte[]) fieldChunkData.get(nmsPacket1); + int len = data.length; - fieldBitMask.set(nmsPacket, packet.getChunk().getBitMask()); - NBTBase heightMap = adapter.fromNative(packet.getHeightMap()); - fieldHeightMap.set(nmsPacket, heightMap); + 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(); + } + } + } - fieldChunkData.set(nmsPacket, packet.getSectionBytes()); + 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() */ new CompoundTag(new HashMap<>())); + fieldHeightMap.set(nmsPacket, heightMap); - Map tiles = packet.getChunk().getTiles(); - ArrayList nmsTiles = new ArrayList<>(tiles.size()); - for (Map.Entry entry : tiles.entrySet()) { - NBTBase nmsTag = adapter.fromNative(entry.getValue()); - nmsTiles.add((NBTTagCompound) nmsTag); + fieldChunkData.set(nmsPacket, packet.getSectionBytes()); + + Map tiles = packet.getChunk().getTiles(); + ArrayList nmsTiles = new ArrayList<>(tiles.size()); + for (Map.Entry entry : tiles.entrySet()) { + NBTBase nmsTag = adapter.fromNative(entry.getValue()); + nmsTiles.add((NBTTagCompound) nmsTag); + } + fieldBlockEntities.set(nmsPacket, nmsTiles); + fieldFull.set(nmsPacket, packet.isFull()); } - fieldBlockEntities.set(nmsPacket, nmsTiles); - fieldFull.set(nmsPacket, packet.isFull()); - } catch (IllegalAccessException e) { + return nmsPacket; + } catch (Exception e) { e.printStackTrace(); return null; } - - return nmsPacket; } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/Spigot_v1_14_R4.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/Spigot_v1_14_R4.java index d3546afbb..dbc653f40 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/Spigot_v1_14_R4.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/Spigot_v1_14_R4.java @@ -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 { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java index 03cd25794..b7d6ee80b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java @@ -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,9 +139,15 @@ public interface IBlocks extends Trimable { // } // } if (writeBiomes) { - for (int i = 0; i < 256; i++) { - // TODO biomes - sectionWriter.writeInt(0); + 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) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java index f3d49af3f..f063565b8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java @@ -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); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java index e267ad732..02b431a15 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java @@ -170,6 +170,11 @@ public interface IDelegateChunk extends IQueueChunk { return getParent().getBiomes(); } + @Override + default boolean hasBiomes() { + return getParent().hasBiomes(); + } + default T findParent(Class clazz) { IChunk root = getParent(); if (clazz.isAssignableFrom(root.getClass())) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java index d33cee71e..18d3c26cd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java @@ -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]; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/ChunkSendProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/ChunkSendProcessor.java index 5528300fc..6c3d20371 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/ChunkSendProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/processors/ChunkSendProcessor.java @@ -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 stream = this.players.get(); if (stream == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java index 61a288049..a49632fc3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java @@ -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); } }