mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-21 16:47:57 +01:00
Merge branch 'master' into dev
# Conflicts: # gradle.properties # gradle/libs.versions.toml
This commit is contained in:
commit
6ad1dc4195
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
github: kennytv
|
||||
patreon: kennytv
|
4
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
4
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -21,11 +21,11 @@ body:
|
||||
attributes:
|
||||
label: Console Error
|
||||
description: |
|
||||
If you encounter warnings/errors in your console, **paste them with https://paste.gg/ and put the paste link here**.
|
||||
If you encounter warnings/errors in your console, **paste them with https://mclo.gs/ and put the paste link here**.
|
||||
If the error is small/less than 10 lines, you may put it directly into this field.
|
||||
value: |
|
||||
```
|
||||
Put the paste.gg link or text here.
|
||||
Put the mclo.gs link or text here.
|
||||
```
|
||||
placeholder: Please do not remove the grave accents; simply replace the line of text in the middle.
|
||||
validations:
|
||||
|
@ -6,7 +6,7 @@ plugins {
|
||||
allprojects {
|
||||
group = "com.viaversion"
|
||||
version = property("projectVersion") as String // from gradle.properties
|
||||
description = "Allow older clients to join newer server versions."
|
||||
description = "Allows older Minecraft client versions to connect to newer server versions."
|
||||
}
|
||||
|
||||
val main = setOf(
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: ViaBackwards
|
||||
version: ${version}
|
||||
description: Allow older Minecraft versions to connect to a newer server version.
|
||||
description: ${description}
|
||||
main: com.viaversion.viabackwards.BukkitPlugin
|
||||
api-version: 1.13
|
||||
folia-supported: true
|
||||
|
@ -78,13 +78,13 @@ public class EnchantmentRewriter {
|
||||
|
||||
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
List<Tag> loreToAdd = new ArrayList<>();
|
||||
ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class);
|
||||
List<StringTag> loreToAdd = new ArrayList<>();
|
||||
boolean changed = false;
|
||||
|
||||
Iterator<Tag> iterator = enchantments.iterator();
|
||||
Iterator<CompoundTag> iterator = enchantments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
CompoundTag enchantmentEntry = (CompoundTag) iterator.next();
|
||||
CompoundTag enchantmentEntry = iterator.next();
|
||||
StringTag idTag = enchantmentEntry.getStringTag("id");
|
||||
|
||||
String enchantmentId = idTag.getValue();
|
||||
@ -123,9 +123,9 @@ public class EnchantmentRewriter {
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
ListTag loreTag = display.getListTag("Lore");
|
||||
ListTag<StringTag> loreTag = display.getListTag("Lore", StringTag.class);
|
||||
if (loreTag == null) {
|
||||
display.put("Lore", loreTag = new ListTag(StringTag.class));
|
||||
display.put("Lore", loreTag = new ListTag<>(StringTag.class));
|
||||
} else {
|
||||
// Save original lore
|
||||
itemRewriter.saveListTag(display, loreTag, "Lore");
|
||||
|
@ -64,15 +64,10 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
name.setValue(newValue);
|
||||
}
|
||||
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
|
||||
if (lore != null) {
|
||||
boolean changed = false;
|
||||
for (Tag loreEntryTag : lore) {
|
||||
if (!(loreEntryTag instanceof StringTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StringTag loreEntry = (StringTag) loreEntryTag;
|
||||
for (StringTag loreEntry : lore) {
|
||||
String newValue = protocol.getTranslatableRewriter().processText(loreEntry.getValue()).toString();
|
||||
if (!changed && !newValue.equals(loreEntry.getValue())) {
|
||||
// Backup original lore before doing any modifications
|
||||
|
@ -66,17 +66,11 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveListTag(CompoundTag displayTag, ListTag original, String name) {
|
||||
protected void saveListTag(CompoundTag displayTag, ListTag<?> original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = nbtTagName + "|o" + name;
|
||||
if (!displayTag.contains(backupName)) {
|
||||
// Clone all tag entries
|
||||
ListTag listTag = new ListTag();
|
||||
for (Tag tag : original.getValue()) {
|
||||
listTag.add(tag.copy());
|
||||
}
|
||||
|
||||
displayTag.put(backupName, listTag);
|
||||
displayTag.put(backupName, original.copy());
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +101,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
protected void restoreListTag(CompoundTag tag, String tagName) {
|
||||
Tag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
if (original instanceof ListTag) {
|
||||
tag.put(tagName, new ListTag(((ListTag) original).getValue()));
|
||||
tag.put(tagName, ((ListTag<?>) original).copy());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,23 +47,18 @@ public class LegacyEnchantmentRewriter {
|
||||
|
||||
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "ench";
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
ListTag remappedEnchantments = new ListTag(CompoundTag.class);
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
for (Tag enchantmentEntry : enchantments.copy()) {
|
||||
if (!(enchantmentEntry instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
|
||||
NumberTag idTag = entryTag.getNumberTag("id");
|
||||
ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class);
|
||||
ListTag<CompoundTag> remappedEnchantments = new ListTag<>(CompoundTag.class);
|
||||
List<StringTag> lore = new ArrayList<>();
|
||||
for (CompoundTag enchantmentEntry : enchantments.copy()) {
|
||||
NumberTag idTag = enchantmentEntry.getNumberTag("id");
|
||||
if (idTag == null) continue;
|
||||
|
||||
short newId = idTag.asShort();
|
||||
String enchantmentName = enchantmentMappings.get(newId);
|
||||
if (enchantmentName != null) {
|
||||
enchantments.remove(enchantmentEntry);
|
||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
||||
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
|
||||
short level = levelTag != null ? levelTag.asShort() : 1;
|
||||
if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) {
|
||||
lore.add(new StringTag(enchantmentName));
|
||||
@ -99,9 +94,9 @@ public class LegacyEnchantmentRewriter {
|
||||
if (display == null) {
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
ListTag loreTag = display.getListTag("Lore");
|
||||
ListTag<StringTag> loreTag = display.getListTag("Lore", StringTag.class);
|
||||
if (loreTag == null) {
|
||||
display.put("Lore", loreTag = new ListTag(StringTag.class));
|
||||
display.put("Lore", loreTag = new ListTag<>(StringTag.class));
|
||||
}
|
||||
|
||||
lore.addAll(loreTag.getValue());
|
||||
@ -111,21 +106,15 @@ public class LegacyEnchantmentRewriter {
|
||||
|
||||
public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) {
|
||||
String key = storedEnchant ? "StoredEnchantments" : "ench";
|
||||
ListTag remappedEnchantments = tag.remove(nbtTagName + "|" + key);
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class);
|
||||
if (enchantments == null) {
|
||||
enchantments = new ListTag(CompoundTag.class);
|
||||
enchantments = new ListTag<>(CompoundTag.class);
|
||||
}
|
||||
|
||||
if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) {
|
||||
for (Tag enchantment : enchantments.copy()) {
|
||||
if (!(enchantment instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag entryTag = (CompoundTag) enchantment;
|
||||
NumberTag idTag = entryTag.getNumberTag("id");
|
||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
||||
for (CompoundTag enchantment : enchantments.copy()) {
|
||||
NumberTag idTag = enchantment.getNumberTag("id");
|
||||
NumberTag levelTag = enchantment.getNumberTag("lvl");
|
||||
short id = idTag != null ? idTag.asShort() : 0;
|
||||
short level = levelTag != null ? levelTag.asShort() : 0;
|
||||
if (id == 0 && level == 0) {
|
||||
@ -143,8 +132,9 @@ public class LegacyEnchantmentRewriter {
|
||||
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
// A few null checks just to be safe, though they shouldn't actually be
|
||||
ListTag lore = display != null ? display.getListTag("Lore") : null;
|
||||
for (Tag enchantment : remappedEnchantments.copy()) {
|
||||
ListTag<StringTag> lore = display != null ? display.getListTag("Lore", StringTag.class) : null;
|
||||
ListTag<CompoundTag> remappedEnchantments = tag.remove(nbtTagName + "|" + key);
|
||||
for (CompoundTag enchantment : remappedEnchantments.copy()) {
|
||||
enchantments.add(enchantment);
|
||||
if (lore != null && !lore.isEmpty()) {
|
||||
lore.remove(lore.get(0));
|
||||
|
@ -115,7 +115,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
|
||||
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
@ -91,7 +91,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
|
||||
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
@ -49,7 +49,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
|
||||
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
@ -48,14 +48,11 @@ public class BannerHandler implements BackwardsBlockEntityHandler {
|
||||
}
|
||||
|
||||
// Invert colors
|
||||
ListTag patternsTag = tag.getListTag("Patterns");
|
||||
ListTag<CompoundTag> patternsTag = tag.getListTag("Patterns", CompoundTag.class);
|
||||
if (patternsTag != null) {
|
||||
for (Tag pattern : patternsTag) {
|
||||
if (!(pattern instanceof CompoundTag)) continue;
|
||||
|
||||
CompoundTag patternTag = (CompoundTag) pattern;
|
||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
||||
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||
for (CompoundTag pattern : patternsTag) {
|
||||
NumberTag colorTag = pattern.getNumberTag("Color");
|
||||
pattern.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
|
||||
addEntries(entry.getKey(), entry.getValue());
|
||||
}
|
||||
} else {
|
||||
ListTag blockStates = MappingDataLoader.loadNBT("blockstates-1.13.nbt").get("blockstates");
|
||||
ListTag<StringTag> blockStates = MappingDataLoader.loadNBT("blockstates-1.13.nbt").getListTag("blockstates", StringTag.class);
|
||||
for (int id = 0; id < blockStates.size(); id++) {
|
||||
StringTag state = blockStates.get(id);
|
||||
String key = state.getValue();
|
||||
|
@ -602,10 +602,10 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
private void rewriteCanPlaceToClient(CompoundTag tag, String tagName) {
|
||||
// The tag was manually created incorrectly so ignore rewriting it
|
||||
ListTag blockTag = tag.getListTag(tagName);
|
||||
ListTag<?> blockTag = tag.getListTag(tagName);
|
||||
if (blockTag == null) return;
|
||||
|
||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
||||
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
|
||||
tag.put(extraNbtTag + "|" + tagName, blockTag.copy());
|
||||
for (Tag oldTag : blockTag) {
|
||||
Object value = oldTag.getValue();
|
||||
@ -616,7 +616,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
newCanPlaceOn.add(new StringTag(newValue));
|
||||
}
|
||||
} else {
|
||||
newCanPlaceOn.add(oldTag);
|
||||
newCanPlaceOn.add(new StringTag(oldTag.getValue().toString()));
|
||||
}
|
||||
}
|
||||
tag.put(tagName, newCanPlaceOn);
|
||||
@ -625,19 +625,14 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
//TODO un-ugly all of this
|
||||
private void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnch) {
|
||||
String key = storedEnch ? "StoredEnchantments" : "Enchantments";
|
||||
ListTag enchantments = tag.getListTag(key);
|
||||
ListTag<CompoundTag> enchantments = tag.getListTag(key, CompoundTag.class);
|
||||
if (enchantments == null) return;
|
||||
|
||||
ListTag noMapped = new ListTag(CompoundTag.class);
|
||||
ListTag newEnchantments = new ListTag(CompoundTag.class);
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
ListTag<CompoundTag> noMapped = new ListTag<>(CompoundTag.class);
|
||||
ListTag<CompoundTag> newEnchantments = new ListTag<>(CompoundTag.class);
|
||||
List<StringTag> lore = new ArrayList<>();
|
||||
boolean hasValidEnchants = false;
|
||||
for (Tag enchantmentEntryTag : enchantments.copy()) {
|
||||
if (!(enchantmentEntryTag instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag;
|
||||
for (CompoundTag enchantmentEntry : enchantments.copy()) {
|
||||
StringTag idTag = enchantmentEntry.getStringTag("id");
|
||||
if (idTag == null) {
|
||||
continue;
|
||||
@ -725,13 +720,13 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
ListTag loreTag = display.getListTag("Lore");
|
||||
ListTag<StringTag> loreTag = display.getListTag("Lore", StringTag.class);
|
||||
if (loreTag == null) {
|
||||
display.put("Lore", loreTag = new ListTag(StringTag.class));
|
||||
display.put("Lore", loreTag = new ListTag<>(StringTag.class));
|
||||
tag.put(extraNbtTag + "|DummyLore", new ByteTag());
|
||||
} else if (!loreTag.isEmpty()) {
|
||||
ListTag oldLore = new ListTag(StringTag.class);
|
||||
for (Tag value : loreTag) {
|
||||
ListTag<StringTag> oldLore = new ListTag<>(StringTag.class);
|
||||
for (StringTag value : loreTag) {
|
||||
oldLore.add(value.copy());
|
||||
}
|
||||
tag.put(extraNbtTag + "|OldLore", oldLore);
|
||||
@ -859,11 +854,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) {
|
||||
if (tag.getListTag(tagName) == null) return;
|
||||
|
||||
ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName);
|
||||
ListTag<?> blockTag = tag.remove(extraNbtTag + "|" + tagName);
|
||||
if (blockTag != null) {
|
||||
tag.put(tagName, blockTag.copy());
|
||||
} else if ((blockTag = tag.getListTag(tagName)) != null) {
|
||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
||||
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
|
||||
for (Tag oldTag : blockTag) {
|
||||
Object value = oldTag.getValue();
|
||||
String oldId = Key.stripMinecraftNamespace(value.toString());
|
||||
@ -889,10 +884,10 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
private void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnch) {
|
||||
String key = storedEnch ? "StoredEnchantments" : "Enchantments";
|
||||
ListTag enchantments = tag.getListTag(storedEnch ? key : "ench");
|
||||
ListTag<CompoundTag> enchantments = tag.getListTag(storedEnch ? key : "ench", CompoundTag.class);
|
||||
if (enchantments == null) return;
|
||||
|
||||
ListTag newEnchantments = new ListTag(CompoundTag.class);
|
||||
ListTag<CompoundTag> newEnchantments = new ListTag<>(CompoundTag.class);
|
||||
boolean dummyEnchant = false;
|
||||
if (!storedEnch) {
|
||||
Tag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
|
||||
@ -905,12 +900,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
}
|
||||
|
||||
for (Tag enchEntry : enchantments) {
|
||||
if (!(enchEntry instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CompoundTag entryTag = (CompoundTag) enchEntry;
|
||||
for (CompoundTag entryTag : enchantments) {
|
||||
NumberTag idTag = entryTag.getNumberTag("id");
|
||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
||||
CompoundTag enchantmentEntry = new CompoundTag();
|
||||
@ -930,11 +920,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
newEnchantments.add(enchantmentEntry);
|
||||
}
|
||||
|
||||
Tag noMapped = tag.remove(extraNbtTag + "|Enchantments");
|
||||
if (noMapped instanceof ListTag) {
|
||||
for (Tag value : ((ListTag) noMapped)) {
|
||||
ListTag<CompoundTag> noMapped = tag.getListTag(extraNbtTag + "|Enchantments", CompoundTag.class);
|
||||
if (noMapped != null) {
|
||||
for (CompoundTag value : noMapped) {
|
||||
newEnchantments.add(value);
|
||||
}
|
||||
tag.remove(extraNbtTag + "|Enchantments");
|
||||
}
|
||||
|
||||
CompoundTag display = tag.getCompoundTag("display");
|
||||
@ -942,14 +933,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
tag.put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
Tag oldLore = tag.remove(extraNbtTag + "|OldLore");
|
||||
if (oldLore instanceof ListTag) {
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
ListTag<StringTag> oldLore = tag.getListTag(extraNbtTag + "|OldLore", StringTag.class);
|
||||
if (oldLore != null) {
|
||||
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
|
||||
if (lore == null) {
|
||||
tag.put("Lore", lore = new ListTag());
|
||||
tag.put("Lore", lore = new ListTag<>(StringTag.class));
|
||||
}
|
||||
|
||||
lore.setValue(((ListTag) oldLore).getValue());
|
||||
lore.setValue(oldLore.getValue());
|
||||
tag.remove(extraNbtTag + "|OldLore");
|
||||
} else if (tag.remove(extraNbtTag + "|DummyLore") != null) {
|
||||
display.remove("Lore");
|
||||
if (display.isEmpty()) {
|
||||
@ -974,14 +966,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
blockEntityTag.putInt("Base", 15 - base.asInt()); // Invert color id
|
||||
}
|
||||
|
||||
ListTag patterns = blockEntityTag.getListTag("Patterns");
|
||||
ListTag<CompoundTag> patterns = blockEntityTag.getListTag("Patterns", CompoundTag.class);
|
||||
if (patterns != null) {
|
||||
for (Tag pattern : patterns) {
|
||||
if (!(pattern instanceof CompoundTag)) continue;
|
||||
|
||||
CompoundTag patternTag = (CompoundTag) pattern;
|
||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
||||
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||
for (CompoundTag pattern : patterns) {
|
||||
NumberTag colorTag = pattern.getNumberTag("Color");
|
||||
pattern.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -473,17 +473,14 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
CompoundTag tag = item.tag();
|
||||
CompoundTag display;
|
||||
if (tag != null && (display = tag.getCompoundTag("display")) != null) {
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
|
||||
if (lore != null) {
|
||||
saveListTag(display, lore, "Lore");
|
||||
|
||||
for (Tag loreEntry : lore) {
|
||||
if (!(loreEntry instanceof StringTag)) continue;
|
||||
|
||||
StringTag loreEntryTag = (StringTag) loreEntry;
|
||||
String value = loreEntryTag.getValue();
|
||||
for (StringTag loreEntry : lore) {
|
||||
String value = loreEntry.getValue();
|
||||
if (value != null && !value.isEmpty()) {
|
||||
loreEntryTag.setValue(ComponentUtil.jsonToLegacy(value));
|
||||
loreEntry.setValue(ComponentUtil.jsonToLegacy(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,13 +499,10 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
CompoundTag display;
|
||||
if (tag != null && (display = tag.getCompoundTag("display")) != null) {
|
||||
// Transform to json if no backup tag is found (else process that in the super method)
|
||||
ListTag lore = display.getListTag("Lore");
|
||||
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
|
||||
if (lore != null && !hasBackupTag(display, "Lore")) {
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
StringTag loreEntryTag = (StringTag) loreEntry;
|
||||
loreEntryTag.setValue(ComponentUtil.legacyToJsonString(loreEntryTag.getValue()));
|
||||
}
|
||||
for (StringTag loreEntry : lore) {
|
||||
loreEntry.setValue(ComponentUtil.legacyToJsonString(loreEntry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,16 +309,11 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
// Handle hover event changes in written book pages
|
||||
if (item.identifier() == 759 && tag != null) {
|
||||
ListTag pagesTag = tag.getListTag("pages");
|
||||
ListTag<StringTag> pagesTag = tag.getListTag("pages", StringTag.class);
|
||||
if (pagesTag != null) {
|
||||
for (Tag page : pagesTag) {
|
||||
if (!(page instanceof StringTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StringTag pageTag = (StringTag) page;
|
||||
JsonElement jsonElement = protocol.getTranslatableRewriter().processText(pageTag.getValue());
|
||||
pageTag.setValue(jsonElement.toString());
|
||||
for (StringTag page : pagesTag) {
|
||||
JsonElement jsonElement = protocol.getTranslatableRewriter().processText(page.getValue());
|
||||
page.setValue(jsonElement.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
|
||||
CompoundTag properties = skullOwnerTag.getCompoundTag("Properties");
|
||||
if (properties == null) return;
|
||||
|
||||
ListTag textures = properties.getListTag("textures");
|
||||
ListTag<CompoundTag> textures = properties.getListTag("textures", CompoundTag.class);
|
||||
if (textures == null) return;
|
||||
|
||||
CompoundTag first = !textures.isEmpty() ? textures.get(0) : null;
|
||||
|
@ -76,13 +76,12 @@ public class EntityPackets1_16_2 extends EntityRewriter<ClientboundPackets1_16_2
|
||||
if (wrapper.user().getProtocolInfo().protocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_15_2)) {
|
||||
// Store biomes for <1.16 client handling
|
||||
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||
ListTag biomes = biomeRegistry.get("value");
|
||||
ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
|
||||
biomeStorage.clear();
|
||||
for (Tag biome : biomes) {
|
||||
CompoundTag biomeCompound = (CompoundTag) biome;
|
||||
StringTag name = biomeCompound.get("name");
|
||||
NumberTag id = biomeCompound.get("id");
|
||||
for (CompoundTag biome : biomes) {
|
||||
StringTag name = biome.get("name");
|
||||
NumberTag id = biome.get("id");
|
||||
biomeStorage.addBiome(name.getValue(), id.asInt());
|
||||
}
|
||||
} else if (!warned) {
|
||||
|
@ -81,9 +81,9 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
|
||||
handler(wrapper -> {
|
||||
CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||
ListTag biomes = biomeRegistry.get("value");
|
||||
for (Tag biome : biomes) {
|
||||
CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
|
||||
ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||
for (CompoundTag biome : biomes) {
|
||||
CompoundTag biomeCompound = biome.get("element");
|
||||
StringTag category = biomeCompound.get("category");
|
||||
if (category.getValue().equalsIgnoreCase("underground")) {
|
||||
category.setValue("none");
|
||||
@ -91,9 +91,9 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
|
||||
}
|
||||
|
||||
CompoundTag dimensionRegistry = registry.get("minecraft:dimension_type");
|
||||
ListTag dimensions = dimensionRegistry.get("value");
|
||||
for (Tag dimension : dimensions) {
|
||||
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
|
||||
ListTag<CompoundTag> dimensions = dimensionRegistry.getListTag("value", CompoundTag.class);
|
||||
for (CompoundTag dimension : dimensions) {
|
||||
CompoundTag dimensionCompound = dimension.get("element");
|
||||
reduceExtendedHeight(dimensionCompound, false);
|
||||
}
|
||||
|
||||
|
@ -62,9 +62,9 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
|
||||
handler(wrapper -> {
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||
final ListTag biomes = biomeRegistry.get("value");
|
||||
for (final Tag biome : biomes.getValue()) {
|
||||
final CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
|
||||
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag biome : biomes) {
|
||||
final CompoundTag biomeCompound = biome.get("element");
|
||||
final StringTag category = biomeCompound.get("category");
|
||||
if (category.getValue().equals("mountain")) {
|
||||
category.setValue("extreme_hills");
|
||||
|
@ -102,10 +102,10 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
|
||||
wrapper.passthrough(Type.VAR_INT); // Slot comes first
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
ListTag pagesTag;
|
||||
ListTag<StringTag> pagesTag;
|
||||
StringTag titleTag = null;
|
||||
// Sanity checks
|
||||
if (tag == null || (pagesTag = tag.getListTag("pages")) == null
|
||||
if (tag == null || (pagesTag = tag.getListTag("pages", StringTag.class)) == null
|
||||
|| (signing && (titleTag = tag.getStringTag("title")) == null)) {
|
||||
wrapper.write(Type.VAR_INT, 0); // Pages length
|
||||
wrapper.write(Type.BOOLEAN, false); // Optional title
|
||||
@ -114,12 +114,12 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
|
||||
|
||||
// Write pages - limit them first
|
||||
if (pagesTag.size() > MAX_PAGES) {
|
||||
pagesTag = new ListTag(pagesTag.getValue().subList(0, MAX_PAGES));
|
||||
pagesTag = new ListTag<>(pagesTag.getValue().subList(0, MAX_PAGES));
|
||||
}
|
||||
|
||||
wrapper.write(Type.VAR_INT, pagesTag.size());
|
||||
for (Tag pageTag : pagesTag) {
|
||||
String page = ((StringTag) pageTag).getValue();
|
||||
for (StringTag pageTag : pagesTag) {
|
||||
String page = pageTag.getValue();
|
||||
// Limit page length
|
||||
if (page.length() > MAX_PAGE_LENGTH) {
|
||||
page = page.substring(0, MAX_PAGE_LENGTH);
|
||||
|
@ -23,7 +23,6 @@ import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@ -39,11 +38,10 @@ public final class BackwardsMappings extends com.viaversion.viabackwards.api.dat
|
||||
protected void loadExtras(final CompoundTag data) {
|
||||
super.loadExtras(data);
|
||||
|
||||
final ListTag chatTypes = VBMappingDataLoader.loadNBT("chat-types-1.19.1.nbt").get("values");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
defaultChatTypes.put(idTag.asInt(), chatTypeCompound);
|
||||
final ListTag<CompoundTag> chatTypes = VBMappingDataLoader.loadNBT("chat-types-1.19.1.nbt").getListTag("values", CompoundTag.class);
|
||||
for (final CompoundTag chatType : chatTypes) {
|
||||
final NumberTag idTag = chatType.get("id");
|
||||
defaultChatTypes.put(idTag.asInt(), chatType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,12 +131,11 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
|
||||
// Cache dimensions and find current dimension
|
||||
final String dimensionKey = wrapper.read(Type.STRING);
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final ListTag dimensions = ((CompoundTag) registry.get("minecraft:dimension_type")).get("value");
|
||||
final ListTag<CompoundTag> dimensions = ((CompoundTag) registry.get("minecraft:dimension_type")).getListTag("value", CompoundTag.class);
|
||||
boolean found = false;
|
||||
for (final Tag dimension : dimensions) {
|
||||
final CompoundTag dimensionCompound = (CompoundTag) dimension;
|
||||
final StringTag nameTag = dimensionCompound.get("name");
|
||||
final CompoundTag dimensionData = dimensionCompound.get("element");
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
final StringTag nameTag = dimension.get("name");
|
||||
final CompoundTag dimensionData = dimension.get("element");
|
||||
dimensionRegistryStorage.addDimension(nameTag.getValue(), dimensionData.copy());
|
||||
|
||||
if (!found && nameTag.getValue().equals(dimensionKey)) {
|
||||
@ -150,19 +149,18 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
|
||||
|
||||
// Add biome category and track biomes
|
||||
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||
final ListTag biomes = biomeRegistry.get("value");
|
||||
for (final Tag biome : biomes.getValue()) {
|
||||
final CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
|
||||
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag biome : biomes.getValue()) {
|
||||
final CompoundTag biomeCompound = biome.get("element");
|
||||
biomeCompound.putString("category", "none");
|
||||
}
|
||||
tracker(wrapper.user()).setBiomesSent(biomes.size());
|
||||
|
||||
// Cache and remove chat types
|
||||
final ListTag chatTypes = ((CompoundTag) registry.remove("minecraft:chat_type")).get("value");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
dimensionRegistryStorage.addChatType(idTag.asInt(), chatTypeCompound);
|
||||
final ListTag<CompoundTag> chatTypes = ((CompoundTag) registry.remove("minecraft:chat_type")).getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag chatType : chatTypes) {
|
||||
final NumberTag idTag = chatType.get("id");
|
||||
dimensionRegistryStorage.addChatType(idTag.asInt(), chatType);
|
||||
}
|
||||
});
|
||||
map(Type.STRING); // World
|
||||
|
@ -82,9 +82,9 @@ public final class Protocol1_18To1_18_2 extends BackwardsProtocol<ClientboundPac
|
||||
handler(wrapper -> {
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
|
||||
final ListTag dimensions = dimensionsHolder.get("value");
|
||||
for (final Tag dimension : dimensions) {
|
||||
removeTagPrefix(((CompoundTag) dimension).get("element"));
|
||||
final ListTag<CompoundTag> dimensions = dimensionsHolder.getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
removeTagPrefix(dimension.get("element"));
|
||||
}
|
||||
|
||||
removeTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));
|
||||
|
@ -82,11 +82,10 @@ public final class EntityPackets1_19_3 extends EntityRewriter<ClientboundPackets
|
||||
final ChatTypeStorage1_19_3 chatTypeStorage = wrapper.user().get(ChatTypeStorage1_19_3.class);
|
||||
chatTypeStorage.clear();
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final ListTag chatTypes = registry.getCompoundTag("minecraft:chat_type").get("value");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
chatTypeStorage.addChatType(idTag.asInt(), chatTypeCompound);
|
||||
final ListTag<CompoundTag> chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag chatType : chatTypes) {
|
||||
final NumberTag idTag = chatType.get("id");
|
||||
chatTypeStorage.addChatType(idTag.asInt(), chatType);
|
||||
}
|
||||
});
|
||||
handler(wrapper -> {
|
||||
|
@ -68,9 +68,9 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
|
||||
registry.remove("minecraft:damage_type");
|
||||
|
||||
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||
final ListTag biomes = biomeRegistry.get("value");
|
||||
for (final Tag biomeTag : biomes) {
|
||||
final CompoundTag biomeData = ((CompoundTag) biomeTag).get("element");
|
||||
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag biomeTag : biomes) {
|
||||
final CompoundTag biomeData = biomeTag.get("element");
|
||||
final NumberTag hasPrecipitation = biomeData.get("has_precipitation");
|
||||
biomeData.putString("precipitation", hasPrecipitation.asByte() == 1 ? "rain" : "none");
|
||||
}
|
||||
|
@ -218,13 +218,13 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
}
|
||||
|
||||
private void writeMessages(final CompoundTag frontText, final CompoundTag tag, final boolean filtered) {
|
||||
final ListTag messages = frontText.getListTag(filtered ? "filtered_messages" : "messages");
|
||||
final ListTag<StringTag> messages = frontText.getListTag(filtered ? "filtered_messages" : "messages", StringTag.class);
|
||||
if (messages == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (final Tag message : messages) {
|
||||
for (final StringTag message : messages) {
|
||||
tag.put((filtered ? "FilteredText" : "Text") + ++i, message);
|
||||
}
|
||||
|
||||
|
@ -80,20 +80,20 @@ public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_
|
||||
handler(wrapper -> {
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
|
||||
final ListTag values;
|
||||
final ListTag<CompoundTag> values;
|
||||
// A 1.20 server can't send this element, and the 1.20 client still works, if the element is missing
|
||||
// on a 1.19.4 client there is an exception, so in case the 1.20 server doesn't send the element we put in an original 1.20 element
|
||||
final CompoundTag trimPatternTag = registry.getCompoundTag("minecraft:trim_pattern");
|
||||
if (trimPatternTag != null) {
|
||||
values = trimPatternTag.getListTag("value");
|
||||
values = trimPatternTag.getListTag("value", CompoundTag.class);
|
||||
} else {
|
||||
final CompoundTag trimPatternRegistry = Protocol1_19_4To1_20.MAPPINGS.getTrimPatternRegistry().copy();
|
||||
registry.put("minecraft:trim_pattern", trimPatternRegistry);
|
||||
values = trimPatternRegistry.get("value");
|
||||
}
|
||||
|
||||
for (final Tag entry : values) {
|
||||
final CompoundTag element = ((CompoundTag) entry).get("element");
|
||||
for (final CompoundTag entry : values) {
|
||||
final CompoundTag element = entry.get("element");
|
||||
final StringTag templateItem = element.get("template_item");
|
||||
if (newTrimPatterns.contains(Key.stripMinecraftNamespace(templateItem.getValue()))) {
|
||||
templateItem.setValue("minecraft:spire_armor_trim_smithing_template");
|
||||
|
@ -103,11 +103,10 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
|
||||
chatTypeStorage.clear();
|
||||
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final ListTag chatTypes = registry.getCompoundTag("minecraft:chat_type").get("value");
|
||||
for (final Tag chatType : chatTypes) {
|
||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
||||
final NumberTag idTag = chatTypeCompound.get("id");
|
||||
chatTypeStorage.addChatType(idTag.asInt(), chatTypeCompound);
|
||||
final ListTag<CompoundTag> chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class);
|
||||
for (final CompoundTag chatType : chatTypes) {
|
||||
final NumberTag idTag = chatType.get("id");
|
||||
chatTypeStorage.addChatType(idTag.asInt(), chatType);
|
||||
}
|
||||
|
||||
// Replace with 1.19 chat types
|
||||
|
@ -102,7 +102,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
|
||||
// Write to old format
|
||||
final CompoundTag registryTag = new CompoundTag();
|
||||
final ListTag entriesTag = new ListTag();
|
||||
final ListTag<CompoundTag> entriesTag = new ListTag<>(CompoundTag.class);
|
||||
registryTag.putString("type", registryKey);
|
||||
registryTag.put("value", entriesTag);
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
|
@ -49,7 +49,7 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
|
||||
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
@ -3,10 +3,10 @@
|
||||
"id": "viabackwards",
|
||||
"name": "ViaBackwards",
|
||||
"version": "${version}",
|
||||
"description": "Allow older Minecraft versions to connect to a newer server version.",
|
||||
"description": "${description}",
|
||||
"license": "GPL-3.0",
|
||||
"contact": {
|
||||
"homepage": "https://github.com/ViaVersion/ViaBackwards",
|
||||
"homepage": "https://viaversion.com/backwards",
|
||||
"issues": "https://github.com/ViaVersion/ViaBackwards/issues",
|
||||
"sources": "https://github.com/ViaVersion/ViaBackwards"
|
||||
},
|
||||
@ -30,5 +30,12 @@
|
||||
},
|
||||
"recommends": {
|
||||
"viarewind": "*"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu:api": true,
|
||||
"modmenu": {
|
||||
"badges": [ "library" ],
|
||||
"parent": "viafabric"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import java.util.logging.Logger;
|
||||
name = "ViaBackwards",
|
||||
version = VersionInfo.VERSION,
|
||||
authors = {"Matsv", "kennytv", "Gerrygames", "creeper123123321", "ForceUpdate1"},
|
||||
description = "Allow older Minecraft versions to connect to a newer server version.",
|
||||
description = "Allows older Minecraft client versions to connect to newer server versions.",
|
||||
dependencies = {@Dependency(id = "viaversion")}
|
||||
)
|
||||
public class VelocityPlugin implements ViaBackwardsPlatform {
|
||||
|
Loading…
Reference in New Issue
Block a user