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

Merge pull request #1283 from Gerrygames/master

1.14 heightmap
Dieser Commit ist enthalten in:
Myles 2019-04-24 17:43:07 +01:00 committet von GitHub
Commit e297d825e3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 8599 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -15,8 +15,19 @@ public class BaseChunk implements Chunk {
protected int bitmask;
protected ChunkSection[] sections;
protected int[] biomeData;
protected CompoundTag heightMap;
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
public boolean isBiomeData() {
return biomeData != null;

Datei anzeigen

@ -17,6 +17,10 @@ public interface Chunk {
int[] getBiomeData();
CompoundTag getHeightMap();
void setHeightMap(CompoundTag heightMap);
List<CompoundTag> getBlockEntities();
boolean isGroundUp();

Datei anzeigen

@ -12,13 +12,17 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class MappingData {
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
public static BlockMappings blockStateMappings;
public static BlockMappings blockMappings;
public static SoundMappings soundMappings;
public static Set<Integer> motionBlocking;
public static void init() {
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"));
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
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) {

Datei anzeigen

@ -1,5 +1,7 @@
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 io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper;
@ -126,7 +128,11 @@ public class WorldPackets {
Chunk chunk = wrapper.read(new Chunk1_13Type(clientWorld));
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;
boolean hasBlock = false;
for (int i = 0; i < section.getPaletteSize(); i++) {
@ -148,6 +154,10 @@ public class WorldPackets {
int id = section.getFlatBlock(x, y, z);
if (id != AIR && id != VOID_AIR && id != CAVE_AIR) {
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);
}
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);
lightPacket.write(Type.VAR_INT, chunk.getX());
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;
}
}

Datei anzeigen

@ -30,7 +30,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
boolean groundUp = input.readBoolean();
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);
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
@ -78,7 +78,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp());
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();
for (int i = 0; i < 16; i++) {

Datei-Diff unterdrückt, da er zu groß ist Diff laden