mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Fix biome sending
This commit is contained in:
parent
b38ff03ca6
commit
601890fe64
@ -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,15 +75,38 @@ 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 {
|
||||||
|
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());
|
fieldX.setInt(nmsPacket, packet.getChunkX());
|
||||||
fieldZ.setInt(nmsPacket, packet.getChunkZ());
|
fieldZ.setInt(nmsPacket, packet.getChunkZ());
|
||||||
|
|
||||||
fieldBitMask.set(nmsPacket, packet.getChunk().getBitMask());
|
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);
|
fieldHeightMap.set(nmsPacket, heightMap);
|
||||||
|
|
||||||
fieldChunkData.set(nmsPacket, packet.getSectionBytes());
|
fieldChunkData.set(nmsPacket, packet.getSectionBytes());
|
||||||
@ -84,11 +119,11 @@ public class MapChunkUtil_1_14 {
|
|||||||
}
|
}
|
||||||
fieldBlockEntities.set(nmsPacket, nmsTiles);
|
fieldBlockEntities.set(nmsPacket, nmsTiles);
|
||||||
fieldFull.set(nmsPacket, packet.isFull());
|
fieldFull.set(nmsPacket, packet.isFull());
|
||||||
} catch (IllegalAccessException e) {
|
}
|
||||||
|
return nmsPacket;
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nmsPacket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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,11 +139,17 @@ 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++) {
|
||||||
|
BiomeType biome = getBiomeType(x, z);
|
||||||
|
if (biome != null) {
|
||||||
|
sectionWriter.writeInt(biome.getLegacyId());
|
||||||
|
} else {
|
||||||
sectionWriter.writeInt(0);
|
sectionWriter.writeInt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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())) {
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user