Compare commits

..
42 Commits
Author SHA1 Message Date
Nassim Jahnke fdfbee3099 Remove cushion display name 2026-10-29 11:31:43 +01:00
Nassim Jahnke 4e021f23ad 5.12.2 Release 2026-10-27 16:24:13 +01:00
Nassim Jahnke 9bf8a6b447 Remove map decorations from hover events in 26.3->26.2 2026-10-27 16:24:02 +01:00
olcxja 0452ac26f3 Fix unknown block states in registry data for pre-26.3 clients (#1372) 2026-10-27 16:03:46 +01:00
Nassim Jahnke 4938de8a33 Add more vanilla limits/sanity checks 2026-10-27 15:36:38 +01:00
Nassim Jahnke c3bdf7230c Fix project id 2026-10-21 13:35:56 +02:00
Nassim Jahnke 104d68c29f Update deps, move from minotaur to mod-publish-plugin
Minotaur is barely maintained, and mod-publish-plugin lets us remove the annoying version handling
2026-10-21 13:29:09 +02:00
Nassim Jahnke c7702cc5a3 Update VV usage 2026-10-18 22:13:36 +02:00
Florian Reuth 90fb84e012 Fix items atlas text components in 1.21.11->1.21.9 being invalid (#1364) 2026-10-18 22:05:44 +02:00
Florian Reuth 2aec24449e Add missing creative item backup code to 1.21.2->1.21 item handling (#1358) 2026-10-12 18:58:31 +02:00
Nassim Jahnke cbafc0564e Replace block state providers with dummy entries
They're never shown or used by the client.

Closes #1357
2026-10-11 20:36:51 +02:00
Florian Reuth e7b588b965 Handle long arrays inside lists in 1.12->1.11.1 (#1355) 2026-10-11 20:15:24 +02:00
Florian Reuth d85de3461a Fix spawner handling registering in 1.11->1.10 (#1354) 2026-10-11 20:14:31 +02:00
Florian Reuth 924179d2af Always rewrite enchantments in 1.19->1.18.2 (#1356) 2026-10-11 20:10:20 +02:00
mfishma 465dc5bbef Fix 26.3 map decorations not getting restored (#1350) 2026-10-11 09:27:38 +02:00
Rocco 71038072ed Save original int map ID if conversion is lossy in 1.13->1.12 (#1341) 2026-10-11 09:26:05 +02:00
mfishma 6cdf663490 Map poplar leaves backwards to varied leaves in 26.3->26.2 2026-10-09 16:44:14 +02:00
Nassim Jahnke 0ba32cf4a5 Handle experimental minecart velocity in 1.21.2->1.21
Fixes #1333
2026-10-09 15:46:04 +02:00
Nassim Jahnke 5b1c323274 Bump version to 5.12.2-SNAPSHOT 2026-10-09 15:35:31 +02:00
Nassim Jahnke 1d954e23ab Separate Fabric platform on modrinth
... or it'll fail when specifying versions below 1.14
2026-10-08 16:05:02 +02:00
Nassim Jahnke cece459a36 5.12.1 Release 2026-10-08 15:42:33 +02:00
TomoyaandNassim Jahnke d413b4af3a Fix some enchantment term rewriting in 26.3->26.2 (#1346)
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
2026-10-08 15:13:55 +02:00
Florian Reuth ec63e9f808 Back up non-default canDestroyBlocksInCreative in 1.21.5->1.21.4 (#1345) 2026-10-01 18:37:24 +02:00
Florian Reuth 5a84625078 Backup wolf collar in 1.21.5->1.21.4 (#1344) 2026-10-01 18:36:35 +02:00
Florian Reuth a36dfbc799 Fix conditions swap in kinetic weapon restore in 1.21.11->1.21.9 (#1343) 2026-10-01 14:56:13 +02:00
Florian Reuth db6fc3d60d Fix jukebox_playable restore in 1.21->1.20.5 (#1342) 2026-10-01 14:54:58 +02:00
Nassim Jahnke 9a5b384e55 Remove no longer needed head yaw packet for mannequins 2026-09-29 18:41:36 +02:00
Florian Reuth f801af36f8 Update VV api usage (#1340) 2026-09-29 18:41:17 +02:00
Rocco 883ca8dc01 Send player head yaw on spawn in 1.20.2->1.20 (#1337) 2026-09-29 18:27:35 +02:00
Florian Reuth 41fbca556e Handle tag displays without tag key in 26.3->26.2 (#1336) 2026-09-29 18:24:11 +02:00
Rocco 32e81d9887 Fix 1.12.2 red=0 dust particle color (#1323) 2026-09-29 18:19:52 +02:00
terbin 906b3afa0b Add statistic mappings for 1.17->1.16.2 (#1339) 2026-09-29 14:46:47 +02:00
Rocco ddc776c284 Change resin trim material to gold for 1.21.2 clients (#1330) 2026-09-28 19:54:49 +02:00
Florian Reuth c73db36674 Update VV api usage (#1335) 2026-09-28 19:35:18 +02:00
Happy-FZM 7bb4a5d69c Move Dyeable to correct version 2026-09-25 15:01:13 +02:00
Rocco 4bb1b681e6 Add potion color mappings for new 1.19.4 colors (#1329) 2026-09-22 21:58:28 +02:00
Nassim Jahnke 53c43db7ad Add missing tags across protocols 2026-09-20 13:08:36 +02:00
Florian Reuth 3f9073ee68 Always show end credits in 1.21->1.20.5 (#1324) 2026-09-20 13:00:13 +02:00
Nassim Jahnke 283e40d32d Map cushion to carpet falling block
Closes #1322
2026-09-19 17:27:04 +02:00
Rocco 53105e644d Update armor from containers in 1.21.2->1.21 (#1321) 2026-09-19 11:41:11 +02:00
Rocco cd4470c7df Calculate painting offsets in 1.19->1.18.2 (#1313) 2026-09-19 11:39:27 +02:00
Nassim Jahnke 64e049fa0f Bump version to 4.12.1-SNAPSHOT 2026-09-19 11:12:16 +02:00
47 changed files with 705 additions and 203 deletions

No files matched your search

+2 -2
View File
@@ -15,12 +15,12 @@ jobs:
with:
persist-credentials: false
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v6.3.0
uses: gradle/actions/setup-gradle@v6.4.0
with:
cache-disabled: false
cache-provider: basic
- name: Set up JDK 17
uses: actions/setup-java@v5.7.0
uses: actions/setup-java@v6.1.0
with:
distribution: 'temurin'
java-version: 17
+3 -3
View File
@@ -20,12 +20,12 @@ jobs:
with:
persist-credentials: false
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v6.3.0
uses: gradle/actions/setup-gradle@v6.4.0
with:
cache-disabled: false
cache-provider: basic
- name: Set up JDK 17
uses: actions/setup-java@v5.7.0
uses: actions/setup-java@v6.1.0
with:
distribution: 'temurin'
java-version: 17
@@ -40,5 +40,5 @@ jobs:
- name: Publish to Modrinth
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
run: ./gradlew modrinth --stacktrace
run: ./gradlew publishMods --stacktrace
continue-on-error: true
@@ -82,7 +82,7 @@ import java.util.logging.Logger;
public interface ViaBackwardsPlatform {
String MINIMUM_VV_VERSION = "5.12.0";
String MINIMUM_VV_VERSION = "5.12.2";
default void init(final File configFile) {
init(new ViaBackwardsConfig(configFile, getLogger()));
@@ -21,6 +21,7 @@ import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
import com.viaversion.viaversion.util.Key;
@@ -58,7 +59,8 @@ public class BackwardsRegistryRewriter extends RegistryDataRewriter {
}
@Override
public void updateJukeboxSongs(final RegistryEntry[] entries) {
public void updateJukeboxSongs(final UserConnection connection, final RegistryEntry[] entries) {
super.updateJukeboxSongs(connection, entries);
for (final RegistryEntry entry : entries) {
if (entry.tag() == null) {
continue;
@@ -68,6 +70,28 @@ public class BackwardsRegistryRewriter extends RegistryDataRewriter {
}
}
@Override
protected boolean updateBlockState(final Tag blockStateTag) {
if (!(blockStateTag instanceof CompoundTag blockState) || blockState.getStringTag("Name") == null) {
return super.updateBlockState(blockStateTag);
}
// Up to 26.2, block states use "Name" and "Properties" instead of "id" and "properties"
final FullMappings blockMappings = protocol.getMappingData().getFullBlockMappings();
if (blockMappings == null) {
return false;
}
final int blockId = blockMappings.id(blockState.getString("Name"));
if (blockId == -1 || protocol.getMappingData().hasBlockChanged(blockId)) {
// Replace unknown or changed blocks with a dummy state, else the client will fail to load the registry
blockState.putString("Name", "minecraft:dirt");
blockState.remove("Properties");
return true;
}
return false;
}
private void updateBiomeEffects(final CompoundTag effects) {
updateSound(effects.getCompoundTag("mood_sound"), "sound");
updateSound(effects.getCompoundTag("additions_sound"), "sound");
@@ -100,10 +124,16 @@ public class BackwardsRegistryRewriter extends RegistryDataRewriter {
}
final String mappedSound = protocol.getMappingData().getMappedNamedSound(sound);
if (mappedSound == null) {
if (mappedSound != null) {
tag.putString(name, mappedSound);
} else if (name.equals("sound_id")) {
// If it's already an inlined sound
tag.putString(name, "minecraft:intentionally_empty");
} else {
tag.putString(name, mappedSound);
// Write as custom sound, so the id doesn't actually need to exist later on
final CompoundTag soundEvent = new CompoundTag();
soundEvent.putString("sound_id", "minecraft:intentionally_empty");
tag.put(name, soundEvent);
}
}
}
@@ -33,6 +33,7 @@ import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.objects.ObjectIterator;
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Limit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -195,7 +196,12 @@ public class StructuredEnchantmentRewriter {
}
final Enchantments enchantments = new Enchantments(tag.remove(itemRewriter.nbtTagName("show_" + key.identifier())) != null);
int i = 0;
for (final CompoundTag enchantment : enchantmentsTag) {
if (i++ > 255) {
break;
}
enchantments.add(enchantment.getInt("id"), enchantment.getInt("lvl"));
}
data.set(key, enchantments);
@@ -22,27 +22,39 @@ import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
public class SplashPotionMappings1_10 {
private static final Int2IntMap DATA = new Int2IntOpenHashMap(14, 0.99F);
private static final Int2IntMap DATA = new Int2IntOpenHashMap(26, 0.99F);
static {
DATA.defaultReturnValue(-1);
DATA.put(2039713, 5); // night vision
DATA.put(8356754, 7); // invisibility
DATA.put(2293580, 9); // jump boost
DATA.put(14981690, 12); // fire resistance
DATA.put(8171462, 14); // swiftness
DATA.put(5926017, 17); // slowness
DATA.put(3035801, 19); // water breathing
DATA.put(16262179, 21); // instant health
DATA.put(4393481, 23); // instant damage
DATA.put(5149489, 25); // poison
DATA.put(13458603, 28); // regeneration
DATA.put(9643043, 31); // strength
DATA.put(4738376, 34); // weakness
DATA.put(3381504, 36); // luck
DATA.put(0x1F1FA1, 5); // night vision
DATA.put(0xC2FF66, 5); // night vision 1.19.4
DATA.put(0x7F8392, 7); // invisibility
DATA.put(0xF6F6F6, 7); // invisibility 1.19.4
DATA.put(0x22FF4C, 9); // jump boost
DATA.put(0xFDFF84, 9); // jump boost 1.19.4
DATA.put(0xE49A3A, 12); // fire resistance
DATA.put(0xFF9900, 12); // fire resistance 1.19.4
DATA.put(0x7CAFC6, 14); // swiftness
DATA.put(0x33EBFF, 14); // swiftness 1.19.4
DATA.put(0x5A6C81, 17); // slowness
DATA.put(0x8BAFE0, 17); // slowness 1.19.4
DATA.put(0x2E5299, 19); // water breathing
DATA.put(0x98DAC0, 19); // water breathing 1.19.4
DATA.put(0xF82423, 21); // instant health
DATA.put(0x430A09, 23); // instant damage
DATA.put(0xA9656A, 23); // instant damage 1.19.4
DATA.put(0x4E9331, 25); // poison
DATA.put(0x87A363, 25); // poison 1.19.4
DATA.put(0xCD5CAB, 28); // regeneration
DATA.put(0x932423, 31); // strength
DATA.put(0xFFC700, 31); // strength 1.19.4
DATA.put(0x484D48, 34); // weakness
DATA.put(0x339900, 36); // luck
DATA.put(0x59C106, 36); // luck 1.19.4
}
public static int getOldData(int data) {
return DATA.get(data);
// newer servers send as ARGB
return DATA.get(data & 0xFFFFFF);
}
}
@@ -40,7 +40,6 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityMappings1_11;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
import com.viaversion.viaversion.util.IdAndData;
import java.util.Arrays;
import java.util.Optional;
@@ -252,7 +251,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
@Override
protected void registerRewrites() {
// Handle spawner block entity (map to itself with custom handler)
MappedLegacyBlockItem data = itemReplacements.computeIfAbsent(IdAndData.toRawData(52), s -> new MappedLegacyBlockItem(52));
MappedLegacyBlockItem data = blockReplacements.computeIfAbsent(compress(52, -1), s -> new MappedLegacyBlockItem(52, (short) -1, null, MappedLegacyBlockItem.Type.BLOCK));
data.setBlockEntityHandler((b, tag) -> EntityMappings1_11.toClientSpawner(tag, true));
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
@@ -18,8 +18,10 @@
package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
import com.google.common.primitives.Ints;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongArrayTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
@@ -230,6 +232,30 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
backupTag.put(entry.getKey(), fromLongArrayTag(tag));
iterator.remove();
hasLongArrayTag = true;
} else if (entry.getValue() instanceof ListTag<?> tag) {
if (tag.getElementType() == LongArrayTag.class) {
// Lists can't hold mixed tag types, so the whole list has to be removed
ListTag<IntArrayTag> intArrays = new ListTag<>(IntArrayTag.class);
for (Tag longArrayTag : tag) {
intArrays.add(fromLongArrayTag((LongArrayTag) longArrayTag));
}
backupTag.put(entry.getKey(), intArrays);
iterator.remove();
hasLongArrayTag = true;
} else if (tag.getElementType() == CompoundTag.class) {
// Backed up by list index
CompoundTag listBackupTag = new CompoundTag();
for (int i = 0; i < tag.size(); i++) {
CompoundTag nestedBackupTag = new CompoundTag();
if (handleNbtToClient((CompoundTag) tag.get(i), nestedBackupTag)) {
listBackupTag.put(Integer.toString(i), nestedBackupTag);
}
}
if (!listBackupTag.isEmpty()) {
backupTag.put(entry.getKey(), listBackupTag);
hasLongArrayTag = true;
}
}
}
}
return hasLongArrayTag;
@@ -252,11 +278,33 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
private void handleNbtToServer(CompoundTag compoundTag, CompoundTag backupTag) {
// Restore the removed long array tags
for (Map.Entry<String, Tag> entry : backupTag) {
if (entry.getValue() instanceof CompoundTag) {
CompoundTag nestedTag = compoundTag.getCompoundTag(entry.getKey());
handleNbtToServer(nestedTag, (CompoundTag) entry.getValue());
} else {
compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue()));
if (entry.getValue() instanceof CompoundTag nestedBackupTag) {
Tag tag = compoundTag.get(entry.getKey());
if (tag instanceof CompoundTag nestedTag) {
handleNbtToServer(nestedTag, nestedBackupTag);
} else if (tag instanceof ListTag<?> listTag) {
handleListToServer(listTag, nestedBackupTag);
}
} else if (entry.getValue() instanceof IntArrayTag intArrayTag) {
compoundTag.put(entry.getKey(), fromIntArrayTag(intArrayTag));
} else if (entry.getValue() instanceof ListTag<?> intArrays) {
ListTag<LongArrayTag> longArrays = new ListTag<>(LongArrayTag.class);
for (Tag intArrayTag : intArrays) {
if (intArrayTag instanceof IntArrayTag) {
longArrays.add(fromIntArrayTag((IntArrayTag) intArrayTag));
}
}
compoundTag.put(entry.getKey(), longArrays);
}
}
}
private void handleListToServer(ListTag<?> listTag, CompoundTag backupTag) {
for (Map.Entry<String, Tag> entry : backupTag) {
Integer index = Ints.tryParse(entry.getKey());
if (index != null && index >= 0 && index < listTag.size()
&& listTag.get(index) instanceof CompoundTag nestedTag && entry.getValue() instanceof CompoundTag nestedBackupTag) {
handleNbtToServer(nestedTag, nestedBackupTag);
}
}
}
@@ -275,7 +323,7 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
private LongArrayTag fromIntArrayTag(IntArrayTag tag) {
long[] longArray = new long[tag.length() / 2];
int[] intArray = tag.getValue();
for (int i = 0, j = 0; i < intArray.length; i += 2, j++) {
for (int i = 0, j = 0; j < longArray.length; i += 2, j++) {
longArray[j] = (long) intArray[i] << 32 | ((long) intArray[i + 1] & 0xFFFFFFFFL);
}
return new LongArrayTag(longArray);
@@ -57,6 +57,6 @@ public class PaintingNames1_13 {
}
public static String getStringId(int id) {
return PAINTINGS.getOrDefault(id, "kebab");
return PAINTINGS.getOrDefault(id, "Kebab");
}
}
@@ -76,6 +76,11 @@ public class ParticleIdMappings1_12_2 {
float b = wrapper.read(Types.FLOAT);
float scale = wrapper.read(Types.FLOAT);
if (r == 0.0) {
// In 1.12.2 and below, a zero x offset becomes r = 1.0
r = Float.MIN_NORMAL;
}
wrapper.set(Types.FLOAT, 3, r); // 5 - Offset X index=3
wrapper.set(Types.FLOAT, 4, g); // 6 - Offset Y index=4
wrapper.set(Types.FLOAT, 5, b); // 7 - Offset Z index=5
@@ -463,8 +463,12 @@ public class BlockItemPacketRewriter1_13 extends BackwardsItemRewriter<Clientbou
if (item.identifier() == 358) { // map
Tag mapTag = tag.remove("map");
if (!gotRawIdFromTag && mapTag instanceof NumberTag) {
item.setData(((NumberTag) mapTag).asShort());
if (!gotRawIdFromTag && mapTag instanceof NumberTag numberTag) {
item.setData((short) (numberTag.asInt() & 0x7FFF));
// Keep original ID if conversion is lossy
if (numberTag.asInt() > Short.MAX_VALUE) {
tag.put("map", numberTag);
}
}
}
@@ -667,7 +671,9 @@ public class BlockItemPacketRewriter1_13 extends BackwardsItemRewriter<Clientbou
}
if (item.identifier() == 358) { // map
if (tag == null) item.setTag(tag = new CompoundTag());
tag.putInt("map", item.data());
if (!tag.contains("map")) {
tag.putInt("map", item.data());
}
}
// NBT Changes
@@ -54,6 +54,7 @@ import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPacke
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
import com.viaversion.viaversion.util.CipherUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Limit;
import com.viaversion.viaversion.util.Pair;
import com.viaversion.viaversion.util.TagUtil;
import java.security.SignatureException;
@@ -230,7 +231,7 @@ public final class Protocol1_19_1To1_19 extends BackwardsProtocol<ClientboundPac
final SignableCommandArgumentsProvider argumentsProvider = Via.getManager().getProviders().get(SignableCommandArgumentsProvider.class);
if (chatSession != null && argumentsProvider != null) {
final int signatures = wrapper.read(Types.VAR_INT);
final int signatures = Limit.max(wrapper.read(Types.VAR_INT), 8);
for (int i = 0; i < signatures; i++) {
wrapper.read(Types.STRING); // Argument name
wrapper.read(Types.BYTE_ARRAY_PRIMITIVE); // Signature
@@ -41,7 +41,9 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
@@ -61,6 +63,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
import com.viaversion.viaversion.util.CipherUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Limit;
import com.viaversion.viaversion.util.Pair;
import java.security.SignatureException;
import java.util.BitSet;
@@ -70,6 +73,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_1, ServerboundPackets1_19_3, ServerboundPackets1_19_1> {
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.19.3", "1.19", Protocol1_19_1To1_19_3.class);
private static final Type<PlayerMessageSignature[]> LAST_SEEN_MESSAGES_TYPE = new ArrayType<>(Types.PLAYER_MESSAGE_SIGNATURE, 5);
private final EntityPacketRewriter1_19_3 entityRewriter = new EntityPacketRewriter1_19_3(this);
private final BlockItemPacketRewriter1_19_3 itemRewriter = new BlockItemPacketRewriter1_19_3(this);
private final ParticleRewriter<ClientboundPackets1_19_3> particleRewriter = new ParticleRewriter<>(this);
@@ -207,7 +211,7 @@ public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol<ClientboundP
map(Types.LONG); // Salt
read(Types.BYTE_ARRAY_PRIMITIVE); // Signature
read(Types.BOOLEAN); // Signed preview
read(Types.PLAYER_MESSAGE_SIGNATURE_ARRAY); // Last seen messages
read(LAST_SEEN_MESSAGES_TYPE); // Last seen messages
read(Types.OPTIONAL_PLAYER_MESSAGE_SIGNATURE); // Last received message
handler(wrapper -> {
final ChatSession1_19_3 chatSession = wrapper.user().get(ChatSession1_19_3.class);
@@ -250,7 +254,7 @@ public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol<ClientboundP
final long timestamp = wrapper.get(Types.LONG, 0);
final long salt = wrapper.get(Types.LONG, 1);
final int signatures = wrapper.read(Types.VAR_INT);
final int signatures = Limit.max(wrapper.read(Types.VAR_INT), 8);
for (int i = 0; i < signatures; i++) {
wrapper.read(Types.STRING); // Name
wrapper.read(Types.BYTE_ARRAY_PRIMITIVE); // Signature
@@ -282,7 +286,7 @@ public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol<ClientboundP
wrapper.write(Types.VAR_INT, offset);
wrapper.write(new BitSetType(20), acknowledged);
});
read(Types.PLAYER_MESSAGE_SIGNATURE_ARRAY); // Last seen messages
read(LAST_SEEN_MESSAGES_TYPE); // Last seen messages
read(Types.OPTIONAL_PLAYER_MESSAGE_SIGNATURE); // Last received message
}
});
@@ -24,21 +24,14 @@ import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.LastDeathPosition;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.GlobalBlockPosition;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.v1_16_4to1_17.packet.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.rewriter.RecipeRewriter;
import com.viaversion.viaversion.util.MathUtil;
public final class BlockItemPacketRewriter1_19 extends BackwardsItemRewriter<ClientboundPackets1_19, ServerboundPackets1_17, Protocol1_19To1_18_2> {
@@ -187,6 +180,7 @@ public final class BlockItemPacketRewriter1_19 extends BackwardsItemRewriter<Cli
final int identifier = item.identifier();
item = super.handleItemToClient(connection, item);
enchantmentRewriter.handleToClient(item);
if (identifier != 834) {
return item;
@@ -205,8 +199,6 @@ public final class BlockItemPacketRewriter1_19 extends BackwardsItemRewriter<Cli
lodestonePosTag.putInt("X", position.x());
lodestonePosTag.putInt("Y", position.y());
lodestonePosTag.putInt("Z", position.z());
enchantmentRewriter.handleToClient(item);
return item;
}
@@ -49,12 +49,6 @@ import com.viaversion.viaversion.util.TagUtil;
public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPackets1_19, Protocol1_19To1_18_2> {
private static final IntSet WIDE_PAINTINGS = IntOpenHashSet.of(
7, 8, 9, 10, 11,
14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25
);
public EntityPacketRewriter1_19(final Protocol1_19To1_18_2 protocol) {
super(protocol);
}
@@ -124,17 +118,68 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
final TrackedEntity entity = tracker(wrapper.user()).entity(entityId);
final StoredPainting storedPainting = entity != null ? entity.get(StoredPainting.class) : null;
// Presumably there is a more correct way of fixing this? Only north and east looking paintings with a width of >1 seem to be extra special
if (storedPainting != null && (storedPainting.direction() == 2 || storedPainting.direction() == 3)
&& WIDE_PAINTINGS.contains(storedPainting.type())) {
wrapper.write(Types.DOUBLE, storedPainting.direction() == 2 ? x : x + 1);
wrapper.write(Types.DOUBLE, y + 1);
wrapper.write(Types.DOUBLE, storedPainting.direction() == 3 ? z : z + 1);
} else {
if (storedPainting == null) {
wrapper.write(Types.DOUBLE, x + 1);
wrapper.write(Types.DOUBLE, y + 1);
wrapper.write(Types.DOUBLE, z + 1);
return;
}
// In 1.18 and below, the teleport position is the painting entity's position.
// In 1.19+, it is the block position the painting is attached to.
// The game calculates the entity's position as follows.
// See PaintingVariants in 1.19
double width = 0, height = 0;
int type = storedPainting.type();
if (type <= 6) {
width = 16;
height = 16;
} else if (type <= 11) {
width = 32;
height = 16;
} else if (type <= 13) {
width = 16;
height = 32;
} else if (type <= 19 || (type >= 25 && type <= 28)) {
width = 32;
height = 32;
} else if (type == 20) {
width = 64;
height = 32;
} else if (type <= 23) {
width = 64;
height = 64;
} else if (type == 24 || type == 29) {
width = 64;
height = 48;
}
// See HangingEntity#recalculateBoundingBox
double resX = x + 0.5, resY = y + 0.5, resZ = z + 0.5;
final double againstWall = -0.46875;
switch (storedPainting.direction()) {
case 2 -> resZ -= againstWall; // North -z
case 0 -> resZ += againstWall; // South +z
case 1 -> resX -= againstWall; // West -x
case 3 -> resX += againstWall; // East +x
}
// Counter-clockwise
final double horizontalOffset = width % 32 == 0 ? 0.5 : 0.0;
final double verticalOffset = height % 32 == 0 ? 0.5 : 0.0;
resY += verticalOffset;
switch (storedPainting.direction()) {
case 3 -> resZ -= horizontalOffset; // East -> North -z
case 1 -> resZ += horizontalOffset; // West -> South +z
case 2 -> resX -= horizontalOffset; // North -> West -x
case 0 -> resX += horizontalOffset; // South -> East +x
}
wrapper.write(Types.DOUBLE, resX);
wrapper.write(Types.DOUBLE, resY);
wrapper.write(Types.DOUBLE, resZ);
});
protocol.registerClientbound(ClientboundPackets1_19.UPDATE_MOB_EFFECT, new PacketHandlers() {
@@ -364,8 +409,16 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
final TrackedEntity entity = tracker(event.user()).entity(event.entityId());
final StoredPainting storedPainting = entity != null ? entity.get(StoredPainting.class) : null;
if (storedPainting != null) {
final int type = data.value();
int type = data.value();
storedPainting.setType(type);
type = switch (type) {
case 29 -> 25; // kong painting changed ID
case 25 -> 19; // earth -> wither
case 26 -> 16; // wind -> stage
case 27 -> 18; // water -> skull_and_roses
case 28 -> 14; // fire -> match
default -> type;
};
final PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_18.ADD_PAINTING, event.user());
packet.write(Types.VAR_INT, storedPainting.entityId());
@@ -79,26 +79,30 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
final byte pitch = wrapper.read(Types.BYTE);
wrapper.passthrough(Types.BYTE); // Yaw
wrapper.write(Types.BYTE, pitch);
wrapper.read(Types.BYTE); // Head yaw
final byte headYaw = wrapper.read(Types.BYTE); // Head yaw
wrapper.read(Types.VAR_INT); // Data
final short velocityX = wrapper.read(Types.SHORT);
final short velocityY = wrapper.read(Types.SHORT);
final short velocityZ = wrapper.read(Types.SHORT);
if (velocityX == 0 && velocityY == 0 && velocityZ == 0) {
return;
}
// Follow up with velocity packet
wrapper.send(Protocol1_20_2To1_20.class);
wrapper.cancel();
final PacketWrapper velocityPacket = wrapper.create(ClientboundPackets1_19_4.SET_ENTITY_MOTION);
velocityPacket.write(Types.VAR_INT, entityId);
velocityPacket.write(Types.SHORT, velocityX);
velocityPacket.write(Types.SHORT, velocityY);
velocityPacket.write(Types.SHORT, velocityZ);
velocityPacket.send(Protocol1_20_2To1_20.class);
final PacketWrapper headRotation = wrapper.create(ClientboundPackets1_19_4.ROTATE_HEAD);
headRotation.write(Types.VAR_INT, entityId);
headRotation.write(Types.BYTE, headYaw);
headRotation.send(Protocol1_20_2To1_20.class);
// Follow up with velocity packet
if (velocityX != 0 || velocityY != 0 || velocityZ != 0) {
final PacketWrapper velocityPacket = wrapper.create(ClientboundPackets1_19_4.SET_ENTITY_MOTION);
velocityPacket.write(Types.VAR_INT, entityId);
velocityPacket.write(Types.SHORT, velocityX);
velocityPacket.write(Types.SHORT, velocityY);
velocityPacket.write(Types.SHORT, velocityZ);
velocityPacket.send(Protocol1_20_2To1_20.class);
}
});
}
});
@@ -84,7 +84,7 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
protected void registerPackets() {
super.registerPackets();
tagRewriter.addEmptyTag(RegistryType.ITEM, "minecraft:axolotl_tempt_items");
tagRewriter.renameTag(RegistryType.ITEM, "axolotl_food", "axolotl_tempt_items");
replaceClientbound(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS, wrapper -> {
// Send off registry data first, needed for tags
sendRegistryData(wrapper.user());
@@ -56,6 +56,7 @@ import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.ParticleRewriter;
import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.rewriter.block.BlockRewriter1_21_5;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.TagUtil;
import java.util.function.Function;
@@ -75,7 +76,7 @@ public final class Protocol1_21_11To1_21_9 extends BackwardsProtocol<Clientbound
private final NBTComponentRewriter<ClientboundPacket1_21_11> translatableRewriter = new ComponentRewriter1_21_11(this);
private final TagRewriter<ClientboundPacket1_21_11> tagRewriter = new TagRewriter<>(this);
private final RecipeDisplayRewriter<ClientboundPacket1_21_11> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(this);
private final BlockRewriter<ClientboundPacket1_21_11> blockRewriter = BlockRewriter.for1_20_2(this, ChunkType1_21_5::new);
private final BlockRewriter<ClientboundPacket1_21_11> blockRewriter = new BlockRewriter1_21_5<>(this, ChunkType1_21_5::new);
private final BackwardsRegistryRewriter registryDataRewriter = new BackwardsRegistryRewriter(this) {
@Override
protected void updateType(final CompoundTag tag, final String key, final FullMappings mappings) {
@@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.AttackRange;
import com.viaversion.viaversion.api.minecraft.item.data.DamageType;
import com.viaversion.viaversion.api.minecraft.item.data.KineticWeapon;
import com.viaversion.viaversion.api.minecraft.item.data.PiercingWeapon;
import com.viaversion.viaversion.api.minecraft.item.data.SwingAnimation;
@@ -109,14 +108,14 @@ public final class BlockItemPacketRewriter1_21_11 extends BackwardsStructuredIte
if (kineticTag != null) {
final int contactCooldownTicks = kineticTag.getInt("contact_cooldown_ticks");
final int delayTicks = kineticTag.getInt("delay_ticks");
final KineticWeapon.Condition damageConditions = loadDamageCondition(kineticTag, "damage_conditions");
final KineticWeapon.Condition dismountConditions = loadDamageCondition(kineticTag, "dismount_conditions");
final KineticWeapon.Condition knockbackConditions = loadDamageCondition(kineticTag, "knockback_conditions");
final KineticWeapon.Condition damageConditions = loadDamageCondition(kineticTag, "damage_conditions");
final float forwardMovement = kineticTag.getFloat("forward_movement");
final float damageMultiplier = kineticTag.getFloat("damage_multiplier");
final Holder<SoundEvent> sound = kineticTag.contains("sound") ? restoreSoundEventHolder(kineticTag, "sound") : null;
final Holder<SoundEvent> hitSound = kineticTag.contains("hit_sound") ? restoreSoundEventHolder(kineticTag, "hit_sound") : null;
container.set(StructuredDataKey.KINETIC_WEAPON, new KineticWeapon(contactCooldownTicks, delayTicks, damageConditions, dismountConditions, knockbackConditions, forwardMovement, damageMultiplier, sound, hitSound));
container.set(StructuredDataKey.KINETIC_WEAPON, new KineticWeapon(contactCooldownTicks, delayTicks, dismountConditions, knockbackConditions, damageConditions, forwardMovement, damageMultiplier, sound, hitSound));
}
final CompoundTag piercingTag = backupTag.getCompoundTag("piercing_weapon");
@@ -131,9 +130,9 @@ public final class BlockItemPacketRewriter1_21_11 extends BackwardsStructuredIte
final Tag damageTypeId = backupTag.get("damage_type_id");
if (damageTypeId != null) {
if (damageTypeId instanceof StringTag stringTag) {
container.set(StructuredDataKey.DAMAGE_TYPE1_21_11, new DamageType(Either.right(stringTag.getValue())));
container.set(StructuredDataKey.DAMAGE_TYPE1_21_11, Either.right(stringTag.getValue()));
} else if (damageTypeId instanceof IntTag intTag) {
container.set(StructuredDataKey.DAMAGE_TYPE1_21_11, new DamageType(Either.left(intTag.asInt())));
container.set(StructuredDataKey.DAMAGE_TYPE1_21_11, Either.left(intTag.asInt()));
}
}
@@ -197,9 +196,9 @@ public final class BlockItemPacketRewriter1_21_11 extends BackwardsStructuredIte
final CompoundTag kineticTag = new CompoundTag();
kineticTag.putInt("contact_cooldown_ticks", kineticWeapon.contactCooldownTicks());
kineticTag.putInt("delay_ticks", kineticWeapon.delayTicks());
saveDamageCondition(kineticTag, "damage_conditions", kineticWeapon.damageConditions());
saveDamageCondition(kineticTag, "dismount_conditions", kineticWeapon.dismountConditions());
saveDamageCondition(kineticTag, "knockback_conditions", kineticWeapon.knockbackConditions());
saveDamageCondition(kineticTag, "damage_conditions", kineticWeapon.damageConditions());
kineticTag.putFloat("forward_movement", kineticWeapon.forwardMovement());
kineticTag.putFloat("damage_multiplier", kineticWeapon.damageMultiplier());
if (kineticWeapon.sound() != null) {
@@ -225,12 +224,12 @@ public final class BlockItemPacketRewriter1_21_11 extends BackwardsStructuredIte
backupTag.put("piercing_weapon", piercingTag);
}
final DamageType damageType = dataContainer.get(StructuredDataKey.DAMAGE_TYPE1_21_11);
final Either<Integer, String> damageType = dataContainer.get(StructuredDataKey.DAMAGE_TYPE1_21_11);
if (damageType != null) {
if (damageType.id().isLeft()) {
backupTag.putInt("damage_type_id", damageType.id().left());
if (damageType.isLeft()) {
backupTag.putInt("damage_type_id", damageType.left());
} else {
backupTag.putString("damage_type_id", damageType.id().right());
backupTag.putString("damage_type_id", damageType.right());
}
}
@@ -18,11 +18,13 @@
package com.viaversion.viabackwards.protocol.v1_21_11to1_21_9.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.rewriters.text.NBTComponentRewriter;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.protocols.v1_21_9to1_21_11.packet.ClientboundPacket1_21_11;
import com.viaversion.viaversion.util.Key;
public final class ComponentRewriter1_21_11 extends NBTComponentRewriter<ClientboundPacket1_21_11> {
@@ -30,6 +32,16 @@ public final class ComponentRewriter1_21_11 extends NBTComponentRewriter<Clientb
super(protocol);
}
@Override
protected void processCompoundTag(final UserConnection connection, final CompoundTag tag) {
super.processCompoundTag(connection, tag);
final StringTag atlas = tag.getStringTag("atlas");
if (atlas != null && Key.stripMinecraftNamespace(atlas.getValue()).equals("items")) {
atlas.setValue("blocks");
}
}
@Override
protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) {
super.handleShowItem(connection, itemTag, componentsTag);
@@ -86,8 +86,6 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol<ClientboundPac
wrapper.write(Types.STRING_ARRAY, ArrayUtil.add(enabledFeatures, "bundle"));
});
cancelClientbound(ClientboundPackets1_21_2.MOVE_MINECART_ALONG_TRACK); // TODO
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
wrapper.passthrough(Types.UUID); // UUID
wrapper.passthrough(Types.STRING); // Name
@@ -45,6 +45,7 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
import com.viaversion.viaversion.api.minecraft.item.data.DamageResistant1_21_2;
import com.viaversion.viaversion.api.minecraft.item.data.DeathProtection;
import com.viaversion.viaversion.api.minecraft.item.data.Enchantable;
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
@@ -52,11 +53,13 @@ import com.viaversion.viaversion.api.minecraft.item.data.Equippable;
import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_20_5;
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_21_2;
import com.viaversion.viaversion.api.minecraft.item.data.ItemModel;
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect;
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffectData;
import com.viaversion.viaversion.api.minecraft.item.data.Repairable;
import com.viaversion.viaversion.api.minecraft.item.data.UseCooldown;
import com.viaversion.viaversion.api.minecraft.item.data.consumable.ApplyStatusEffects;
import com.viaversion.viaversion.api.minecraft.item.data.consumable.Consumable1_21_2;
import com.viaversion.viaversion.api.minecraft.item.data.consumable.ConsumeEffect;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
@@ -220,13 +223,30 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsFullStructured
passthroughClientboundItem(wrapper);
});
protocol.replaceClientbound(ClientboundPackets1_21_2.CONTAINER_SET_SLOT, wrapper -> {
varIntToByte(wrapper);
final int containerId = wrapper.read(Types.VAR_INT);
wrapper.write(Types.BYTE, (byte) containerId);
final int stateId = wrapper.passthrough(Types.VAR_INT);
wrapper.user().<BackwardsStorables1_21_2>storables(protocol).inventoryStateIdStorage().setStateId(stateId);
wrapper.passthrough(Types.SHORT); // Slot id
passthroughClientboundItem(wrapper);
final short slotId = wrapper.passthrough(Types.SHORT);
final Item item = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
if (containerId == 0 && slotId >= 5 && slotId <= 8) {
wrapper.write(mappedItemType(), item.copy());
// 1.21.2+ servers use set slot packets to update equipment while inside containers, 1.21 only expects
// it for hotbar/offhand
final EntityTracker tracker = wrapper.user().getEntityTracker(protocol);
final PacketWrapper equipment = PacketWrapper.create(ClientboundPackets1_21.SET_EQUIPMENT, wrapper.user());
equipment.write(Types.VAR_INT, tracker.clientEntityId());
// helmet-boots is 5-8 in container but 5-2 in equipment
equipment.write(Types.BYTE, (byte) (10 - slotId));
equipment.write(mappedItemType(), item);
equipment.send(Protocol1_21_2To1_21.class);
} else {
wrapper.write(mappedItemType(), item);
}
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, wrapper -> {
varIntToUnsignedByte(wrapper);
@@ -553,6 +573,34 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsFullStructured
backupTag.put("death_protection", tag);
}
final Consumable1_21_2 consumable = data.get(StructuredDataKey.CONSUMABLE1_21_2);
if (consumable != null) {
final CompoundTag tag = new CompoundTag();
tag.putFloat("consume_seconds", consumable.consumeSeconds());
tag.putInt("animation", consumable.animationType());
saveSoundEventHolder(tag, consumable.sound());
tag.putBoolean("has_consume_particles", consumable.hasConsumeParticles());
final ListTag<CompoundTag> effects = new ListTag<>(CompoundTag.class);
for (final ConsumeEffect<?> effect : consumable.consumeEffects()) {
final CompoundTag effectTag = new CompoundTag();
convertConsumableEffect(effectTag, effect);
effects.add(effectTag);
}
tag.put("consume_effects", effects);
backupTag.put("consumable", tag);
}
final DamageResistant1_21_2 damageResistant = data.get(StructuredDataKey.DAMAGE_RESISTANT1_21_2);
if (damageResistant != null) {
backupTag.putString("damage_resistant", damageResistant.typesTagKey().original());
}
final PotionContents potionContents = data.get(StructuredDataKey.POTION_CONTENTS1_21_2);
if (potionContents != null && potionContents.customName() != null) {
backupTag.putString("potion_custom_name", potionContents.customName());
}
if (!backupTag.isEmpty()) {
saveTag(createCustomTag(item), backupTag, "inconvertible_data");
}
@@ -713,6 +761,34 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsFullStructured
data.set(StructuredDataKey.DEATH_PROTECTION1_21_2, new DeathProtection(effects.toArray(ConsumeEffect[]::new)));
}
final CompoundTag consumable = backupTag.getCompoundTag("consumable");
if (consumable != null) {
final List<ConsumeEffect<?>> effects = new ArrayList<>();
for (final CompoundTag effectTag : consumable.getListTag("consume_effects", CompoundTag.class)) {
final ConsumeEffect<?> effect = convertConsumableEffect(effectTag);
if (effect != null) {
effects.add(effect);
}
}
data.set(StructuredDataKey.CONSUMABLE1_21_2, new Consumable1_21_2(
consumable.getFloat("consume_seconds"),
consumable.getInt("animation"),
restoreSoundEventHolder(consumable),
consumable.getBoolean("has_consume_particles"),
effects.toArray(ConsumeEffect[]::new)
));
}
final String damageResistant = backupTag.getString("damage_resistant");
if (damageResistant != null) {
data.set(StructuredDataKey.DAMAGE_RESISTANT1_21_2, new DamageResistant1_21_2(Key.of(damageResistant)));
}
final String potionCustomName = backupTag.getString("potion_custom_name");
if (potionCustomName != null) {
data.replace(StructuredDataKey.POTION_CONTENTS1_21_2, potionContents -> new PotionContents(potionContents.potion(), potionContents.customColor(), potionContents.customEffects(), potionCustomName));
}
removeCustomTag(data, customData);
}
}
@@ -199,6 +199,48 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
writePackedRotation(wrapper, yaw, pitch);
});
protocol.registerClientbound(ClientboundPackets1_21_2.MOVE_MINECART_ALONG_TRACK, ClientboundPackets1_21.TELEPORT_ENTITY, wrapper -> {
// Only sent with the experimental minecart improvements, old clients can only lerp to a single position
final int entityId = wrapper.passthrough(Types.VAR_INT);
final int steps = wrapper.read(Types.VAR_INT);
if (steps == 0) {
wrapper.cancel();
return;
}
double x = 0, y = 0, z = 0;
double movementX = 0, movementY = 0, movementZ = 0;
byte yaw = 0, pitch = 0;
for (int i = 0; i < steps; i++) {
x = wrapper.read(Types.DOUBLE);
y = wrapper.read(Types.DOUBLE);
z = wrapper.read(Types.DOUBLE);
movementX = wrapper.read(Types.DOUBLE);
movementY = wrapper.read(Types.DOUBLE);
movementZ = wrapper.read(Types.DOUBLE);
yaw = wrapper.read(Types.BYTE);
pitch = wrapper.read(Types.BYTE);
wrapper.read(Types.FLOAT); // Weight
}
wrapper.write(Types.DOUBLE, x);
wrapper.write(Types.DOUBLE, y);
wrapper.write(Types.DOUBLE, z);
wrapper.write(Types.BYTE, (byte) (128 - yaw));
wrapper.write(Types.BYTE, pitch);
wrapper.write(Types.BOOLEAN, false); // On ground
wrapper.send(Protocol1_21_2To1_21.class);
wrapper.cancel();
final PacketWrapper entityMotionPacket = wrapper.create(ClientboundPackets1_21.SET_ENTITY_MOTION);
entityMotionPacket.write(Types.VAR_INT, entityId);
entityMotionPacket.write(Types.SHORT, VelocityUtil.toLegacyVelocity(movementX));
entityMotionPacket.write(Types.SHORT, VelocityUtil.toLegacyVelocity(movementY));
entityMotionPacket.write(Types.SHORT, VelocityUtil.toLegacyVelocity(movementZ));
entityMotionPacket.send(Protocol1_21_2To1_21.class);
});
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_LOOK_AT, wrapper -> {
final float yaw = wrapper.read(Types.FLOAT);
final float pitch = wrapper.read(Types.FLOAT);
@@ -101,6 +101,10 @@ public final class Protocol1_21_4To1_21_2 extends BackwardsProtocol<ClientboundP
final CompoundTag compoundTag = ((CompoundTag) entry.tag());
compoundTag.putFloat("item_model_index", itemModelIndex(entry.key()));
if ("resin".equals(compoundTag.getString("asset_name"))) {
compoundTag.putString("asset_name", "gold");
}
}
}
@@ -265,7 +269,7 @@ public final class Protocol1_21_4To1_21_2 extends BackwardsProtocol<ClientboundP
case "copper" -> 0.5F;
case "diamond" -> 0.8F;
case "emerald" -> 0.7F;
case "gold" -> 0.6F;
case "gold", "resin" -> 0.6F;
case "iron" -> 0.2F;
case "lapis" -> 0.9F;
case "netherite" -> 0.3F;
@@ -27,6 +27,7 @@ import com.viaversion.viabackwards.protocol.v1_21_5to1_21_4.rewriter.EntityPacke
import com.viaversion.viabackwards.protocol.v1_21_5to1_21_4.rewriter.RegistryDataRewriter1_21_5;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.data.version.StructuredDataKeys1_21_2;
import com.viaversion.viaversion.api.minecraft.data.version.StructuredDataKeys1_21_5;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_4;
@@ -100,6 +101,8 @@ public final class Protocol1_21_5To1_21_4 extends BackwardsProtocol<ClientboundP
protected void registerPackets() {
super.registerPackets();
tagRewriter.renameTag(RegistryType.BLOCK, "dry_vegetation_may_place_on", "dead_bush_may_place_on");
final CommandRewriter1_19_4<ClientboundPacket1_21_5> commandRewriter = new CommandRewriter1_19_4<>(this) {
@Override
public void handleArgument(final PacketWrapper wrapper, final String argumentType) {
@@ -49,6 +49,7 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.BlocksAttacks;
import com.viaversion.viaversion.api.minecraft.item.data.BlocksAttacks.DamageReduction;
import com.viaversion.viaversion.api.minecraft.item.data.BlocksAttacks.ItemDamageFunction;
import com.viaversion.viaversion.api.minecraft.item.data.BreakSound;
import com.viaversion.viaversion.api.minecraft.item.data.Equippable;
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
import com.viaversion.viaversion.api.minecraft.item.data.TooltipDisplay;
@@ -296,6 +297,10 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
}
final OriginalHashedItem originalHashedItem = backedUpOriginalHashes(originalHashes, item);
if (originalHashedItem == null) {
return null;
}
// Return as regular hashed item if the tag was forced in this protocol and it would otherwise be passed on
// to the final serverbound protocol without the required handling.
return originalHashedItem.backupTagName().equals(nbtTagName()) ? originalHashedItem.asRegularItem() : originalHashedItem;
@@ -363,8 +368,8 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
protected void backupInconvertibleData(final UserConnection connection, final Item item, final StructuredDataContainer dataContainer, final CompoundTag backupTag) {
super.backupInconvertibleData(connection, item, dataContainer, backupTag);
final ToolProperties toolProperties = dataContainer.get(StructuredDataKey.TOOL1_21_5);
if (toolProperties != null && toolProperties.canDestroyBlocksInCreative()) {
backupTag.putBoolean("tool", true);
if (toolProperties != null && !toolProperties.canDestroyBlocksInCreative()) {
backupTag.putBoolean("tool", false);
}
final Equippable equippable = dataContainer.get(StructuredDataKey.EQUIPPABLE1_21_5);
@@ -462,6 +467,7 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
saveIntData(StructuredDataKey.COW_VARIANT, dataContainer, backupTag);
saveIntData(StructuredDataKey.PIG_VARIANT, dataContainer, backupTag);
saveIntData(StructuredDataKey.WOLF_VARIANT, dataContainer, backupTag);
saveIntData(StructuredDataKey.WOLF_COLLAR, dataContainer, backupTag);
final Either<Integer, String> chickenVariant = dataContainer.get(StructuredDataKey.CHICKEN_VARIANT1_21_5);
if (chickenVariant != null) {
@@ -484,7 +490,10 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
}
});
saveHolderData(StructuredDataKey.BREAK_SOUND, dataContainer, backupTag, this::saveSoundEvent);
final BreakSound breakSound = dataContainer.get(StructuredDataKey.BREAK_SOUND);
if (breakSound != null) {
backupTag.put(StructuredDataKey.BREAK_SOUND.identifier(), holderToTag(breakSound.sound(), this::saveSoundEvent));
}
}
@Override
@@ -511,8 +520,9 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
data.set(StructuredDataKey.TOOLTIP_DISPLAY, new TooltipDisplay(data.has(StructuredDataKey.HIDE_TOOLTIP), new IntLinkedOpenHashSet(hiddenComponentsTag.getValue())));
}
if (backupTag.getBoolean("tool")) {
data.replace(StructuredDataKey.TOOL1_20_5, StructuredDataKey.TOOL1_21_5, t -> new ToolProperties(t.rules(), t.defaultMiningSpeed(), t.damagePerBlock(), true));
if (backupTag.contains("tool")) {
final boolean canDestroyBlocksInCreative = backupTag.getBoolean("tool");
data.replace(StructuredDataKey.TOOL1_20_5, StructuredDataKey.TOOL1_21_5, t -> new ToolProperties(t.rules(), t.defaultMiningSpeed(), t.damagePerBlock(), canDestroyBlocksInCreative));
}
if (backupTag.getBoolean("equippable")) {
@@ -546,7 +556,7 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
final float disableCooldownScale = blocksAttackTag.getFloat("disable_cooldown_scale");
final CompoundTag itemDamageTag = blocksAttackTag.getCompoundTag("item_damage");
final ItemDamageFunction itemDamage = new ItemDamageFunction(itemDamageTag.getFloat("threshold"), itemDamageTag.getFloat("base"), itemDamageTag.getFloat("factor"));
final String bypassedBy = blocksAttackTag.getString("bypassed_by");
final String bypassedBy = itemDamageTag.getString("bypassed_by");
final Holder<SoundEvent> blockSound = blocksAttackTag.contains("block_sound") ? restoreHolder(blocksAttackTag, "block_sound", this::tagToSound) : null;
final Holder<SoundEvent> disableSound = blocksAttackTag.contains("disable_sound") ? restoreHolder(blocksAttackTag, "disable_sound", this::tagToSound) : null;
@@ -602,8 +612,11 @@ public final class BlockItemPacketRewriter1_21_5 extends BackwardsStructuredItem
restoreIntData(StructuredDataKey.COW_VARIANT, data, backupTag);
restoreIntData(StructuredDataKey.PIG_VARIANT, data, backupTag);
restoreIntData(StructuredDataKey.WOLF_VARIANT, data, backupTag);
restoreIntData(StructuredDataKey.WOLF_COLLAR, data, backupTag);
restoreHolderData(StructuredDataKey.BREAK_SOUND, data, backupTag, this::tagToSound);
if (backupTag.contains(StructuredDataKey.BREAK_SOUND.identifier())) {
data.set(StructuredDataKey.BREAK_SOUND, new BreakSound(restoreHolder(backupTag, StructuredDataKey.BREAK_SOUND.identifier(), this::tagToSound)));
}
restoreHolderData(StructuredDataKey.PAINTING_VARIANT, data, backupTag, tag -> {
final int width = tag.getInt("width");
final int height = tag.getInt("height");
@@ -38,6 +38,7 @@ import com.viaversion.viabackwards.protocol.v1_21_6to1_21_5.storage.ServerLinks;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_6;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@@ -93,6 +94,8 @@ public final class Protocol1_21_6To1_21_5 extends BackwardsProtocol<ClientboundP
protected void registerPackets() {
super.registerPackets();
tagRewriter.renameTag(RegistryType.BLOCK, "triggers_ambient_desert_dry_vegetation_block_sounds", "plays_ambient_desert_block_sounds");
replaceClientbound(ClientboundPackets1_21_6.UPDATE_TAGS, this::updateTags);
replaceClientbound(ClientboundConfigurationPackets1_21_6.UPDATE_TAGS, this::updateTags);
@@ -456,11 +456,6 @@ public final class EntityPacketRewriter1_21_9 extends EntityRewriter<Clientbound
equipment.send(Protocol1_21_9To1_21_7.class);
}
final PacketWrapper setHeadRotation = PacketWrapper.create(ClientboundPackets1_21_6.ROTATE_HEAD, event.user());
setHeadRotation.write(Types.VAR_INT, event.entityId());
setHeadRotation.write(Types.BYTE, mannequinData.headYaw());
setHeadRotation.send(Protocol1_21_9To1_21_7.class);
if (!isBundling) {
final PacketWrapper bundleStart = PacketWrapper.create(ClientboundPackets1_21_6.BUNDLE_DELIMITER, event.user());
bundleStart.send(Protocol1_21_9To1_21_7.class);
@@ -173,6 +173,19 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol<ClientboundPac
final String[] enabledFeatures = wrapper.read(Types.STRING_ARRAY);
wrapper.write(Types.STRING_ARRAY, ArrayUtil.add(enabledFeatures, "minecraft:update_1_21"));
});
// 1.21+ clients ignore the value of the win game event and always show the end poem, while older clients
// skip it for a value of 0, which servers send to players that have already seen the credits
appendClientbound(ClientboundPackets1_21.GAME_EVENT, wrapper -> {
wrapper.resetReader();
final short event = wrapper.passthrough(Types.UNSIGNED_BYTE);
if (event != 4) { // Win game
return;
}
wrapper.read(Types.FLOAT);
wrapper.write(Types.FLOAT, 1F); // Roll the credits
});
}
@Override
@@ -302,7 +302,7 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsFullStructuredIt
final CompoundTag jukeboxPlayableTag = tag.getCompoundTag("jukebox_playable");
if (jukeboxPlayableTag != null) {
final EitherHolder<JukeboxPlayable.JukeboxSong> song;
final String songIdentifier = tag.getString("song_identifier");
final String songIdentifier = jukeboxPlayableTag.getString("song_identifier");
if (songIdentifier != null) {
song = EitherHolder.of(songIdentifier);
} else {
@@ -315,7 +315,7 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsFullStructuredIt
}));
}
final JukeboxPlayable jukeboxPlayable = new JukeboxPlayable(song, tag.getBoolean("show_in_tooltip"));
final JukeboxPlayable jukeboxPlayable = new JukeboxPlayable(song, jukeboxPlayableTag.getBoolean("show_in_tooltip"));
data.set(StructuredDataKey.JUKEBOX_PLAYABLE1_21, jukeboxPlayable);
}
@@ -31,7 +31,9 @@ import com.viaversion.viabackwards.protocol.v26_3to26_2.rewriter.EntityPacketRew
import com.viaversion.viabackwards.protocol.v26_3to26_2.rewriter.RegistryDataRewriter26_3;
import com.viaversion.viabackwards.protocol.v26_3to26_2.storage.ProtocolStorables26_3;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.item.data.ChatType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
@@ -76,12 +78,29 @@ public final class Protocol26_3To26_2 extends BackwardsProtocol<ClientboundPacke
private final BackwardsRegistryRewriter registryDataRewriter = new RegistryDataRewriter26_3(this);
private final RecipeDisplayRewriter<ClientboundPacket26_3> recipeRewriter = new RecipeDisplayRewriter26_3<>(this) {
@Override
protected void handleTag(final PacketWrapper wrapper) {
protected void handleSlotDisplay(final PacketWrapper wrapper) {
final FullMappings mappings = protocol.getMappingData().getSlotDisplayMappings();
final int type = wrapper.passthrough(Types.VAR_INT);
wrapper.rewindReader(1); // Only peek at the type
if (type != mappings.id("tag")) {
super.handleSlotDisplay(wrapper);
return;
}
wrapper.read(Types.VAR_INT);
final HolderSet items = wrapper.read(Types.HOLDER_SET);
if (items.hasTagKey()) {
wrapper.write(Types.VAR_INT, mappings.getNewId(type));
wrapper.write(Types.STRING, items.tagKey());
} else {
wrapper.write(Types.STRING, "planks"); // dummy
return;
}
// 26.2 tag displays only take a tag key, so send direct item lists as a composite of item displays
wrapper.write(Types.VAR_INT, mappings.mappedId("composite"));
wrapper.write(Types.VAR_INT, items.ids().length);
for (final int id : items.ids()) {
wrapper.write(Types.VAR_INT, mappings.mappedId("item"));
wrapper.write(Types.VAR_INT, rewriteItemId(id));
}
}
};
@@ -94,6 +113,8 @@ public final class Protocol26_3To26_2 extends BackwardsProtocol<ClientboundPacke
protected void registerPackets() {
super.registerPackets();
tagRewriter.renameTag(RegistryType.BLOCK, "convertible_to_mud", "convertable_to_mud");
registryDataRewriter.remove("decorated_pot_pattern");
registryDataRewriter.remove("block_transformer");
registryDataRewriter.remove("worldgen/block_state_provider");
@@ -85,7 +85,7 @@ public final class BlockItemPacketRewriter26_3 extends BackwardsStructuredItemRe
final int icons = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < icons; i++) {
final int decorationType = wrapper.read(Types.VAR_INT);
wrapper.write(Types.VAR_INT, Math.min(decorationType, 34)); // Map new ones to trial chambers
wrapper.write(Types.VAR_INT, decorationType > 34 ? 4 : decorationType); // Map new ones to target_x (4)
wrapper.passthrough(Types.BYTE); // X
wrapper.passthrough(Types.BYTE); // Y
wrapper.passthrough(Types.BYTE); // Rotation
@@ -561,7 +561,7 @@ public final class BlockItemPacketRewriter26_3 extends BackwardsStructuredItemRe
final CompoundTag types = new CompoundTag();
for (final Map.Entry<String, Tag> entry : mapDecorations.entrySet()) {
types.put(entry.getKey(), ((CompoundTag) entry.getValue()).getStringTag("type"));
types.put(entry.getKey(), ((CompoundTag) entry.getValue()).getStringTag("type").copy());
}
backupTag.put("map_decorations", types);
}
@@ -40,7 +40,8 @@ public final class ComponentRewriter26_3 extends NBTComponentRewriter<Clientboun
removeDataComponents(componentsTag, StructuredDataKey.PROVIDES_TRIM_MATERIAL26_3, StructuredDataKey.PROVIDES_POTTERY_PATTERN, StructuredDataKey.BLOCK_TRANSFORMER,
StructuredDataKey.COMPOSTABLE, StructuredDataKey.INTERACT_ANIMATION, StructuredDataKey.ATTACK_ANIMATION, StructuredDataKey.TRIM26_3,
StructuredDataKey.COOKING_FUEL, StructuredDataKey.BREWING_FUEL, StructuredDataKey.VILLAGER_FOOD, StructuredDataKey.MOB_VISIBILITY,
StructuredDataKey.SIGN_TEXT_BACK, StructuredDataKey.SIGN_TEXT_FRONT, StructuredDataKey.WAXED, StructuredDataKey.CUSHION_COLOR);
StructuredDataKey.SIGN_TEXT_BACK, StructuredDataKey.SIGN_TEXT_FRONT, StructuredDataKey.WAXED, StructuredDataKey.CUSHION_COLOR,
StructuredDataKey.MAP_DECORATIONS);
removeDataComponents(componentsTag, "pot_decorations");
}
}
@@ -22,6 +22,8 @@ import com.viaversion.viabackwards.protocol.v26_3to26_2.Protocol26_3To26_2;
import com.viaversion.viabackwards.protocol.v26_3to26_2.storage.ProtocolStorables26_3;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes26_3;
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes26_1;
import com.viaversion.viaversion.api.minecraft.item.data.SwingAnimation;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@@ -32,12 +34,15 @@ import com.viaversion.viaversion.protocols.v1_21_11to26_1.packet.ServerboundPack
import com.viaversion.viaversion.protocols.v26_2to26_3.packet.ClientboundPacket26_3;
import com.viaversion.viaversion.protocols.v26_2to26_3.packet.ClientboundPackets26_3;
import com.viaversion.viaversion.protocols.v26_2to26_3.packet.ServerboundPackets26_3;
import java.util.ArrayList;
import java.util.List;
public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPacket26_3, Protocol26_3To26_2> {
private static final EntityDataTypes26_1 MAPPED_DATA_TYPES = VersionedTypes.V26_2.entityDataTypes;
private static final int NO_SWING_ANIMATION = 0;
private static final int CHANGE_DESTROY_DIRECTION_ACTION = 1;
private static final int WHITE_CARPET_BLOCK_STATE = 12896;
public EntityPacketRewriter26_3(final Protocol26_3To26_2 protocol) {
super(protocol, MAPPED_DATA_TYPES.optionalComponentType, MAPPED_DATA_TYPES.booleanType);
@@ -191,6 +196,29 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
});
protocol.registerServerbound(ServerboundPackets26_1.SPECTATE_ENTITY, ServerboundPackets26_3.SPECTATOR_ACTION);
protocol.appendClientbound(ClientboundPackets26_3.ADD_ENTITY, wrapper -> {
final int entityId = wrapper.get(Types.VAR_INT, 0);
final TrackedEntity entity = tracker(wrapper.user()).entity(entityId);
if (entity == null || entity.entityType() != EntityTypes26_3.CUSHION) {
return;
}
// Set falling block data to white carpet block state
wrapper.set(Types.VAR_INT, 2, WHITE_CARPET_BLOCK_STATE);
wrapper.send(Protocol26_3To26_2.class);
wrapper.cancel();
// Send no gravity entity data
final List<EntityData> entityDataList = new ArrayList<>();
entityDataList.add(new EntityData(5, MAPPED_DATA_TYPES.booleanType, true)); // No gravity
final PacketWrapper entityDataPacket = wrapper.create(ClientboundPackets26_1.SET_ENTITY_DATA);
entityDataPacket.write(Types.VAR_INT, entityId);
entityDataPacket.write(VersionedTypes.V26_2.entityDataList, entityDataList);
entityDataPacket.send(Protocol26_3To26_2.class);
});
}
private void handleGamemodes(final PacketWrapper wrapper) {
@@ -248,6 +276,7 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
@Override
public void onMappingDataLoaded() {
super.onMappingDataLoaded();
mapEntityTypeWithData(EntityTypes26_3.CUSHION, EntityTypes26_3.FALLING_BLOCK);
}
@Override
@@ -18,24 +18,42 @@
package com.viaversion.viabackwards.protocol.v26_3to26_2.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viabackwards.api.rewriters.BackwardsRegistryRewriter;
import com.viaversion.viabackwards.protocol.v26_3to26_2.Protocol26_3To26_2;
import com.viaversion.viaversion.util.Key;
import java.util.List;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class RegistryDataRewriter26_3 extends BackwardsRegistryRewriter {
public RegistryDataRewriter26_3(final Protocol26_3To26_2 protocol) {
super(protocol);
addEnchantmentEffectRewriter("replace_disk", this::replaceBlockStateProvider);
addEnchantmentEffectRewriter("replace_block", this::replaceBlockStateProvider);
}
@Override
public void updateEnchantmentTerm(final CompoundTag term) {
final String type = term.getString("type");
if (type != null) {
term.putString("condition", type);
// 26.3 uses "type" instead of "condition" - rename it back for 26.2
final StringTag typeTag = term.removeUnchecked("type");
if (typeTag != null) {
term.put("condition", typeTag);
}
final String type = typeTag != null ? typeTag.getValue() : null;
// In 26.3, the "terms" field of all_of/any_of can be an inline term (CompoundTag)
// instead of always being a ListTag<CompoundTag>. Convert it to a list for 26.2.
final Tag termsTag = term.get("terms");
if (termsTag instanceof CompoundTag inlineTerm) {
final ListTag<CompoundTag> termsList = new ListTag<>(CompoundTag.class);
termsList.add(inlineTerm);
term.put("terms", termsList);
}
if (Key.equals(type, "damage_source_properties")) {
@@ -49,6 +67,20 @@ public final class RegistryDataRewriter26_3 extends BackwardsRegistryRewriter {
} else if (Key.equals(type, "match_block")) {
// Has to run before super, which would otherwise replace the term by a dummy effect
updateMatchBlock(term);
} else if (Key.equals(type, "int_value_check") || Key.equals(type, "float_value_check")) {
term.putString("condition", "minecraft:value_check");
if (!convert(term, "value", "value", RegistryDataRewriter26_3::toNumberProvider)
|| !convert(term, "test", "range", RegistryDataRewriter26_3::toIntRange)) {
replaceWithAlwaysTrue(term);
}
} else if (Key.equals(type, "time_check")) {
if (!convert(term, "value", "value", RegistryDataRewriter26_3::toIntRange)) {
replaceWithAlwaysTrue(term);
}
} else if (Key.equals(type, "random_chance")) {
if (!convert(term, "chance", "chance", RegistryDataRewriter26_3::toNumberProvider)) {
replaceWithAlwaysTrue(term);
}
}
super.updateEnchantmentTerm(term);
@@ -56,31 +88,18 @@ public final class RegistryDataRewriter26_3 extends BackwardsRegistryRewriter {
@Override
public boolean updateBlockStateProvider(final CompoundTag tag) {
String type = tag.getString("type");
if (type == null) {
// Move block state to a block provider
final CompoundTag stateTag = tag.copy();
handleFullBlockState(stateTag);
tag.put("state", stateTag);
tag.putString("type", "simple_state_provider");
return true;
}
return false; // Handled in replaceBlockStateProvider, as providers can also be registry references now
}
type = Key.stripMinecraftNamespace(type);
switch (type) {
case "simple_state_provider", "rotated_block_provider" -> {
handleBlockState(tag, "state");
}
case "weighted_state_provider" -> {
for (final CompoundTag entry : tag.getListTag("entries", CompoundTag.class)) {
handleBlockState(entry, "data");
}
}
case "noise_threshold_provider" -> {
handleBlockState(tag, "default_state");
}
}
return super.updateBlockStateProvider(tag);
private void replaceBlockStateProvider(final CompoundTag effect) {
// Provider types were renamed and reworked, but they're only actually used on the server
final CompoundTag state = new CompoundTag();
state.putString("Name", "minecraft:dirt");
final CompoundTag provider = new CompoundTag();
provider.putString("type", "minecraft:simple_state_provider");
provider.put("state", state);
effect.put("block_state", provider);
}
@Override
@@ -91,18 +110,6 @@ public final class RegistryDataRewriter26_3 extends BackwardsRegistryRewriter {
}
}
private void handleBlockState(final CompoundTag parent, final String key) {
final Tag blockStateTag = parent.get(key);
if (blockStateTag instanceof CompoundTag compoundTag) {
handleFullBlockState(compoundTag);
} else if (blockStateTag instanceof StringTag stringTag) {
// Needs to be a compound tag in older versions
final CompoundTag updatedBlockStateTag = new CompoundTag();
updatedBlockStateTag.putString("Name", stringTag.getValue());
parent.put(key, updatedBlockStateTag);
}
}
private void handleFullBlockState(final CompoundTag tag) {
final Tag id = tag.remove("id");
tag.put("Name", id);
@@ -127,12 +134,105 @@ public final class RegistryDataRewriter26_3 extends BackwardsRegistryRewriter {
return;
}
// Block tags and lists have no equivalent, replace the term by an always true condition
// Block tags and lists have no equivalent
replaceWithAlwaysTrue(term);
}
private static void replaceWithAlwaysTrue(final CompoundTag term) {
term.clear();
term.putString("condition", "minecraft:all_of");
term.put("terms", new ListTag<>(CompoundTag.class));
}
// Int and float providers have been merged into a single number provider type
private static @Nullable Tag toNumberProvider(final Tag tag) {
if (tag instanceof NumberTag) {
return tag;
}
if (!(tag instanceof CompoundTag provider)) {
return null; // References to provider registries
}
return switch (Key.stripMinecraftNamespace(provider.getString("type", ""))) {
case "constant", "enchantment_level", "environment_attribute" -> provider;
case "storage", "score" -> {
provider.remove("fallback");
yield provider;
}
case "uniform" -> convert(provider, "min", "min", RegistryDataRewriter26_3::toNumberProvider)
&& convert(provider, "max", "max", RegistryDataRewriter26_3::toNumberProvider) ? provider : null;
case "binomial" -> convert(provider, "n", "n", RegistryDataRewriter26_3::toNumberProvider)
&& convert(provider, "p", "p", RegistryDataRewriter26_3::toNumberProvider) ? provider : null;
case "add" -> {
provider.putString("type", "minecraft:sum");
yield convert(provider, "inputs", "summands", RegistryDataRewriter26_3::toNumberProviderList) ? provider : null;
}
// Old int conversion rounds instead of truncating
case "from_int", "from_float", "round" -> {
final Tag input = provider.get("input");
yield input != null ? toNumberProvider(input) : null;
}
default -> null;
};
}
private static @Nullable Tag toNumberProviderList(final Tag tag) {
final ListTag<CompoundTag> list = new ListTag<>(CompoundTag.class);
for (final Tag element : tag instanceof ListTag<?> listTag ? listTag : List.of(tag)) {
final Tag provider = toNumberProvider(element);
if (provider == null) {
return null;
}
if (provider instanceof CompoundTag compoundTag) {
list.add(compoundTag);
} else {
final CompoundTag constant = new CompoundTag();
constant.putString("type", "minecraft:constant");
constant.put("value", provider);
list.add(constant);
}
}
return list;
}
private static @Nullable Tag toIntRange(final Tag tag) {
if (tag instanceof NumberTag numberTag) {
return tag instanceof IntTag ? tag : new IntTag(Math.round(numberTag.asFloat()));
}
if (!(tag instanceof CompoundTag range)) {
return null;
}
if (range.contains("type")) {
// Single provider, convert to an exact range
final Tag value = toNumberProvider(range);
if (value == null) {
return null;
}
final CompoundTag exactRange = new CompoundTag();
exactRange.put("min", value);
exactRange.put("max", value.copy());
return exactRange;
}
return convert(range, "min", "min", RegistryDataRewriter26_3::toNumberProvider)
&& convert(range, "max", "max", RegistryDataRewriter26_3::toNumberProvider) ? range : null;
}
private static boolean convert(final CompoundTag tag, final String key, final String newKey, final Function<Tag, @Nullable Tag> converter) {
final Tag value = tag.remove(key);
if (value == null) {
return true;
}
final Tag converted = converter.apply(value);
if (converted == null) {
return false;
}
tag.put(newKey, converted);
return true;
}
private void updateTagKey(final ListTag<CompoundTag> tags) {
for (final CompoundTag tag : tags) {
final Tag idTag = tag.get("id");
+3 -4
View File
@@ -1,9 +1,8 @@
projectVersion=5.12.0
projectVersion=5.12.3-SNAPSHOT
# Smile emoji (note that modrinth may not have added the version on release yet)
mcVersions=26.3, 26.2, 26.1.2, 26.1.1, 26.1, 1.21.11, 1.21.10, 1.21.9, 1.21.8, 1.21.7, 1.21.6, 1.21.5, 1.21.4, 1.21.3, 1.21.2, 1.21.1, 1.21, 1.20.6, 1.20.5, 1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
# note that modrinth may not have added the version on release yet
mcVersionRange=1.10-26.3
velocityVersion=3.4-3.5
velocityVersion=3.4-4.2.1
org.gradle.configureondemand=true
org.gradle.parallel=true
+2 -2
View File
@@ -3,14 +3,14 @@ metadata.format.version = "1.1"
[versions]
# ViaVersion
viaver = "5.12.0"
viaver = "5.12.2-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"
guava = "17.0"
log4j = "2.8.1"
checkerQual = "4.2.2"
checkerQual = "4.3.1"
# Platforms
paper = "1.16.5-R0.1-SNAPSHOT"
Binary file not shown.
+2 -2
View File
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=acd53f1edaf02f1a8ff99879f8a34b302661a057d9b063ae9e35b552f804d20a
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
Vendored
+41 -11
View File
@@ -26,6 +26,33 @@
@rem Set local scope for the variables, and ensure extensions are enabled
setlocal EnableExtensions
@rem Catch executions from older scripts and ensure they exit cleanly.
@rem This can be removed once we can be reasonably confident that few people
@rem will be migrating directly to this new wrapper.
goto afterSafetyNet
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto exitWithErrorLevel
:afterSafetyNet
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
@@ -45,13 +72,14 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
1>&2 echo.
1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
1>&2 echo.
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
1>&2 echo location of your Java installation.
"%COMSPEC%" /c exit 1
goto exitWithErrorLevel
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
@@ -59,13 +87,14 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
1>&2 echo.
1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
1>&2 echo.
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
1>&2 echo location of your Java installation.
"%COMSPEC%" /c exit 1
goto exitWithErrorLevel
:execute
@rem Setup the command line
@@ -75,8 +104,9 @@ echo location of your Java installation. 1>&2
@rem Execute gradlew
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
@rem This label must not be changed. We rely on old scripts being able to jump to this point.
:exitWithErrorLevel
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%
+33 -30
View File
@@ -1,6 +1,6 @@
plugins {
id("me.modmuss50.mod-publish-plugin") version "2.2.1"
id("io.papermc.hangar-publish-plugin") version "0.1.4"
id("com.modrinth.minotaur") version "2.+"
// A nice no-conflict comment for patching in downgrading
}
@@ -43,32 +43,38 @@ if (runNumber != null && (!isRelease || isMainBranch)) { // Only publish release
val commitHash = rootProject.latestCommitHash()
"[$commitHash](https://github.com/ViaVersion/ViaBackwards/commit/$commitHash) ${rootProject.latestCommitMessage()}"
}
modrinth {
val mcVersions: List<String> = (property("mcVersions") as String)
.split(",")
.map { it.trim() }
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("viabackwards")
versionType.set(if (isRelease) "release" else if (isMainBranch) "beta" else "alpha")
versionNumber.set(suffixedVersion)
versionName.set(suffixedVersion)
changelog.set(changelogContent)
uploadFile.set(tasks.shadowJar.flatMap { it.archiveFile })
gameVersions.set(mcVersions)
loaders.add("fabric")
loaders.add("paper")
loaders.add("folia")
loaders.add("velocity")
autoAddDependsOn.set(false)
detectLoaders.set(false)
dependencies {
required.project("viaversion")
optional.project("viafabric")
optional.project("viarewind")
val mcVersionRange = property("mcVersionRange") as String
val (mcVersionStart, mcVersionEnd) = mcVersionRange.split("-", limit = 2)
publishMods {
file = tasks.shadowJar.flatMap { it.archiveFile }
type = if (isRelease) STABLE else if (isMainBranch) BETA else ALPHA
version = suffixedVersion
displayName = suffixedVersion
changelog = changelogContent
val modrinthOptions = modrinthOptions {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "NpvuJQoq"
requires("viaversion")
optional("viafabric", "viarewind")
}
modrinth {
from(modrinthOptions)
modLoaders.addAll("paper", "folia", "velocity")
minecraftVersionRange {
start = mcVersionStart
end = mcVersionEnd
}
}
// Fabric requires 1.14+ (18w43b), so it is uploaded separately with only the supported versions...
modrinth("modrinthFabric") {
from(modrinthOptions)
modLoaders.add("fabric")
minecraftVersionRange {
start = "1.14"
end = mcVersionEnd
}
}
}
tasks.modrinth {
notCompatibleWithConfigurationCache("")
}
hangarPublish {
@@ -81,7 +87,7 @@ if (runNumber != null && (!isRelease || isMainBranch)) { // Only publish release
platforms {
paper {
jar = tasks.shadowJar.flatMap { it.archiveFile }
platformVersions = listOf(property("mcVersionRange") as String)
platformVersions = listOf(mcVersionRange)
dependencies {
hangar("ViaVersion") {
required = true
@@ -106,7 +112,4 @@ if (runNumber != null && (!isRelease || isMainBranch)) { // Only publish release
}
}
}
tasks.named("publishPluginPublicationToHangar") {
notCompatibleWithConfigurationCache("")
}
}
@@ -47,7 +47,7 @@
},
{
"id": "viaversion",
"version": "[5.12.0-SNAPSHOT,)"
"version": "[5.12.2-SNAPSHOT,)"
}
]
},