3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-09-06 08:02:50 +02:00

Fix biome sending

Dieser Commit ist enthalten in:
Jesse Boyd 2019-11-14 19:21:28 +00:00
Ursprung b38ff03ca6
Commit 601890fe64
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
8 geänderte Dateien mit 80 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -1,27 +1,39 @@
package com.boydti.fawe.bukkit.adapter.mc1_14; 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.beta.implementation.packet.ChunkPacket;
import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweOutputStream; import com.boydti.fawe.object.FaweOutputStream;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.math.BlockVector3; 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.Chunk;
import net.minecraft.server.v1_14_R1.ChunkSection; 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.NBTBase;
import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk; import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import java.util.function.Supplier; import java.util.function.Supplier;
public class MapChunkUtil_1_14 { public class MapChunkUtil_1_14 {
@ -63,32 +75,55 @@ public class MapChunkUtil_1_14 {
} }
} }
public static PacketPlayOutMapChunk create(BukkitImplAdapter<NBTBase> adapter, ChunkPacket packet) { public static PacketPlayOutMapChunk create(WorldServer world, BukkitImplAdapter<NBTBase> adapter, ChunkPacket packet) {
PacketPlayOutMapChunk nmsPacket = new PacketPlayOutMapChunk(); IBlocks chunk = packet.getChunk();
try { try {
fieldX.setInt(nmsPacket, packet.getChunkX()); PacketPlayOutMapChunk nmsPacket;
fieldZ.setInt(nmsPacket, packet.getChunkZ()); 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;
fieldBitMask.set(nmsPacket, packet.getChunk().getBitMask()); ByteBuffer buffer = ByteBuffer.wrap(data, len - 256 * 4, 256 * 4);
NBTBase heightMap = adapter.fromNative(packet.getHeightMap()); for (int z = 0; z < 16; z++) {
fieldHeightMap.set(nmsPacket, heightMap); 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<BlockVector3, CompoundTag> tiles = packet.getChunk().getTiles(); fieldChunkData.set(nmsPacket, packet.getSectionBytes());
ArrayList<NBTTagCompound> nmsTiles = new ArrayList<>(tiles.size());
for (Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) { Map<BlockVector3, CompoundTag> tiles = packet.getChunk().getTiles();
NBTBase nmsTag = adapter.fromNative(entry.getValue()); ArrayList<NBTTagCompound> nmsTiles = new ArrayList<>(tiles.size());
nmsTiles.add((NBTTagCompound) nmsTag); for (Map.Entry<BlockVector3, CompoundTag> 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); return nmsPacket;
fieldFull.set(nmsPacket, packet.isFull()); } catch (Exception e) {
} catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
return nmsPacket;
} }
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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