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

Update VV usage

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-05 15:38:37 +02:00
Ursprung f7dad9b5d7
Commit 9f652ad24a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
6 geänderte Dateien mit 22 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -76,7 +76,7 @@ public abstract class BackwardsItemRewriterBase<C extends ClientboundPacketType,
protected void saveGenericTagList(CompoundTag tag, List<Tag> original, String name) {
// List tags cannot contain tags of different types, so we have to store them a bit more awkwardly as an indexed compound tag
String backupName = getNbtTagName() + "|" + name;
String backupName = nbtTagName(name);
if (!tag.contains(backupName)) {
CompoundTag output = new CompoundTag();
for (int i = 0; i < original.size(); i++) {
@ -87,7 +87,7 @@ public abstract class BackwardsItemRewriterBase<C extends ClientboundPacketType,
}
protected List<Tag> removeGenericTagList(CompoundTag tag, String name) {
String backupName = getNbtTagName() + "|" + name;
String backupName = nbtTagName(name);
CompoundTag data = tag.getCompoundTag(backupName);
if (data == null) {
return null;

Datei anzeigen

@ -101,7 +101,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
// Set custom name - only done if there is no original one
if (!data.contains(StructuredDataKey.CUSTOM_NAME)) {
data.set(StructuredDataKey.CUSTOM_NAME, mappedItem.tagName());
tag.putBoolean(getNbtTagName() + "|customName", true);
tag.putBoolean(nbtTagName("customName"), true);
}
return item;
}
@ -162,7 +162,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
}
// Remove custom name
if (customData.value().remove(getNbtTagName() + "|customName") != null) {
if (customData.value().remove(nbtTagName("customName")) != null) {
data.remove(StructuredDataKey.CUSTOM_NAME);
} else {
final Tag name = removeBackupTag(customData.value(), "Name");
@ -173,13 +173,13 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
}
protected void saveTag(CompoundTag customData, Tag tag, String name) {
String backupName = getNbtTagName() + "|o" + name;
String backupName = nbtTagName(name);
if (!customData.contains(backupName)) {
customData.put(backupName, tag);
}
}
protected @Nullable Tag removeBackupTag(CompoundTag customData, String tagName) {
return customData.remove(getNbtTagName() + "|o" + tagName);
return customData.remove(nbtTagName(tagName));
}
}

Datei anzeigen

@ -60,10 +60,10 @@ public class StructuredEnchantmentRewriter {
}
final CompoundTag tag = customData.value();
if (tag.contains(itemRewriter.getNbtTagName() + "|enchantments")) {
if (tag.contains(itemRewriter.nbtTagName("enchantments"))) {
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.ENCHANTMENTS, false);
}
if (tag.contains(itemRewriter.getNbtTagName() + "|stored_enchantments")) {
if (tag.contains(itemRewriter.nbtTagName("stored_enchantments"))) {
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.STORED_ENCHANTMENTS, true);
}
}
@ -121,9 +121,9 @@ public class StructuredEnchantmentRewriter {
if (!storedEnchant && enchantments.size() == 0) {
final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
if (glintOverride != null) {
tag.putBoolean(itemRewriter.getNbtTagName() + "|glint", glintOverride.value());
tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value());
} else {
tag.putBoolean(itemRewriter.getNbtTagName() + "|noglint", true);
tag.putBoolean(itemRewriter.nbtTagName("noglint"), true);
}
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
}
@ -135,11 +135,11 @@ public class StructuredEnchantmentRewriter {
itemRewriter.saveGenericTagList(tag, loreList, "lore");
loreToAdd.addAll(loreList);
} else {
tag.putBoolean(itemRewriter.getNbtTagName() + "|nolore", true);
tag.putBoolean(itemRewriter.nbtTagName("nolore"), true);
}
if (enchantments.showInTooltip()) {
tag.putBoolean(itemRewriter.getNbtTagName() + "|show_" + key.identifier(), true);
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
}
data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0]));
@ -162,21 +162,21 @@ public class StructuredEnchantmentRewriter {
return;
}
final Tag glintTag = tag.remove(itemRewriter.getNbtTagName() + "|glint");
final Tag glintTag = tag.remove(itemRewriter.nbtTagName("glint"));
if (glintTag instanceof ByteTag) {
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, ((NumberTag) glintTag).asBoolean());
} else if (tag.remove(itemRewriter.getNbtTagName() + "|noglint") != null) {
} else if (tag.remove(itemRewriter.nbtTagName("noglint")) != null) {
data.remove(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
}
final List<Tag> lore = itemRewriter.removeGenericTagList(tag, "lore");
if (lore != null) {
data.set(StructuredDataKey.LORE, lore.toArray(new Tag[0]));
} else if (tag.remove(itemRewriter.getNbtTagName() + "|nolore") != null) {
} else if (tag.remove(itemRewriter.nbtTagName("nolore")) != null) {
data.remove(StructuredDataKey.LORE);
}
final Enchantments enchantments = new Enchantments(tag.remove(itemRewriter.getNbtTagName() + "|show_" + key.identifier()) != null);
final Enchantments enchantments = new Enchantments(tag.remove(itemRewriter.nbtTagName("show_" + key.identifier())) != null);
for (final CompoundTag enchantment : enchantmentsTag) {
enchantments.add(enchantment.getInt("id"), enchantment.getInt("lvl"));
}

Datei anzeigen

@ -76,7 +76,6 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundP
protected void registerPackets() {
// TODO Trim storage in registry sending
// TODO also for banners?
// TODO Update translation mappings once before release
super.registerPackets();
final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);

Datei anzeigen

@ -18,8 +18,6 @@
package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter;
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.Particle;
@ -34,12 +32,14 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.Recip
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.packet.ClientboundPacket1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.StructuredDataConverter;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_3, Protocol1_20_3To1_20_5> {
private static final StructuredDataConverter DATA_CONVERTER = new StructuredDataConverter(true);
private final Protocol1_20_5To1_20_3 vvProtocol = Via.getManager().getProtocolManager().getProtocol(Protocol1_20_5To1_20_3.class);
public BlockItemPacketRewriter1_20_5(final Protocol1_20_3To1_20_5 protocol) {
@ -161,7 +161,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
if (item == null) return null;
super.handleItemToClient(item);
return vvProtocol.getItemRewriter().toOldItem(item);
return vvProtocol.getItemRewriter().toOldItem(item, DATA_CONVERTER);
}
@Override

Datei anzeigen

@ -40,7 +40,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPac
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects1_20_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.MathUtil;
@ -402,13 +402,13 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
final Tag primaryEffect = tag.remove("primary_effect");
if (primaryEffect instanceof StringTag) {
final String effectKey = Key.stripMinecraftNamespace(((StringTag) primaryEffect).getValue());
tag.putInt("Primary", PotionEffects.keyToId(effectKey));
tag.putInt("Primary", PotionEffects1_20_2.keyToId(effectKey) + 1); // Empty effect at 0
}
final Tag secondaryEffect = tag.remove("secondary_effect");
if (secondaryEffect instanceof StringTag) {
final String effectKey = Key.stripMinecraftNamespace(((StringTag) secondaryEffect).getValue());
tag.putInt("Secondary", PotionEffects.keyToId(effectKey));
tag.putInt("Secondary", PotionEffects1_20_2.keyToId(effectKey) + 1); // Empty effect at 0
}
return tag;
}