Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Commit
e297d825e3
@ -15,8 +15,19 @@ public class BaseChunk implements Chunk {
|
|||||||
protected int bitmask;
|
protected int bitmask;
|
||||||
protected ChunkSection[] sections;
|
protected ChunkSection[] sections;
|
||||||
protected int[] biomeData;
|
protected int[] biomeData;
|
||||||
|
protected CompoundTag heightMap;
|
||||||
protected List<CompoundTag> blockEntities;
|
protected List<CompoundTag> blockEntities;
|
||||||
|
|
||||||
|
public BaseChunk(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, int[] biomeData, List<CompoundTag> blockEntities) {
|
||||||
|
this.x = x;
|
||||||
|
this.z = z;
|
||||||
|
this.groundUp = groundUp;
|
||||||
|
this.bitmask = bitmask;
|
||||||
|
this.sections = sections;
|
||||||
|
this.biomeData = biomeData;
|
||||||
|
this.blockEntities = blockEntities;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBiomeData() {
|
public boolean isBiomeData() {
|
||||||
return biomeData != null;
|
return biomeData != null;
|
||||||
|
@ -17,6 +17,10 @@ public interface Chunk {
|
|||||||
|
|
||||||
int[] getBiomeData();
|
int[] getBiomeData();
|
||||||
|
|
||||||
|
CompoundTag getHeightMap();
|
||||||
|
|
||||||
|
void setHeightMap(CompoundTag heightMap);
|
||||||
|
|
||||||
List<CompoundTag> getBlockEntities();
|
List<CompoundTag> getBlockEntities();
|
||||||
|
|
||||||
boolean isGroundUp();
|
boolean isGroundUp();
|
||||||
|
@ -12,13 +12,17 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MappingData {
|
public class MappingData {
|
||||||
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
||||||
public static BlockMappings blockStateMappings;
|
public static BlockMappings blockStateMappings;
|
||||||
public static BlockMappings blockMappings;
|
public static BlockMappings blockMappings;
|
||||||
public static SoundMappings soundMappings;
|
public static SoundMappings soundMappings;
|
||||||
|
public static Set<Integer> motionBlocking;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
JsonObject mapping1_13_2 = loadData("mapping-1.13.2.json");
|
JsonObject mapping1_13_2 = loadData("mapping-1.13.2.json");
|
||||||
@ -32,6 +36,27 @@ public class MappingData {
|
|||||||
mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
|
mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
|
||||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
|
||||||
soundMappings = new SoundMappingShortArray(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
|
soundMappings = new SoundMappingShortArray(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
|
||||||
|
|
||||||
|
Via.getPlatform().getLogger().info("Loading 1.14 blockstates...");
|
||||||
|
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
|
||||||
|
Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());
|
||||||
|
for (Map.Entry<String, JsonElement> entry : blockStates.entrySet()) {
|
||||||
|
blockStateMap.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Via.getPlatform().getLogger().info("Loading 1.14 heightmap data...");
|
||||||
|
JsonObject heightMapData = loadData("heightMapData-1.14.json");
|
||||||
|
JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
|
||||||
|
MappingData.motionBlocking = new HashSet<>(motionBlocking.size());
|
||||||
|
for (JsonElement blockState : motionBlocking) {
|
||||||
|
String key = blockState.getAsString();
|
||||||
|
Integer id = blockStateMap.get(key);
|
||||||
|
if (id == null) {
|
||||||
|
Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :(");
|
||||||
|
} else {
|
||||||
|
MappingData.motionBlocking.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject loadData(String name) {
|
public static JsonObject loadData(String name) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
|
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
@ -126,7 +128,11 @@ public class WorldPackets {
|
|||||||
Chunk chunk = wrapper.read(new Chunk1_13Type(clientWorld));
|
Chunk chunk = wrapper.read(new Chunk1_13Type(clientWorld));
|
||||||
wrapper.write(new Chunk1_14Type(clientWorld), chunk);
|
wrapper.write(new Chunk1_14Type(clientWorld), chunk);
|
||||||
|
|
||||||
for (ChunkSection section : chunk.getSections()) {
|
int[] motionBlocking = new int[16 * 16];
|
||||||
|
int[] worldSurface = new int[16 * 16];
|
||||||
|
|
||||||
|
for (int s = 0; s < 16; s++) {
|
||||||
|
ChunkSection section = chunk.getSections()[s];
|
||||||
if (section == null) continue;
|
if (section == null) continue;
|
||||||
boolean hasBlock = false;
|
boolean hasBlock = false;
|
||||||
for (int i = 0; i < section.getPaletteSize(); i++) {
|
for (int i = 0; i < section.getPaletteSize(); i++) {
|
||||||
@ -148,6 +154,10 @@ public class WorldPackets {
|
|||||||
int id = section.getFlatBlock(x, y, z);
|
int id = section.getFlatBlock(x, y, z);
|
||||||
if (id != AIR && id != VOID_AIR && id != CAVE_AIR) {
|
if (id != AIR && id != VOID_AIR && id != CAVE_AIR) {
|
||||||
nonAirBlockCount++;
|
nonAirBlockCount++;
|
||||||
|
worldSurface[x + z * 16] = y + s * 16 + 2; // Should be +1 (top of the block) but +2 works :tm:
|
||||||
|
}
|
||||||
|
if (MappingData.motionBlocking.contains(id)) {
|
||||||
|
motionBlocking[x + z * 16] = y + s * 16 + 2; // Should be +1 (top of the block) but +2 works :tm:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,6 +165,11 @@ public class WorldPackets {
|
|||||||
section.setNonAirBlocksCount(nonAirBlockCount);
|
section.setNonAirBlocksCount(nonAirBlockCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompoundTag heightMap = new CompoundTag("");
|
||||||
|
heightMap.put(new LongArrayTag("MOTION_BLOCKING", encodeHeightMap(motionBlocking)));
|
||||||
|
heightMap.put(new LongArrayTag("WORLD_SURFACE", encodeHeightMap(worldSurface)));
|
||||||
|
chunk.setHeightMap(heightMap);
|
||||||
|
|
||||||
PacketWrapper lightPacket = wrapper.create(0x24);
|
PacketWrapper lightPacket = wrapper.create(0x24);
|
||||||
lightPacket.write(Type.VAR_INT, chunk.getX());
|
lightPacket.write(Type.VAR_INT, chunk.getX());
|
||||||
lightPacket.write(Type.VAR_INT, chunk.getZ());
|
lightPacket.write(Type.VAR_INT, chunk.getZ());
|
||||||
@ -360,4 +375,27 @@ public class WorldPackets {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long[] encodeHeightMap(int[] heightMap) {
|
||||||
|
final int bitsPerBlock = 9;
|
||||||
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
|
||||||
|
int length = (int) Math.ceil(heightMap.length * bitsPerBlock / 64.0);
|
||||||
|
long[] data = new long[length];
|
||||||
|
|
||||||
|
for (int index = 0; index < heightMap.length; index++) {
|
||||||
|
int value = heightMap[index];
|
||||||
|
int bitIndex = index * 9;
|
||||||
|
int startIndex = bitIndex / 64;
|
||||||
|
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
||||||
|
int startBitSubIndex = bitIndex % 64;
|
||||||
|
data[startIndex] = data[startIndex] & ~(maxEntryValue << startBitSubIndex) | ((long) value & maxEntryValue) << startBitSubIndex;
|
||||||
|
if (startIndex != endIndex) {
|
||||||
|
int endBitSubIndex = 64 - startBitSubIndex;
|
||||||
|
data[endIndex] = data[endIndex] >>> endBitSubIndex << endBitSubIndex | ((long) value & maxEntryValue) >> endBitSubIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
|
|
||||||
boolean groundUp = input.readBoolean();
|
boolean groundUp = input.readBoolean();
|
||||||
int primaryBitmask = Type.VAR_INT.read(input);
|
int primaryBitmask = Type.VAR_INT.read(input);
|
||||||
Type.NBT.read(input); // todo save this
|
CompoundTag heightMap = Type.NBT.read(input);
|
||||||
Type.VAR_INT.read(input);
|
Type.VAR_INT.read(input);
|
||||||
|
|
||||||
BitSet usedSections = new BitSet(16);
|
BitSet usedSections = new BitSet(16);
|
||||||
@ -68,7 +68,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, heightMap, nbtData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,7 +78,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
|
|
||||||
output.writeBoolean(chunk.isGroundUp());
|
output.writeBoolean(chunk.isGroundUp());
|
||||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||||
Type.NBT.write(output, new CompoundTag("")); //TODO unknown compound tag
|
Type.NBT.write(output, chunk.getHeightMap());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
|
8517
common/src/main/resources/assets/viaversion/data/heightMapData-1.14.json
Normale Datei
8517
common/src/main/resources/assets/viaversion/data/heightMapData-1.14.json
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren