Skip to content

Commit 7eb3632

Browse files
Fix written_book_content and potion_contents data to tag conversion (ViaVersion#4218)
1 parent 1ac668d commit 7eb3632

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@
100100
import java.util.logging.Level;
101101
import org.checkerframework.checker.nullness.qual.Nullable;
102102

103-
public final class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends ComponentRewriter<C> {
103+
public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends ComponentRewriter<C> {
104104

105-
private final Map<StructuredDataKey<?>, ConverterPair<?>> converters = new Reference2ObjectOpenHashMap<>();
106-
private final StructuredDataType structuredDataType;
105+
protected final Map<StructuredDataKey<?>, ConverterPair<?>> converters = new Reference2ObjectOpenHashMap<>();
106+
protected final StructuredDataType structuredDataType;
107107

108108
/**
109109
* @param protocol protocol
@@ -327,7 +327,7 @@ public StructuredData<?> readFromTag(final String identifier, final Tag tag) {
327327
return readFromTag(key, id, tag);
328328
}
329329

330-
private <T> StructuredData<T> readFromTag(final StructuredDataKey<T> key, final int id, final Tag tag) {
330+
protected <T> StructuredData<T> readFromTag(final StructuredDataKey<T> key, final int id, final Tag tag) {
331331
final TagConverter<T> converter = tagConverter(key);
332332
Preconditions.checkNotNull(converter, "No converter found for: %s", key);
333333
return StructuredData.of(key, converter.convert(tag), id);
@@ -338,7 +338,6 @@ private String mappedIdentifier(final int id) {
338338
}
339339

340340
// ---------------------------------------------------------------------------------------
341-
// Conversion methods, can be overridden in future protocols to handle new changes
342341

343342
protected CompoundTag convertCustomData(final CompoundTag value) {
344343
return value;
@@ -601,8 +600,15 @@ protected CompoundTag convertPotionContents(final PotionContents value) {
601600
if (value.customColor() != null) {
602601
tag.putInt("custom_color", value.customColor());
603602
}
603+
final ListTag<CompoundTag> customEffects = new ListTag<>(CompoundTag.class);
604604
for (final PotionEffect effect : value.customEffects()) {
605-
convertPotionEffect(tag, effect);
605+
final CompoundTag effectTag = new CompoundTag();
606+
convertPotionEffect(effectTag, effect);
607+
customEffects.add(effectTag);
608+
}
609+
tag.put("custom_effects", customEffects);
610+
if (value.customName() != null) {
611+
tag.putString("custom_name", value.customName());
606612
}
607613
return tag;
608614
}
@@ -645,15 +651,14 @@ protected CompoundTag convertWritableBookContent(final FilterableString[] value)
645651

646652
protected CompoundTag convertWrittenBookContent(final WrittenBook value) {
647653
final CompoundTag tag = new CompoundTag();
648-
convertFilterableString(tag, value.title(), 32);
649-
tag.putString("author", value.author());
650-
if (value.generation() != 0) {
651-
tag.put("generation", convertIntRange(value.generation(), 0, 3));
652-
}
653654

654655
final CompoundTag title = new CompoundTag();
655656
convertFilterableString(title, value.title(), 32);
656657
tag.put("title", title);
658+
tag.putString("author", value.author());
659+
if (value.generation() != 0) {
660+
tag.put("generation", convertIntRange(value.generation(), 0, 3));
661+
}
657662

658663
final ListTag<CompoundTag> pagesTag = new ListTag<>(CompoundTag.class);
659664
for (final FilterableComponent page : value.pages()) {
@@ -1123,17 +1128,17 @@ protected StringTag convertDyeColor(final Integer value) {
11231128

11241129
// ---------------------------------------------------------------------------------------
11251130

1126-
private int checkIntRange(final int min, final int max, final int value) {
1131+
protected int checkIntRange(final int min, final int max, final int value) {
11271132
Preconditions.checkArgument(value >= min && value <= max, "Value out of range: " + value);
11281133
return value;
11291134
}
11301135

1131-
private float checkFloatRange(final float min, final float max, final float value) {
1136+
protected float checkFloatRange(final float min, final float max, final float value) {
11321137
Preconditions.checkArgument(value >= min && value <= max, "Value out of range: " + value);
11331138
return value;
11341139
}
11351140

1136-
private String checkStringRange(final int min, final int max, final String value) {
1141+
protected String checkStringRange(final int min, final int max, final String value) {
11371142
final int length = value.length();
11381143
Preconditions.checkArgument(length >= min && length <= max, "Value out of range: " + value);
11391144
return value;

common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ protected void handleHoverEvent(final UserConnection connection, final CompoundT
385385
return;
386386
}
387387

388-
// Until they're properly parsed
389388
final CompoundTag componentsTag = contentsTag.getCompoundTag("components");
390389
handleShowItem(connection, contentsTag, componentsTag);
391390
if (componentsTag != null) {

0 commit comments

Comments
 (0)