3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Fix various issues

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-03-15 19:01:26 +01:00
Ursprung 4255876c22
Commit c2567115d8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
12 geänderte Dateien mit 96 neuen und 71 gelöschten Zeilen

Datei anzeigen

@ -130,4 +130,11 @@ public final class StructuredDataContainer {
public Map<StructuredDataKey<?>, StructuredData<?>> data() {
return data;
}
@Override
public String toString() {
return "StructuredDataContainer{" +
"data=" + data +
'}';
}
}

Datei anzeigen

@ -114,4 +114,12 @@ public final class StructuredDataKey<T> {
public String identifier() {
return identifier;
}
@Override
public String toString() {
return "StructuredDataKey{" +
"identifier='" + identifier + '\'' +
", type=" + type +
'}';
}
}

Datei anzeigen

@ -55,8 +55,8 @@ public abstract class Filterable<T> {
private final Type<T> elementType;
private final Type<T> optionalElementType;
protected FilterableType(final Type<T> elementType, final Type<T> optionalElementType) {
super(Filterable.class);
protected FilterableType(final Type<T> elementType, final Type<T> optionalElementType, final Class<F> outputClass) {
super(outputClass);
this.elementType = elementType;
this.optionalElementType = optionalElementType;
}

Datei anzeigen

@ -29,13 +29,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class FilterableComponent extends Filterable<Tag> {
public static final Type<FilterableComponent> TYPE = new FilterableType<Tag, FilterableComponent>(Type.TAG, Type.OPTIONAL_TAG) {
public static final Type<FilterableComponent> TYPE = new FilterableType<Tag, FilterableComponent>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) {
@Override
protected FilterableComponent create(final Tag raw, final Tag filtered) {
return new FilterableComponent(raw, filtered);
}
};
public static final Type<FilterableComponent[]> ARRAY_TYPE = new ArrayType<>(TYPE);
public static final Type<FilterableComponent[]> ARRAY_TYPE = new ArrayType<>(FilterableComponent.TYPE);
public FilterableComponent(final Tag raw, @Nullable final Tag filtered) {
super(raw, filtered);

Datei anzeigen

@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class FilterableString extends Filterable<String> {
public static final Type<FilterableString> TYPE = new FilterableType<String, FilterableString>(Type.STRING, Type.OPTIONAL_STRING) {
public static final Type<FilterableString> TYPE = new FilterableType<String, FilterableString>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) {
@Override
protected FilterableString create(final String raw, final String filtered) {
return new FilterableString(raw, filtered);

Datei anzeigen

@ -17,10 +17,11 @@
*/
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.KeyMappings;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class Attributes1_20_3 {
public final class Attributes1_20_5 {
private static final KeyMappings ATTRIBUTES = new KeyMappings(
"generic.armor",
@ -28,22 +29,33 @@ public final class Attributes1_20_3 {
"generic.attack_damage",
"generic.attack_knockback",
"generic.attack_speed",
"player.block_break_speed",
"player.block_interaction_range",
"player.entity_interaction_range",
"generic.fall_damage_multiplier",
"generic.flying_speed",
"generic.follow_range",
"horse.jump_strength",
"generic.gravity",
"generic.jump_strength",
"generic.knockback_resistance",
"generic.luck",
"generic.max_absorption",
"generic.max_health",
"generic.movement_speed",
"zombie.spawn_reinforcements"
"generic.safe_fall_distance",
"generic.scale",
"zombie.spawn_reinforcements",
"generic.step_height"
);
public static @Nullable String idToKey(final int id) {
return ATTRIBUTES.idToKey(id);
}
public static int keyToId(final String attribute) {
public static int keyToId(String attribute) {
if (Key.stripMinecraftNamespace(attribute).equals("horse.jump_strength")) {
attribute = "generic.jump_strength";
}
return ATTRIBUTES.keyToId(attribute);
}
}

Datei anzeigen

@ -23,16 +23,16 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class TrimMaterials1_20_3 {
private static final KeyMappings MATERIALS = new KeyMappings(
"quartz",
"iron",
"netherite",
"redstone",
"amethyst",
"copper",
"gold",
"emerald",
"diamond",
"emerald",
"quartz",
"gold",
"iron",
"lapis",
"amethyst"
"netherite",
"redstone"
);
public static @Nullable String idToKey(final int id) {

Datei anzeigen

@ -1,6 +1,6 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2023 ViaVersion and contributors
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,27 +20,25 @@ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data;
import com.viaversion.viaversion.util.KeyMappings;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class TrimPatterns1_20_5 {
public final class TrimPatterns1_20_3 {
private static final KeyMappings PATTERNS = new KeyMappings(
"sentry",
"dune",
"coast",
"wild",
"ward",
"dune",
"eye",
"vex",
"tide",
"snout",
"host",
"raiser",
"rib",
"spire",
"wayfinder",
"sentry",
"shaper",
"silence",
"raiser",
"host",
"flow",
"bolt"
"snout",
"spire",
"tide",
"vex",
"ward",
"wayfinder",
"wild"
);
public static @Nullable String idToKey(final int id) {

Datei anzeigen

@ -73,7 +73,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.Clientb
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.RecipeRewriter1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.BannerPatterns1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.DyeColors;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantments1_20_3;
@ -81,7 +81,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Instrumen
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.MapDecorations1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimMaterials1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimPatterns1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimPatterns1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.rewriter.BlockRewriter;
@ -233,14 +233,14 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
public @Nullable Item handleItemToClient(@Nullable final Item item) {
if (item == null) return null;
super.handleItemToClient(item);
// Add the original as custom data, to be re-used for creative clients as well
final CompoundTag tag = item.tag();
if (tag != null) {
tag.putBoolean(nbtTagName(), true);
}
return toStructuredItem(item);
final Item structuredItem = toStructuredItem(item);
return super.handleItemToClient(structuredItem);
}
@Override
@ -275,7 +275,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final StructuredItem item = new StructuredItem(old.identifier(), (byte) old.amount(), new StructuredDataContainer());
final StructuredDataContainer data = item.structuredData();
data.setIdLookup(protocol, true);
// TODO add default data if needed (e.g. when getting a goat horn via the give command) :>
//TODO add default data if needed, e.g. when getting an item via /give without extra data
// Goat horn
// (check more)
if (tag == null) {
return item;
}
@ -464,7 +466,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return null;
}
holders = HolderSet.of(new int[]{Protocol1_20_5To1_20_3.MAPPINGS.getNewBlockId(id)});
holders = HolderSet.of(new int[]{id});
} else {
holders = HolderSet.of(identifier.substring(1));
}
@ -514,12 +516,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return null;
}
final int operationId = modifierTag.getInt("Operation", -1);
final int operationId = modifierTag.getInt("Operation");
if (operationId < 0 || operationId > 2) {
return null;
}
final int attributeId = Attributes1_20_3.keyToId(attributeName);
final int attributeId = Attributes1_20_5.keyToId(attributeName);
if (attributeId == -1) {
return null;
}
@ -592,6 +594,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final Tag materialTag = trimTag.get("material");
final Holder<ArmorTrimMaterial> materialHolder;
if (materialTag instanceof StringTag) {
// Would technically have to be stored and retreived from registry data, but that'd mean a lot of work
final int id = TrimMaterials1_20_3.keyToId(((StringTag) materialTag).getValue());
if (id == -1) {
return;
@ -638,7 +641,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final Tag patternTag = trimTag.get("pattern");
final Holder<ArmorTrimPattern> patternHolder;
if (patternTag instanceof StringTag) {
final int id = TrimPatterns1_20_5.keyToId(((StringTag) patternTag).getValue());
// Would technically have to be stored and retreived from registry data, but that'd mean a lot of work
final int id = TrimPatterns1_20_3.keyToId(((StringTag) patternTag).getValue());
if (id == -1) {
return;
}
@ -841,8 +845,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return;
}
tag.remove(key);
final Enchantments enchantments = new Enchantments(new Int2IntOpenHashMap(), show);
for (final CompoundTag enchantment : enchantmentsTag) {
final String id = enchantment.getString("id");
@ -862,7 +864,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(newKey, enchantments);
// Add glint if none of the enchantments were valid
if (enchantments.size() == 0 && !enchantmentsTag.isEmpty()) {
if (!enchantmentsTag.isEmpty() && enchantments.size() == 0) {
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
}
}
@ -1011,6 +1013,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
containerLoot.putLong("loot_table_seed", lootTableSeed);
data.set(StructuredDataKey.CONTAINER_LOOT, containerLoot);
}
final Tag baseColorTag = tag.remove("Base");
if (baseColorTag instanceof NumberTag) {
data.set(StructuredDataKey.BASE_COLOR, ((NumberTag) baseColorTag).asInt());
}
updateItemList(data, tag, "Items", StructuredDataKey.CONTAINER);
}
final Tag skullOwnerTag = tag.remove("SkullOwner");
@ -1022,14 +1031,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
updateSkullOwnerTag(tag, (CompoundTag) skullOwnerTag);
}
final Tag baseColorTag = tag.remove("Base");
if (baseColorTag instanceof NumberTag) {
tag.put("base_color", baseColorTag);
if (data != null) {
data.set(StructuredDataKey.BASE_COLOR, ((NumberTag) baseColorTag).asInt());
}
}
final ListTag<CompoundTag> patternsTag = tag.getListTag("Patterns", CompoundTag.class);
if (patternsTag != null) {
final BannerPatternLayer[] layers = patternsTag.stream().map(patternTag -> {
@ -1055,8 +1056,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(StructuredDataKey.BANNER_PATTERNS, layers);
}
}
updateItemList(data, tag, "Items", StructuredDataKey.CONTAINER);
}
private void updateSkullOwnerTag(final CompoundTag tag, final CompoundTag skullOwnerTag) {

Datei anzeigen

@ -35,11 +35,10 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.Clientb
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.BannerPatterns1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.Key;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
@ -67,14 +66,14 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
for (final Map.Entry<String, Tag> entry : registryData.entrySet()) {
final CompoundTag entryTag = (CompoundTag) entry.getValue();
final StringTag typeTag = entryTag.getStringTag("type");
final String type = entryTag.getString("type");
final ListTag<CompoundTag> valueTag = entryTag.getListTag("value", CompoundTag.class);
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
boolean requiresDummyValues = false;
int entriesLength = registryEntries.length;
for (final CompoundTag tag : valueTag) {
final StringTag nameTag = tag.getStringTag("name");
final int id = tag.getNumberTag("id").asInt();
final String name = tag.getString("name");
final int id = tag.getInt("id");
entriesLength = Math.max(entriesLength, id + 1);
if (id >= registryEntries.length) {
// It was previously possible to have arbitrary ids
@ -82,7 +81,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
requiresDummyValues = true;
}
registryEntries[id] = new RegistryEntry(nameTag.getValue(), tag.get("element"));
registryEntries[id] = new RegistryEntry(name, tag.get("element"));
}
if (requiresDummyValues) {
@ -94,7 +93,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}
final PacketWrapper registryPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
registryPacket.write(Type.STRING, typeTag.getValue());
registryPacket.write(Type.STRING, type);
registryPacket.write(Type.REGISTRY_ENTRY_ARRAY, registryEntries);
registryPacket.send(Protocol1_20_5To1_20_3.class);
}
@ -155,6 +154,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
map(Type.VAR_INT); // Portal cooldown
create(Type.BOOLEAN, false); // Enforces secure chat - moved from server data (which is unfortunately sent a while after this)
handler(worldDataTrackerHandlerByKey1_20_5(3)); // Tracks world height and name for chunk data and entity (un)tracking
handler(playerTrackerHandler());
}
});
@ -184,9 +184,9 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
// From a string to a registry int ID
final String attributeIdentifier = Key.stripMinecraftNamespace(wrapper.read(Type.STRING));
final int id = Attributes1_20_3.keyToId(attributeIdentifier);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewAttributeId(id));
final String attributeIdentifier = wrapper.read(Type.STRING);
final int id = Attributes1_20_5.keyToId(attributeIdentifier);
wrapper.write(Type.VAR_INT, id != -1 ? id : 0);
wrapper.passthrough(Type.DOUBLE); // Base
final int modifierSize = wrapper.passthrough(Type.VAR_INT);
@ -220,13 +220,13 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
protected void registerRewrites() {
filter().mapMetaType(typeId -> {
int id = typeId;
if (typeId >= Types1_20_5.META_TYPES.particlesType.typeId()) {
if (id >= Types1_20_5.META_TYPES.particlesType.typeId()) {
id++;
}
if (typeId >= Types1_20_5.META_TYPES.armadilloState.typeId()) {
if (id >= Types1_20_5.META_TYPES.wolfVariantType.typeId()) {
id++;
}
if (typeId >= Types1_20_5.META_TYPES.wolfVariantType.typeId()) {
if (id >= Types1_20_5.META_TYPES.armadilloState.typeId()) {
id++;
}
return Types1_20_5.META_TYPES.byId(id);
@ -259,7 +259,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
public void rewriteParticle(final Particle particle) {
super.rewriteParticle(particle);
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
particle.add(Type.INT, 0); // rgb
particle.add(Type.INT, 0); // rgb // TODO
}
}

Datei anzeigen

@ -46,7 +46,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.StatePropertyMatcher;
import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.BannerPatterns1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantments1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Instruments1_20_3;
@ -94,13 +94,13 @@ final class StructuredDataConverter {
register(StructuredDataKey.ATTRIBUTE_MODIFIERS, (data, tag) -> {
final ListTag<CompoundTag> modifiers = new ListTag<>(CompoundTag.class);
for (final AttributeModifier modifier : data.modifiers()) {
final String identifier = Attributes1_20_3.idToKey(modifier.attribute());
final String identifier = Attributes1_20_5.idToKey(modifier.attribute());
if (identifier == null) {
continue;
}
final CompoundTag modifierTag = new CompoundTag();
modifierTag.putString("AttributeName", identifier);
modifierTag.putString("AttributeName", identifier.equals("generic.jump_strength") ? "horse.jump_strength" : identifier);
modifierTag.putString("Name", modifier.modifier().name());
modifierTag.putDouble("Amount", modifier.modifier().amount());
modifierTag.putInt("Slot", modifier.slotType());

Datei anzeigen

@ -68,6 +68,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
map(Type.VAR_INT); // Dimension id
map(Type.STRING); // World
handler(worldDataTrackerHandlerByKey1_20_5(3)); // Tracks world height and name for chunk data and entity (un)tracking
handler(playerTrackerHandler());
}
});