3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-25 15:50:12 +01:00
Dieser Commit ist enthalten in:
Nassim Jahnke 2021-11-16 19:20:23 +01:00
Ursprung becba6498e
Commit ce6ca4dc0f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
9 geänderte Dateien mit 55 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@ plugins {
allprojects { allprojects {
group = "com.viaversion" group = "com.viaversion"
version = "4.1.0-1.18-pre1-SNAPSHOT" version = "4.1.0-1.18-pre2-SNAPSHOT"
description = "Allow older clients to join newer server versions." description = "Allow older clients to join newer server versions."
} }

Datei anzeigen

@ -83,7 +83,8 @@ public class BackwardsMappings extends MappingDataBase {
if (!oldMappings.has(key) || !newMappings.has(key)) return null; if (!oldMappings.has(key) || !newMappings.has(key)) return null;
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null; JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
return new VBMappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), diff, shouldWarnOnMissing(key)); return VBMappings.vbBuilder().unmapped(oldMappings.getAsJsonArray(key)).mapped(newMappings.getAsJsonArray(key))
.diffMappings(diff).warnOnMissing(shouldWarnOnMissing(key)).build();
} }
@Override @Override
@ -91,7 +92,8 @@ public class BackwardsMappings extends MappingDataBase {
if (!oldMappings.has(key) || !newMappings.has(key)) return null; if (!oldMappings.has(key) || !newMappings.has(key)) return null;
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null; JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
return new VBMappings(oldMappings.getAsJsonObject(key), newMappings.getAsJsonObject(key), diff, shouldWarnOnMissing(key)); return VBMappings.vbBuilder().unmapped(oldMappings.getAsJsonObject(key)).mapped(newMappings.getAsJsonObject(key))
.diffMappings(diff).warnOnMissing(shouldWarnOnMissing(key)).build();
} }
@Override @Override

Datei anzeigen

@ -38,7 +38,7 @@ import java.io.InputStreamReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class VBMappingDataLoader { public final class VBMappingDataLoader {
public static JsonObject loadFromDataDir(String name) { public static JsonObject loadFromDataDir(String name) {
File file = new File(ViaBackwards.getPlatform().getDataFolder(), name); File file = new File(ViaBackwards.getPlatform().getDataFolder(), name);
@ -68,10 +68,6 @@ public class VBMappingDataLoader {
} }
} }
public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers) {
mapIdentifiers(output, oldIdentifiers, newIdentifiers, diffIdentifiers, true);
}
public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) { public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) {
Object2IntMap<String> newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers); Object2IntMap<String> newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers);
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
@ -137,10 +133,6 @@ public class VBMappingDataLoader {
return mappings; return mappings;
} }
public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
return loadItemMappings(oldMapping, newMapping, diffMapping, false);
}
public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) { public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
Int2ObjectMap<MappedItem> itemMapping = new Int2ObjectOpenHashMap<>(diffMapping.size(), 0.99F); Int2ObjectMap<MappedItem> itemMapping = new Int2ObjectOpenHashMap<>(diffMapping.size(), 0.99F);
Object2IntMap<String> newIdenfierMap = MappingDataLoader.indexedObjectToMap(newMapping); Object2IntMap<String> newIdenfierMap = MappingDataLoader.indexedObjectToMap(newMapping);

Datei anzeigen

@ -18,33 +18,44 @@
package com.viaversion.viabackwards.api.data; package com.viaversion.viabackwards.api.data;
import com.viaversion.viaversion.api.data.IntArrayMappings; import com.viaversion.viaversion.api.data.IntArrayMappings;
import com.viaversion.viaversion.libs.gson.JsonArray; import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.api.data.Mappings;
import java.util.Arrays; public final class VBMappings extends IntArrayMappings {
public class VBMappings extends IntArrayMappings { private VBMappings(final int[] oldToNew, final int mappedIds) {
super(oldToNew, mappedIds);
public VBMappings(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
super(create(size, oldMapping, newMapping, diffMapping, warnOnMissing));
} }
public VBMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) { public static Mappings.Builder<VBMappings> vbBuilder() {
super(create(oldMapping.entrySet().size(), oldMapping, newMapping, diffMapping, warnOnMissing)); return new Builder(VBMappings::new);
} }
public VBMappings(JsonObject oldMapping, JsonObject newMapping, boolean warnOnMissing) { public static final class Builder extends Mappings.Builder<VBMappings> {
this(oldMapping, newMapping, null, warnOnMissing);
private Builder(final MappingsSupplier<VBMappings> supplier) {
super(supplier);
} }
public VBMappings(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) { @Override
super(oldMapping.size(), oldMapping, newMapping, diffMapping, warnOnMissing); public VBMappings build() {
final int size = this.size != -1 ? this.size : size(unmapped);
final int mappedSize = this.mappedSize != -1 ? this.mappedSize : size(mapped);
final int[] mappings = new int[size];
// Do conversion if one is an array and the other an object, otherwise directly map
if (unmapped.isJsonArray()) {
if (mapped.isJsonObject()) {
VBMappingDataLoader.mapIdentifiers(mappings, toJsonObject(unmapped.getAsJsonArray()), mapped.getAsJsonObject(), diffMappings, warnOnMissing);
} else {
// Use the normal loader
MappingDataLoader.mapIdentifiers(mappings, unmapped.getAsJsonArray(), mapped.getAsJsonArray(), diffMappings, warnOnMissing);
}
} else if (mapped.isJsonArray()) {
VBMappingDataLoader.mapIdentifiers(mappings, unmapped.getAsJsonObject(), toJsonObject(mapped.getAsJsonArray()), diffMappings, warnOnMissing);
} else {
VBMappingDataLoader.mapIdentifiers(mappings, unmapped.getAsJsonObject(), mapped.getAsJsonObject(), diffMappings, warnOnMissing);
}
return supplier.supply(mappings, mappedSize);
} }
private static int[] create(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
int[] oldToNew = new int[size];
Arrays.fill(oldToNew, -1);
VBMappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing);
return oldToNew;
} }
} }

Datei anzeigen

@ -52,6 +52,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
private final MetaType displayVisibilityMetaType; private final MetaType displayVisibilityMetaType;
private final int displayNameIndex; private final int displayNameIndex;
private final int displayVisibilityIndex; private final int displayVisibilityIndex;
protected boolean allowNullEntityType;
EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex, EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex,
MetaType displayVisibilityMetaType, int displayVisibilityIndex) { MetaType displayVisibilityMetaType, int displayVisibilityIndex) {
@ -65,12 +66,16 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
@Override @Override
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) { public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) {
EntityType type = tracker(connection).entityType(entityId); EntityType type = tracker(connection).entityType(entityId);
if (type == null) { if (type == null && !allowNullEntityType) {
return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling return;
} }
super.handleMetadata(entityId, metadataList, connection); super.handleMetadata(entityId, metadataList, connection);
if (type == null) {
return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling
}
EntityData entityData = entityDataForType(type); EntityData entityData = entityDataForType(type);
// Set the mapped entity name if there is no custom name set already // Set the mapped entity name if there is no custom name set already

Datei anzeigen

@ -49,7 +49,8 @@ public class BackwardsMappings extends com.viaversion.viabackwards.api.data.Back
@Override @Override
public void loadVBExtras(JsonObject oldMappings, JsonObject newMappings) { public void loadVBExtras(JsonObject oldMappings, JsonObject newMappings) {
enchantmentMappings = new VBMappings(oldMappings.getAsJsonObject("enchantments"), newMappings.getAsJsonObject("enchantments"), false); enchantmentMappings = VBMappings.vbBuilder().warnOnMissing(false)
.unmapped(oldMappings.getAsJsonObject("enchantments")).mapped(newMappings.getAsJsonObject("enchantments")).build();
for (Map.Entry<String, Integer> entry : StatisticMappings.CUSTOM_STATS.entrySet()) { for (Map.Entry<String, Integer> entry : StatisticMappings.CUSTOM_STATS.entrySet()) {
statisticMappings.put(entry.getValue().intValue(), entry.getKey()); statisticMappings.put(entry.getValue().intValue(), entry.getKey());
} }

Datei anzeigen

@ -40,6 +40,7 @@ public final class EntityPackets1_18 extends EntityRewriter<Protocol1_17_1To1_18
public EntityPackets1_18(final Protocol1_17_1To1_18 protocol) { public EntityPackets1_18(final Protocol1_17_1To1_18 protocol) {
super(protocol); super(protocol);
allowNullEntityType = true;
} }
@Override @Override
@ -120,6 +121,7 @@ public final class EntityPackets1_18 extends EntityRewriter<Protocol1_17_1To1_18
}); });
// Particles have already been handled // Particles have already been handled
//registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, null);
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, null); registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, null);
} }

Datei anzeigen

@ -14,6 +14,12 @@
"music.overworld.snowy_slopes": "", "music.overworld.snowy_slopes": "",
"music.overworld.stony_peaks": "" "music.overworld.stony_peaks": ""
}, },
"items": {
"minecraft:music_disc_otherside": {
"id": "minecraft:music_disc_ward",
"name": "1.18 Otherside Music Disc"
}
},
"particles": { "particles": {
"block_marker": "barrier" "block_marker": "barrier"
} }

Datei anzeigen

@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions] [versions]
# ViaVersion # ViaVersion
viaver = "4.1.0-21w44a-SNAPSHOT" viaver = "4.1.0-1.18-pre2-SNAPSHOT"
# Common provided # Common provided
netty = "4.0.20.Final" netty = "4.0.20.Final"