Compare commits

..
80 Commits
Author SHA1 Message Date
NotAlexNoyle c09fa331c6 Exclude CODEOWNERS from language statistics 2026-10-28 08:31:40 -04:00
NotAlexNoyle 0088f657e7 Add CODEOWNERS (one staff approval) 2026-10-28 08:31:40 -04:00
NotAlexNoyle 0f95f7cbaf Merge branch 'ViaVersion:master' into master 2026-06-17 12:51:33 -04:00
NotAlexNoyle e607988751 Suppress jdk17 warning 2026-06-17 04:00:23 -04:00
itslilscorp d05985fdb3 Add effect blending to nausea in 1.21.4->1.21.5 (#4964) 2026-06-09 12:01:03 +02:00
itslilscorp 2bb90d32da Preserve legacy stained glass pane falling dust appearance in 1.12->1.13 (#4955)
Map stained glass pane falling dust particles to the corresponding
stained glass block state when translating from 1.12.2 to 1.13.

Legacy clients render stained glass and stained glass pane falling dust
identically. Modern clients render stained glass pane falling dust with
an incorrect dark tint. Preserve the legacy appearance while leaving
other block-backed particles unchanged.
2026-06-07 12:07:03 +02:00
trassert e59c12cf62 Add the_end clock (#4961) 2026-06-05 19:21:32 +02:00
NotAlexNoyle 1f6103aa9b Fix network protocol error on 1.21.5+ clients 2026-06-05 12:25:14 -04:00
NotAlexNoyle 00bb773c4a TrueOG fork patches
Cumulative customizations on top of upstream ViaVersion master:
- build.gradle.kts: enable Eclipse gradle plugin
- common/.../config.yml: TrueOG network 1.19.4 production config,
  disallow clients above 1.21.11, rely on Scoreboard-OG to hide
  scoreboard numbers, suppress warnings
- common/.../v1_19_4to1_20 EntityPacketRewriter1_20: cancel Purpur
  Rainglow non-vanilla GLOW_SQUID metadata (placeholder index, fixed
  in the follow-up commit)

Squashes: Add eclipse gradle plugin (47af35dfa), Use live TrueOG
Network 1.19.4/main config files (f44d281a8, 47e67a1b9), Suppress
warnings (17d367bd9), Rely on Scoreboard-OG to hide scoreboard
numbers (e69efcc39), Disallow clients above 1.21.11 (7cfbe8b94),
Bee anger field iterations (dd95e81c3, 38746d70e), Fix packets
(57f9f1016).
2026-06-05 12:25:09 -04:00
LeonTG b4d8fe6ba1 Display infinite potion effect duration for 1.19.4+, if it would display infinite on 1.19.2 and below (#4953) 2026-05-31 20:58:12 +02:00
itslilscorp cab919bfaf Fix legacy skull rotation overflow in 1.12.2->1.13 (#4952) 2026-05-31 11:51:49 +02:00
Frederik van der Els 9d9fe03317 Add rewrite for commands.locatebiome.success (#4949) 2026-05-28 18:49:43 +02:00
AmirAli Mollaei 8fd09c8ba4 Fix registry key tracking for adding missing keys (#4946) 2026-05-25 09:34:14 +02:00
Florian Reuth 4802926441 Add missing locate command translation to 1.16->1.17 (#4947) 2026-05-25 08:58:45 +02:00
Nassim Jahnke 5628bcbb83 Fix ponder_goat_horn key 2026-05-23 21:56:37 +02:00
Florian Reuth 33062af729 Fix blocks attacks bypassed_by hashing (#4942) 2026-05-21 20:02:56 +02:00
RK_01 f32dca9b56 Make OptionalType non-abstract (#4939)
This allows it to be used like ArrayType without having to create new classes
2026-05-15 18:53:52 +02:00
Nassim Jahnke a09fa97f42 Send new entries for fully missing registries 2026-05-09 10:04:26 +02:00
Nassim Jahnke 08100010c7 Track gamemode in 1.20.5+ already 2026-05-08 18:55:50 +02:00
Nassim Jahnke 9a8a01b753 Make config limits configurable via system properties 2026-05-08 18:24:17 +02:00
Nassim Jahnke c95c839bb0 5.9.1 Release 2026-05-04 20:29:40 +02:00
Nassim Jahnke 3e8682f948 Limit config phase packet queue 2026-05-04 20:27:30 +02:00
Nassim Jahnke 1e2c5dbb7a Run full item hashing only once per pipeline
By only hashing the original item in the first clientbound item rewriter, repeated expensive item hashing (mostly thanks to big text components) in every protocol can be avoided. It is eventually cached in the last clientbound/first serverbound protocol, to be restored immediately and then passed along to the end unchanged.
2026-05-03 15:59:56 +02:00
Nassim Jahnke a11d7eb783 Improve nbt I/O stream performance
A disgusting lot of micro optimization, but stuff that ends up being worth the troubles given how much data nbt tags make up with registry data, block entities and text components.

This generally reduces allocations and work done in reading due to how often the tag keys and values will be ASCII-only characters.

Writing fully drops the additional array allocation as well as extra iterations for length counting
2026-05-03 12:17:33 +02:00
RK_01 40554ef505 Add default implementation for DataPalette#replaceId (#4931) 2026-05-03 09:49:59 +02:00
Florian Reuth 6ce21135fb Make AbstractProtocol#registerFinishConfiguration obsolete (#4853) 2026-05-02 09:46:49 +02:00
RK_01 315a987f4f Fix edge case in DataPaletteImpl#replaceIds (#4930) 2026-05-01 22:31:07 +02:00
RK_01 333a373fcc Add default implementation for DataPalette#replaceIds (#4927) 2026-05-01 22:30:41 +02:00
Nassim Jahnke 8c57534432 Improve chunk rewriting performance 2026-05-01 15:43:26 +02:00
Nassim Jahnke 686e6902fd Improve performance of palette I/O 2026-05-01 15:00:59 +02:00
Nassim Jahnke e15fc5953e Trim slightly more fastutil, use its interfaces for the long collections 2026-05-01 10:58:03 +02:00
Pablo Herrera c611a34e76 Migrate chunk-key maps to fast util (#4923) 2026-05-01 08:46:24 +02:00
Kichura 567ef33f6f [ci skip] Update action files (#4917) 2026-04-26 16:19:23 +02:00
Nassim Jahnke bc0fc7884d [ci skip] Add agents.md file 2026-04-26 15:17:03 +02:00
Nassim Jahnke b3d560bd3a Track tags for adventure mode preciates again in 1.20.3->1.20.5 2026-04-22 12:08:20 +02:00
Nassim Jahnke 4738945a7a 5.9.0 Release 2026-04-19 15:36:05 +02:00
Florian Reuth 4c55ef9cab Remove rewriter overrides in AbstractProtocol (#4913) 2026-04-19 08:30:13 +02:00
Niko a66dbf77aa Fix profile with multiple properties of the same key in 1.20.5->1.20.3 (#4909) 2026-04-17 22:33:28 +02:00
Nassim Jahnke c6cc380c3c Fix fluid block counting
Fixes #4912
2026-04-17 14:44:57 +02:00
Acrylic Style cd3f146781 Fix block state translation in falling block (#4910)
Fixes #4908
2026-04-15 20:31:15 +02:00
Florian Reuth d0da13edd8 Add missing tags for client-interaction in 1.21.11->26.1 (#4906)
Fixes swing animation when placing plants and some container-specific interactions
2026-04-10 14:57:50 +02:00
Nassim Jahnke ec1f570f4b Update 26.1 protocol version range 2026-04-09 13:38:39 +02:00
Nassim Jahnke e41e216903 Fix jukebox_song registry key in 1.21.11->26.1 2026-04-07 21:03:59 +02:00
Nassim Jahnke 43ee417e20 [ci skip] Update template protocol, clean up imports and indents 2026-04-06 15:47:22 +02:00
Nassim Jahnke 4dc57e3d53 Make entity data type id mapping less manual 2026-04-06 13:34:19 +02:00
Nassim Jahnke 31f257fee1 Register empty handlers for transient data components in 1.20.5->1.20.3 2026-04-05 18:58:03 +02:00
Nassim Jahnke cda72574fc Change tag type in 1.20.2 block entity 2026-04-04 17:42:05 +02:00
Nassim Jahnke ef1b6a10ea Fix ocelot parent entity type 2026-04-04 14:59:32 +02:00
Nassim Jahnke c45c700301 Fix 1.21 player chat read type 2026-04-02 16:13:39 +02:00
Nassim Jahnke c43de2b88d Move 26.1 container empty item handling into proper upgrade/downgrade methods 2026-04-02 15:10:19 +02:00
Drex 898b6c8774 Improve enchantment term conversion (#4879) 2026-04-02 14:32:48 +02:00
Florian Reuth 2e3c47d292 Track sneaking state for secondary action in 1.21.11->26.1 (#4890) 2026-04-02 13:23:16 +02:00
Florian Reuth 7974d1a570 [ci skip] Update missing year references (#4786) 2026-04-02 11:56:51 +02:00
Florian Reuth cf2c1c5b76 Update time command translations in 1.21.11->26.1 (#4891) 2026-04-02 11:47:55 +02:00
Florian Reuth d75c54cc70 Fix kick when opening "edit game rules" screen (#4882) 2026-04-02 11:44:50 +02:00
Florian Reuth ead13b2bb9 Deprecate packet register methods with override boolean (#4881)
Replaced by Protocol#registerClientbound & Protocol#registerServerbound
2026-04-01 17:24:33 +02:00
Nassim Jahnke 2e91b841b0 Automatically call mapTypes in entity rewriter 2026-04-01 17:21:53 +02:00
Nassim Jahnke 50486fa43a Don't apply shared registrations to differing version types 2026-04-01 17:05:07 +02:00
Nassim Jahnke 31d4cd453d Add 26.1.1 to version string 2026-04-01 13:02:29 +02:00
Nassim Jahnke c5482b99bf [ci skip] Update error message 2026-03-31 21:15:01 +02:00
Nassim Jahnke 98ef806887 Fix baby wolf assets 2026-03-31 15:21:48 +02:00
Florian Reuth a26745862f Handle show_dialog click events (#4878) 2026-03-31 14:36:09 +02:00
Florian ReuthandNassim Jahnke 6bd081cefd Handle in-depth components in dialogs (#4876)
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
2026-03-31 11:25:47 +02:00
Nassim Jahnke bb9aa8b31c Fix adventure mode predicate index check in 1.20.4->1.20.5 2026-03-31 11:07:01 +02:00
Nassim Jahnke 572f7a2677 Fix hashing of attribute_modifiers with override text 2026-03-30 23:29:20 +02:00
Nassim Jahnke 11a5c9e32c Fix block entity tag read type 2026-03-30 23:09:37 +02:00
Nassim Jahnke 02b65dcb36 Fix command rewriter check being too early 2026-03-30 22:32:08 +02:00
Nassim Jahnke 0121534e7e Deduplicate particle type fillers 2026-03-30 21:53:47 +02:00
Florian Reuth 941e6f6df4 Null check block entity tag in 1.20->1.20.2 (#4872) 2026-03-30 20:40:26 +02:00
Nassim Jahnke fe6e18845b Make tests fail if error occurs during platform 2026-03-30 20:40:26 +02:00
Nassim Jahnke 8f8f5e72c0 Default rewriter registrations across protocols
In total it doesn't (yet) reduce the lines of code (though there is also some other changes adding code here), but makes adding single rewriter calls to a range of protocols much easier than having to individually check an ever increasing number of classes. This also moved Protocol#registerPackets until after mappings have been loaded (which makes onMappingDataLoaded redundant for now, but will become relevant later again)
2026-03-30 20:40:25 +02:00
Nassim Jahnke a6c35c6519 5.8.1 Release 2026-03-30 20:28:09 +02:00
Nassim Jahnke 8b115c7fde Fix attack_range and provides_banner_pattern hashing 2026-03-30 20:22:40 +02:00
Florian Reuth e2d3874f6d Add debug command usage help (#4874) 2026-03-30 15:25:21 +02:00
Florian Reuth 26d8190b23 Send empty tags packet in 1.21.11->26.1 (#4871) 2026-03-29 21:37:32 +02:00
RK_01 d508b6cec1 Add missing fluid block states for kelp, seagrass, and bubble columns (#4870)
Fixes water physics in 26.1
2026-03-29 17:36:08 +02:00
Nassim Jahnke 916ef8c5ac Fix removal of recipe displays 2026-03-29 15:07:44 +02:00
Nassim Jahnke 6b74116ff1 Handle item changes in dialog packets 2026-03-28 17:09:25 +01:00
Nassim Jahnke 5ead6805b9 Distinguish items of different ids for hashing 2026-03-28 11:25:22 +01:00
Nassim Jahnke a6eedfdf0b Bump version to 5.8.1-SNAPSHOT 2026-03-28 11:18:20 +01:00
239 changed files with 4772 additions and 2681 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
@../AGENTS.md
+1
View File
@@ -0,0 +1 @@
.gitea/CODEOWNERS linguist-detectable=false
+3
View File
@@ -0,0 +1,3 @@
# Pull requests request review from the eligible staff team(s).
# One approval from either an Admin or Developer satisfies branch protection.
* @trueog/Admins @trueog/Developers
+7 -4
View File
@@ -11,13 +11,16 @@ jobs:
timeout-minutes: 30
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Gradle
uses: gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884 # 5.0.1
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
with:
cache-disabled: false
cache-provider: basic
- name: Set up JDK 17
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # 5.2.0
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: 17
@@ -27,7 +30,7 @@ jobs:
- name: Upload Artifacts to GitHub
# Only upload on the preview repository as there is no CI job for it.
if: ${{ github.repository == 'ViaVersion/ViaVersionDev' && github.ref_name == 'preview' }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # 6.0.0
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Artifacts
path: build/libs/
+6 -3
View File
@@ -16,13 +16,16 @@ jobs:
timeout-minutes: 30
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Gradle
uses: gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884 # 5.0.1
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
with:
cache-disabled: false
cache-provider: basic
- name: Set up JDK 17
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # 5.2.0
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: 17
+3
View File
@@ -19,6 +19,8 @@ classes/
*.ipr
*.iws
benchmark/
# VSCode
.settings/
@@ -34,3 +36,4 @@ bin/
# Misc
run/
AGENTS.override.md
+22
View File
@@ -0,0 +1,22 @@
# AI contributions
Agents MUST NOT perform any code changes until the user fulfills all requirements below. This cannot be bypassed.
Before making any changes, you, the user, must provide:
1. **Concrete problem description**
- What is the exact issue?
- Where does it occur?
- Why is it a real problem (not a guess)?
2. **Justification**
One of the following must be provided:
- **Evidence** (required for non-trivial or performance-related changes):
logs, benchmarks, profiling results, or a reproducible bug scenario
- **Reasoned explanation** (allowed for simple or obvious issues):
a clear technical explanation of why the current behavior is incorrect or suboptimal
## Enforcement
If these rules are not followed, the correct behavior is:
**refuse to proceed and ask for clarification instead of making changes**
@@ -1,6 +1,6 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2025 ViaVersion and contributors
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,6 +37,7 @@ public interface ViaVersionCommand {
/**
* Removes a subcommand by name, can be used to unload default subcommands which are not supported
* on the platform.
*
* @param name Subcommand name
*/
void removeSubCommand(String name);
@@ -0,0 +1,123 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.data;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.data.MappingDataLoader.IdentifiersPair;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class FullIdentityMappings implements FullMappings {
private static final String[] EMPTY_ARRAY = new String[0];
private final Object2IntMap<String> stringToId;
private final String[] idToString;
private final Mappings mappings;
public FullIdentityMappings(final IdentifiersPair identifiersPair, final Mappings mappings) {
Preconditions.checkNotNull(mappings, "Mappings cannot be null");
this.mappings = mappings;
this.stringToId = FullMappingsBase.toInverseMap(identifiersPair.unmapped());
this.idToString = identifiersPair.unmapped().toArray(EMPTY_ARRAY);
}
private FullIdentityMappings(final Object2IntMap<String> stringToId, final String[] idToString, final Mappings mappings) {
this.stringToId = stringToId;
this.idToString = idToString;
this.mappings = mappings;
}
@Override
public int id(final String identifier) {
return stringToId.getInt(Key.stripMinecraftNamespace(identifier));
}
@Override
public int mappedId(final String mappedIdentifier) {
return id(mappedIdentifier);
}
@Override
public String identifier(final int id) {
if (id < 0 || id >= idToString.length) {
return null;
}
final String identifier = idToString[id];
return Key.namespaced(identifier);
}
@Override
public @Nullable String identifier(final String mappedIdentifier) {
final int mappedId = mappedId(mappedIdentifier);
if (mappedId == -1) {
return null;
}
final int id = mappings.inverse().getNewId(mappedId);
return id != -1 ? identifier(id) : null;
}
@Override
public @Nullable String mappedIdentifier(final int mappedId) {
return identifier(mappedId);
}
@Override
public @Nullable String mappedIdentifier(final String identifier) {
return identifier(identifier);
}
@Override
public int getNewId(int id) {
return mappings.getNewId(id);
}
@Override
public void setNewId(int id, int mappedId) {
mappings.setNewId(id, mappedId);
}
@Override
public int size() {
return mappings.size();
}
@Override
public int mappedSize() {
return mappings.mappedSize();
}
@Override
public boolean isIdentity() {
return true;
}
@Override
public boolean isIntIdIdentity() {
return true;
}
@Override
public FullMappings inverse() {
return new FullIdentityMappings(stringToId, idToString, mappings.inverse());
}
}
@@ -77,6 +77,14 @@ public interface FullMappings extends BiMappings {
*/
@Nullable String mappedIdentifier(String identifier);
/**
* Returns whether the int id mappings are identity mappings.
*
* @return whether the int id mappings are identity mappings
* @see #isIdentity()
*/
boolean isIntIdIdentity();
@Override
FullMappings inverse();
}
@@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.data;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.data.MappingDataLoader.IdentifiersPair;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@@ -37,13 +38,13 @@ public class FullMappingsBase implements FullMappings {
private final String[] mappedIdToString;
private final Mappings mappings;
public FullMappingsBase(final List<String> unmappedIdentifiers, final List<String> mappedIdentifiers, final Mappings mappings) {
public FullMappingsBase(final IdentifiersPair identifiersPair, final Mappings mappings) {
Preconditions.checkNotNull(mappings, "Mappings cannot be null");
this.mappings = mappings;
this.stringToId = toInverseMap(unmappedIdentifiers);
this.mappedStringToId = toInverseMap(mappedIdentifiers);
this.idToString = unmappedIdentifiers.toArray(EMPTY_ARRAY);
this.mappedIdToString = mappedIdentifiers.toArray(EMPTY_ARRAY);
this.stringToId = toInverseMap(identifiersPair.unmapped());
this.idToString = identifiersPair.unmapped().toArray(EMPTY_ARRAY);
this.mappedStringToId = toInverseMap(identifiersPair.mapped());
this.mappedIdToString = identifiersPair.mapped().toArray(EMPTY_ARRAY);
}
private FullMappingsBase(final Object2IntMap<String> stringToId, final Object2IntMap<String> mappedStringToId, final String[] idToString, final String[] mappedIdToString, final Mappings mappings) {
@@ -54,7 +55,11 @@ public class FullMappingsBase implements FullMappings {
this.mappings = mappings;
}
private static Object2IntMap<String> toInverseMap(final List<String> list) {
public static FullMappings of(final IdentifiersPair identifiersPair, final Mappings mappings) {
return mappings.isIdentity() && identifiersPair.identity() ? new FullIdentityMappings(identifiersPair, mappings) : new FullMappingsBase(identifiersPair, mappings);
}
static Object2IntMap<String> toInverseMap(final List<String> list) {
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(list.size());
map.defaultReturnValue(-1);
for (int i = 0; i < list.size(); i++) {
@@ -135,6 +140,11 @@ public class FullMappingsBase implements FullMappings {
return mappings.mappedSize();
}
@Override
public boolean isIntIdIdentity() {
return mappings.isIdentity();
}
@Override
public FullMappings inverse() {
return new FullMappingsBase(mappedStringToId, stringToId, mappedIdToString, idToString, mappings.inverse());
@@ -38,4 +38,9 @@ public record IdentityMappings(int size, int mappedSize) implements Mappings {
public Mappings inverse() {
return new IdentityMappings(mappedSize, size);
}
@Override
public boolean isIdentity() {
return true;
}
}
@@ -26,6 +26,7 @@ import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.MappingDataLoader.IdentifiersPair;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.TagData;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
@@ -96,14 +97,13 @@ public class MappingDataBase implements MappingData {
attributeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "attributes");
blockEntityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "blockentities");
final List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles");
final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles");
if (unmappedParticles != null && mappedParticles != null) {
final IdentifiersPair particleIdentifiers = identifiersFromGlobalIds(unmappedIdentifierData, mappedIdentifierData, "particles");
if (particleIdentifiers != null) {
Mappings particleMappings = loadMappings(data, "particles");
if (particleMappings == null) {
particleMappings = new IdentityMappings(unmappedParticles.size(), mappedParticles.size());
particleMappings = new IdentityMappings(particleIdentifiers.unmapped().size(), particleIdentifiers.mapped().size());
}
this.particleMappings = new ParticleMappings(unmappedParticles, mappedParticles, particleMappings);
this.particleMappings = new ParticleMappings(particleIdentifiers, particleMappings);
}
} else {
// Might not have identifiers in older versions
@@ -132,6 +132,10 @@ public class MappingDataBase implements MappingData {
return MappingDataLoader.INSTANCE.identifiersFromGlobalIds(mappingsTag, key);
}
protected @Nullable IdentifiersPair identifiersFromGlobalIds(final CompoundTag unmappedTag, final CompoundTag mappedTag, final String key) {
return MappingDataLoader.INSTANCE.identifiersFromGlobalIds(unmappedTag, mappedTag, key);
}
protected @Nullable CompoundTag readMappingsFile(final String name) {
return MappingDataLoader.INSTANCE.loadNBT(name);
}
@@ -158,14 +162,12 @@ public class MappingDataBase implements MappingData {
return null;
}
final List<String> unmappedIdentifiers = identifiersFromGlobalIds(unmappedIdentifiersTag, key);
final List<String> mappedIdentifiers = identifiersFromGlobalIds(mappedIdentifiersTag, key);
final IdentifiersPair identifiersPair = identifiersFromGlobalIds(unmappedIdentifiersTag, mappedIdentifiersTag, key);
Mappings mappings = loadBiMappings(data, key); // Load as bi-mappings to keep the inverse cached
if (mappings == null) {
mappings = new IdentityMappings(unmappedIdentifiers.size(), mappedIdentifiers.size());
mappings = new IdentityMappings(identifiersPair.unmapped().size(), identifiersPair.mapped().size());
}
return new FullMappingsBase(unmappedIdentifiers, mappedIdentifiers, mappings);
return FullMappingsBase.of(identifiersPair, mappings);
}
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
@@ -81,8 +81,9 @@ public class MappingDataLoader {
for (final Map.Entry<String, Tag> entry : globalIdentifiers.entrySet()) {
//noinspection unchecked
final ListTag<StringTag> value = (ListTag<StringTag>) entry.getValue();
final String[] array = new String[value.size()];
for (int i = 0, size = value.size(); i < size; i++) {
final int size = value.size();
final String[] array = new String[size];
for (int i = 0; i < size; i++) {
array[i] = value.get(i).getValue();
}
GLOBAL_IDENTIFIER_INDEXES.put(entry.getKey(), array);
@@ -272,13 +273,60 @@ public class MappingDataLoader {
public @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) {
final Mappings mappings = loadMappings(mappingsTag, key);
if (mappings == null) {
return mappings != null ? identifiers(mappings, key) : null;
}
/**
* Returns a pair of identifier lists, also keeping track of whether the two lists are equal.
*
* @param unmappedTag unmapped mappings tag
* @param mappedTag mapped mappings tag
* @param key mappings key
* @return pair of identifier lists
*/
public @Nullable IdentifiersPair identifiersFromGlobalIds(final CompoundTag unmappedTag, final CompoundTag mappedTag, final String key) {
final Mappings unmapped = loadMappings(unmappedTag, key);
if (unmapped == null) {
return null;
}
final Mappings mapped = loadMappings(mappedTag, key);
if (mapped == null) {
return null;
}
final int size = unmapped.size();
if (size != mapped.size()) {
return new IdentifiersPair(identifiers(unmapped, key), identifiers(mapped, key), false);
}
// Small optimization to only load one array and reduce loading for full mappings
final List<String> unmappedIdentifiers = new ArrayList<>(size);
final List<String> mappedIdentifiers = new ArrayList<>(size);
boolean identity = true;
for (int i = 0; i < size; i++) {
final int unmappedGlobalId = unmapped.getNewId(i);
final int mappedGlobalId = mapped.getNewId(i);
final String unmappedIdentifier = identifierFromGlobalId(key, unmappedGlobalId);
if (unmappedGlobalId == mappedGlobalId) {
unmappedIdentifiers.add(unmappedIdentifier);
mappedIdentifiers.add(unmappedIdentifier);
continue;
}
identity = false;
unmappedIdentifiers.add(unmappedIdentifier);
mappedIdentifiers.add(identifierFromGlobalId(key, mappedGlobalId));
}
return identity ? new IdentifiersPair(unmappedIdentifiers) : new IdentifiersPair(unmappedIdentifiers, mappedIdentifiers);
}
private List<String> identifiers(final Mappings mappings, final String key) {
final List<String> identifiers = new ArrayList<>(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
identifiers.add(identifierFromGlobalId(key, mappings.getNewId(i)));
final int globalId = mappings.getNewId(i);
identifiers.add(identifierFromGlobalId(key, globalId));
}
return identifiers;
}
@@ -342,4 +390,15 @@ public class MappingDataLoader {
T create(V mappings, int mappedSize);
}
public record IdentifiersPair(List<String> unmapped, List<String> mapped, boolean identity) {
public IdentifiersPair(final List<String> unmapped, final List<String> mapped) {
this(unmapped, mapped, false);
}
public IdentifiersPair(final List<String> identifiers) {
this(identifiers, identifiers, true);
}
}
}
@@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.data;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface Mappings {
/**
@@ -84,4 +86,40 @@ public interface Mappings {
* @return mappings with keys and values swapped
*/
Mappings inverse();
/**
* Returns whether the mappings are unchanged identity mappings.
*
* @return whether the mappings are unchanged identity mappings
*/
default boolean isIdentity() {
return false;
}
/**
* Returns whether the mappings null or identity mappings.
*
* @param mappings mappings
* @return whether the mappings are identity mappings
* @see #isFullIdentity(Mappings)
*/
static boolean isIntIdIdentity(@Nullable final Mappings mappings) {
if (mappings == null) {
return true;
}
return mappings instanceof FullMappings fullMappings ? fullMappings.isIntIdIdentity() : mappings.isIdentity();
}
/**
* Returns whether the mappings null or full identity mappings.
* Stronger than {@link #isIntIdIdentity(Mappings)}, but equal to that if not {@link FullMappings}.
*
* @param mappings mappings
* @return whether the mappings are full identity mappings
* @see #isIntIdIdentity(Mappings)
*/
static boolean isFullIdentity(@Nullable final Mappings mappings) {
return mappings == null || mappings.isIdentity();
}
}
@@ -22,16 +22,16 @@
*/
package com.viaversion.viaversion.api.data;
import com.viaversion.viaversion.api.data.MappingDataLoader.IdentifiersPair;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.List;
public class ParticleMappings extends FullMappingsBase {
private final IntList itemParticleIds = new IntArrayList(4);
private final IntList blockParticleIds = new IntArrayList(4);
public ParticleMappings(final List<String> unmappedIdentifiers, final List<String> mappedIdentifiers, final Mappings mappings) {
super(unmappedIdentifiers, mappedIdentifiers, mappings);
public ParticleMappings(final IdentifiersPair identifiersPair, final Mappings mappings) {
super(identifiersPair, mappings);
addBlockParticle("block");
addBlockParticle("falling_dust");
addBlockParticle("block_marker");
@@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.data.entity;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.util.KeyMappings;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -210,4 +211,8 @@ public interface EntityTracker {
@Nullable DimensionData dimensionData(int dimensionId);
void setDimensions(Map<String, DimensionData> dimensions);
@Nullable KeyMappings registryKeys(String registryKey);
void addRegistryKeys(String registryKey, KeyMappings mappings);
}
@@ -31,8 +31,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* Represents an animal variant (e.g. for cows, pigs, chickens).
*
* @param modelType model type id
* @param texture texture path
* @param biomes biomes this variant can spawn in, if limited to specific biomes
* @param texture texture path
* @param biomes biomes this variant can spawn in, if limited to specific biomes
*/
public record AnimalVariant(int modelType, String texture, @Nullable HolderSet biomes) {
@@ -38,7 +38,7 @@ public interface EitherHolder<T> {
/**
* Returns an indirect holder via the resource key.
*
* @param key the resource key
* @param key the resource key
* @param <T> the type of the value
* @return a new holder with the given resource key
*/
@@ -22,11 +22,12 @@
*/
package com.viaversion.viaversion.api.minecraft;
import com.google.common.base.Preconditions;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import java.util.function.Function;
import java.util.function.ToIntFunction;
/**
* Set of ids that either holds a string tag key or an array of ids.
@@ -40,6 +41,7 @@ public interface HolderSet {
* @return a new holder set
*/
static HolderSet of(final String tagKey) {
Preconditions.checkNotNull(tagKey);
return new HolderSetImpl.Tag(tagKey);
}
@@ -50,22 +52,23 @@ public interface HolderSet {
* @return a new holder set
*/
static HolderSet of(final int[] ids) {
Preconditions.checkNotNull(ids);
return new HolderSetImpl.Ids(ids);
}
static HolderSet fromTag(final Tag tag, final Function<String, Integer> mappingFunction) {
static HolderSet fromTag(final Tag tag, final ToIntFunction<String> mappingFunction) {
if (tag instanceof StringTag stringTag) {
if (stringTag.getValue().startsWith("#")) {
return HolderSet.of(stringTag.getValue().substring(1));
}
final int id = mappingFunction.apply(stringTag.getValue());
final int id = mappingFunction.applyAsInt(stringTag.getValue());
return HolderSet.of(new int[]{id});
} else if (tag instanceof ListTag<?> listTag) {
final int[] ids = new int[listTag.size()];
for (int i = 0; i < listTag.size(); i++) {
final String value = ((StringTag) listTag.get(i)).getValue();
ids[i] = mappingFunction.apply(value);
ids[i] = mappingFunction.applyAsInt(value);
}
return HolderSet.of(ids);
}
@@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.minecraft.chunks;
import java.util.function.IntUnaryOperator;
public interface DataPalette {
/**
@@ -108,6 +110,21 @@ public interface DataPalette {
*/
void setPaletteIndexAt(int sectionCoordinate, int index);
/**
* Replaces every id in the palette by applying the given mapper.
*
* @param mapper function from old id to new id
*/
default void replaceIds(IntUnaryOperator mapper) {
for (int i = 0; i < this.size(); i++) {
final int id = this.idByIndex(i);
final int newId = mapper.applyAsInt(id);
if (newId != id) {
this.setIdByIndex(i, newId);
}
}
}
/**
* Adds a new id to the palette.
*
@@ -121,7 +138,13 @@ public interface DataPalette {
* @param oldId old id
* @param newId new id
*/
void replaceId(int oldId, int newId);
default void replaceId(int oldId, int newId) {
for (int i = 0; i < this.size(); i++) {
if (this.idByIndex(i) == oldId) {
this.setIdByIndex(i, newId);
}
}
}
/**
* Returns the size of the palette.
@@ -25,13 +25,13 @@ package com.viaversion.viaversion.api.minecraft.chunks;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.function.IntUnaryOperator;
public final class DataPaletteImpl implements DataPalette {
private static final int DEFAULT_INITIAL_SIZE = 16;
private final IntList palette;
private final IntArrayList palette;
private final Int2IntMap inversePalette;
private final int sizeBits;
private ChunkData values;
@@ -41,7 +41,7 @@ public final class DataPaletteImpl implements DataPalette {
}
public DataPaletteImpl(final int valuesLength, final int initialSize) {
values = new EmptyChunkData(valuesLength);
values = new SingleChunkData(valuesLength);
sizeBits = Integer.numberOfTrailingZeros(valuesLength) / 3;
// Pre-size the palette array/map
palette = new IntArrayList(initialSize);
@@ -123,6 +123,53 @@ public final class DataPaletteImpl implements DataPalette {
}
}
@Override
public void replaceIds(final IntUnaryOperator mapper) {
final int oldSize = palette.size();
if (oldSize == 0) {
return;
}
inversePalette.clear();
int writeIndex = 0;
int[] indexRemap = null;
int firstCollision = 0;
final int[] palette = this.palette.elements();
for (int readIndex = 0; readIndex < oldSize; readIndex++) {
final int mappedId = mapper.applyAsInt(palette[readIndex]);
final int existingIndex = inversePalette.putIfAbsent(mappedId, writeIndex);
if (existingIndex == -1) {
palette[writeIndex] = mappedId;
if (indexRemap != null) {
indexRemap[readIndex - firstCollision] = writeIndex;
}
writeIndex++;
continue;
}
// The mapped value already exists in the palette. The original index will be removed at the end
if (indexRemap == null) {
indexRemap = new int[oldSize - readIndex];
firstCollision = readIndex;
}
indexRemap[readIndex - firstCollision] = existingIndex;
}
// If any mapped ids were already present (writeIndex < oldSize),
// collapse the entries and set values to their shifted palette indexes
if (indexRemap != null) {
this.palette.removeElements(writeIndex, oldSize);
final int len = values.size();
for (int i = 0; i < len; i++) {
final int oldIndex = values.get(i);
if (oldIndex >= firstCollision) {
values.set(i, indexRemap[oldIndex - firstCollision]);
}
}
}
}
@Override
public void addId(final int id) {
inversePalette.put(id, palette.size());
@@ -139,13 +186,15 @@ public final class DataPaletteImpl implements DataPalette {
int get(int idx);
void set(int idx, int val);
int size();
}
private class EmptyChunkData implements ChunkData {
private final class SingleChunkData implements ChunkData {
private final int size;
public EmptyChunkData(int size) {
public SingleChunkData(int size) {
this.size = size;
}
@@ -161,9 +210,14 @@ public final class DataPaletteImpl implements DataPalette {
values.set(idx, val);
}
}
@Override
public int size() {
return size;
}
}
private class ByteChunkData implements ChunkData {
private final class ByteChunkData implements ChunkData {
private final byte[] data;
public ByteChunkData(int size) {
@@ -185,9 +239,14 @@ public final class DataPaletteImpl implements DataPalette {
}
data[idx] = (byte) val;
}
@Override
public int size() {
return data.length;
}
}
private static class ShortChunkData implements ChunkData {
private static final class ShortChunkData implements ChunkData {
private final short[] data;
public ShortChunkData(byte[] data) {
@@ -206,6 +265,11 @@ public final class DataPaletteImpl implements DataPalette {
public void set(int idx, int val) {
data[idx] = (short) val;
}
@Override
public int size() {
return data.length;
}
}
}
@@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.minecraft.codec;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.protocol.Protocol;
@@ -35,8 +36,12 @@ public interface CodecContext {
boolean isSupported(StructuredDataKey<?> key);
UserConnection connection();
interface RegistryAccess {
UserConnection connection();
Key item(int id);
Key attributeModifier(int id);
@@ -53,7 +58,7 @@ public interface CodecContext {
* Returns the key for a stored mapping type and its numeric id.
*
* @param mappingType mapping type
* @param id numeric id
* @param id numeric id
* @return the key
*/
Key key(MappingData.MappingType mappingType, int id);
@@ -62,20 +67,20 @@ public interface CodecContext {
* Returns the numeric id for a stored mapping type and its identifier.
*
* @param mappingType mapping type
* @param identifier identifier
* @param identifier identifier
* @return the numeric id, or -1 if not found
*/
int id(MappingData.MappingType mappingType, String identifier);
static RegistryAccess of(final Protocol<?, ?, ?, ?> protocol) {
return new RegistryAccessImpl(protocol);
static RegistryAccess of(final Protocol<?, ?, ?, ?> protocol, final UserConnection connection) {
return new RegistryAccessImpl(protocol, connection);
}
/**
* Returns the key for a client-synchronized registry element.
*
* @param registry registry key
* @param id numeric id
* @param id numeric id
* @return the key
*/
Key registryKey(String registry, int id);
@@ -81,12 +81,12 @@ public interface Ops {
/**
* Writes the given value or default value if the value is null.
*
* @param key map key
* @param type type of the value
* @param key map key
* @param type type of the value
* @param value the value to write, or null
* @param def default value to write if the value is null
* @param def default value to write if the value is null
* @param <V> value type
* @return self
* @param <V> value type
*/
default <V> MapSerializer write(final String key, final Type<V> type, @Nullable final V value, final V def) {
write(Types.STRING, key, type, value != null ? value : def);
@@ -96,11 +96,11 @@ public interface Ops {
/**
* Writes the given value if it is not null.
*
* @param key map key
* @param type type of the value
* @param key map key
* @param type type of the value
* @param value the value to write, or null
* @param <V> value type
* @return self
* @param <V> value type
*/
default <V> MapSerializer writeOptional(final String key, final Type<V> type, @Nullable final V value) {
if (value != null) {
@@ -112,12 +112,12 @@ public interface Ops {
/**
* Writes the given value if it is not null and not equal to the default value.
*
* @param key map key
* @param type type of the value
* @param key map key
* @param type type of the value
* @param value the value to write, or null
* @param def default value to compare against
* @param def default value to compare against
* @param <V> value type
* @return self
* @param <V> value type
*/
default <V> MapSerializer writeOptional(final String key, final Type<V> type, @Nullable final V value, final V def) {
if (value != null && !Objects.deepEquals(value, def)) {
@@ -23,31 +23,40 @@
package com.viaversion.viaversion.api.minecraft.codec;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.rewriter.RegistryDataRewriter;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.KeyMappings;
import org.checkerframework.checker.nullness.qual.Nullable;
final class RegistryAccessImpl implements CodecContext.RegistryAccess {
private final RegistryDataRewriter registryDataRewriter;
private final EntityTracker entityTracker;
private final MappingData mappingData;
private final UserConnection connection;
private final boolean mapped;
RegistryAccessImpl(final Protocol<?, ?, ?, ?> protocol) {
this.mappingData = protocol.getMappingData();
this.registryDataRewriter = protocol.getRegistryDataRewriter();
RegistryAccessImpl(final Protocol<?, ?, ?, ?> protocol, final UserConnection connection) {
this.mappingData = Preconditions.checkNotNull(protocol.getMappingData());
this.entityTracker = Preconditions.checkNotNull(protocol.getEntityRewriter().tracker(connection));
this.connection = connection;
this.mapped = false;
}
private RegistryAccessImpl(final MappingData mappingData, final RegistryDataRewriter registryDataRewriter, final boolean mapped) {
private RegistryAccessImpl(final MappingData mappingData, final UserConnection connection, final EntityTracker entityTracker, final boolean mapped) {
this.mappingData = mappingData;
this.registryDataRewriter = registryDataRewriter;
this.connection = connection;
this.entityTracker = entityTracker;
this.mapped = mapped;
}
@Override
public UserConnection connection() {
return connection;
}
@Override
public Key item(final int id) {
return key(mappingData.getFullItemMappings(), id);
@@ -91,8 +100,8 @@ final class RegistryAccessImpl implements CodecContext.RegistryAccess {
@Override
public Key registryKey(final String registry, final int id) {
final KeyMappings mappings = registryDataRewriter.getMappings(registry);
Preconditions.checkNotNull(mappings, "No registry mappings for registry: " + registry);
final KeyMappings mappings = entityTracker.registryKeys(registry);
Preconditions.checkNotNull(mappings, "No registry mappings for registry: %s", registry);
final String identifier = id >= 0 && id < mappings.size() ? mappings.idToKey(id) : null;
return key(identifier, id);
}
@@ -108,6 +117,6 @@ final class RegistryAccessImpl implements CodecContext.RegistryAccess {
@Override
public CodecContext.RegistryAccess withMapped(final boolean mapped) {
return this.mapped == mapped ? this : new RegistryAccessImpl(this.mappingData, this.registryDataRewriter, mapped);
return this.mapped == mapped ? this : new RegistryAccessImpl(this.mappingData, this.connection, this.entityTracker, mapped);
}
}
@@ -145,13 +145,13 @@ public enum EntityTypes1_14 implements EntityType {
SHEEP(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -146,13 +146,13 @@ public enum EntityTypes1_15 implements EntityType {
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -148,13 +148,13 @@ public enum EntityTypes1_16 implements EntityType {
FOX(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -148,13 +148,13 @@ public enum EntityTypes1_16_2 implements EntityType {
FOX(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -154,13 +154,13 @@ public enum EntityTypes1_17 implements EntityType {
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -158,13 +158,13 @@ public enum EntityTypes1_19 implements EntityType {
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -158,13 +158,13 @@ public enum EntityTypes1_19_3 implements EntityType {
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -165,13 +165,13 @@ public enum EntityTypes1_19_4 implements EntityType {
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -166,13 +166,13 @@ public enum EntityTypes1_20_3 implements EntityType {
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -171,13 +171,13 @@ public enum EntityTypes1_20_5 implements EntityType {
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -185,6 +185,7 @@ public enum EntityTypes1_21_11 implements EntityType {
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
HAPPY_GHAST(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
ABSTRACT_COW(ABSTRACT_ANIMAL, null),
COW(ABSTRACT_COW),
@@ -192,7 +193,6 @@ public enum EntityTypes1_21_11 implements EntityType {
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -176,13 +176,13 @@ public enum EntityTypes1_21_2 implements EntityType {
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -176,13 +176,13 @@ public enum EntityTypes1_21_4 implements EntityType {
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -179,6 +179,7 @@ public enum EntityTypes1_21_5 implements EntityType {
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
ABSTRACT_COW(ABSTRACT_ANIMAL, null),
COW(ABSTRACT_COW),
@@ -186,7 +187,6 @@ public enum EntityTypes1_21_5 implements EntityType {
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -180,6 +180,7 @@ public enum EntityTypes1_21_6 implements EntityType {
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
HAPPY_GHAST(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
ABSTRACT_COW(ABSTRACT_ANIMAL, null),
COW(ABSTRACT_COW),
@@ -187,7 +188,6 @@ public enum EntityTypes1_21_6 implements EntityType {
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -185,6 +185,7 @@ public enum EntityTypes1_21_9 implements EntityType {
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
HAPPY_GHAST(ABSTRACT_ANIMAL),
OCELOT(ABSTRACT_ANIMAL),
ABSTRACT_COW(ABSTRACT_ANIMAL, null),
COW(ABSTRACT_COW),
@@ -192,7 +193,6 @@ public enum EntityTypes1_21_9 implements EntityType {
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),
@@ -43,6 +43,10 @@ public abstract class AbstractEntityDataTypes implements EntityDataTypes {
return values;
}
public Class<? extends EntityDataType> getDataTypeClass() {
return byId(0).getClass();
}
protected EntityDataType add(final int typeId, final Type<?> type) {
if (values[typeId] != null) {
throw new IllegalArgumentException("Entity data type ID " + typeId + " is already registered as " + values[typeId]);
@@ -56,8 +56,8 @@ public record AttackRange(float minRange, float maxRange,
@Override
public void write(final Ops ops, final AttackRange AttackRange) {
ops.writeMap(map -> map
.writeOptional("min_range", Types.FLOAT, AttackRange.minRange, 0F)
.writeOptional("max_range", Types.FLOAT, AttackRange.maxRange, 3F)
.writeOptional("min_reach", Types.FLOAT, AttackRange.minRange, 0F)
.writeOptional("max_reach", Types.FLOAT, AttackRange.maxRange, 3F)
.writeOptional("min_creative_reach", Types.FLOAT, AttackRange.minCreativeRange, 0F)
.writeOptional("max_creative_reach", Types.FLOAT, AttackRange.maxCreativeRange, 5F)
.writeOptional("hitbox_margin", Types.FLOAT, AttackRange.hitboxMargin, 0.3F)
@@ -37,6 +37,7 @@ import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public record AttributeModifiers1_21(AttributeModifier[] modifiers, boolean showInTooltip) implements Copyable, Rewritable {
@@ -226,7 +227,7 @@ public record AttributeModifiers1_21(AttributeModifier[] modifiers, boolean show
}
public static class Display implements Copyable {
public static final String[] DISPLAY_TYPES = {"default", "hidden", "override_text"};
public static final String[] DISPLAY_TYPES = {"default", "hidden", "override"};
public static final Display DEFAULT = new Display(0);
private final int id;
@@ -246,6 +247,17 @@ public record AttributeModifiers1_21(AttributeModifier[] modifiers, boolean show
public Display copy() {
return this;
}
@Override
public boolean equals(final Object o) {
if (!(o instanceof final Display display)) return false;
return id == display.id;
}
@Override
public int hashCode() {
return id;
}
}
public static final class OverrideText extends Display {
@@ -271,5 +283,19 @@ public record AttributeModifiers1_21(AttributeModifier[] modifiers, boolean show
public OverrideText copy() {
return new OverrideText(this.component.copy());
}
@Override
public boolean equals(final Object o) {
if (!(o instanceof final OverrideText that)) return false;
if (!super.equals(o)) return false;
return Objects.equals(component, that.component);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Objects.hashCode(component);
return result;
}
}
}
@@ -122,7 +122,7 @@ public record BlocksAttacks(
.writeOptional("disable_cooldown_scale", Types.FLOAT, value.disableCooldownScale(), 1F)
.writeOptional("damage_reductions", DamageReduction.ARRAY_TYPE, value.damageReductions(), defaultDamageReductions)
.writeOptional("item_damage", ItemDamageFunction.TYPE, value.itemDamage(), defaultItemDamage)
.writeOptional("bypassed_by", Types.HOLDER_SET, value.bypassedBy())
.writeOptional("bypassed_by", new HolderSetType(RegistryKey.of("damage_type")), value.bypassedBy())
.writeOptional("block_sound", Types.SOUND_EVENT, value.blockSound())
.writeOptional("disabled_sound", Types.SOUND_EVENT, value.disableSound()));
}
@@ -24,18 +24,11 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.minecraft.RegistryKey;
import com.viaversion.viaversion.api.minecraft.codec.Ops;
import com.viaversion.viaversion.api.type.TransformingType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
public record ProvidesBannerPatterns(HolderSet patterns) {
public static final Type<ProvidesBannerPatterns> TYPE = new TransformingType<>(Types.HOLDER_SET, ProvidesBannerPatterns.class, ProvidesBannerPatterns::new, ProvidesBannerPatterns::patterns) {
@Override
public void write(final Ops ops, final ProvidesBannerPatterns value) {
ops.writeMap(map -> map.write("items", new HolderSetType(RegistryKey.of("banner_pattern")), value.patterns));
}
};
public static final Type<ProvidesBannerPatterns> TYPE = TransformingType.of(new HolderSetType(RegistryKey.of("banner_pattern")), ProvidesBannerPatterns.class, ProvidesBannerPatterns::new, ProvidesBannerPatterns::patterns);
}
@@ -180,7 +180,7 @@ public interface ViaPlatform<T> {
/**
* Modify the server details payload before it is sent.
* This method allows adding, changing, or removing fields from the payload.
* It is only called if {@link ViaVersionConfig#sendPlayerDetails()} is true.
* It is only called if {@link ViaVersionConfig#sendServerDetails()} is true.
*
* @param connection The UserConnection
* @param payload The constructed payload to modify
@@ -68,10 +68,6 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
}
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
/**
* Registers a serverbound packet, with id transformation and remapper.
*
@@ -79,19 +75,17 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param unmappedPacketId unmapped packet id
* @param mappedPacketId mapped packet id
* @param handler packet handler
* @param override whether an existing mapper should be overridden
* @see #registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketHandler, boolean)
*/
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
@Deprecated(forRemoval = true)
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
void cancelServerbound(State state, int mappedPacketId);
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
void cancelClientbound(State state, int unmappedPacketId);
/**
* Registers a clientbound packet, with id transformation and remapper.
*
@@ -99,9 +93,15 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param unmappedPacketId unmapped packet id
* @param mappedPacketId mapped packet id
* @param handler packet handler
* @param override whether an existing mapper should be overridden
* @see #registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketHandler, boolean)
*/
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
void cancelClientbound(State state, int unmappedPacketId);
@Deprecated(forRemoval = true)
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
// ---------------------------------------------------------------------------------------
@@ -144,6 +144,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param handler packet handler
* @param override whether an existing mapping should be overridden if present
*/
@Deprecated(forRemoval = true)
void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler, boolean override);
/**
@@ -191,6 +192,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param handler packet handler
* @param override whether an existing mapping should be overridden if present
*/
@Deprecated(forRemoval = true)
void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override);
/**
@@ -260,6 +262,22 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
*/
void appendServerbound(SU type, PacketHandler handler);
/**
* Replaces a clientbound packet type handler with another.
*
* @param type clientbound packet type
* @param handler packet handler
*/
void replaceClientbound(CU type, @Nullable PacketHandler handler);
/**
* Replaces a serverbound packet type handler with another.
*
* @param type serverbound packet type
* @param handler packet handler
*/
void replaceServerbound(SU type, @Nullable PacketHandler handler);
/**
* Transform a packet using this protocol
*
@@ -441,4 +459,13 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
default boolean isBaseProtocol() {
return false;
}
/**
* Marks this protocol as dependent on another. Before being initialized, it will wait for the dependency's completion.
*
* @return protocol class to depend on
*/
default @Nullable Class<? extends Protocol<?, ?, ?, ?>> dependsOn() {
return null;
}
}
@@ -249,7 +249,17 @@ public interface ProtocolManager {
*
* @return true if the executor has now been shut down
*/
boolean checkForMappingCompletion();
default boolean checkForMappingCompletion() {
return checkForMappingCompletion(false);
}
/**
* Shuts down the executor and uncaches mappings if all futures have been completed.
*
* @param propagateErrors whether to propagate errors from the futures to the caller
* @return true if the executor has now been shut down
*/
boolean checkForMappingCompletion(boolean propagateErrors);
/**
* Executes the given runnable asynchronously, adding a {@link CompletableFuture}
@@ -50,6 +50,11 @@ final class PacketIdMapping implements PacketMapping {
}
}
@Override
public void setHandler(@Nullable final PacketHandler handler) {
this.handler = handler;
}
@Override
public @Nullable PacketHandler handler() {
return handler;
@@ -39,6 +39,13 @@ public interface PacketMapping {
*/
void applyType(PacketWrapper wrapper);
/**
* Replaces the current packet handler.
*
* @param handler packet transformer
*/
void setHandler(@Nullable PacketHandler handler);
/**
* Returns a packet transformer to transform a packet from one protocol version to another.
*
@@ -52,6 +52,11 @@ final class PacketTypeMapping implements PacketMapping {
}
}
@Override
public void setHandler(@Nullable final PacketHandler handler) {
this.handler = handler;
}
@Override
public @Nullable PacketHandler handler() {
return handler;
@@ -74,6 +74,11 @@ public interface PacketTypesProvider<CU extends ClientboundPacketType, CM extend
return map != null ? map.typeByName(typeName) : null;
}
default @Nullable CM mappedClientboundType(final State state, final String typeName) {
PacketTypeMap<CM> map = mappedClientboundPacketTypes().get(state);
return map != null ? map.typeByName(typeName) : null;
}
default @Nullable SU unmappedServerboundType(final State state, final String typeName) {
PacketTypeMap<SU> map = unmappedServerboundPacketTypes().get(state);
return map != null ? map.typeByName(typeName) : null;
@@ -93,7 +93,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
public static final ProtocolVersion v1_21_7 = register(772, "1.21.7-1.21.8", new SubVersionRange("1.21", 7, 8));
public static final ProtocolVersion v1_21_9 = register(773, "1.21.9-1.21.10", new SubVersionRange("1.21", 9, 10));
public static final ProtocolVersion v1_21_11 = register(774, "1.21.11");
public static final ProtocolVersion v26_1 = register(775, "26.1");
public static final ProtocolVersion v26_1 = register(775, "26.1-26.1.2", new SubVersionRange("26.1", 0, 2));
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
static {
@@ -26,6 +26,7 @@ import com.google.gson.JsonElement;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface ComponentRewriter {
@@ -37,4 +38,6 @@ public interface ComponentRewriter {
JsonElement processText(UserConnection connection, @Nullable String json);
void handleShowItem(UserConnection connection, CompoundTag itemTag);
void passthroughAndProcess(PacketWrapper wrapper);
}
@@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.protocol.Protocol;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface EntityRewriter<T extends Protocol<?, ?, ?, ?>> extends Rewriter<T> {
@@ -39,6 +40,8 @@ public interface EntityRewriter<T extends Protocol<?, ?, ?, ?>> extends Rewriter
*/
EntityType typeFromId(int type);
@Nullable EntityType typeFromId(String type);
/**
* Returns the entity type from the given id.
* From 1.14 and onwards, this is the same exact value as {@link #typeFromId(int)}.
@@ -70,9 +73,9 @@ public interface EntityRewriter<T extends Protocol<?, ?, ?, ?>> extends Rewriter
/**
* Handles and transforms entity data of an entity.
*
* @param entityId entity id
* @param dataList full, mutable list of entity data
* @param connection user connection
* @param entityId entity id
* @param dataList full, mutable list of entity data
* @param connection user connection
*/
void handleEntityData(int entityId, List<EntityData> dataList, UserConnection connection);
@@ -22,13 +22,25 @@
*/
package com.viaversion.viaversion.api.rewriter;
import com.viaversion.viaversion.util.KeyMappings;
import org.checkerframework.checker.nullness.qual.Nullable;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
public interface RegistryDataRewriter {
@Nullable
KeyMappings getMappings(String registryKey);
void handle(PacketWrapper wrapper);
boolean shouldRemoveRegistry(String registryKey);
boolean hasRegistriesToRemove();
void updateDialog(UserConnection connection, CompoundTag tag);
/**
* Sends registries that had additional entries configured, but weren't sent by the server at all
* by the time finish_configuration was sent to the client.
*
* @param connection the user connection
*/
void sendMissingRegistries(final UserConnection connection);
}
@@ -26,10 +26,10 @@ import com.viaversion.viaversion.api.minecraft.codec.Ops;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class OptionalType<T> extends Type<T> {
public class OptionalType<T> extends Type<T> {
private final Type<T> type;
protected OptionalType(final Type<T> type) {
public OptionalType(final Type<T> type) {
super(type.getOutputClass());
this.type = type;
}
@@ -107,6 +107,7 @@ import com.viaversion.viaversion.api.type.types.math.LowPrecisionVectorType;
import com.viaversion.viaversion.api.type.types.math.QuaternionType;
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
import com.viaversion.viaversion.api.type.types.math.VectorType;
import com.viaversion.viaversion.api.type.types.misc.CompoundTagHolderType;
import com.viaversion.viaversion.api.type.types.misc.CompoundTagType;
import com.viaversion.viaversion.api.type.types.misc.GameProfileType;
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
@@ -207,6 +208,7 @@ public final class Types {
public static final Type<CompoundTag[]> NAMED_COMPOUND_TAG_ARRAY = new ArrayType<>(Types.NAMED_COMPOUND_TAG);
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = CompoundTagType.OptionalCompoundTagType.type();
public static final HolderType<CompoundTag> TRUSTED_COMPOUND_TAG_HOLDER = new CompoundTagHolderType();
public static final Type<Tag> TAG = new TagType();
public static final Type<Tag[]> TAG_ARRAY = new ArrayType<>(TAG);
@@ -40,7 +40,7 @@ public class BlockEntityType1_20_2 extends Type<BlockEntity> {
final byte xz = buffer.readByte();
final short y = buffer.readShort();
final int typeId = Types.VAR_INT.readPrimitive(buffer);
final CompoundTag tag = Types.COMPOUND_TAG.read(buffer);
final CompoundTag tag = Types.TRUSTED_COMPOUND_TAG.read(buffer);
return new BlockEntityImpl(xz, y, typeId, tag);
}
@@ -49,6 +49,6 @@ public class BlockEntityType1_20_2 extends Type<BlockEntity> {
buffer.writeByte(entity.packedXZ());
buffer.writeShort(entity.y());
Types.VAR_INT.writePrimitive(buffer, entity.typeId());
Types.COMPOUND_TAG.write(buffer, entity.tag());
Types.TRUSTED_COMPOUND_TAG.write(buffer, entity.tag());
}
}
@@ -20,17 +20,21 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.protocol;
package com.viaversion.viaversion.api.type.types.misc;
/**
* A simple protocol which does not have any packet types.
* <p>
* {@link AbstractProtocol} should be preferred over this class in most cases.
*/
public abstract class AbstractSimpleProtocol extends AbstractProtocol<SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes,
SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes> implements SimpleProtocol {
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
protected AbstractSimpleProtocol() {
super(null, null, null, null);
public final class CompoundTagHolderType extends HolderType<CompoundTag> {
@Override
public CompoundTag readDirect(final ByteBuf buffer) {
return Types.TRUSTED_COMPOUND_TAG.read(buffer);
}
@Override
public void writeDirect(final ByteBuf buffer, final CompoundTag value) {
Types.TRUSTED_COMPOUND_TAG.write(buffer, value);
}
}
@@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.nbt.limiter.TagLimiter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.minecraft.codec.Ops;
@@ -49,7 +50,7 @@ public class CompoundTagType extends Type<CompoundTag> {
public CompoundTagType(final boolean limitMaxBytes) {
super(CompoundTag.class);
this.maxBytes = limitMaxBytes ? NamedCompoundTagType.MAX_NBT_BYTES : Integer.MAX_VALUE;
this.maxBytes = limitMaxBytes ? TagLimiter.DEFAULT_MAX_BYTES : Integer.MAX_VALUE;
}
@Override
@@ -28,17 +28,14 @@ import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.io.FastByteBufInputStream;
import com.viaversion.viaversion.io.FastByteBufOutputStream;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.Nullable;
public class NamedCompoundTagType extends Type<CompoundTag> {
public static final int MAX_NBT_BYTES = 2097152; // 2mb
public static final int MAX_NESTING_LEVEL = 512;
public NamedCompoundTagType() {
super(CompoundTag.class);
}
@@ -46,7 +43,7 @@ public class NamedCompoundTagType extends Type<CompoundTag> {
@Override
public CompoundTag read(final ByteBuf buffer) {
try {
return read(buffer, MAX_NBT_BYTES, true);
return read(buffer, TagLimiter.DEFAULT_MAX_BYTES, true);
} catch (final IOException e) {
throw new RuntimeException(e);
}
@@ -74,8 +71,8 @@ public class NamedCompoundTagType extends Type<CompoundTag> {
buffer.skipBytes(buffer.readUnsignedShort());
}
final TagLimiter tagLimiter = TagLimiter.create(maxBytes, MAX_NESTING_LEVEL);
return CompoundTag.read(new ByteBufInputStream(buffer), tagLimiter, 0);
final TagLimiter tagLimiter = TagLimiter.create(maxBytes, TagLimiter.DEFAULT_MAX_NESTING_LEVEL);
return CompoundTag.read(new FastByteBufInputStream(buffer), tagLimiter, 0);
}
public static void write(final ByteBuf buffer, final Tag tag, final @Nullable String name) throws IOException {
@@ -84,7 +81,7 @@ public class NamedCompoundTagType extends Type<CompoundTag> {
return;
}
final ByteBufOutputStream out = new ByteBufOutputStream(buffer);
final FastByteBufOutputStream out = new FastByteBufOutputStream(buffer);
out.writeByte(tag.getTagId());
if (name != null) {
out.writeUTF(name);
@@ -59,17 +59,13 @@ public class ParticleType extends DynamicType<Particle> {
return protocol.getMappingData().getParticleMappings();
}
public static DataReader<Particle> itemHandler(final Type<Item> itemType) {
return (buf, particle) -> particle.add(itemType, itemType.read(buf));
}
public static final class Readers {
public static final DataReader<Particle> BLOCK = (buf, particle) -> {
particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Flat Block
};
public static final DataReader<Particle> ITEM1_13 = itemHandler(Types.ITEM1_13);
public static final DataReader<Particle> ITEM1_13_2 = itemHandler(Types.ITEM1_13_2);
public static final DataReader<Particle> ITEM1_13 = item(Types.ITEM1_13);
public static final DataReader<Particle> ITEM1_13_2 = item(Types.ITEM1_13_2);
public static final DataReader<Particle> DUST = (buf, particle) -> {
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Red 0-1
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Green 0-1
@@ -172,4 +168,103 @@ public class ParticleType extends DynamicType<Particle> {
return (buf, particle) -> particle.add(item, item.read(buf));
}
}
public static final class Fillers {
public static DynamicType<Particle>.DataFiller fill1_13_2(final Protocol<?, ?, ?, ?> protocol, final ParticleType type, final boolean useMappedNames) {
return type.filler(protocol, useMappedNames)
.reader("item", Readers.item(protocol.getItemRewriter().mappedItemType()))
.reader("block", Readers.BLOCK)
.reader("dust", Readers.DUST)
.reader("falling_dust", Readers.BLOCK);
}
public static DataFiller fill1_17(final Protocol<?, ?, ?, ?> protocol, final ParticleType type) {
return fill1_13_2(protocol, type, true)
.reader("dust_color_transition", Readers.DUST_TRANSITION)
.reader("vibration", Readers.VIBRATION);
}
public static void fill1_18(final Protocol<?, ?, ?, ?> protocol, final ParticleType type) {
fill1_17(protocol, type).reader("block_marker", Readers.BLOCK);
}
public static void fill1_19(final Protocol<?, ?, ?, ?> protocol, final ParticleType type) {
type.filler(protocol)
.reader("item", Readers.item(protocol.getItemRewriter().mappedItemType()))
.reader("block", Readers.BLOCK)
.reader("block_marker", Readers.BLOCK)
.reader("dust", Readers.DUST)
.reader("falling_dust", Readers.BLOCK)
.reader("dust_color_transition", Readers.DUST_TRANSITION)
.reader("vibration", Readers.VIBRATION1_19)
.reader("sculk_charge", Readers.SCULK_CHARGE)
.reader("shriek", Readers.SHRIEK);
}
public static DataFiller fill1_20_3(final Protocol<?, ?, ?, ?> protocol, final ParticleType type) {
return type.filler(protocol)
.reader("item", Readers.item(protocol.getItemRewriter().mappedItemType()))
.reader("block", Readers.BLOCK)
.reader("block_marker", Readers.BLOCK)
.reader("dust", Readers.DUST)
.reader("falling_dust", Readers.BLOCK)
.reader("dust_color_transition", Readers.DUST_TRANSITION)
.reader("vibration", Readers.VIBRATION1_20_3)
.reader("sculk_charge", Readers.SCULK_CHARGE)
.reader("shriek", Readers.SHRIEK);
}
public static void fill1_20_5(final Protocol<?, ?, ?, ?> protocol, final ParticleType type) {
fill1_20_3(protocol, type)
.reader("dust_pillar", Readers.BLOCK)
.reader("entity_effect", Readers.COLOR);
}
public static void fill1_21_2(final Protocol<?, ?, ?, ?> protocol) {
protocol.mappedTypes().particle().filler(protocol)
.reader("item", Readers.item(protocol.getItemRewriter().mappedItemType()))
.reader("block", Readers.BLOCK)
.reader("block_marker", Readers.BLOCK)
.reader("dust_pillar", Readers.BLOCK)
.reader("falling_dust", Readers.BLOCK)
.reader("block_crumble", Readers.BLOCK)
.reader("dust", Readers.DUST1_21_2)
.reader("dust_color_transition", Readers.DUST_TRANSITION1_21_2)
.reader("vibration", Readers.VIBRATION1_20_3)
.reader("sculk_charge", Readers.SCULK_CHARGE)
.reader("shriek", Readers.SHRIEK)
.reader("entity_effect", Readers.COLOR)
.reader("trail", Readers.TRAIL1_21_2);
}
public static DataFiller fill1_21_4(final Protocol<?, ?, ?, ?> protocol) {
return protocol.mappedTypes().particle().filler(protocol)
.reader("item", Readers.item(protocol.getItemRewriter().mappedItemTemplateType()))
.reader("block", Readers.BLOCK)
.reader("block_marker", Readers.BLOCK)
.reader("dust_pillar", Readers.BLOCK)
.reader("falling_dust", Readers.BLOCK)
.reader("block_crumble", Readers.BLOCK)
.reader("dust", Readers.DUST1_21_2)
.reader("dust_color_transition", Readers.DUST_TRANSITION1_21_2)
.reader("vibration", Readers.VIBRATION1_20_3)
.reader("sculk_charge", Readers.SCULK_CHARGE)
.reader("shriek", Readers.SHRIEK)
.reader("entity_effect", Readers.COLOR)
.reader("trail", Readers.TRAIL1_21_4);
}
public static DataFiller fill1_21_5(final Protocol<?, ?, ?, ?> protocol) {
return fill1_21_4(protocol).reader("tinted_leaves", Readers.COLOR);
}
public static void fill1_21_9(final Protocol<?, ?, ?, ?> protocol) {
fill1_21_5(protocol)
.reader("dragon_breath", Readers.POWER)
.reader("effect", Readers.SPELL)
.reader("instant_effect", Readers.SPELL)
.reader("flash", Readers.COLOR);
}
}
}
@@ -43,8 +43,8 @@ import com.viaversion.viaversion.api.minecraft.codec.Ops;
import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.io.FastByteBufInputStream;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import java.io.IOException;
import java.util.Map;
@@ -58,7 +58,7 @@ public class TagType extends Type<Tag> {
public TagType(final boolean limitBytes) {
super(Tag.class);
this.maxBytes = limitBytes ? NamedCompoundTagType.MAX_NBT_BYTES : Integer.MAX_VALUE;
this.maxBytes = limitBytes ? TagLimiter.DEFAULT_MAX_BYTES : Integer.MAX_VALUE;
}
@Override
@@ -68,9 +68,9 @@ public class TagType extends Type<Tag> {
return null;
}
final TagLimiter tagLimiter = TagLimiter.create(this.maxBytes, NamedCompoundTagType.MAX_NESTING_LEVEL);
final TagLimiter tagLimiter = TagLimiter.create(this.maxBytes, TagLimiter.DEFAULT_MAX_NESTING_LEVEL);
try {
return TagRegistry.read(id, new ByteBufInputStream(buffer), tagLimiter, 0);
return TagRegistry.read(id, new FastByteBufInputStream(buffer), tagLimiter, 0);
} catch (final IOException e) {
if (Via.getManager().isDebug()) {
throw new RuntimeException(e);
@@ -60,7 +60,7 @@ public class InformativeException extends RuntimeException {
@Override
public String getMessage() {
final StringBuilder builder = new StringBuilder("Please report this on the Via support Discord or open an issue on the relevant GitHub repository\n");
final StringBuilder builder = new StringBuilder("Please report the full error (!) from the console on the Via support Discord or open an issue on the relevant GitHub repository.\n");
boolean first = true;
for (final DataEntry entry : dataEntries) {
if (!first) {
@@ -0,0 +1,312 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.io;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import java.io.DataInput;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UTFDataFormatException;
import java.nio.charset.StandardCharsets;
/**
* {@link ByteBufInputStream} alternative with a more fine-tuned {@link #readUTF()} implementation
* for fast reading of NBT strings.
*/
public final class FastByteBufInputStream extends InputStream implements DataInput {
private static final byte[] EMPTY_BYTES = new byte[0];
private static final char[] EMPTY_CHARS = new char[0];
private byte[] bytearr = EMPTY_BYTES;
private char[] chararr = EMPTY_CHARS;
private final ByteBuf buf;
public FastByteBufInputStream(final ByteBuf buffer) {
Preconditions.checkNotNull(buffer);
this.buf = buffer;
buffer.markReaderIndex();
}
@Override
public String readUTF() throws IOException {
// Note that this is a modified UTF-8 format, so we can't use netty's string reading
final int utflen = readUnsignedShort();
if (utflen == 0) {
return "";
}
final ByteBuf buf = this.buf;
final int readerIdx = buf.readerIndex();
if (buf.readableBytes() < utflen) {
throw new EOFException();
}
final String result;
if (buf.hasArray()) {
// Directly pass in the backing array
result = decodeFromArray(buf.array(), buf.arrayOffset() + readerIdx, utflen);
buf.readerIndex(readerIdx + utflen);
} else {
// We need to construct some array for the String anyway, so reading it into an array is fine;
// share the byte array.
final byte[] data = ensureBytes(utflen);
buf.readBytes(data, 0, utflen);
result = decodeFromArray(data, 0, utflen);
}
return result;
}
private String decodeFromArray(final byte[] data, final int offset, final int utflen) throws UTFDataFormatException {
// Go through ASCII symbols and directly pass through as a latin-1 string if possible
int i = 0;
while (i < utflen && data[offset + i] >= 0) {
i++;
}
if (i == utflen) {
return new String(data, offset, utflen, StandardCharsets.ISO_8859_1);
}
// Continue with a regular UTF-8 char decode
final char[] chars = ensureChars(utflen);
for (int j = 0; j < i; j++) {
chars[j] = (char) data[offset + j];
}
final int charCount = decode(data, offset + i, offset + utflen, chars, i);
return new String(chars, 0, charCount);
}
private static int decode(final byte[] data, int pos, final int end, final char[] chars, int charCount) throws UTFDataFormatException {
// From DataInputStream
while (pos < end) {
final int c = data[pos] & 0xff;
switch (c >> 4) {
case 0, 1, 2, 3, 4, 5, 6, 7 -> {
pos++;
chars[charCount++] = (char) c;
}
case 12, 13 -> {
if (pos + 2 > end) {
throw new UTFDataFormatException("malformed input: partial character at end");
}
final int char2 = data[pos + 1];
if ((char2 & 0xC0) != 0x80) {
throw new UTFDataFormatException("malformed input around byte " + (pos + 2));
}
chars[charCount++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
pos += 2;
}
case 14 -> {
if (pos + 3 > end) {
throw new UTFDataFormatException("malformed input: partial character at end");
}
final int char2 = data[pos + 1];
final int char3 = data[pos + 2];
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
throw new UTFDataFormatException("malformed input around byte " + (pos + 2));
}
chars[charCount++] = (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | (char3 & 0x3F));
pos += 3;
}
default -> throw new UTFDataFormatException("malformed input around byte " + pos);
}
}
return charCount;
}
private byte[] ensureBytes(final int len) {
if (bytearr.length < len) {
bytearr = new byte[Math.max(len, 64)];
}
return bytearr;
}
private char[] ensureChars(final int len) {
if (chararr.length < len) {
chararr = new char[Math.max(len, 64)];
}
return chararr;
}
@Override
public int available() {
return buf.readableBytes();
}
@Override
public void mark(final int readlimit) {
buf.markReaderIndex();
}
@Override
public boolean markSupported() {
return true;
}
@Override
public int read() throws IOException {
if (!buf.isReadable()) {
return -1;
}
return buf.readByte() & 0xff;
}
@Override
public int read(final byte[] b, final int off, int len) throws IOException {
final int available = buf.readableBytes();
if (available == 0) {
return -1;
}
len = Math.min(available, len);
buf.readBytes(b, off, len);
return len;
}
@Override
public void reset() throws IOException {
buf.resetReaderIndex();
}
@Override
public long skip(final long n) throws IOException {
if (n > Integer.MAX_VALUE) {
return skipBytes(Integer.MAX_VALUE);
} else {
return skipBytes((int) n);
}
}
@Override
public boolean readBoolean() throws IOException {
checkAvailable(1);
return buf.readBoolean();
}
@Override
public byte readByte() throws IOException {
checkAvailable(1);
return buf.readByte();
}
@Override
public char readChar() {
return (char) buf.readShort();
}
@Override
public double readDouble() {
return Double.longBitsToDouble(buf.readLong());
}
@Override
public float readFloat() throws IOException {
return Float.intBitsToFloat(buf.readInt());
}
@Override
public void readFully(final byte[] b) throws IOException {
readFully(b, 0, b.length);
}
@Override
public void readFully(final byte[] b, final int off, final int len) throws IOException {
if (len < 0) {
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
}
checkAvailable(len);
buf.readBytes(b, off, len);
}
@Override
public int readInt() throws IOException {
checkAvailable(4);
return buf.readInt();
}
@Override
public String readLine() {
// Don't reuse the StringBuilder here, this is not relevant for packet reading
final StringBuilder lineBuf = new StringBuilder();
int available = available();
if (available == 0) {
return null;
}
loop:
do {
int c = buf.readUnsignedByte();
--available;
switch (c) {
case '\n':
break loop;
case '\r':
if (available > 0 && (char) buf.getUnsignedByte(buf.readerIndex()) == '\n') {
buf.skipBytes(1);
--available;
}
break loop;
default:
lineBuf.append((char) c);
}
} while (available > 0);
return !lineBuf.isEmpty() ? lineBuf.toString() : "";
}
@Override
public long readLong() throws IOException {
checkAvailable(8);
return buf.readLong();
}
@Override
public short readShort() throws IOException {
checkAvailable(2);
return buf.readShort();
}
@Override
public int readUnsignedByte() {
return buf.readByte() & 0xff;
}
@Override
public int readUnsignedShort() {
return buf.readShort() & 0xffff;
}
@Override
public int skipBytes(final int n) {
final int nBytes = Math.min(available(), n);
buf.skipBytes(nBytes);
return nBytes;
}
private void checkAvailable(final int fieldSize) throws IOException {
if (fieldSize > buf.readableBytes()) {
throw new EOFException("fieldSize is too long! Length is " + fieldSize + ", but maximum is " + available());
}
}
}
@@ -0,0 +1,178 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.io;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import java.io.DataOutput;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UTFDataFormatException;
/**
* {@link ByteBufOutputStream} alternative with a more fine-tuned {@link #writeUTF(String)} implementation
* for fast writing of NBT strings.
*/
public final class FastByteBufOutputStream extends OutputStream implements DataOutput {
private final ByteBuf buf;
public FastByteBufOutputStream(final ByteBuf buffer) {
Preconditions.checkNotNull(buffer);
this.buf = buffer;
}
@Override
public void writeUTF(final String s) throws IOException {
// This writes the individual characters to the buffer without an intermediary array.
// What's lost from no longer bulk writing is gained from avoiding allocation and multiple
// extra iterations of the full string.
final int len = s.length();
if (len == 0) {
buf.writeShort(0);
return;
}
if (len > 65535) {
throw new UTFDataFormatException("encoded string too long: " + len + " characters");
}
// Reserve space for the length prefix
final int lenIndex = buf.writerIndex();
final int startIndex = lenIndex + Short.BYTES;
buf.ensureWritable(Short.BYTES + len); // even if it ends up being larger, netty does a good job at avoiding constant resizing
buf.writeShort(len);
// Start writing single ASCII bytes
int i = 0;
for (; i < len; i++) {
final char c = s.charAt(i);
if (c >= 0x80 || c == 0) break;
buf.writeByte(c);
}
if (i == len) {
return; // done
}
// Write the rest
for (; i < len; i++) {
final char c = s.charAt(i);
if (c < 0x80 && c != 0) {
buf.writeByte(c);
} else if (c >= 0x800) {
buf.writeByte(0xE0 | ((c >> 12) & 0x0F));
buf.writeByte(0x80 | ((c >> 6) & 0x3F));
buf.writeByte(0x80 | (c & 0x3F));
} else {
buf.writeByte(0xC0 | ((c >> 6) & 0x1F));
buf.writeByte(0x80 | (c & 0x3F));
}
}
// Don't do another round of counting just for the bounds check; check at the end,
// even if that means that in the worst case this might have already written a good bit over the threshold.
final int utflen = buf.writerIndex() - startIndex;
if (utflen > 65535) {
buf.writerIndex(lenIndex);
throw new UTFDataFormatException("encoded string too long: " + utflen + " bytes");
}
// Set the actual length
buf.setShort(lenIndex, utflen);
}
@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
buf.writeBytes(b, off, len);
}
@Override
public void write(final byte[] b) throws IOException {
buf.writeBytes(b);
}
@Override
public void write(final int b) throws IOException {
buf.writeByte(b);
}
@Override
public void writeBoolean(final boolean v) throws IOException {
buf.writeBoolean(v);
}
@Override
public void writeByte(final int v) throws IOException {
buf.writeByte(v);
}
@Override
public void writeBytes(final String s) throws IOException {
final int length = s.length();
buf.ensureWritable(length);
final int offset = buf.writerIndex();
for (int i = 0; i < length; i++) {
buf.setByte(offset + i, (byte) s.charAt(i));
}
buf.writerIndex(offset + length);
}
@Override
public void writeChar(final int v) {
buf.writeChar(v);
}
@Override
public void writeChars(final String s) {
final int len = s.length();
for (int i = 0; i < len; i++) {
buf.writeChar(s.charAt(i));
}
}
@Override
public void writeDouble(final double v) throws IOException {
buf.writeDouble(v);
}
@Override
public void writeFloat(final float v) throws IOException {
buf.writeFloat(v);
}
@Override
public void writeInt(final int v) throws IOException {
buf.writeInt(v);
}
@Override
public void writeLong(final long v) throws IOException {
buf.writeLong(v);
}
@Override
public void writeShort(final int v) throws IOException {
buf.writeShort((short) v);
}
}
@@ -23,6 +23,7 @@
package com.viaversion.viaversion.util;
import java.util.function.IntToLongFunction;
import java.util.function.IntUnaryOperator;
public final class CompactArrayUtil {
private static final long[] RECIPROCAL_MULT_AND_ADD = {
@@ -51,40 +52,39 @@ public final class CompactArrayUtil {
throw new UnsupportedOperationException();
}
public static long[] createCompactArrayWithPadding(int bitsPerEntry, int entries, IntToLongFunction valueGetter) {
long maxEntryValue = (1L << bitsPerEntry) - 1;
char valuesPerLong = (char) (64 / bitsPerEntry);
int magicIndex = valuesPerLong - 1;
long divideAdd = RECIPROCAL_MULT_AND_ADD[magicIndex];
long divideMul = divideAdd != 0 ? divideAdd : 0x80000000L; // Special case for the 0x80000000/0x00000000 tuple
int divideShift = RECIPROCAL_RIGHT_SHIFT[magicIndex];
int size = (entries + valuesPerLong - 1) / valuesPerLong;
public static long[] createCompactArrayWithPadding(int bitsPerEntry, int entries, IntUnaryOperator valueGetter) {
final long maxEntryValue = (1L << bitsPerEntry) - 1;
final int valuesPerLong = (char) (64 / bitsPerEntry);
final int size = (entries + valuesPerLong - 1) / valuesPerLong;
final long[] data = new long[size];
long[] data = new long[size];
for (int i = 0; i < entries; i++) {
long value = valueGetter.applyAsLong(i);
int cellIndex = (int) (i * divideMul + divideAdd >> 32L >> divideShift);
int bitIndex = (i - cellIndex * valuesPerLong) * bitsPerEntry;
data[cellIndex] = data[cellIndex] & ~(maxEntryValue << bitIndex) | (value & maxEntryValue) << bitIndex;
int i = 0;
for (int cellIndex = 0; cellIndex < size; cellIndex++) {
long cell = 0L;
int bitIndex = 0;
final int limit = Math.min(i + valuesPerLong, entries);
while (i < limit) {
cell |= (valueGetter.applyAsInt(i++) & maxEntryValue) << bitIndex;
bitIndex += bitsPerEntry;
}
data[cellIndex] = cell;
}
return data;
}
public static void iterateCompactArrayWithPadding(int bitsPerEntry, int entries, long[] data, BiIntConsumer consumer) {
long maxEntryValue = (1L << bitsPerEntry) - 1;
char valuesPerLong = (char) (64 / bitsPerEntry);
int magicIndex = valuesPerLong - 1;
long divideAdd = RECIPROCAL_MULT_AND_ADD[magicIndex];
long divideMul = divideAdd != 0 ? divideAdd : 0x80000000L;
int divideShift = RECIPROCAL_RIGHT_SHIFT[magicIndex];
final long maxEntryValue = (1L << bitsPerEntry) - 1;
final int valuesPerLong = 64 / bitsPerEntry;
final int size = data.length;
for (int i = 0; i < entries; i++) {
int cellIndex = (int) (i * divideMul + divideAdd >> 32L >> divideShift);
int bitIndex = (i - cellIndex * valuesPerLong) * bitsPerEntry;
int value = (int) (data[cellIndex] >> bitIndex & maxEntryValue);
consumer.consume(i, value);
int i = 0;
for (int cellIndex = 0; cellIndex < size; cellIndex++) {
long cell = data[cellIndex];
final int limit = Math.min(i + valuesPerLong, entries);
while (i < limit) {
consumer.consume(i++, (int) (cell & maxEntryValue));
cell >>>= bitsPerEntry;
}
}
}
@@ -48,7 +48,7 @@ public final class Key {
* Creates a new key with the given namespace and path.
*
* @param namespace the namespace of the identifier
* @param path the path of the identifier
* @param path the path of the identifier
* @return a new key with the given namespace and path
*/
public static Key of(final String namespace, final String path) {
@@ -49,7 +49,7 @@ fun ShadowJar.configureRelocations() {
}
fun ShadowJar.configureExcludes() {
// FastUtil - we only want object, int, and certain reference maps
// FastUtil - we only want object, int, long-to-object, and certain reference maps
// Object types
exclude("it/unimi/dsi/fastutil/*/*2Reference*")
exclude("it/unimi/dsi/fastutil/*/*Reference2Int*")
@@ -58,17 +58,23 @@ fun ShadowJar.configureExcludes() {
exclude("it/unimi/dsi/fastutil/*/*Short*")
exclude("it/unimi/dsi/fastutil/*/*Float*")
exclude("it/unimi/dsi/fastutil/*/*Double*")
exclude("it/unimi/dsi/fastutil/*/*Long*")
exclude("it/unimi/dsi/fastutil/*/*2Long*")
exclude("it/unimi/dsi/fastutil/*/*Char*")
// Map types
exclude("it/unimi/dsi/fastutil/*/*Custom*")
exclude("it/unimi/dsi/fastutil/*/*Tree*")
exclude("it/unimi/dsi/fastutil/*/*Heap*")
exclude("it/unimi/dsi/fastutil/*/*Queue*")
exclude("it/unimi/dsi/fastutil/longs/*2Int*")
exclude("it/unimi/dsi/fastutil/longs/*ArrayMap*")
exclude("it/unimi/dsi/fastutil/longs/*LinkedOpenHashMap*")
exclude("it/unimi/dsi/fastutil/longs/*SortedMap*")
// Crossing fingers
exclude("it/unimi/dsi/fastutil/*Big*")
exclude("it/unimi/dsi/fastutil/*/*Big*")
exclude("it/unimi/dsi/fastutil/*/*Synchronized*")
exclude("it/unimi/dsi/fastutil/*/*Unmodifiable*")
// More
exclude("it/unimi/dsi/fastutil/io/TextIO")
exclude("it/unimi/dsi/fastutil/io/TextIO.class")
exclude("it/unimi/dsi/fastutil/io/BinIO.class")
}
+1
View File
@@ -1,5 +1,6 @@
plugins {
base
eclipse
id("via.build-logic")
}
@@ -49,6 +49,20 @@ public final class NMSUtil {
}
}
public static Class<?> nms(String className, String... fallbackFullClassNames) throws ClassNotFoundException {
try {
return Class.forName(NMS + "." + className);
} catch (ClassNotFoundException ignored) {
}
for (final String fallbackFullClassName : fallbackFullClassNames) {
try {
return Class.forName(fallbackFullClassName);
} catch (ClassNotFoundException ignored) {
}
}
throw new ClassNotFoundException(className);
}
public static Class<?> obc(String className) throws ClassNotFoundException {
return Class.forName(BASE + "." + className);
}
@@ -105,7 +105,8 @@ public class BukkitViaInjector extends LegacyViaInjector {
// Grab the ping class and find the field to access it
Class<?> pingClazz = NMSUtil.nms(
"ServerPing",
"net.minecraft.network.protocol.status.ServerPing"
"net.minecraft.network.protocol.status.ServerPing",
"net.minecraft.network.protocol.status.ServerStatus"
);
Object ping = null;
for (Field field : serverClazz.getDeclaredFields()) {
@@ -120,7 +121,8 @@ public class BukkitViaInjector extends LegacyViaInjector {
// Now get the ServerData inside ServerPing
Class<?> serverDataClass = NMSUtil.nms(
"ServerPing$ServerData",
"net.minecraft.network.protocol.status.ServerPing$ServerData"
"net.minecraft.network.protocol.status.ServerPing$ServerData",
"net.minecraft.network.protocol.status.ServerStatus$Version"
);
Object serverData = null;
for (Field field : pingClazz.getDeclaredFields()) {
@@ -155,7 +157,8 @@ public class BukkitViaInjector extends LegacyViaInjector {
);
Class<?> connectionClass = NMSUtil.nms(
"ServerConnection",
"net.minecraft.server.network.ServerConnection"
"net.minecraft.server.network.ServerConnection",
"net.minecraft.server.network.ServerConnectionListener"
);
Object server = ReflectionUtil.invokeStatic(serverClass, "getServer");
@@ -267,8 +267,8 @@ public class ViaManagerImpl implements ViaManager {
platform.getLogger().warning("ViaVersion no longer officially supports this version of Java, only offering unsupported compatibility builds.");
platform.getLogger().warning("See https://github.com/ViaVersion/ViaVersion/releases/tag/5.0.0 for more information.");
} else if (version < 21) {
platform.getLogger().warning("Please update your Java runtime to at least Java 21 (your version is " + javaVersion + ").");
platform.getLogger().warning("At some point in the future, ViaVersion will no longer be compatible with this version of Java.");
// platform.getLogger().warning("Please update your Java runtime to at least Java 21 (your version is " + javaVersion + ").");
// platform.getLogger().warning("At some point in the future, ViaVersion will no longer be compatible with this version of Java.");
}
}
@@ -2,23 +2,18 @@
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.api.protocol;
@@ -27,6 +22,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.data.item.ItemHasher;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
@@ -39,10 +35,17 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypeMap;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.rewriter.MappingDataListener;
import com.viaversion.viaversion.api.rewriter.Rewriter;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.data.item.ItemHasherBase;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.exception.InformativeException;
import com.viaversion.viaversion.protocol.shared_registration.SharedRegistrations;
import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
import com.viaversion.viaversion.util.ProtocolLogger;
import com.viaversion.viaversion.util.ProtocolUtil;
import java.util.HashMap;
@@ -74,6 +77,8 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
private final Map<Class<?>, Object> storedObjects = new HashMap<>();
private boolean initialized;
private ProtocolLogger logger;
private ProtocolVersion serverVersion;
private ProtocolVersion clientVersion;
@Deprecated
protected AbstractProtocol() {
@@ -104,8 +109,12 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
if (logger == null) {
logger = createLogger();
}
// Apply shared registrations based on protocol version range
// Run before registerPackets, so implementations have to call append intentionally
applySharedRegistrations();
registerPackets();
registerConfigurationChangeHandlers();
// Register the rest of the ids with no handlers if necessary
if (unmappedClientboundPacketType != null && mappedClientboundPacketType != null
@@ -128,33 +137,15 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
protected ProtocolLogger createLogger() {
return new ProtocolLogger(getClass());
/**
* Applies shared registrations. Can be overridden to remove or add registrations.
*/
protected void applySharedRegistrations() {
SharedRegistrations.defaultRegistrations().applyMatching(this);
}
protected void registerConfigurationChangeHandlers() {
// Register handlers for protocol state switching
// Assuming ids will change too often, it is cleaner to register them here instead of the base protocols,
// even if there will be multiple of these handlers
final SU configurationAcknowledgedPacket = configurationAcknowledgedPacket();
if (configurationAcknowledgedPacket != null) {
appendServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
}
final CU startConfigurationPacket = startConfigurationPacket();
if (startConfigurationPacket != null) {
appendClientbound(startConfigurationPacket, startConfigurationHandler());
}
final SU finishConfigurationPacket = serverboundFinishConfigurationPacket();
if (finishConfigurationPacket != null) {
appendServerbound(finishConfigurationPacket, setClientStateHandler(State.PLAY));
}
final CU clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
if (clientboundFinishConfigurationPacket != null) {
appendClientbound(clientboundFinishConfigurationPacket, setServerStateHandler(State.PLAY));
}
protected ProtocolLogger createLogger() {
return new ProtocolLogger(getClass());
}
@Override
@@ -177,6 +168,20 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
@Override
public void replaceClientbound(final CU type, @Nullable final PacketHandler handler) {
final PacketMapping mapping = clientboundMappings.mappedPacket(type.state(), type.getId());
Preconditions.checkNotNull(mapping, "Packet %s has no handler to replace", type);
mapping.setHandler(handler);
}
@Override
public void replaceServerbound(final SU type, @Nullable final PacketHandler handler) {
final PacketMapping mapping = serverboundMappings.mappedPacket(type.state(), type.getId());
Preconditions.checkNotNull(mapping, "Packet %s has no handler to replace", type);
mapping.setHandler(handler);
}
private <U extends PacketType, M extends PacketType> void registerPacketIdChanges(
Map<State, PacketTypeMap<U>> unmappedPacketTypes,
Map<State, PacketTypeMap<M>> mappedPacketTypes,
@@ -203,17 +208,10 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
public void registerFinishConfiguration(final CU packetType, final PacketHandler handler) {
registerClientbound(packetType, wrapper -> {
// TODO Temporary solution to handle the finish configuration packet already having changed our tracked protocol state in a previous handler
wrapper.user().getProtocolInfo().setServerState(State.CONFIGURATION);
handler.handle(wrapper);
});
}
@Override
public final void loadMappingData() {
getMappingData().load();
initialize();
onMappingDataLoaded();
}
@@ -248,10 +246,21 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
protected void addEntityTracker(UserConnection connection) {
final EntityType playerEntityType = getEntityRewriter().typeFromId("player");
Preconditions.checkNotNull(playerEntityType, "Player entity type not found");
connection.addEntityTracker(this.getClass(), new EntityTrackerBase(connection, playerEntityType));
}
protected void addEntityTracker(UserConnection connection, EntityTracker tracker) {
connection.addEntityTracker(this.getClass(), tracker);
}
protected void addItemHasher(UserConnection connection) {
connection.addItemHasher(this.getClass(), new ItemHasherBase(this, connection));
}
@Deprecated(forRemoval = true)
protected void addItemHasher(UserConnection connection, ItemHasher hasher) {
connection.addItemHasher(this.getClass(), hasher);
}
@@ -273,20 +282,44 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
return PacketMappings.arrayMappings();
}
protected @Nullable SU configurationAcknowledgedPacket() {
return packetTypesProvider.unmappedServerboundType(State.PLAY, "CONFIGURATION_ACKNOWLEDGED");
/**
* Returns the server protocol version for this protocol,
* or null if not set (e.g. for base protocols).
*
* @return the server protocol version
*/
public @Nullable ProtocolVersion getServerVersion() {
return serverVersion;
}
protected @Nullable CU startConfigurationPacket() {
return packetTypesProvider.unmappedClientboundType(State.PLAY, "START_CONFIGURATION");
/**
* Sets the server protocol version for this protocol.
* Called by the protocol manager before {@link #initialize()}.
*
* @param serverVersion the server protocol version
*/
public void setServerVersion(final ProtocolVersion serverVersion) {
this.serverVersion = serverVersion;
}
protected @Nullable SU serverboundFinishConfigurationPacket() {
return packetTypesProvider.unmappedServerboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
/**
* Returns the client protocol version for this protocol,
* or null if not set (e.g. for base protocols).
*
* @return the client protocol version for this protocol
*/
public @Nullable ProtocolVersion getClientVersion() {
return clientVersion;
}
protected @Nullable CU clientboundFinishConfigurationPacket() {
return packetTypesProvider.unmappedClientboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
/**
* Sets the client protocol version for this protocol.
* Called by the protocol manager before {@link #initialize()}.
*
* @param clientVersion the client protocol version for this protocol
*/
public void setClientVersion(final ProtocolVersion clientVersion) {
this.clientVersion = clientVersion;
}
// ---------------------------------------------------------------------------------
@@ -297,7 +330,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
PacketMapping packetMapping = PacketMapping.of(mappedPacketId, handler);
if (!override && serverboundMappings.hasMapping(state, unmappedPacketId)) {
Via.getPlatform().getLogger().log(Level.WARNING, unmappedPacketId + " already registered!" +
" If this override is intentional, set override to true. Stacktrace: ", new Exception());
" If this override is intentional, use replaceServerbound instead. Stacktrace: ", new Exception());
}
serverboundMappings.addMapping(state, unmappedPacketId, packetMapping);
}
@@ -313,7 +346,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
PacketMapping packetMapping = PacketMapping.of(mappedPacketId, handler);
if (!override && clientboundMappings.hasMapping(state, unmappedPacketId)) {
Via.getPlatform().getLogger().log(Level.WARNING, unmappedPacketId + " already registered!" +
" If override is intentional, set override to true. Stacktrace: ", new Exception());
" If override is intentional, use replaceClientbound instead. Stacktrace: ", new Exception());
}
clientboundMappings.addMapping(state, unmappedPacketId, packetMapping);
}
@@ -373,8 +406,8 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
PacketMapping packetMapping = PacketMapping.of(mappedPacketType, handler);
if (!override && packetMappings.hasMapping(packetType)) {
getLogger().log(Level.WARNING, packetType + " already registered!" +
" If override is intentional, set override to true. Stacktrace: ", new Exception());
throw new IllegalArgumentException("Packet type " + packetType + " already registered! If override is intentional, use "
+ (packetType.direction() == Direction.SERVERBOUND ? "replaceServerbound" : "replaceClientbound") + " instead.");
}
packetMappings.addMapping(packetType, packetMapping);
}
@@ -443,6 +476,14 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
return logger;
}
public com.viaversion.viaversion.rewriter.@Nullable BlockRewriter<CU> getBlockRewriter() {
return null;
}
public @Nullable RecipeDisplayRewriter<CU> getRecipeRewriter() {
return null;
}
private void printRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) {
// Don't print errors during handshake/login/status
if (state != State.PLAY && direction == Direction.SERVERBOUND && !Via.getManager().debugHandler().enabled()) {
@@ -472,23 +513,6 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
private PacketHandler setClientStateHandler(final State state) {
return wrapper -> wrapper.user().getProtocolInfo().setClientState(state);
}
private PacketHandler setServerStateHandler(final State state) {
return wrapper -> wrapper.user().getProtocolInfo().setServerState(state);
}
private PacketHandler startConfigurationHandler() {
return setServerStateHandler(State.CONFIGURATION).then(wrapper -> {
// Mimic client behaviour
final EntityTracker tracker = wrapper.user().getEntityTracker(getClass());
if (tracker != null) {
tracker.clear();
}
});
}
@Override
public final PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
@@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.codec;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.codec.CodecContext;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.protocol.Protocol;
@@ -48,4 +49,9 @@ public record CodecRegistryContext(Protocol<?, ?, ?, ?> protocol, RegistryAccess
final VersionedTypesHolder types = mapped ? protocol.mappedTypes() : protocol.types();
return (NOT_IMPLEMENTED.isEmpty() || !NOT_IMPLEMENTED.contains(key)) && types.structuredDataKeys().supportsOps(key);
}
@Override
public UserConnection connection() {
return registryAccess.connection();
}
}
@@ -37,6 +37,11 @@ public class DebugSubCmd implements ViaSubCommand {
return "Toggle various debug modes.";
}
@Override
public String usage() {
return "debug [clear|pre|post], or debug <add|remove> <packet>";
}
@Override
public boolean execute(ViaCommandSender sender, String[] args) {
final DebugHandler debug = Via.getManager().debugHandler();
@@ -49,11 +54,11 @@ public class DebugSubCmd implements ViaSubCommand {
debug.clearPacketTypesToLog();
sendMessage(sender, "&6Cleared packet types to log");
return true;
} else if (args[0].equalsIgnoreCase("logpretransform")) {
} else if (args[0].equalsIgnoreCase("pre")) {
debug.setLogPrePacketTransform(!debug.logPrePacketTransform());
sendMessage(sender, "&6Pre transform packet logging is now %s", (debug.logPrePacketTransform() ? "&aenabled" : "&cdisabled"));
return true;
} else if (args[0].equalsIgnoreCase("logposttransform")) {
} else if (args[0].equalsIgnoreCase("post")) {
debug.setLogPostPacketTransform(!debug.logPostPacketTransform());
sendMessage(sender, "&6Post transform packet logging is now %s", (debug.logPostPacketTransform() ? "&aenabled" : "&cdisabled"));
return true;
@@ -75,7 +80,7 @@ public class DebugSubCmd implements ViaSubCommand {
@Override
public List<String> onTabComplete(final ViaCommandSender sender, final String[] args) {
if (args.length == 1) {
return Arrays.asList("clear", "logposttransform", "add", "remove");
return Arrays.asList("clear", "pre", "post", "add", "remove");
}
return Collections.emptyList();
}
@@ -37,7 +37,7 @@ public class DisplayLeaksSubCmd implements ViaSubCommand {
@Override
public String usage() {
return "displayleaks <level>";
return "displayleaks [level]";
}
@Override
@@ -43,6 +43,7 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.CodecException;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -52,7 +53,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class UserConnectionImpl implements UserConnection {
@@ -27,14 +27,17 @@ import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.KeyMappings;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeListener {
protected final Int2ObjectMap<TrackedEntity> entities = new Int2ObjectOpenHashMap<>();
private final Map<String, KeyMappings> registryKeyMappings = new HashMap<>();
private final UserConnection connection;
private final EntityType playerType;
private Integer clientEntityId;
@@ -115,6 +118,7 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
}
clientEntityId = null;
registryKeyMappings.clear();
}
@Override
@@ -222,4 +226,14 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
public void setDimensions(Map<String, DimensionData> dimensions) {
this.dimensions = dimensions;
}
@Override
public @Nullable KeyMappings registryKeys(String registryKey) {
return registryKeyMappings.get(Key.stripMinecraftNamespace(registryKey));
}
@Override
public void addRegistryKeys(String registryKey, KeyMappings mappings) {
registryKeyMappings.put(Key.stripMinecraftNamespace(registryKey), mappings);
}
}
@@ -34,22 +34,20 @@ import com.viaversion.viaversion.codec.CodecRegistryContext;
import com.viaversion.viaversion.codec.hash.HashFunction;
import com.viaversion.viaversion.codec.hash.HashOps;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemHasherBase implements ItemHasher {
public static int UNKNOWN_HASH = 399825415; // some random-ish number, from hashing Integer.MIN_VALUE+1 with crc32c
private final Map<Integer, HashedItem> hashes = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(1024).<Integer, HashedItem>build().asMap();
private final Map<Integer, OriginalHashedItem> hashes = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(1024).<Integer, OriginalHashedItem>build().asMap();
protected final UserConnection connection;
private boolean processingClientboundInventoryPacket;
private final CodecContext context;
private final CodecContext mappedContext;
public ItemHasherBase(final Protocol<?, ?, ?, ?> protocol, final UserConnection connection) {
final RegistryAccess registryAccess = RegistryAccess.of(protocol);
final RegistryAccess registryAccess = RegistryAccess.of(protocol, connection);
this.context = new CodecRegistryContext(protocol, registryAccess, false);
this.mappedContext = new CodecRegistryContext(protocol, registryAccess, true);
this.connection = connection;
@@ -58,7 +56,7 @@ public class ItemHasherBase implements ItemHasher {
/**
* Returns the hashed item for the given item. Not all data may be successfully hashed.
*
* @param item the item to hash
* @param item the item to hash
* @param mapped whether the item is mapped to the client version
* @return the hashed item
*/
@@ -83,25 +81,26 @@ public class ItemHasherBase implements ItemHasher {
/**
* Tracks the data for the given data container, storing the original hashes via the now transformed data hashes.
*
* @param customData custom_data tag
* @param customData custom_data tag
* @param originalHashedItem the original (pre-transformed) hashed item
* @param backupTagName protocol-specific backup tag name where the item should become a regular hashed item again
*/
public void trackOriginalHashedItem(final CompoundTag customData, final HashedItem originalHashedItem) {
public void trackOriginalHashedItem(final CompoundTag customData, final HashedItem originalHashedItem, final String backupTagName) {
// Store them via the custom_data hash, which includes the original data hashes.
// Not perfect (as opposed to storing it by the full hashed item), but good enough. In the rare occasion there is a collision, we ignore it without issues.
final int customDataHash = hashTag(customData);
this.hashes.put(customDataHash, originalHashedItem);
this.hashes.put(customDataHash, new OriginalHashedItem(originalHashedItem, backupTagName));
}
/**
* Returns a copy of the original hashed item for a given custom_data hash.
*
* @param customDataHash custom_data hash
* @param clientItem the hashed item from the client that the original should be retrieved for
* @param clientItem the hashed item from the client that the original should be retrieved for
* @return the original hashed item, or null if not found
*/
public @Nullable HashedItem originalHashedItem(final int customDataHash, final HashedItem clientItem) {
HashedItem originalItem = this.hashes.get(customDataHash);
public @Nullable OriginalHashedItem originalHashedItem(final int customDataHash, final HashedItem clientItem) {
OriginalHashedItem originalItem = this.hashes.get(customDataHash);
if (originalItem == null) {
return null;
}
@@ -116,6 +115,8 @@ public class ItemHasherBase implements ItemHasher {
entry.setValue(clientProvidedHash);
}
}
originalItem.setAmount(clientItem.amount());
return originalItem;
}
@@ -0,0 +1,60 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.data.item;
import com.viaversion.viaversion.api.minecraft.item.HashedItem;
import com.viaversion.viaversion.api.minecraft.item.HashedStructuredItem;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
/**
* Marker class to avoid continuous hashing and restoration of items in every protocol.
* Instead, this restores it once and passes the result through to the protocol that originally stored the backup.
*/
public final class OriginalHashedItem extends HashedStructuredItem {
private final String backupTagName;
public OriginalHashedItem(final HashedItem item, final String backupTagName) {
this(item.identifier(), item.amount(), item.dataHashesById(), item.removedDataIds(), backupTagName); // don't copy
}
public OriginalHashedItem(final int identifier, final int amount, final String backupTagName) {
super(identifier, amount);
this.backupTagName = backupTagName;
}
private OriginalHashedItem(final int identifier, final int amount, final Int2IntMap dataHashes, final IntSet removedData, final String backupTagName) {
super(identifier, amount, dataHashes, removedData);
this.backupTagName = backupTagName;
}
public String backupTagName() {
return backupTagName;
}
public HashedItem asRegularItem() {
return new HashedStructuredItem(identifier(), amount(), dataHashesById(), removedDataIds());
}
@Override
public OriginalHashedItem copy() {
return new OriginalHashedItem(identifier(), amount(), new Int2IntOpenHashMap(dataHashesById()), new IntOpenHashSet(removedDataIds()), backupTagName);
}
}
@@ -0,0 +1,34 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.SimpleProtocol;
/**
* A simple protocol which does not have any packet types.
* <p>
* {@link AbstractProtocol} should be preferred over this class in most cases.
*/
public abstract class AbstractSimpleProtocol extends AbstractProtocol<SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes,
SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes> implements SimpleProtocol {
protected AbstractSimpleProtocol() {
super(null, null, null, null);
}
}
@@ -23,6 +23,7 @@ import com.google.common.collect.Range;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.ProtocolManager;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
@@ -38,6 +39,7 @@ import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl;
import com.viaversion.viaversion.protocol.packet.VersionedPacketTransformerImpl;
import com.viaversion.viaversion.protocol.shared_registration.def.DefaultRegistrations;
import com.viaversion.viaversion.protocols.base.InitialBaseProtocol;
import com.viaversion.viaversion.protocols.base.v1_16.ClientboundBaseProtocol1_16;
import com.viaversion.viaversion.protocols.base.v1_7.ClientboundBaseProtocol1_7;
@@ -95,6 +97,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -113,9 +116,7 @@ import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function;
import java.util.logging.Level;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ProtocolManagerImpl implements ProtocolManager {
@@ -146,6 +147,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
worker.setName("Via-Mappingloader-" + threadIndex.incrementAndGet());
return worker;
}, ForkJoinWorkerThread.getDefaultUncaughtExceptionHandler(), true);
DefaultRegistrations.apply();
}
public void registerProtocols() {
@@ -225,8 +228,11 @@ public class ProtocolManagerImpl implements ProtocolManager {
@Override
public void registerProtocol(Protocol protocol, List<ProtocolVersion> supportedClientVersion, ProtocolVersion serverVersion) {
// Register the protocol's handlers
protocol.initialize();
// Set the server version on AbstractProtocol instances before initialization
if (protocol instanceof AbstractProtocol<?, ?, ?, ?> abstractProtocol) {
abstractProtocol.setServerVersion(serverVersion);
abstractProtocol.setClientVersion(supportedClientVersion.stream().max(ProtocolVersion::compareTo).orElseThrow());
}
// Clear cache as this may make new routes.
if (!pathCache.isEmpty()) {
@@ -248,14 +254,22 @@ public class ProtocolManagerImpl implements ProtocolManager {
refreshVersions();
}
if (protocol.hasMappingDataToLoad()) {
if (mappingLoaderExecutor != null) {
// Submit mapping data loading
addMappingLoaderFuture(protocol.getClass(), protocol::loadMappingData);
// Load mapping data and register the protocol's handlers
if (!protocol.hasMappingDataToLoad()) {
protocol.initialize();
return;
}
// Submit mapping data loading
if (mappingLoaderExecutor != null) {
if (protocol.dependsOn() != null) {
addMappingLoaderFuture(protocol.getClass(), protocol.dependsOn(), protocol::loadMappingData);
} else {
// Late protocol adding - just do it on the current thread
protocol.loadMappingData();
addMappingLoaderFuture(protocol.getClass(), protocol::loadMappingData);
}
} else {
// Late protocol adding - just do it on the current thread
protocol.loadMappingData();
}
}
@@ -484,7 +498,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
}
@Override
public boolean checkForMappingCompletion() {
public boolean checkForMappingCompletion(final boolean propagateErrors) {
mappingLoaderLock.readLock().lock();
try {
if (mappingsLoaded) {
@@ -496,6 +510,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
if (!future.isDone()) {
return false;
}
if (propagateErrors) {
future.join();
}
}
shutdownLoaderExecutor();
@@ -507,7 +524,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
@Override
public void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass));
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, mappingLoaderExecutor)
.whenComplete(($, t) -> logIfErrored(protocolClass, t));
mappingLoaderLock.writeLock().lock();
try {
@@ -519,8 +537,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
@Override
public void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn)
.whenCompleteAsync((v, throwable) -> runnable.run(), mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass));
CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn).thenRunAsync(runnable, mappingLoaderExecutor)
.whenComplete(($, t) -> logIfErrored(protocolClass, t));
mappingLoaderLock.writeLock().lock();
try {
@@ -571,10 +589,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
MappingDataLoader.INSTANCE.clearCache();
}
private Function<Throwable, Void> mappingLoaderThrowable(Class<? extends Protocol> protocolClass) {
return throwable -> {
Via.getPlatform().getLogger().log(Level.SEVERE, "Error during mapping loading of " + protocolClass.getSimpleName(), throwable);
return null;
};
private void logIfErrored(final Class<? extends Protocol> protocolClass, @Nullable final Throwable throwable) {
if (throwable != null) {
Via.getPlatform().getLogger().log(Level.SEVERE, "Error during loading of " + protocolClass.getSimpleName(), throwable);
}
}
}
@@ -338,7 +338,10 @@ public class PacketWrapperImpl implements PacketWrapper {
final ProtocolInfo protocolInfo = user().getProtocolInfo();
final List<Protocol> protocols = protocolInfo.getPipeline().pipes(protocolClass, skipCurrentPipeline, direction);
apply(direction, protocolInfo.getState(direction), protocols);
// Use the packet's own state if known to avoid issues with stale tracked connection state
// (e.g. a previous protocol in the pipeline already having changed serverState to PLAY while still processing FINISH_CONFIGURATION)
final State state = this.packetType != null ? this.packetType.state() : protocolInfo.getState(direction);
apply(direction, state, protocols);
final ByteBuf output = allocateOutputBuffer();
try {
writeToBuffer(output);
@@ -599,11 +602,12 @@ public class PacketWrapperImpl implements PacketWrapper {
@Override
public void consumeReadsOnly(final Runnable runnable) {
final boolean previous = this.allActionsRead;
this.allActionsRead = true;
try {
runnable.run();
} finally {
this.allActionsRead = false;
this.allActionsRead = previous;
}
}
@@ -0,0 +1,23 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration;
public enum PacketBound {
ADDED_AT_MIN,
REMOVED_AT_MAX
}
@@ -0,0 +1,151 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import com.viaversion.viaversion.protocol.shared_registration.SharedRegistrations.RegistrationAction;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
public final class RegistrationBuilder {
private final List<VersionedTemplateGroup> groups = new ArrayList<>();
private final SharedRegistrations registrations;
private VersionType versionType;
RegistrationBuilder(final SharedRegistrations registrations) {
this.registrations = registrations;
}
/**
* Adds a registration for an open-ended version range.
*
* @param min minimum version, inclusive
* @param action registration action
* @return this
*/
public RegistrationBuilder since(final ProtocolVersion min, final RegistrationAction<?, ?> action) {
checkVersionType(min);
groups.add(new VersionedTemplateGroup(action, min, null));
return this;
}
/**
* Adds a registration for a version range.
*
* @param min minimum version, inclusive
* @param max maximum version, exclusive
* @param action registration action
* @return this
*/
public RegistrationBuilder range(final ProtocolVersion min, final ProtocolVersion max, final RegistrationAction<?, ?> action) {
checkVersionType(min);
checkVersionType(max);
groups.add(new VersionedTemplateGroup(action, min, max));
return this;
}
public <CU extends ClientboundPacketType, SU extends ServerboundPacketType> RegistrationBuilder ranges(
final ProtocolVersion min, final Consumer<RangesBuilder<CU, SU>> consumer
) {
consumer.accept(new RangesBuilder<>(min));
return this;
}
public <CU extends ClientboundPacketType, SU extends ServerboundPacketType, R> RegistrationBuilder ranges(
final Function<RegistrationContext<CU, SU>, R> adapter, final ProtocolVersion min,
final Consumer<TypedRangesBuilder<CU, SU, R>> consumer
) {
consumer.accept(new TypedRangesBuilder<>(adapter, min));
return this;
}
public void register() {
registrations.register(versionType, groups);
}
private void checkVersionType(final ProtocolVersion version) {
if (versionType == null) {
versionType = version.getVersionType();
} else if (versionType != version.getVersionType()) {
throw new IllegalArgumentException("Cannot mix different version types in the same registration builder");
}
}
public class RangesBuilder<CU extends ClientboundPacketType, SU extends ServerboundPacketType> {
private ProtocolVersion currentMin;
private boolean completed;
private RangesBuilder(final ProtocolVersion min) {
this.currentMin = min;
}
public RangesBuilder<CU, SU> to(final ProtocolVersion max, final RegistrationAction<CU, SU> action) {
Preconditions.checkState(!completed, "Range chain already completed");
RegistrationBuilder.this.range(currentMin, max, action);
currentMin = max;
return this;
}
public RegistrationBuilder since(final RegistrationAction<CU, SU> action) {
Preconditions.checkState(!completed, "Range chain already completed");
completed = true;
return RegistrationBuilder.this.since(currentMin, action);
}
}
public final class TypedRangesBuilder<CU extends ClientboundPacketType, SU extends ServerboundPacketType, R> extends RangesBuilder<CU, SU> {
private final Function<RegistrationContext<CU, SU>, R> adapter;
private TypedRangesBuilder(final Function<RegistrationContext<CU, SU>, R> adapter, final ProtocolVersion min) {
super(min);
this.adapter = adapter;
}
public TypedRangesBuilder<CU, SU, R> to(final ProtocolVersion max, final TypedRegistrationAction<CU, SU, R> action) {
to(max, wrapAction(action));
return this;
}
public TypedRangesBuilder<CU, SU, R> since(final TypedRegistrationAction<CU, SU, R> action) {
since(wrapAction(action));
return this;
}
private RegistrationAction<CU, SU> wrapAction(final TypedRegistrationAction<CU, SU, R> action) {
return ctx -> {
final R rewriter = adapter.apply(ctx);
if (rewriter != null) {
action.accept(ctx, rewriter);
}
};
}
}
@FunctionalInterface
public interface TypedRegistrationAction<CU extends ClientboundPacketType, SU extends ServerboundPacketType, R> {
void accept(RegistrationContext<CU, SU> ctx, R r);
}
}
@@ -0,0 +1,127 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import java.util.function.Consumer;
import org.checkerframework.checker.nullness.qual.Nullable;
public record RegistrationContext<CU extends ClientboundPacketType, SU extends ServerboundPacketType>(
AbstractProtocol<CU, ?, ?, SU> protocol,
ProtocolVersion min,
@Nullable ProtocolVersion max
) {
public <P extends AbstractProtocol<CU, ?, ?, SU>> P protocol(@SuppressWarnings("unused") final Class<P> protocolClass) {
//noinspection unchecked
return (P) protocol;
}
public <P extends AbstractProtocol<CU, ?, ?, SU>> P castProtocol() {
//noinspection unchecked
return (P) protocol;
}
public void clientbound(final ClientboundPacketType type, final Consumer<CU> action) {
action.accept(clientboundPacketType(type));
}
public void clientbound(final ClientboundPacketType type, final Consumer<CU> action, final PacketBound... markers) {
if (!shouldSkip(markers)) {
action.accept(clientboundPacketType(type));
}
}
public void clientboundHandler(final ClientboundPacketType type, final PacketHandler handler) {
protocol.registerClientbound(clientboundPacketType(type), handler);
}
public void clientboundHandler(final ClientboundPacketType type, final PacketHandler handler, final PacketBound... markers) {
if (!shouldSkip(markers)) {
protocol.registerClientbound(clientboundPacketType(type), handler);
}
}
public void serverbound(final ServerboundPacketType type, final Consumer<SU> action) {
action.accept(serverboundPacketType(type));
}
public void serverbound(final ServerboundPacketType type, final Consumer<SU> action, final PacketBound... markers) {
if (!shouldSkip(markers)) {
action.accept(serverboundPacketType(type));
}
}
public void serverboundHandler(final ServerboundPacketType type, final PacketHandler handler) {
protocol.registerServerbound(serverboundPacketType(type), handler);
}
public void serverboundHandler(final ServerboundPacketType type, final PacketHandler handler, final PacketBound... markers) {
if (!shouldSkip(markers)) {
protocol.registerServerbound(serverboundPacketType(type), handler);
}
}
private boolean shouldSkip(final PacketBound... markers) {
if (markers.length == 0) {
return false;
}
final ProtocolVersion serverVersion = protocol.getServerVersion();
final ProtocolVersion clientVersion = protocol.getClientVersion();
final ProtocolVersion lowerVersion = serverVersion.olderThan(clientVersion) ? serverVersion : clientVersion;
final ProtocolVersion higherVersion = serverVersion.newerThan(clientVersion) ? serverVersion : clientVersion;
for (final PacketBound marker : markers) {
switch (marker) {
case ADDED_AT_MIN -> {
if (lowerVersion.olderThan(min)) {
return true;
}
}
case REMOVED_AT_MAX -> {
Preconditions.checkArgument(max != null, "Cannot use REMOVED_AT_MAX in an open-ended range");
if (higherVersion.newerThanOrEqualTo(max)) {
return true;
}
}
}
}
return false;
}
public SU serverboundPacketType(final ServerboundPacketType genericPacketType) {
final SU type = protocol.getPacketTypesProvider().unmappedServerboundType(genericPacketType.state(), genericPacketType.getName());
if (type == null) {
throw new IllegalArgumentException("Could not find serverbound packet type for " + genericPacketType.state() + " " + genericPacketType.getName());
}
return type;
}
public CU clientboundPacketType(final ClientboundPacketType genericPacketType) {
final CU type = protocol.getPacketTypesProvider().unmappedClientboundType(genericPacketType.state(), genericPacketType.getName());
if (type == null) {
throw new IllegalArgumentException("Could not find clientbound packet type for " + genericPacketType.state() + " " + genericPacketType.getName() + " in " + protocol.getClass().getSimpleName());
}
return type;
}
}
@@ -0,0 +1,107 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
/**
* Central registry for shared packet registrations that are automatically applied
* to protocols based on their version range.
* <p>
* Registrations are done BEFORE registerPackets in {@link AbstractProtocol}.
*/
public final class SharedRegistrations {
private static final SharedRegistrations DEFAULT_REGISTRATIONS = new SharedRegistrations();
private final EnumMap<VersionType, List<VersionedTemplateGroup>> versionedTemplates = new EnumMap<>(VersionType.class);
/**
* Returns the default ViaVersion registration set.
*/
public static SharedRegistrations defaultRegistrations() {
return DEFAULT_REGISTRATIONS;
}
/**
* Creates an independent shared registration set that external projects can populate and apply.
*/
public static SharedRegistrations create() {
return new SharedRegistrations();
}
public RegistrationBuilder registrations() {
return new RegistrationBuilder(this);
}
/**
* Applies all shared registrations whose version range matches the given protocol.
*
* @param protocol the protocol to apply shared registrations to
*/
public void applyMatching(final AbstractProtocol<?, ?, ?, ?> protocol) {
if (protocol.isBaseProtocol()) {
return;
}
final ProtocolVersion version = protocol.getServerVersion();
if (version.getVersionType() != protocol.getClientVersion().getVersionType()) {
// Built on continuous version ranges
return;
}
final List<VersionedTemplateGroup> groups = versionedTemplates.get(version.getVersionType());
if (groups == null) {
return;
}
for (final VersionedTemplateGroup group : groups) {
if (group.min().newerThan(version)) { // TODO binary search?
// Sorted by the minimum, so we can stop early if we're out
break;
}
if (group.max() != null && version.newerThanOrEqualTo(group.max())) {
continue;
}
final RegistrationContext<?, ?> context = new RegistrationContext<>(protocol, group.min(), group.max());
//noinspection unchecked,rawtypes
((RegistrationAction) group.action()).accept(context);
}
}
@FunctionalInterface
public interface RegistrationAction<CU extends ClientboundPacketType, SU extends ServerboundPacketType> {
void accept(RegistrationContext<CU, SU> context);
}
void register(final VersionType versionType, final List<VersionedTemplateGroup> toAdd) {
final List<VersionedTemplateGroup> groups = versionedTemplates.computeIfAbsent(versionType, $ -> new ArrayList<>());
groups.addAll(toAdd);
groups.sort(Comparator.comparing(VersionedTemplateGroup::min, Comparator.nullsFirst(Comparator.naturalOrder())));
}
}
@@ -0,0 +1,32 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocol.shared_registration.SharedRegistrations.RegistrationAction;
record VersionedTemplateGroup(
RegistrationAction<?, ?> action,
ProtocolVersion min,
ProtocolVersion max
) {
public boolean contains(final ProtocolVersion version) {
return version.newerThanOrEqualTo(min) && (max == null || version.olderThan(max));
}
}
@@ -0,0 +1,95 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.protocol.shared_registration.PacketBound;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
final class BlockRegistrations {
static <CU extends ClientboundPacketType> void registerBlockPackets1_13(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_13(ctx, br);
ctx.clientbound(ClientboundPackets1_13.CHUNK_BLOCKS_UPDATE, br::registerChunkBlocksUpdate);
}
private static <CU extends ClientboundPacketType> void common1_13(RegistrationContext<CU, ?> ctx, BlockRewriter<CU> br) {
ctx.clientbound(ClientboundPackets1_13.BLOCK_EVENT, br::registerBlockEvent);
ctx.clientbound(ClientboundPackets1_13.BLOCK_UPDATE, br::registerBlockUpdate);
ctx.clientbound(ClientboundPackets1_13.LEVEL_EVENT, br::registerLevelEvent1_13);
}
static <CU extends ClientboundPacketType> void registerBlockPackets1_14_4(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_13(ctx, br);
ctx.clientbound(ClientboundPackets1_14_4.CHUNK_BLOCKS_UPDATE, br::registerChunkBlocksUpdate, PacketBound.REMOVED_AT_MAX);
ctx.clientbound(ClientboundPackets1_14_4.BLOCK_BREAK_ACK, br::registerBlockBreakAck, PacketBound.ADDED_AT_MIN);
}
static <CU extends ClientboundPacketType> void registerBlockPackets1_16_2(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_13(ctx, br);
ctx.clientbound(ClientboundPackets1_16_2.BLOCK_BREAK_ACK, br::registerBlockBreakAck);
ctx.clientbound(ClientboundPackets1_16_2.SECTION_BLOCKS_UPDATE, br::registerSectionBlocksUpdate, PacketBound.ADDED_AT_MIN);
}
static <CU extends ClientboundPacketType> void registerBlockPackets1_18(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_13(ctx, br);
ctx.clientbound(ClientboundPackets1_18.BLOCK_BREAK_ACK, br::registerBlockBreakAck, PacketBound.REMOVED_AT_MAX);
ctx.clientbound(ClientboundPackets1_18.LEVEL_CHUNK_WITH_LIGHT, br::registerLevelChunk1_18, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_18.SECTION_BLOCKS_UPDATE, br::registerSectionBlocksUpdate);
ctx.clientbound(ClientboundPackets1_18.BLOCK_ENTITY_DATA, br::registerBlockEntityData1_18);
}
static <CU extends ClientboundPacketType> void registerBlockPackets1_19(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_19(ctx, br);
ctx.clientbound(ClientboundPackets1_19.LEVEL_EVENT, br::registerLevelEvent1_13);
ctx.clientbound(ClientboundPackets1_19.SECTION_BLOCKS_UPDATE, br::registerSectionBlocksUpdate);
}
private static <CU extends ClientboundPacketType> void common1_19(RegistrationContext<CU, ?> ctx, BlockRewriter<CU> br) {
ctx.clientbound(ClientboundPackets1_19.BLOCK_EVENT, br::registerBlockEvent);
ctx.clientbound(ClientboundPackets1_19.BLOCK_UPDATE, br::registerBlockUpdate);
ctx.clientbound(ClientboundPackets1_19.LEVEL_CHUNK_WITH_LIGHT, br::registerLevelChunk1_18);
ctx.clientbound(ClientboundPackets1_19.BLOCK_ENTITY_DATA, br::registerBlockEntityData1_18);
}
static <CU extends ClientboundPacketType> void registerBlockPackets1_20(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_19(ctx, br);
ctx.clientbound(ClientboundPackets1_19_4.LEVEL_EVENT, br::registerLevelEvent1_13);
ctx.clientbound(ClientboundPackets1_19_4.SECTION_BLOCKS_UPDATE, br::registerSectionBlocksUpdate1_20);
}
static <CU extends ClientboundPacketType> void registerBlockPackets1_21(final RegistrationContext<CU, ?> ctx, final BlockRewriter<CU> br) {
common1_19(ctx, br);
ctx.clientbound(ClientboundPackets1_21.LEVEL_EVENT, br::registerLevelEvent1_21);
ctx.clientbound(ClientboundPackets1_21.SECTION_BLOCKS_UPDATE, br::registerSectionBlocksUpdate1_20);
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> BlockRewriter<CU> block(final RegistrationContext<CU, SU> ctx) {
return ctx.protocol().getBlockRewriter();
}
}
@@ -0,0 +1,112 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocol.shared_registration.SharedRegistrations;
import com.viaversion.viaversion.protocol.shared_registration.def.base.ConfigurationRegistrations;
public final class DefaultRegistrations {
public static void apply() {
SharedRegistrations.defaultRegistrations().registrations()
.ranges(EntityRegistrations::entity, ProtocolVersion.v1_13, b -> b
.to(ProtocolVersion.v1_14_4, EntityRegistrations::registerEntityPackets1_13)
.to(ProtocolVersion.v1_16_2, EntityRegistrations::registerEntityPackets1_14_4)
.to(ProtocolVersion.v1_17_1, EntityRegistrations::registerEntityPackets1_16_2)
.to(ProtocolVersion.v1_19, EntityRegistrations::registerEntityPackets1_17_1)
.to(ProtocolVersion.v1_20_5, EntityRegistrations::registerEntityPackets1_19)
.to(ProtocolVersion.v1_21_4, EntityRegistrations::registerEntityPackets1_20_5)
.to(ProtocolVersion.v1_21_9, EntityRegistrations::registerEntityPackets1_21_4)
.since(EntityRegistrations::registerEntityPackets1_21_9)
)
.ranges(ItemRegistrations::item, ProtocolVersion.v1_13, b -> b
.to(ProtocolVersion.v1_14, ItemRegistrations::registerItemPackets1_13)
.to(ProtocolVersion.v1_14_4, ItemRegistrations::registerItemPackets1_14)
.to(ProtocolVersion.v1_16, ItemRegistrations::registerItemPackets1_14_4)
.to(ProtocolVersion.v1_17_1, ItemRegistrations::registerItemPackets1_16)
.to(ProtocolVersion.v1_19_1, ItemRegistrations::registerItemPackets1_17_1)
.to(ProtocolVersion.v1_20_3, ItemRegistrations::registerItemPackets1_19_1)
.to(ProtocolVersion.v1_20_5, ItemRegistrations::registerItemPackets1_20_3)
.to(ProtocolVersion.v1_21, ItemRegistrations::registerItemPackets1_20_5)
.to(ProtocolVersion.v1_21_2, ItemRegistrations::registerItemPackets1_21)
.to(ProtocolVersion.v1_21_5, ItemRegistrations::registerItemPackets1_21_2)
)
.ranges(ItemRegistrations::structuredItem, ProtocolVersion.v1_21_5, b -> b
.to(ProtocolVersion.v1_21_6, ItemRegistrations::registerItemPackets1_21_5)
.since(ItemRegistrations::registerItemPackets1_21_6)
)
.ranges(BlockRegistrations::block, ProtocolVersion.v1_13, steps -> steps
.to(ProtocolVersion.v1_14_4, BlockRegistrations::registerBlockPackets1_13)
.to(ProtocolVersion.v1_16_2, BlockRegistrations::registerBlockPackets1_14_4)
.to(ProtocolVersion.v1_18, BlockRegistrations::registerBlockPackets1_16_2)
.to(ProtocolVersion.v1_19, BlockRegistrations::registerBlockPackets1_18)
.to(ProtocolVersion.v1_20, BlockRegistrations::registerBlockPackets1_19)
.to(ProtocolVersion.v1_21, BlockRegistrations::registerBlockPackets1_20)
.since(BlockRegistrations::registerBlockPackets1_21)
)
.ranges(ParticleRegistrations::particle, ProtocolVersion.v1_13, steps -> steps
.to(ProtocolVersion.v1_15_2, ParticleRegistrations::registerParticlePackets1_13)
.to(ProtocolVersion.v1_19, ParticleRegistrations::registerParticlePackets1_15_2)
.to(ProtocolVersion.v1_20, ParticleRegistrations::registerParticlePackets1_19)
.to(ProtocolVersion.v1_20_5, ParticleRegistrations::registerParticlePackets1_20)
.to(ProtocolVersion.v1_21_2, ParticleRegistrations::registerParticlePackets1_20_5)
.to(ProtocolVersion.v1_21_4, ParticleRegistrations::registerParticlePackets1_21_2)
.to(ProtocolVersion.v1_21_9, ParticleRegistrations::registerParticlePackets1_21_4)
.since(ParticleRegistrations::registerParticlePackets1_21_9)
)
.ranges(TextComponentRegistrations::text, ProtocolVersion.v1_12_2, b -> b
.to(ProtocolVersion.v1_14, TextComponentRegistrations::registerComponents1_12_2)
.to(ProtocolVersion.v1_16_2, TextComponentRegistrations::registerComponents1_14)
.to(ProtocolVersion.v1_17, TextComponentRegistrations::registerComponents1_16_2)
.to(ProtocolVersion.v1_19, TextComponentRegistrations::registerComponents1_17)
.to(ProtocolVersion.v1_20_3, TextComponentRegistrations::registerComponents1_19)
.to(ProtocolVersion.v1_20_5, TextComponentRegistrations::registerComponents1_20_3)
.to(ProtocolVersion.v1_21, TextComponentRegistrations::registerComponents1_20_5)
.to(ProtocolVersion.v1_21_4, TextComponentRegistrations::registerComponents1_21)
.to(ProtocolVersion.v1_21_5, TextComponentRegistrations::registerComponents1_21_4)
)
.ranges(TextComponentRegistrations::nbtText, ProtocolVersion.v1_21_5, b -> b
.since(TextComponentRegistrations::registerComponents1_21_5)
)
.ranges(ProtocolVersion.v1_17_1, sbeps -> sbeps
.to(ProtocolVersion.v1_20_2, RegistryRegistrations::registerTags1_17_1)
.since(RegistryRegistrations::registerTags1_20_2)
)
.ranges(ProtocolVersion.v1_10, b -> b
.to(ProtocolVersion.v1_14, RegistryRegistrations::registerSounds1_10)
.to(ProtocolVersion.v1_19_3, RegistryRegistrations::registerSounds1_14)
.since(RegistryRegistrations::registerSounds1_19_3)
)
.since(ProtocolVersion.v1_13, RegistryRegistrations::registerStatistics1_13)
.since(ProtocolVersion.v1_19, RegistryRegistrations::registerCommands1_19)
.since(ProtocolVersion.v1_20_2, ConfigurationRegistrations::registerConfigurationStateSwitching)
.since(ProtocolVersion.v1_21, RegistryRegistrations::registerRegistryData1_21)
.since(ProtocolVersion.v1_21, RegistryRegistrations::registerAttributes1_21)
.since(ProtocolVersion.v1_21_2, RegistryRegistrations::registerRecipePackets1_21_2)
.register();
}
}
@@ -0,0 +1,91 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.protocol.shared_registration.PacketBound;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundPackets1_21_9;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
final class EntityRegistrations {
static <CU extends ClientboundPacketType> void registerEntityPackets1_13(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
ctx.clientbound(ClientboundPackets1_13.REMOVE_ENTITIES, er::registerRemoveEntities);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_14_4(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
ctx.clientbound(ClientboundPackets1_14_4.REMOVE_ENTITIES, er::registerRemoveEntities);
ctx.clientbound(ClientboundPackets1_14_4.ADD_ENTITY, er::registerTrackerWithData);
ctx.clientbound(ClientboundPackets1_14_4.ADD_MOB, er::registerTracker);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_16_2(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
// remove_entities got temporarily changed to only take a single entity...
ctx.clientbound(ClientboundPackets1_14_4.ADD_ENTITY, er::registerTrackerWithData);
ctx.clientbound(ClientboundPackets1_14_4.ADD_MOB, er::registerTracker);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_17_1(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
ctx.clientbound(ClientboundPackets1_14_4.REMOVE_ENTITIES, er::registerRemoveEntities);
ctx.clientbound(ClientboundPackets1_14_4.ADD_ENTITY, er::registerTrackerWithData);
ctx.clientbound(ClientboundPackets1_14_4.ADD_MOB, er::registerTracker, PacketBound.REMOVED_AT_MAX);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_19(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
ctx.clientbound(ClientboundPackets1_9.REMOVE_ENTITIES, er::registerRemoveEntities);
ctx.clientbound(ClientboundPackets1_19.ADD_ENTITY, er::registerTrackerWithData1_19);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_20_5(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
common1_20_5(ctx, er);
ctx.clientbound(ClientboundPackets1_19.ADD_ENTITY, er::registerTrackerWithData1_19);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_21_4(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
common1_20_5(ctx, er);
ctx.clientbound(ClientboundPackets1_21_2.ADD_ENTITY, er::registerTrackerWithData1_19);
}
static <CU extends ClientboundPacketType> void registerEntityPackets1_21_9(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
common1_20_5(ctx, er);
ctx.clientbound(ClientboundPackets1_21_9.ADD_ENTITY, er::registerTrackerWithData1_21_9);
}
private static <CU extends ClientboundPacketType> void common1_20_5(final RegistrationContext<CU, ?> ctx, final EntityRewriter<CU, ?> er) {
ctx.clientbound(ClientboundPackets1_20_5.SET_ENTITY_DATA, er::registerSetEntityData);
ctx.clientbound(ClientboundPackets1_20_5.REMOVE_ENTITIES, er::registerRemoveEntities);
ctx.clientbound(ClientboundPackets1_20_5.LOGIN, er::registerLogin1_20_5);
ctx.clientbound(ClientboundPackets1_20_5.RESPAWN, er::registerRespawn1_20_5);
ctx.clientbound(ClientboundPackets1_20_5.GAME_EVENT, er::registerGameEvent);
ctx.clientbound(ClientboundPackets1_20_5.PLAYER_ABILITIES, er::registerPlayerAbilities);
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> EntityRewriter<CU, ?> entity(final RegistrationContext<CU, SU> ctx) {
return (EntityRewriter<CU, ?>) ctx.protocol().getEntityRewriter();
}
}
@@ -0,0 +1,185 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.protocol.shared_registration.PacketBound;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_16_4to1_17.packet.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.v1_17to1_17_1.packet.ClientboundPackets1_17_1;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ServerboundPackets1_19_3;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.packet.ClientboundPackets1_21_5;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.packet.ServerboundPackets1_21_5;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundConfigurationPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
final class ItemRegistrations {
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_13(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
common1_13(ctx, ir);
ctx.clientbound(ClientboundPackets1_13.SET_EQUIPPED_ITEM, ir::registerSetEquippedItem);
}
private static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void common1_13(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_13.CONTAINER_SET_DATA, ir::registerContainerSetData);
ctx.clientbound(ClientboundPackets1_13.CONTAINER_SET_SLOT, ir::registerSetSlot);
ctx.clientbound(ClientboundPackets1_13.CONTAINER_SET_CONTENT, ir::registerSetContent);
ctx.clientbound(ClientboundPackets1_13.UPDATE_ADVANCEMENTS, ir::registerAdvancements);
ctx.clientbound(ClientboundPackets1_13.COOLDOWN, ir::registerCooldown);
ctx.serverbound(ServerboundPackets1_13.CONTAINER_CLICK, ir::registerContainerClick);
ctx.serverbound(ServerboundPackets1_13.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_14(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
common1_13(ctx, ir);
ctx.clientbound(ClientboundPackets1_14.SET_EQUIPPED_ITEM, ir::registerSetEquippedItem);
ctx.clientbound(ClientboundPackets1_14.OPEN_SCREEN, ir::registerOpenScreen);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_14_4(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
common1_13(ctx, ir);
ctx.clientbound(ClientboundPackets1_14_4.SET_EQUIPPED_ITEM, ir::registerSetEquippedItem, PacketBound.REMOVED_AT_MAX);
ctx.clientbound(ClientboundPackets1_14_4.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_14_4.MERCHANT_OFFERS, ir::registerMerchantOffers1_14_4);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_16(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
common1_13(ctx, ir);
ctx.clientbound(ClientboundPackets1_16.SET_EQUIPMENT, ir::registerSetEquipment, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_16.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_16.MERCHANT_OFFERS, ir::registerMerchantOffers1_14_4);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_17_1(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_17_1.CONTAINER_SET_DATA, ir::registerContainerSetData);
ctx.clientbound(ClientboundPackets1_17_1.CONTAINER_SET_SLOT, ir::registerSetSlot1_17_1);
ctx.clientbound(ClientboundPackets1_17_1.CONTAINER_SET_CONTENT, ir::registerSetContent1_17_1);
ctx.clientbound(ClientboundPackets1_17_1.UPDATE_ADVANCEMENTS, ir::registerAdvancements);
ctx.clientbound(ClientboundPackets1_17_1.COOLDOWN, ir::registerCooldown);
ctx.serverbound(ServerboundPackets1_17.CONTAINER_CLICK, ir::registerContainerClick1_17_1);
ctx.serverbound(ServerboundPackets1_17.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot);
ctx.clientbound(ClientboundPackets1_17_1.SET_EQUIPMENT, ir::registerSetEquipment);
ctx.clientbound(ClientboundPackets1_17_1.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_17_1.MERCHANT_OFFERS, ir::registerMerchantOffers1_14_4);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_19_1(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_19_1.CONTAINER_SET_DATA, ir::registerContainerSetData);
ctx.clientbound(ClientboundPackets1_19_1.CONTAINER_SET_SLOT, ir::registerSetSlot1_17_1);
ctx.clientbound(ClientboundPackets1_19_1.CONTAINER_SET_CONTENT, ir::registerSetContent1_17_1);
ctx.clientbound(ClientboundPackets1_19_1.UPDATE_ADVANCEMENTS, ir::registerAdvancements);
ctx.clientbound(ClientboundPackets1_19_1.COOLDOWN, ir::registerCooldown);
ctx.serverbound(ServerboundPackets1_19_3.CONTAINER_CLICK, ir::registerContainerClick1_17_1);
ctx.serverbound(ServerboundPackets1_19_3.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot);
ctx.clientbound(ClientboundPackets1_19_1.SET_EQUIPMENT, ir::registerSetEquipment);
ctx.clientbound(ClientboundPackets1_19_1.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_19_1.MERCHANT_OFFERS, ir::registerMerchantOffers1_19);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_20_3(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_20_3.CONTAINER_SET_DATA, ir::registerContainerSetData);
ctx.clientbound(ClientboundPackets1_20_3.CONTAINER_SET_SLOT, ir::registerSetSlot1_17_1);
ctx.clientbound(ClientboundPackets1_20_3.CONTAINER_SET_CONTENT, ir::registerSetContent1_17_1);
ctx.clientbound(ClientboundPackets1_20_5.UPDATE_ADVANCEMENTS, ir::registerAdvancements1_20_3);
ctx.clientbound(ClientboundPackets1_20_3.COOLDOWN, ir::registerCooldown);
ctx.serverbound(ServerboundPackets1_20_3.CONTAINER_CLICK, ir::registerContainerClick1_17_1);
ctx.serverbound(ServerboundPackets1_20_2.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot);
ctx.clientbound(ClientboundPackets1_20_5.SET_EQUIPMENT, ir::registerSetEquipment);
ctx.clientbound(ClientboundPackets1_19_4.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_20_2.MERCHANT_OFFERS, ir::registerMerchantOffers1_19);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_20_5(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_20_3.CONTAINER_SET_DATA, ir::registerContainerSetData);
registerItemPackets1_21(ctx, ir);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_21(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_21.CONTAINER_SET_SLOT, ir::registerSetSlot1_17_1);
ctx.clientbound(ClientboundPackets1_21.CONTAINER_SET_CONTENT, ir::registerSetContent1_17_1);
ctx.clientbound(ClientboundPackets1_21.UPDATE_ADVANCEMENTS, ir::registerAdvancements1_20_3);
ctx.clientbound(ClientboundPackets1_21.COOLDOWN, ir::registerCooldown);
ctx.serverbound(ServerboundPackets1_20_5.CONTAINER_CLICK, ir::registerContainerClick1_17_1);
ctx.serverbound(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot1_20_5);
ctx.clientbound(ClientboundPackets1_21.SET_EQUIPMENT, ir::registerSetEquipment);
ctx.clientbound(ClientboundPackets1_21.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_21.MERCHANT_OFFERS, ir::registerMerchantOffers1_20_5);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_21_2(final RegistrationContext<CU, SU> ctx, final ItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_21_2.CONTAINER_SET_SLOT, ir::registerSetSlot1_21_2);
ctx.clientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, ir::registerSetContent1_21_2);
ctx.clientbound(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS, ir::registerAdvancements1_20_3);
ctx.clientbound(ClientboundPackets1_21_2.COOLDOWN, ir::registerCooldown1_21_2);
ctx.serverbound(ServerboundPackets1_21_2.CONTAINER_CLICK, ir::registerContainerClick1_21_2);
ctx.serverbound(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot1_20_5);
ctx.clientbound(ClientboundPackets1_21_2.SET_EQUIPMENT, ir::registerSetEquipment);
ctx.clientbound(ClientboundPackets1_21_2.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_21_2.MERCHANT_OFFERS, ir::registerMerchantOffers1_20_5);
ctx.clientbound(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY, ir::registerSetPlayerInventory, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, ir::registerSetCursorItem, PacketBound.ADDED_AT_MIN);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_21_5(final RegistrationContext<CU, SU> ctx, final StructuredItemRewriter<CU, SU, ?> ir) {
ctx.clientbound(ClientboundPackets1_21_5.CONTAINER_SET_SLOT, ir::registerSetSlot1_21_2);
ctx.clientbound(ClientboundPackets1_21_5.CONTAINER_SET_CONTENT, ir::registerSetContent1_21_2);
ctx.clientbound(ClientboundPackets1_21_5.UPDATE_ADVANCEMENTS, ir::registerAdvancements1_20_3);
ctx.clientbound(ClientboundPackets1_21_5.COOLDOWN, ir::registerCooldown1_21_2);
ctx.serverbound(ServerboundPackets1_21_5.CONTAINER_CLICK, ir::registerContainerClick1_21_5);
ctx.serverbound(ServerboundPackets1_21_5.SET_CREATIVE_MODE_SLOT, ir::registerSetCreativeModeSlot1_21_5);
ctx.clientbound(ClientboundPackets1_21_5.SET_EQUIPMENT, ir::registerSetEquipment);
ctx.clientbound(ClientboundPackets1_21_5.OPEN_SCREEN, ir::registerOpenScreen);
ctx.clientbound(ClientboundPackets1_21_5.MERCHANT_OFFERS, ir::registerMerchantOffers1_20_5);
ctx.clientbound(ClientboundPackets1_21_5.SET_PLAYER_INVENTORY, ir::registerSetPlayerInventory);
ctx.clientbound(ClientboundPackets1_21_5.SET_CURSOR_ITEM, ir::registerSetCursorItem);
}
static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerItemPackets1_21_6(final RegistrationContext<CU, SU> ctx, final StructuredItemRewriter<CU, SU, ?> ir) {
registerItemPackets1_21_5(ctx, ir);
ctx.clientbound(ClientboundPackets1_21_6.SHOW_DIALOG, ir::registerShowDialog, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundConfigurationPackets1_21_6.SHOW_DIALOG, ir::registerShowDialogDirect, PacketBound.ADDED_AT_MIN);
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> ItemRewriter<CU, SU, ?> item(final RegistrationContext<CU, SU> ctx) {
return (ItemRewriter<CU, SU, ?>) ctx.protocol().getItemRewriter();
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> StructuredItemRewriter<CU, SU, ?> structuredItem(final RegistrationContext<CU, SU> ctx) {
return (StructuredItemRewriter<CU, SU, ?>) ctx.protocol().getItemRewriter();
}
}
@@ -0,0 +1,74 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundPackets1_21_9;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.ParticleRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
final class ParticleRegistrations {
static <CU extends ClientboundPacketType> void registerParticlePackets1_13(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_13.LEVEL_PARTICLES, type -> pr.registerLevelParticles1_13(type, Types.FLOAT));
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_15_2(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_15.LEVEL_PARTICLES, type -> pr.registerLevelParticles1_13(type, Types.DOUBLE));
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_19(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_19.LEVEL_PARTICLES, pr::registerLevelParticles1_19);
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_20(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_19.LEVEL_PARTICLES, pr::registerLevelParticles1_19);
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_20_5(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_20_5.LEVEL_PARTICLES, pr::registerLevelParticles1_20_5);
ctx.clientbound(ClientboundPackets1_20_5.EXPLODE, pr::registerExplode1_20_5);
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_21_2(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_21_2.LEVEL_PARTICLES, pr::registerLevelParticles1_20_5);
ctx.clientbound(ClientboundPackets1_21_2.EXPLODE, pr::registerExplode1_21_2);
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_21_4(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_21_2.LEVEL_PARTICLES, pr::registerLevelParticles1_21_4);
ctx.clientbound(ClientboundPackets1_21_2.EXPLODE, pr::registerExplode1_21_2);
}
static <CU extends ClientboundPacketType> void registerParticlePackets1_21_9(final RegistrationContext<CU, ?> ctx, final ParticleRewriter<CU> pr) {
ctx.clientbound(ClientboundPackets1_21_9.LEVEL_PARTICLES, pr::registerLevelParticles1_21_4);
ctx.clientbound(ClientboundPackets1_21_9.EXPLODE, pr::registerExplode1_21_9);
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> ParticleRewriter<CU> particle(final RegistrationContext<CU, SU> ctx) {
return (ParticleRewriter<CU>) ctx.protocol().getParticleRewriter();
}
}
@@ -0,0 +1,105 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.protocol.shared_registration.PacketBound;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_17to1_17_1.packet.ClientboundPackets1_17_1;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ClientboundPackets1_19_3;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.rewriter.CommandRewriter1_19_4;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.AttributeRewriter;
import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
final class RegistryRegistrations {
static <CU extends ClientboundPacketType> void registerTags1_17_1(final RegistrationContext<CU, ?> ctx) {
if (ctx.protocol().getTagRewriter() instanceof final TagRewriter tagRewriter) {
ctx.clientbound(ClientboundPackets1_17_1.UPDATE_TAGS, tagRewriter::registerGeneric);
}
}
static <CU extends ClientboundPacketType> void registerTags1_20_2(final RegistrationContext<CU, ?> ctx) {
if (ctx.protocol().getTagRewriter() instanceof final TagRewriter tagRewriter) {
ctx.clientbound(ClientboundPackets1_20_2.UPDATE_TAGS, tagRewriter::registerGeneric);
ctx.clientbound(ClientboundConfigurationPackets1_20_2.UPDATE_TAGS, tagRewriter::registerGeneric, PacketBound.ADDED_AT_MIN);
}
}
static <CU extends ClientboundPacketType> void registerRegistryData1_21(final RegistrationContext<CU, ?> ctx) {
if (ctx.protocol().getRegistryDataRewriter() == null) return;
ctx.clientboundHandler(ClientboundConfigurationPackets1_21.REGISTRY_DATA, ctx.protocol().getRegistryDataRewriter()::handle);
}
static <CU extends ClientboundPacketType> void registerRecipePackets1_21_2(final RegistrationContext<CU, ?> ctx) {
final RecipeDisplayRewriter<CU> rr = ctx.protocol().getRecipeRewriter();
if (rr == null) return;
ctx.clientbound(ClientboundPackets1_21_2.UPDATE_RECIPES, rr::registerUpdateRecipes);
ctx.clientbound(ClientboundPackets1_21_2.RECIPE_BOOK_ADD, rr::registerRecipeBookAdd, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, rr::registerPlaceGhostRecipe);
}
static <CU extends ClientboundPacketType> void registerStatistics1_13(final RegistrationContext<CU, ?> ctx) {
ctx.clientbound(ClientboundPackets1_13.AWARD_STATS, new StatisticsRewriter<>(ctx.protocol())::register);
}
static <CU extends ClientboundPacketType> void registerSounds1_10(final RegistrationContext<CU, ?> ctx) {
ctx.clientbound(ClientboundPackets1_9_3.SOUND, new SoundRewriter<>(ctx.protocol())::registerSound);
}
static <CU extends ClientboundPacketType> void registerSounds1_14(final RegistrationContext<CU, ?> ctx) {
final SoundRewriter<CU> sr = new SoundRewriter<>(ctx.protocol());
ctx.clientbound(ClientboundPackets1_14.SOUND, sr::registerSound);
ctx.clientbound(ClientboundPackets1_14.SOUND_ENTITY, sr::registerSound, PacketBound.ADDED_AT_MIN);
}
static <CU extends ClientboundPacketType> void registerSounds1_19_3(final RegistrationContext<CU, ?> ctx) {
final SoundRewriter<CU> sr = new SoundRewriter<>(ctx.protocol());
ctx.clientbound(ClientboundPackets1_19_3.SOUND, sr::registerSound1_19_3);
ctx.clientbound(ClientboundPackets1_19_3.SOUND_ENTITY, sr::registerSound1_19_3);
}
static <CU extends ClientboundPacketType> void registerCommands1_19(final RegistrationContext<CU, ?> ctx) {
if ((ctx.protocol().getMappingData() != null && !Mappings.isIntIdIdentity(ctx.protocol().getMappingData().getArgumentTypeMappings()))
|| ctx.protocol().getRegistryDataRewriter() != null) {
ctx.clientbound(ClientboundPackets1_19_3.COMMANDS, new CommandRewriter1_19_4<>(ctx.protocol())::registerDeclareCommands1_19);
}
}
static <CU extends ClientboundPacketType> void registerAttributes1_21(final RegistrationContext<CU, ?> ctx) {
ctx.clientbound(ClientboundPackets1_21.UPDATE_ATTRIBUTES, new AttributeRewriter<>(ctx.protocol())::register1_21);
}
}
@@ -0,0 +1,194 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def;
import com.viaversion.viaversion.api.minecraft.item.data.ChatType;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocol.shared_registration.PacketBound;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_17to1_17_1.packet.ClientboundPackets1_17_1;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.packet.ClientboundPackets1_21_5;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
import com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter;
import com.viaversion.viaversion.rewriter.text.NBTComponentRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
final class TextComponentRegistrations {
static <CU extends ClientboundPacketType> void registerComponents1_12_2(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
ctx.clientbound(ClientboundPackets1_12_1.CHAT, cr::registerComponentPacket);
registerCombatAndTitle1_12_2(ctx, cr);
registerComponentsFrom1_12_2(ctx, cr);
}
static <CU extends ClientboundPacketType> void registerComponents1_14(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
ctx.clientbound(ClientboundPackets1_12_1.CHAT, cr::registerComponentPacket);
registerCombatAndTitle1_12_2(ctx, cr);
registerComponentsFrom1_12_2(ctx, cr);
ctx.clientbound(ClientboundPackets1_16_2.SET_OBJECTIVE, cr::registerSetObjective);
ctx.clientbound(ClientboundPackets1_16_2.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
}
static <CU extends ClientboundPacketType> void registerComponents1_16_2(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
ctx.clientbound(ClientboundPackets1_16.CHAT, cr::registerComponentPacket);
registerComponentsFrom1_12_2(ctx, cr);
ctx.clientbound(ClientboundPackets1_16_2.SET_OBJECTIVE, cr::registerSetObjective);
ctx.clientbound(ClientboundPackets1_16_2.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
if (!(cr instanceof final JsonNBTComponentRewriter<CU> jcr)) return;
ctx.clientbound(ClientboundPackets1_12_1.PLAYER_COMBAT, jcr::registerPlayerCombat, PacketBound.REMOVED_AT_MAX);
ctx.clientbound(ClientboundPackets1_12_1.SET_TITLES, jcr::registerTitle, PacketBound.REMOVED_AT_MAX);
}
static <CU extends ClientboundPacketType> void registerComponents1_17(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
ctx.clientbound(ClientboundPackets1_16.CHAT, cr::registerComponentPacket, PacketBound.REMOVED_AT_MAX);
registerComponentsFrom1_12_2(ctx, cr);
ctx.clientbound(ClientboundPackets1_17_1.SET_ACTION_BAR_TEXT, cr::registerComponentPacket, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_17_1.SET_TITLE_TEXT, cr::registerComponentPacket, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_17_1.SET_SUBTITLE_TEXT, cr::registerComponentPacket, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_16_2.SET_OBJECTIVE, cr::registerSetObjective);
if (cr instanceof final JsonNBTComponentRewriter<CU> jcr) {
ctx.clientbound(ClientboundPackets1_17_1.PLAYER_COMBAT_KILL, jcr::registerPlayerCombatKill, PacketBound.ADDED_AT_MIN);
}
ctx.clientbound(ClientboundPackets1_16_2.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
}
static <CU extends ClientboundPacketType> void registerComponents1_19(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
registerComponentsFrom1_12_2(ctx, cr);
registerActionBarTitleSubtitle1_17_1(ctx, cr);
ctx.clientbound(ClientboundPackets1_16_2.SET_OBJECTIVE, cr::registerSetObjective);
if (cr instanceof final JsonNBTComponentRewriter<CU> jcr) {
ctx.clientbound(ClientboundPackets1_17_1.PLAYER_COMBAT_KILL, jcr::registerPlayerCombatKill);
}
ctx.clientbound(ClientboundPackets1_16_2.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
ctx.clientbound(ClientboundPackets1_19.SYSTEM_CHAT, cr::registerComponentPacket, PacketBound.ADDED_AT_MIN);
ctx.clientbound(ClientboundPackets1_19.SERVER_DATA, cr::registerComponentPacket, PacketBound.ADDED_AT_MIN);
}
static <CU extends ClientboundPacketType> void registerComponents1_20_3(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
registerComponentsFrom1_12_2(ctx, cr);
registerActionBarTitleSubtitle1_17_1(ctx, cr);
ctx.clientbound(ClientboundPackets1_16_2.SET_OBJECTIVE, cr::registerSetObjective);
ctx.clientbound(ClientboundPackets1_19_1.SYSTEM_CHAT, cr::registerComponentPacket);
ctx.clientbound(ClientboundConfigurationPackets1_20_3.DISCONNECT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_3.DISGUISED_CHAT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_3.SET_SCORE, cr::registerSetScore1_20_3);
ctx.clientbound(ClientboundPackets1_20_3.PLAYER_COMBAT_KILL, cr::registerPlayerCombatKill1_20);
ctx.clientbound(ClientboundPackets1_20_5.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
ctx.clientbound(ClientboundPackets1_19.SERVER_DATA, cr::registerComponentPacket);
if (cr instanceof final JsonNBTComponentRewriter<CU> jcr) {
ctx.clientbound(ClientboundPackets1_20_3.PLAYER_CHAT, cu -> jcr.registerPlayerChat(cu, Types.VAR_INT));
ctx.clientbound(ClientboundPackets1_20_3.PLAYER_INFO_UPDATE, jcr::registerPlayerInfoUpdate1_20_3);
}
}
static <CU extends ClientboundPacketType> void registerCombatAndTitle1_12_2(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
if (!(cr instanceof final JsonNBTComponentRewriter<CU> jcr)) return;
ctx.clientbound(ClientboundPackets1_12_1.PLAYER_COMBAT, jcr::registerPlayerCombat);
ctx.clientbound(ClientboundPackets1_12_1.SET_TITLES, jcr::registerTitle);
}
private static <CU extends ClientboundPacketType> void registerComponentsFrom1_12_2(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
// not including set_score, player_info, update_advancements, and open_screen
ctx.clientbound(ClientboundPackets1_12_1.BOSS_EVENT, cr::registerBossEvent);
ctx.clientbound(ClientboundPackets1_12_1.DISCONNECT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_12_1.TAB_LIST, cr::registerTabList);
cr.registerLoginDisconnect();
}
static <CU extends ClientboundPacketType> void registerActionBarTitleSubtitle1_17_1(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
ctx.clientbound(ClientboundPackets1_17_1.SET_ACTION_BAR_TEXT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_17_1.SET_TITLE_TEXT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_17_1.SET_SUBTITLE_TEXT, cr::registerComponentPacket);
}
static <CU extends ClientboundPacketType> void registerComponents1_20_5(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
common1_20_5(ctx, cr);
ctx.clientbound(ClientboundPackets1_20_5.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
ctx.clientbound(ClientboundPackets1_20_5.DISGUISED_CHAT, cr::registerComponentPacket);
if (cr instanceof final JsonNBTComponentRewriter<CU> jcr) {
ctx.clientbound(ClientboundPackets1_20_5.PLAYER_CHAT, cu -> jcr.registerPlayerChat(cu, Types.VAR_INT));
ctx.clientbound(ClientboundPackets1_20_5.PLAYER_INFO_UPDATE, jcr::registerPlayerInfoUpdate1_20_3);
}
}
private static <CU extends ClientboundPacketType> void common1_20_5(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
ctx.clientbound(ClientboundConfigurationPackets1_20_5.DISCONNECT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_5.DISCONNECT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_5.SET_ACTION_BAR_TEXT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_5.SET_TITLE_TEXT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_5.SET_SUBTITLE_TEXT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_5.BOSS_EVENT, cr::registerBossEvent);
ctx.clientbound(ClientboundPackets1_20_5.TAB_LIST, cr::registerTabList);
ctx.clientbound(ClientboundPackets1_20_5.SET_OBJECTIVE, cr::registerSetObjective);
ctx.clientbound(ClientboundPackets1_20_5.SET_SCORE, cr::registerSetScore1_20_3);
ctx.clientbound(ClientboundPackets1_20_5.SYSTEM_CHAT, cr::registerComponentPacket);
ctx.clientbound(ClientboundPackets1_20_5.PLAYER_COMBAT_KILL, cr::registerPlayerCombatKill1_20);
ctx.clientbound(ClientboundPackets1_20_5.SERVER_DATA, cr::registerComponentPacket);
cr.registerLoginDisconnect();
}
static <CU extends ClientboundPacketType> void registerComponents1_21(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
common1_20_5(ctx, cr);
ctx.clientbound(ClientboundPackets1_21.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
ctx.clientbound(ClientboundPackets1_21.DISGUISED_CHAT, cr::registerDisguisedChat);
if (cr instanceof final JsonNBTComponentRewriter<CU> jcr) {
ctx.clientbound(ClientboundPackets1_21.PLAYER_CHAT, cu -> jcr.registerPlayerChat(cu, ChatType.TYPE));
ctx.clientbound(ClientboundPackets1_21.PLAYER_INFO_UPDATE, jcr::registerPlayerInfoUpdate1_20_3);
}
}
static <CU extends ClientboundPacketType> void registerComponents1_21_4(final RegistrationContext<CU, ?> ctx, final ComponentRewriterBase<CU> cr) {
common1_20_5(ctx, cr);
ctx.clientbound(ClientboundPackets1_21_2.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_13);
ctx.clientbound(ClientboundPackets1_21_2.DISGUISED_CHAT, cr::registerDisguisedChat);
ctx.clientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, cr::registerPlayerInfoUpdate1_21_4);
if (cr instanceof final JsonNBTComponentRewriter<CU> jcr) {
ctx.clientbound(ClientboundPackets1_21_2.PLAYER_CHAT, cu -> jcr.registerPlayerChat(cu, ChatType.TYPE));
}
}
static <CU extends ClientboundPacketType> void registerComponents1_21_5(final RegistrationContext<CU, ?> ctx, final NBTComponentRewriter<CU> cr) {
common1_20_5(ctx, cr);
ctx.clientbound(ClientboundPackets1_21_5.SET_PLAYER_TEAM, cr::registerSetPlayerTeam1_21_5);
ctx.clientbound(ClientboundPackets1_21_5.DISGUISED_CHAT, cr::registerDisguisedChat);
ctx.clientbound(ClientboundPackets1_21_5.PLAYER_INFO_UPDATE, cr::registerPlayerInfoUpdate1_21_4);
ctx.clientbound(ClientboundPackets1_21_5.PLAYER_CHAT, cr::registerPlayerChat1_21_5);
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> ComponentRewriterBase<CU> text(final RegistrationContext<CU, SU> ctx) {
return (ComponentRewriterBase<CU>) ctx.protocol().getComponentRewriter();
}
static @Nullable <CU extends ClientboundPacketType, SU extends ServerboundPacketType> NBTComponentRewriter<CU> nbtText(final RegistrationContext<CU, SU> ctx) {
return (NBTComponentRewriter<CU>) ctx.protocol().getComponentRewriter();
}
}
@@ -0,0 +1,66 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocol.shared_registration.def.base;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.rewriter.RegistryDataRewriter;
import com.viaversion.viaversion.protocol.shared_registration.PacketBound;
import com.viaversion.viaversion.protocol.shared_registration.RegistrationContext;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2;
public final class ConfigurationRegistrations {
public static <CU extends ClientboundPacketType, SU extends ServerboundPacketType> void registerConfigurationStateSwitching(final RegistrationContext<CU, SU> ctx) {
ctx.serverbound(ServerboundPackets1_20_2.CONFIGURATION_ACKNOWLEDGED,
packetType -> ctx.protocol().registerServerbound(packetType, wrapper -> wrapper.user().getProtocolInfo().setClientState(State.CONFIGURATION)),
PacketBound.ADDED_AT_MIN
);
ctx.clientbound(ClientboundPackets1_20_2.START_CONFIGURATION, packetType -> ctx.protocol().registerClientbound(packetType, wrapper -> {
wrapper.user().getProtocolInfo().setServerState(State.CONFIGURATION);
// Mimic client behaviour by resetting tracked entities when configuration starts.
final EntityTracker tracker = wrapper.user().getEntityTracker(ctx.protocol().getClass());
if (tracker != null) {
tracker.clear();
}
}), PacketBound.ADDED_AT_MIN);
ctx.serverbound(ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION,
packetType -> ctx.protocol().registerServerbound(packetType, wrapper -> wrapper.user().getProtocolInfo().setClientState(State.PLAY)),
PacketBound.ADDED_AT_MIN
);
ctx.clientbound(ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION, packetType -> ctx.protocol().registerClientbound(packetType, wrapper -> {
final RegistryDataRewriter registryDataRewriter = ctx.protocol().getRegistryDataRewriter();
if (registryDataRewriter != null) {
registryDataRewriter.sendMissingRegistries(wrapper.user());
}
wrapper.user().getProtocolInfo().setServerState(State.PLAY);
}),
PacketBound.ADDED_AT_MIN
);
}
}
Loaded 100 of 239 files, more files were not shown because too many files have changed in this diff. Show more