Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Update ViaNBT
Dieser Commit ist enthalten in:
Ursprung
bd99b892db
Commit
f6c49555bf
@ -22,12 +22,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.io.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.io.TagReader;
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@ -51,11 +52,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class MappingDataLoader {
|
||||
|
||||
private static final Map<String, CompoundTag> MAPPINGS_CACHE = new HashMap<>();
|
||||
private static final TagReader<CompoundTag> MAPPINGS_READER = NBTIO.reader(CompoundTag.class).named();
|
||||
private static final byte DIRECT_ID = 0;
|
||||
private static final byte SHIFTS_ID = 1;
|
||||
private static final byte CHANGES_ID = 2;
|
||||
private static final byte IDENTITY_ID = 3;
|
||||
private static final Map<String, CompoundTag> MAPPINGS_CACHE = new HashMap<>();
|
||||
private static boolean cacheValid = true;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
@ -131,14 +133,14 @@ public final class MappingDataLoader {
|
||||
return loadNBT(name, false);
|
||||
}
|
||||
|
||||
private static @Nullable CompoundTag loadNBTFromFile(final String name) {
|
||||
public static @Nullable CompoundTag loadNBTFromFile(final String name) {
|
||||
final InputStream resource = getResource(name);
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (final InputStream stream = resource) {
|
||||
return NBTIO.readTag(stream);
|
||||
return MAPPINGS_READER.read(stream);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
@ -41,12 +42,12 @@ public class CompoundTagType extends Type<CompoundTag> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag read(final ByteBuf buffer) throws Exception {
|
||||
public CompoundTag read(final ByteBuf buffer) throws IOException {
|
||||
return NamedCompoundTagType.read(buffer, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final CompoundTag object) throws Exception {
|
||||
public void write(final ByteBuf buffer, final CompoundTag object) throws IOException {
|
||||
NamedCompoundTagType.write(buffer, object, null);
|
||||
}
|
||||
|
||||
|
@ -42,16 +42,16 @@ public class NamedCompoundTagType extends Type<CompoundTag> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag read(final ByteBuf buffer) throws Exception {
|
||||
public CompoundTag read(final ByteBuf buffer) throws IOException {
|
||||
return read(buffer, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final CompoundTag object) throws Exception {
|
||||
public void write(final ByteBuf buffer, final CompoundTag object) throws IOException {
|
||||
write(buffer, object, "");
|
||||
}
|
||||
|
||||
public static CompoundTag read(final ByteBuf buffer, final boolean readName) throws Exception {
|
||||
public static CompoundTag read(final ByteBuf buffer, final boolean readName) throws IOException {
|
||||
final byte id = buffer.readByte();
|
||||
if (id == 0) {
|
||||
return null;
|
||||
@ -65,12 +65,10 @@ public class NamedCompoundTagType extends Type<CompoundTag> {
|
||||
}
|
||||
|
||||
final TagLimiter tagLimiter = TagLimiter.create(MAX_NBT_BYTES, MAX_NESTING_LEVEL);
|
||||
final CompoundTag tag = new CompoundTag();
|
||||
tag.read(new ByteBufInputStream(buffer), tagLimiter);
|
||||
return tag;
|
||||
return CompoundTag.read(new ByteBufInputStream(buffer), tagLimiter, 0);
|
||||
}
|
||||
|
||||
public static void write(final ByteBuf buffer, final Tag tag, final @Nullable String name) throws Exception {
|
||||
public static void write(final ByteBuf buffer, final Tag tag, final @Nullable String name) throws IOException {
|
||||
if (tag == null) {
|
||||
buffer.writeByte(0);
|
||||
return;
|
||||
|
@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TagType extends Type<Tag> {
|
||||
|
||||
@ -37,20 +38,18 @@ public class TagType extends Type<Tag> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag read(final ByteBuf buffer) throws Exception {
|
||||
public Tag read(final ByteBuf buffer) throws IOException {
|
||||
final byte id = buffer.readByte();
|
||||
if (id == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final TagLimiter tagLimiter = TagLimiter.create(NamedCompoundTagType.MAX_NBT_BYTES, NamedCompoundTagType.MAX_NESTING_LEVEL);
|
||||
final Tag tag = TagRegistry.createInstance(id);
|
||||
tag.read(new ByteBufInputStream(buffer), tagLimiter);
|
||||
return tag;
|
||||
return TagRegistry.read(id, new ByteBufInputStream(buffer), tagLimiter, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Tag tag) throws Exception {
|
||||
public void write(final ByteBuf buffer, final Tag tag) throws IOException {
|
||||
NamedCompoundTagType.write(buffer, tag, null);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,6 @@ fun ShadowJar.configureExcludes() {
|
||||
exclude("it/unimi/dsi/fastutil/*/*Big*")
|
||||
exclude("it/unimi/dsi/fastutil/*/*Synchronized*")
|
||||
exclude("it/unimi/dsi/fastutil/*/*Unmodifiable*")
|
||||
exclude("it/unimi/dsi/fastutil/io/*")
|
||||
// Flare - only need int maps
|
||||
exclude("space/vectrix/flare/fastutil/*Double*")
|
||||
exclude("space/vectrix/flare/fastutil/*Float*")
|
||||
|
@ -361,7 +361,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
||||
if (tag.get("CanPlaceOn") instanceof ListTag) {
|
||||
ListTag old = tag.get("CanPlaceOn");
|
||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
||||
tag.put(NBT_TAG_NAME + "|CanPlaceOn", old.clone());
|
||||
tag.put(NBT_TAG_NAME + "|CanPlaceOn", old.copy());
|
||||
for (Tag oldTag : old) {
|
||||
Object value = oldTag.getValue();
|
||||
String oldId = Key.stripMinecraftNamespace(value.toString());
|
||||
@ -383,7 +383,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
||||
if (tag.get("CanDestroy") instanceof ListTag) {
|
||||
ListTag old = tag.get("CanDestroy");
|
||||
ListTag newCanDestroy = new ListTag(StringTag.class);
|
||||
tag.put(NBT_TAG_NAME + "|CanDestroy", old.clone());
|
||||
tag.put(NBT_TAG_NAME + "|CanDestroy", old.copy());
|
||||
for (Tag oldTag : old) {
|
||||
Object value = oldTag.getValue();
|
||||
String oldId = Key.stripMinecraftNamespace(value.toString());
|
||||
|
@ -248,7 +248,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
display.put(NBT_TAG_NAME + "|Lore", new ListTag(lore.clone().getValue())); // Save old lore
|
||||
display.put(NBT_TAG_NAME + "|Lore", new ListTag(lore.copy().getValue())); // Save old lore
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
String jsonText = ComponentUtil.legacyToJsonString(((StringTag) loreEntry).getValue(), true);
|
||||
|
@ -17,18 +17,14 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.data;
|
||||
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MappingData extends MappingDataBase {
|
||||
private final Map<String, CompoundTag> dimensionDataMap = new HashMap<>();
|
||||
@ -40,11 +36,7 @@ public class MappingData extends MappingDataBase {
|
||||
|
||||
@Override
|
||||
public void loadExtras(final CompoundTag data) {
|
||||
try {
|
||||
dimensionRegistry = NBTIO.readTag(MappingDataLoader.getResource("dimension-registry-1.16.2.nbt"));
|
||||
} catch (final IOException e) {
|
||||
Via.getPlatform().getLogger().log(Level.SEVERE, "Error loading dimension registry:", e);
|
||||
}
|
||||
dimensionRegistry = MappingDataLoader.loadNBTFromFile("dimension-registry-1.16.2.nbt");
|
||||
|
||||
// Data of each dimension
|
||||
final ListTag dimensions = ((CompoundTag) dimensionRegistry.get("minecraft:dimension_type")).get("value");
|
||||
@ -61,6 +53,6 @@ public class MappingData extends MappingDataBase {
|
||||
}
|
||||
|
||||
public CompoundTag getDimensionRegistry() {
|
||||
return dimensionRegistry.clone();
|
||||
return dimensionRegistry.copy();
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,6 @@ public class EntityPackets {
|
||||
Via.getPlatform().getLogger().severe("Could not get dimension data of " + dimensionType);
|
||||
throw new NullPointerException("Dimension data for " + dimensionType + " is null!");
|
||||
}
|
||||
return tag.clone();
|
||||
return tag.copy();
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class EntityPackets {
|
||||
handler(wrapper -> {
|
||||
wrapper.write(Type.BYTE, (byte) -1); // Previous gamemode, set to none
|
||||
wrapper.write(Type.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length)); // World list - only used for command completion
|
||||
wrapper.write(Type.NAMED_COMPOUND_TAG, DIMENSIONS_TAG.clone()); // Dimension registry
|
||||
wrapper.write(Type.NAMED_COMPOUND_TAG, DIMENSIONS_TAG.copy()); // Dimension registry
|
||||
});
|
||||
handler(DIMENSION_HANDLER); // Dimension
|
||||
map(Type.LONG); // Seed
|
||||
|
@ -230,7 +230,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
||||
}
|
||||
|
||||
// Replace chat types - they won't actually be used
|
||||
registry.put("minecraft:chat_type", CHAT_REGISTRY.clone());
|
||||
registry.put("minecraft:chat_type", CHAT_REGISTRY.copy());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -17,11 +17,9 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.data;
|
||||
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class MappingData extends MappingDataBase {
|
||||
|
||||
@ -33,14 +31,10 @@ public final class MappingData extends MappingDataBase {
|
||||
|
||||
@Override
|
||||
protected void loadExtras(final CompoundTag data) {
|
||||
try {
|
||||
damageTypesRegistry = NBTIO.readTag(MappingDataLoader.getResource("damage-types-1.19.4.nbt"));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
damageTypesRegistry = MappingDataLoader.loadNBTFromFile("damage-types-1.19.4.nbt");
|
||||
}
|
||||
|
||||
public CompoundTag damageTypesRegistry() {
|
||||
return damageTypesRegistry.clone();
|
||||
return damageTypesRegistry.copy();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.data;
|
||||
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||
@ -26,7 +25,6 @@ import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.io.IOException;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class MappingData extends MappingDataBase {
|
||||
@ -39,15 +37,11 @@ public final class MappingData extends MappingDataBase {
|
||||
|
||||
@Override
|
||||
protected void loadExtras(final CompoundTag daata) {
|
||||
try {
|
||||
final ListTag chatTypes = NBTIO.readTag(MappingDataLoader.getResource("chat-types-1.19.nbt")).get("values");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
defaultChatTypes.put(idTag.asInt(), chatTypeCompound);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
final ListTag chatTypes = MappingDataLoader.loadNBTFromFile("chat-types-1.19.nbt").get("values");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
defaultChatTypes.put(idTag.asInt(), chatTypeCompound);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
||||
final CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
|
||||
// Add necessary chat types
|
||||
tag.put("minecraft:chat_type", CHAT_REGISTRY.clone());
|
||||
tag.put("minecraft:chat_type", CHAT_REGISTRY.copy());
|
||||
|
||||
// Cache a whole lot of data
|
||||
final ListTag dimensions = ((CompoundTag) tag.get("minecraft:dimension_type")).get("value");
|
||||
@ -216,7 +216,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
||||
final String name = (String) dimensionCompound.get("name").getValue();
|
||||
addMonsterSpawnData(element);
|
||||
dimensionDataMap.put(name, new DimensionDataImpl(element));
|
||||
dimensionsMap.put(element.clone(), name);
|
||||
dimensionsMap.put(element.copy(), name);
|
||||
}
|
||||
tracker(wrapper.user()).setDimensions(dimensionDataMap);
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class FakeTileEntity {
|
||||
public static CompoundTag createTileEntity(int x, int y, int z, int block) {
|
||||
CompoundTag originalTag = tileEntities.get(block);
|
||||
if (originalTag != null) {
|
||||
CompoundTag tag = originalTag.clone();
|
||||
CompoundTag tag = originalTag.copy();
|
||||
tag.put("x", new IntTag(x));
|
||||
tag.put("y", new IntTag(y));
|
||||
tag.put("z", new IntTag(z));
|
||||
|
@ -69,7 +69,7 @@ public class CommandBlockStorage implements StorableObject {
|
||||
if (tag == null)
|
||||
return Optional.empty();
|
||||
|
||||
tag = tag.clone();
|
||||
tag = tag.copy();
|
||||
tag.put("powered", new ByteTag((byte) 0));
|
||||
tag.put("auto", new ByteTag((byte) 0));
|
||||
tag.put("conditionMet", new ByteTag((byte) 0));
|
||||
|
@ -5,7 +5,7 @@ metadata.format.version = "1.1"
|
||||
gson = "2.10.1"
|
||||
fastutil = "8.5.12"
|
||||
flare = "2.0.1"
|
||||
vianbt = "3.5.0"
|
||||
vianbt = "4.0.0"
|
||||
mcstructs = "2.4.2-SNAPSHOT"
|
||||
|
||||
# Common provided
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren