Banner patterns and wolves

This commit is contained in:
Nassim Jahnke 2024-03-09 16:56:02 +01:00
parent 121f107ff3
commit bfab9b0c11
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
12 changed files with 355 additions and 122 deletions

View File

@ -33,31 +33,31 @@ public final class BannerPatternLayer {
@Override
public BannerPatternLayer read(final ByteBuf buffer) throws Exception {
final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer);
final DyedColor color = DyedColor.TYPE.read(buffer);
final int color = Type.VAR_INT.readPrimitive(buffer);
return new BannerPatternLayer(pattern, color);
}
@Override
public void write(final ByteBuf buffer, final BannerPatternLayer value) throws Exception {
BannerPattern.TYPE.write(buffer, value.pattern);
DyedColor.TYPE.write(buffer, value.color);
Type.VAR_INT.writePrimitive(buffer, value.dyeColor);
}
};
public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final Holder<BannerPattern> pattern;
private final DyedColor color;
private final int dyeColor;
public BannerPatternLayer(final Holder<BannerPattern> pattern, final DyedColor color) {
public BannerPatternLayer(final Holder<BannerPattern> pattern, final int dyeColor) {
this.pattern = pattern;
this.color = color;
this.dyeColor = dyeColor;
}
public Holder<BannerPattern> pattern() {
return pattern;
}
public DyedColor color() {
return color;
public int dyeColor() {
return dyeColor;
}
}

View File

@ -0,0 +1,131 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2023 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data;
import com.viaversion.viaversion.util.KeyMappings;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BannerPatterns1_20_3 {
private static final KeyMappings PATTERNS = new KeyMappings(
"base",
"square_bottom_left",
"square_bottom_right",
"square_top_left",
"square_top_right",
"stripe_bottom",
"stripe_top",
"stripe_left",
"stripe_right",
"stripe_center",
"stripe_middle",
"stripe_downright",
"stripe_downleft",
"small_stripes",
"cross",
"straight_cross",
"triangle_bottom",
"triangle_top",
"triangles_bottom",
"triangles_top",
"diagonal_left",
"diagonal_up_right",
"diagonal_up_left",
"diagonal_right",
"circle",
"rhombus",
"half_vertical",
"half_horizontal",
"half_vertical_right",
"half_horizontal_bottom",
"border",
"curly_border",
"gradient",
"gradient_up",
"bricks",
"globe",
"creeper",
"skull",
"flower",
"mojang",
"piglin"
);
private static final Map<String, String> PATTERN_IDS = new HashMap<>();
static {
PATTERN_IDS.put("b", "base");
PATTERN_IDS.put("bl", "square_bottom_left");
PATTERN_IDS.put("br", "square_bottom_right");
PATTERN_IDS.put("tl", "square_top_left");
PATTERN_IDS.put("tr", "square_top_right");
PATTERN_IDS.put("bs", "stripe_bottom");
PATTERN_IDS.put("ts", "stripe_top");
PATTERN_IDS.put("ls", "stripe_left");
PATTERN_IDS.put("rs", "stripe_right");
PATTERN_IDS.put("cs", "stripe_center");
PATTERN_IDS.put("ms", "stripe_middle");
PATTERN_IDS.put("drs", "stripe_downright");
PATTERN_IDS.put("dls", "stripe_downleft");
PATTERN_IDS.put("ss", "small_stripes");
PATTERN_IDS.put("cr", "cross");
PATTERN_IDS.put("sc", "straight_cross");
PATTERN_IDS.put("bt", "triangle_bottom");
PATTERN_IDS.put("tt", "triangle_top");
PATTERN_IDS.put("bts", "triangles_bottom");
PATTERN_IDS.put("tts", "triangles_top");
PATTERN_IDS.put("ld", "diagonal_left");
PATTERN_IDS.put("rd", "diagonal_up_right");
PATTERN_IDS.put("lud", "diagonal_up_left");
PATTERN_IDS.put("rud", "diagonal_right");
PATTERN_IDS.put("mc", "circle");
PATTERN_IDS.put("mr", "rhombus");
PATTERN_IDS.put("vh", "half_vertical");
PATTERN_IDS.put("hh", "half_horizontal");
PATTERN_IDS.put("vhr", "half_vertical_right");
PATTERN_IDS.put("hhb", "half_horizontal_bottom");
PATTERN_IDS.put("bo", "border");
PATTERN_IDS.put("cbo", "curly_border");
PATTERN_IDS.put("gra", "gradient");
PATTERN_IDS.put("gru", "gradient_up");
PATTERN_IDS.put("bri", "bricks");
PATTERN_IDS.put("glb", "globe");
PATTERN_IDS.put("cre", "creeper");
PATTERN_IDS.put("sku", "skull");
PATTERN_IDS.put("flo", "flower");
PATTERN_IDS.put("moj", "mojang");
PATTERN_IDS.put("pig", "piglin");
}
public static @Nullable String idToKey(final int id) {
return PATTERNS.idToKey(id);
}
public static int keyToId(final String pattern) {
return PATTERNS.keyToId(pattern);
}
public static @Nullable String compactToFullId(final String compactId) {
return PATTERN_IDS.get(compactId);
}
public static String[] keys() {
return PATTERNS.keys();
}
}

View File

@ -0,0 +1,58 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data;
public final class DyeColors {
public static String colorById(final int id) {
switch (id) {
case 1:
return "orange";
case 2:
return "magenta";
case 3:
return "light_blue";
case 4:
return "yellow";
case 5:
return "lime";
case 6:
return "pink";
case 7:
return "gray";
case 8:
return "light_gray";
case 9:
return "cyan";
case 10:
return "purple";
case 11:
return "blue";
case 12:
return "brown";
case 13:
return "green";
case 14:
return "red";
case 15:
return "black";
default:
return "white";
}
}
}

View File

@ -68,7 +68,7 @@ public final class Enchantments1_20_3 {
return ENCHANTMENTS.idToKey(id);
}
public static int id(final String attribute) {
return ENCHANTMENTS.keyToId(attribute);
public static int id(final String enchantment) {
return ENCHANTMENTS.keyToId(enchantment);
}
}

View File

@ -58,7 +58,7 @@ public final class MapDecorations1_20_3 {
"swamp_hut"
);
public static String mapDecoration(final int index) {
public static String idToKey(final int index) {
return index < 0 || index >= MAP_DECORATIONS.size() ? "player" : MAP_DECORATIONS.idToKey(index);
}
}

View File

@ -72,7 +72,7 @@ public final class Potions1_20_3 {
return POTIONS.idToKey(id);
}
public static int keyToId(final String attribute) {
return POTIONS.keyToId(attribute);
public static int keyToId(final String potion) {
return POTIONS.keyToId(potion);
}
}

View File

@ -39,7 +39,7 @@ public final class TrimMaterials1_20_3 {
return MATERIALS.idToKey(id);
}
public static int keyToId(final String attribute) {
return MATERIALS.keyToId(attribute);
public static int keyToId(final String material) {
return MATERIALS.keyToId(material);
}
}

View File

@ -45,7 +45,7 @@ public final class TrimPatterns1_20_3 {
return PATTERNS.idToKey(id);
}
public static int keyToId(final String attribute) {
return PATTERNS.keyToId(attribute);
public static int keyToId(final String pattern) {
return PATTERNS.keyToId(pattern);
}
}

View File

@ -39,6 +39,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrimMaterial;
import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrimPattern;
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifier;
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers;
import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer;
import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties;
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
@ -64,6 +65,8 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.Clientb
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.BannerPatterns1_20_3;
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;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Instruments1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.MapDecorations1_20_3;
@ -79,6 +82,7 @@ import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.UUIDUtil;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -251,7 +255,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return dataItem;
}
// TODO Block entity changes
public Item toStructuredItem(final Item old) {
final CompoundTag tag = old.tag();
final StructuredItem item = new StructuredItem(old.identifier(), (byte) old.amount(), new StructuredDataContainer());
@ -263,8 +266,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
// Rewrite nbt to new data structures
final NumberTag hideFlags = tag.getNumberTag("HideFlags");
final int hideFlagsValue = hideFlags != null ? hideFlags.asInt() : 0;
final int hideFlagsValue = tag.getInt("HideFlags");
if ((hideFlagsValue & 0x20) != 0) {
data.set(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP);
}
@ -329,9 +331,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
final CompoundTag lodestonePosTag = tag.getCompoundTag("LodestonePos");
final StringTag lodestoneDimensionTag = tag.getStringTag("LodestoneDimension");
if (lodestonePosTag != null && lodestoneDimensionTag != null) {
updateLodestoneTracker(tag, lodestonePosTag, lodestoneDimensionTag, data);
final String lodestoneDimension = tag.getString("LodestoneDimension");
if (lodestonePosTag != null && lodestoneDimension != null) {
updateLodestoneTracker(tag, lodestonePosTag, lodestoneDimension, data);
}
final ListTag<CompoundTag> effectsTag = tag.getListTag("effects", CompoundTag.class);
@ -339,9 +341,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
updateEffects(effectsTag, data);
}
final StringTag instrumentTag = tag.getStringTag("instrument");
if (instrumentTag != null) {
final int id = Instruments1_20_3.keyToId(instrumentTag.getValue());
final String instrument = tag.getString("instrument");
if (instrument != null) {
final int id = Instruments1_20_3.keyToId(instrument);
if (id != -1) {
data.set(StructuredDataKey.INSTRUMENT, Holder.of(id));
}
@ -396,8 +398,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
// StructuredDataKey.CREATIVE_SLOT_LOCK
// StructuredDataKey.INTANGIBLE_PROJECTILE
// StructuredDataKey.NOTE_BLOCK_SOUND
// StructuredDataKey.BANNER_PATTERNS
// StructuredDataKey.BASE_COLOR
// StructuredDataKey.POT_DECORATIONS
// StructuredDataKey.CONTAINER
// StructuredDataKey.BEES
@ -410,22 +410,21 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
private void updateAttributes(final StructuredDataContainer data, final ListTag<CompoundTag> attributeModifiersTag, final boolean showInTooltip) {
final AttributeModifier[] modifiers = attributeModifiersTag.stream().map(modifierTag -> {
final StringTag attributeNameTag = modifierTag.getStringTag("AttributeName");
final StringTag nameTag = modifierTag.getStringTag("Name");
final NumberTag operationTag = modifierTag.getNumberTag("Operation");
final String attributeName = modifierTag.getString("AttributeName");
final String name = modifierTag.getString("Name");
final NumberTag amountTag = modifierTag.getNumberTag("Amount");
final IntArrayTag uuidTag = modifierTag.getIntArrayTag("UUID");
final NumberTag slotTag = modifierTag.getNumberTag("Slot");
if (nameTag == null || attributeNameTag == null || operationTag == null || amountTag == null || uuidTag == null || slotTag == null) {
if (name == null || attributeName == null || amountTag == null || uuidTag == null || slotTag == null) {
return null;
}
final int operationId = operationTag.asInt();
final int operationId = modifierTag.getInt("Operation", -1);
if (operationId < 0 || operationId > 2) {
return null;
}
final int attributeId = Attributes1_20_3.keyToId(attributeNameTag.getValue());
final int attributeId = Attributes1_20_3.keyToId(attributeName);
if (attributeId == -1) {
return null;
}
@ -434,7 +433,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
attributeId,
new ModifierData(
UUIDUtil.fromIntArray(uuidTag.getValue()),
nameTag.getValue(),
name,
amountTag.asDouble(),
operationId
),
@ -445,10 +444,10 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
private void updatePotionTags(final StructuredDataContainer data, final CompoundTag tag) {
final StringTag potionTag = tag.getStringTag("Potion");
final String potion = tag.getString("Potion");
Integer potionId = null;
if (potionTag != null) {
final int id = Potions1_20_3.keyToId(potionTag.getValue());
if (potion != null) {
final int id = Potions1_20_3.keyToId(potion);
potionId = id > 0 ? id - 1 : null; // Empty potion type removed
}
@ -457,27 +456,27 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
PotionEffect[] potionEffects = null;
if (customPotionEffectsTag != null) {
potionEffects = customPotionEffectsTag.stream().map(effectTag -> {
final StringTag idTag = effectTag.getStringTag("id");
if (idTag == null) {
final String identifier = effectTag.getString("id");
if (identifier == null) {
return null;
}
final int id = PotionEffects.keyToId(idTag.getValue()) - 1;
final int id = PotionEffects.keyToId(identifier) - 1;
if (id < 0) {
return null;
}
final NumberTag amplifierTag = effectTag.getNumberTag("amplifier");
final NumberTag durationTag = effectTag.getNumberTag("duration");
final NumberTag ambientTag = effectTag.getNumberTag("ambient");
final NumberTag showParticlesTag = effectTag.getNumberTag("show_particles");
final NumberTag showIconTag = effectTag.getNumberTag("show_icon");
final byte amplifier = effectTag.getByte("amplifier");
final int duration = effectTag.getInt("duration");
final boolean ambient = effectTag.getBoolean("ambient");
final boolean showParticles = effectTag.getBoolean("show_particles");
final boolean showIcon = effectTag.getBoolean("show_icon");
final PotionEffectData effectData = new PotionEffectData(
amplifierTag != null ? amplifierTag.asByte() : 0,
durationTag != null ? durationTag.asInt() : 0,
ambientTag != null && ambientTag.asBoolean(),
showParticlesTag != null && showParticlesTag.asBoolean(),
showIconTag != null && showIconTag.asBoolean(),
amplifier,
duration,
ambient,
showParticles,
showIcon,
null //TODO
);
return new PotionEffect(id, effectData);
@ -557,9 +556,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
private void updateFireworks(final StructuredDataContainer data, final CompoundTag fireworksTag, final ListTag<CompoundTag> explosionsTag) {
final NumberTag flightDuration = fireworksTag.getNumberTag("Flight");
final int flightDuration = fireworksTag.getInt("Flight");
final Fireworks fireworks = new Fireworks(
flightDuration != null ? flightDuration.asInt() : 0,
flightDuration,
explosionsTag.stream().map(this::readExplosion).toArray(FireworkExplosion[]::new)
);
data.set(StructuredDataKey.FIREWORKS, fireworks);
@ -569,43 +568,38 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final SuspiciousStewEffect[] suspiciousStewEffects = new SuspiciousStewEffect[effects.size()];
for (int i = 0; i < effects.size(); i++) {
final CompoundTag effect = effects.get(i);
final StringTag effectId = effect.getStringTag("id");
final NumberTag duration = effect.getNumberTag("duration");
final String effectId = effect.getString("id", "luck");
final int duration = effect.getInt("duration");
final SuspiciousStewEffect stewEffect = new SuspiciousStewEffect(
PotionEffects.keyToId(effectId != null ? effectId.getValue() : "luck") - 1,
duration != null ? duration.asInt() : 0
PotionEffects.keyToId(effectId) - 1,
duration
);
suspiciousStewEffects[i] = stewEffect;
}
data.set(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, suspiciousStewEffects);
}
private void updateLodestoneTracker(final CompoundTag tag, final CompoundTag lodestonePosTag, final StringTag lodestoneDimensionTag, final StructuredDataContainer data) {
final NumberTag trackedTag = tag.getNumberTag("LodestoneTracked");
final NumberTag xTag = lodestonePosTag.getNumberTag("X");
final NumberTag yTag = lodestonePosTag.getNumberTag("Y");
final NumberTag zTag = lodestonePosTag.getNumberTag("Z");
final GlobalPosition position = new GlobalPosition(
lodestoneDimensionTag.getValue(),
xTag != null ? xTag.asInt() : 0,
yTag != null ? yTag.asInt() : 0,
zTag != null ? zTag.asInt() : 0
);
data.set(StructuredDataKey.LODESTONE_TRACKER, new LodestoneTracker(position, trackedTag != null && trackedTag.asBoolean()));
private void updateLodestoneTracker(final CompoundTag tag, final CompoundTag lodestonePosTag, final String lodestoneDimensionTag, final StructuredDataContainer data) {
final boolean tracked = tag.getBoolean("LodestoneTracked");
final int x = lodestonePosTag.getInt("X");
final int y = lodestonePosTag.getInt("Y");
final int z = lodestonePosTag.getInt("Z");
final GlobalPosition position = new GlobalPosition(lodestoneDimensionTag, x, y, z);
data.set(StructuredDataKey.LODESTONE_TRACKER, new LodestoneTracker(position, tracked));
}
private FireworkExplosion readExplosion(final CompoundTag tag) {
final NumberTag shape = tag.getNumberTag("Type");
final int shape = tag.getInt("Type");
final IntArrayTag colors = tag.getIntArrayTag("Colors");
final IntArrayTag fadeColors = tag.getIntArrayTag("FadeColors");
final NumberTag trail = tag.getNumberTag("Trail");
final NumberTag flicker = tag.getNumberTag("Flicker");
final boolean trail = tag.getBoolean("Trail");
final boolean flicker = tag.getBoolean("Flicker");
return new FireworkExplosion(
shape != null ? shape.asInt() : 0,
shape,
colors != null ? colors.getValue() : new int[0],
fadeColors != null ? fadeColors.getValue() : new int[0],
trail != null && trail.asBoolean(),
flicker != null && flicker.asBoolean()
trail,
flicker
);
}
@ -654,17 +648,17 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
pages.add(new FilterableComponent(parsedPage, filtered));
}
final StringTag title = tag.getStringTag("title");
final StringTag filteredTitle = tag.getStringTag("filtered_title");
final StringTag author = tag.getStringTag("author");
final NumberTag generation = tag.getNumberTag("generation");
final NumberTag resolved = tag.getNumberTag("resolved");
final String title = tag.getString("title", "");
final String filteredTitle = tag.getString("filtered_title"); // Nullable
final String author = tag.getString("author", "");
final int generation = tag.getInt("generation");
final boolean resolved = tag.getBoolean("resolved");
final WrittenBook writtenBook = new WrittenBook(
new FilterableString(title != null ? title.getValue() : "", filteredTitle != null ? filteredTitle.getValue() : null),
author != null ? author.getValue() : "",
generation != null ? generation.asInt() : 0,
new FilterableString(title, filteredTitle),
author,
generation,
pages.toArray(new FilterableComponent[0]),
resolved != null && resolved.asBoolean()
resolved
);
data.set(StructuredDataKey.WRITTEN_BOOK_CONTENT, writtenBook);
}
@ -697,13 +691,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final Enchantments enchantments = new Enchantments(new Int2IntOpenHashMap(), show);
for (final CompoundTag enchantment : enchantmentsTag) {
final StringTag id = enchantment.getStringTag("id");
final String id = enchantment.getString("id");
final NumberTag lvl = enchantment.getNumberTag("lvl");
if (id == null || lvl == null) {
continue;
}
final int intId = Enchantments1_20_3.id(id.getValue());
final int intId = Enchantments1_20_3.id(id);
if (intId == -1) {
continue;
}
@ -725,8 +719,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(StructuredDataKey.PROFILE, new GameProfile(name, null, EMPTY_PROPERTIES));
} else if (skullOwnerTag instanceof CompoundTag) {
final CompoundTag skullOwner = (CompoundTag) skullOwnerTag;
final StringTag nameTag = skullOwner.getStringTag("Name");
final String name = nameTag != null ? nameTag.getValue() : "";
final String name = skullOwner.getString("Name", "");
final IntArrayTag idTag = skullOwner.getIntArrayTag("Id");
UUID uuid = null;
@ -754,14 +747,10 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
continue;
}
final StringTag valueTag = ((CompoundTag) propertyTag).getStringTag("Value");
final StringTag signatureTag = ((CompoundTag) propertyTag).getStringTag("Signature");
final GameProfile.Property property = new GameProfile.Property(
entry.getKey(),
valueTag != null ? valueTag.getValue() : "",
signatureTag != null ? signatureTag.getValue() : null
);
properties.add(property);
final CompoundTag compoundTag = (CompoundTag) propertyTag;
final String value = compoundTag.getString("Value", "");
final String signature = compoundTag.getString("Signature");
properties.add(new GameProfile.Property(entry.getKey(), value, signature));
}
}
}
@ -769,19 +758,17 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
private void updateMapDecorations(final StructuredDataContainer data, final ListTag<CompoundTag> decorationsTag) {
final CompoundTag updatedDecorationsTag = new CompoundTag();
for (final CompoundTag decorationTag : decorationsTag) {
final StringTag idTag = decorationTag.getStringTag("id");
final String id = idTag != null ? idTag.asRawString() : "";
final NumberTag typeTag = decorationTag.getNumberTag("type");
final int type = typeTag != null ? typeTag.asInt() : 0;
final NumberTag xTag = decorationTag.getNumberTag("x");
final NumberTag zTag = decorationTag.getNumberTag("z");
final NumberTag rotationTag = decorationTag.getNumberTag("rot");
final String id = decorationTag.getString("id", "");
final int type = decorationTag.getInt("type");
final double x = decorationTag.getDouble("x");
final double z = decorationTag.getDouble("z");
final float rotation = decorationTag.getFloat("rot");
final CompoundTag updatedDecorationTag = new CompoundTag();
updatedDecorationTag.putString("type", MapDecorations1_20_3.mapDecoration(type));
updatedDecorationTag.putDouble("x", xTag != null ? xTag.asDouble() : 0);
updatedDecorationTag.putDouble("z", zTag != null ? zTag.asDouble() : 0);
updatedDecorationTag.putFloat("rotation", rotationTag != null ? rotationTag.asFloat() : 0);
updatedDecorationTag.putString("type", MapDecorations1_20_3.idToKey(type));
updatedDecorationTag.putDouble("x", x);
updatedDecorationTag.putDouble("z", z);
updatedDecorationTag.putFloat("rotation", rotation);
updatedDecorationsTag.put(id, updatedDecorationTag);
}
@ -841,16 +828,42 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
}
// TODO Lots of stuff
final ListTag<CompoundTag> patternsTag = tag.getListTag("Patterns", CompoundTag.class);
if (patternsTag != null) {
final BannerPatternLayer[] layers = patternsTag.stream().map(patternTag -> {
final String pattern = patternTag.getString("Pattern", "");
final int color = patternTag.getInt("Color", -1);
final String fullPatternIdentifier = BannerPatterns1_20_3.compactToFullId(pattern);
if (fullPatternIdentifier == null || color == -1) {
return null;
}
patternTag.remove("Pattern");
patternTag.remove("Color");
patternTag.putString("pattern", fullPatternIdentifier);
patternTag.putString("color", DyeColors.colorById(color));
final int id = BannerPatterns1_20_3.keyToId(fullPatternIdentifier);
return new BannerPatternLayer(Holder.of(id), color);
}).filter(Objects::nonNull).toArray(BannerPatternLayer[]::new);
tag.remove("Patterns");
tag.put("patterns", patternsTag);
if (data != null) {
data.set(StructuredDataKey.BANNER_PATTERNS, layers);
}
}
// TODO Beehive needed?
}
private void updateSkullOwnerTag(final CompoundTag tag, final CompoundTag skullOwnerTag) {
final CompoundTag profileTag = new CompoundTag();
tag.put("profile", profileTag);
final StringTag nameTag = skullOwnerTag.getStringTag("Name");
if (nameTag != null) {
profileTag.putString("name", nameTag.getValue());
final String name = skullOwnerTag.getString("Name");
if (name != null) {
profileTag.putString("name", name);
}
final IntArrayTag idTag = skullOwnerTag.getIntArrayTag("Id");
@ -869,20 +882,20 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
continue;
}
final ListTag<?> value = (ListTag<?>) entry.getValue();
for (final Tag propertyTag : value) {
final ListTag<?> entryValue = (ListTag<?>) entry.getValue();
for (final Tag propertyTag : entryValue) {
if (!(propertyTag instanceof CompoundTag)) {
continue;
}
final CompoundTag updatedPropertyTag = new CompoundTag();
final CompoundTag propertyCompoundTag = (CompoundTag) propertyTag;
final StringTag valueTag = propertyCompoundTag.getStringTag("Value");
final StringTag signatureTag = propertyCompoundTag.getStringTag("Signature");
final String value = propertyCompoundTag.getString("Value", "");
final String signature = propertyCompoundTag.getString("Signature");
updatedPropertyTag.putString("name", entry.getKey());
updatedPropertyTag.putString("value", valueTag != null ? valueTag.getValue() : "");
if (signatureTag != null) {
updatedPropertyTag.putString("signature", signatureTag.getValue());
updatedPropertyTag.putString("value", value);
if (signature != null) {
updatedPropertyTag.putString("signature", signature);
}
propertiesListTag.add(updatedPropertyTag);
}

View File

@ -35,6 +35,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_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.BannerPatterns1_20_3;
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;
@ -98,6 +99,32 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}
wrapper.cancel();
// Send banner patterns and default wolf variant
final PacketWrapper wolfVariantsPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
wolfVariantsPacket.write(Type.STRING, "minecraft:wolf_variant");
final CompoundTag paleWolf = new CompoundTag();
paleWolf.putString("texture", "textures/entity/wolf/wolf.png");
paleWolf.putString("tame_texture", "textures/entity/wolf/wolf_tame.png");
paleWolf.putString("angry_texture", "textures/entity/wolf/wolf_angry.png");
paleWolf.put("biomes", new ListTag<>(StringTag.class));
wolfVariantsPacket.write(Type.REGISTRY_ENTRY_ARRAY, new RegistryEntry[]{new RegistryEntry("minecraft:pale", paleWolf)});
wolfVariantsPacket.send(Protocol1_20_5To1_20_3.class);
final PacketWrapper bannerPatternsPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
bannerPatternsPacket.write(Type.STRING, "minecraft:banner_pattern");
final RegistryEntry[] patternEntries = new RegistryEntry[BannerPatterns1_20_3.keys().length];
final String[] keys = BannerPatterns1_20_3.keys();
for (int i = 0; i < keys.length; i++) {
final CompoundTag pattern = new CompoundTag();
final String key = keys[i];
final String resourceLocation = "minecraft:" + key;
pattern.putString("asset_id", key);
pattern.putString("translation_key", "block.minecraft.banner." + key);
patternEntries[i] = new RegistryEntry(resourceLocation, pattern);
}
bannerPatternsPacket.write(Type.REGISTRY_ENTRY_ARRAY, patternEntries);
bannerPatternsPacket.send(Protocol1_20_5To1_20_3.class);
});
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {

View File

@ -45,6 +45,10 @@ public final class KeyMappings {
return keyToId.getInt(Key.stripMinecraftNamespace(identifier));
}
public String[] keys() {
return keys;
}
public int size() {
return keys.length;
}

View File

@ -4,7 +4,7 @@ metadata.format.version = "1.1"
gson = "2.10.1"
fastutil = "8.5.12"
vianbt = "4.4.2"
vianbt = "4.4.3"
mcstructs = "2.4.2"
# Common provided