mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2026-11-04 17:00:16 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aecd74425d | ||
|
|
53584b01f7 | ||
|
|
7f97ae80c3 | ||
|
|
4dd4b2f53b | ||
|
|
8a9cc8bd9b | ||
|
|
9e3861fb21 | ||
|
|
b74ac19d9d | ||
|
|
4cca914c5d | ||
|
|
fa90711056 | ||
|
|
d5d4073857 | ||
|
|
b8e0b39eeb | ||
|
|
6ec175dff2 | ||
|
|
9bd1785886 | ||
|
|
9fabc4b11e | ||
|
|
3969186439 | ||
|
|
422826a9b8 | ||
|
|
ddcaa78b61 | ||
|
|
d3c6065367 | ||
|
|
df5353be29 | ||
|
|
9e8e23d308 | ||
|
|
3693ec6021 | ||
|
|
0a5ba125f7 | ||
|
|
8f861f670c | ||
|
|
0f806f1016 | ||
|
|
fbba2dc81b | ||
|
|
61f537e9b9 | ||
|
|
ba84a588f1 | ||
|
|
4ec0969b45 | ||
|
|
19a04666e5 | ||
|
|
9a5e2f8e8c | ||
|
|
a33feff59b | ||
|
|
612a6b3696 | ||
|
|
b42e466248 | ||
|
|
e4ea6aa5e2 | ||
|
|
c40e092b48 | ||
|
|
46a33a42ec | ||
|
|
d31892513c | ||
|
|
e6af10a0b6 | ||
|
|
f6dcd149cb | ||
|
|
1fb2bd410f | ||
|
|
b1e667fadb | ||
|
|
7eb0522150 | ||
|
|
3f6c172d7b | ||
|
|
9e7fad2840 | ||
|
|
2f3c869f4d | ||
|
|
c6b287bfac | ||
|
|
0f59bf96c8 | ||
|
|
ca5028a7fa | ||
|
|
9740910d98 | ||
|
|
cb9907743d | ||
|
|
4617e6e416 | ||
|
|
de0c869dbb | ||
|
|
29ec02687c | ||
|
|
481b06cd2a | ||
|
|
624fb6acd4 | ||
|
|
284810f1e5 | ||
|
|
28df61e98e | ||
|
|
a1a71a160a | ||
|
|
4265866c93 | ||
|
|
b197c758b5 | ||
|
|
a38904e5c6 | ||
|
|
b214235c04 | ||
|
|
0dc7b471b8 | ||
|
|
da75e1957f | ||
|
|
9675bbd8fe | ||
|
|
f0def507fd | ||
|
|
e0430c0f45 | ||
|
|
c770c3e1fa | ||
|
|
3896a12166 | ||
|
|
563a3e518d | ||
|
|
8896528c34 | ||
|
|
8ec7c27153 | ||
|
|
5f0cb34e64 | ||
|
|
b67d7c076f | ||
|
|
5f6696f741 | ||
|
|
7b48d1bd56 | ||
|
|
b6828aa73d | ||
|
|
7711974b58 | ||
|
|
07037fd201 | ||
|
|
c6ac4542f1 | ||
|
|
1805777b6f | ||
|
|
4f6fa42f53 | ||
|
|
07272b7ab3 | ||
|
|
b3e508444d | ||
|
|
68b8481de1 | ||
|
|
402aff9656 | ||
|
|
2456b05ea6 | ||
|
|
9d5cd04d4b | ||
|
|
30499c8b30 | ||
|
|
fb328d4753 | ||
|
|
5347820c28 | ||
|
|
c4af653e42 | ||
|
|
5240487a35 | ||
|
|
276953f6cb | ||
|
|
1dfef5b97e | ||
|
|
4a9c98aa1b | ||
|
|
07e2848e5b | ||
|
|
1db6824391 | ||
|
|
82a7c9bc3d | ||
|
|
3a67be7fe5 | ||
|
|
8cb285db69 | ||
|
|
04a692022a | ||
|
|
498bec9065 | ||
|
|
ab2a407742 | ||
|
|
cfad15a9b2 | ||
|
|
2c3c62d246 | ||
|
|
d6c27add17 | ||
|
|
7b5ee01929 | ||
|
|
c7a5de1176 | ||
|
|
16aa6a51a2 | ||
|
|
562651cd9d | ||
|
|
3e8086e136 | ||
|
|
368f450e11 | ||
|
|
80b530a368 | ||
|
|
d2d1d0014f | ||
|
|
5a576d66b4 | ||
|
|
a94d06716c | ||
|
|
8af8319839 | ||
|
|
927ffaf20a | ||
|
|
31d5a98f26 | ||
|
|
b3c1266da7 | ||
|
|
0a6d143d92 | ||
|
|
b1f4a88050 | ||
|
|
4f119d26d7 | ||
|
|
afb8384319 | ||
|
|
f27c977be2 | ||
|
|
90878517db | ||
|
|
a0f2a8595e | ||
|
|
2ce11704ba | ||
|
|
0827b6f6bb | ||
|
|
1c7017a056 | ||
|
|
4d4f66a1a2 | ||
|
|
f274d643a5 | ||
|
|
c7324b1b35 | ||
|
|
c8ec145880 | ||
|
|
30d3b0d02e | ||
|
|
545365786f | ||
|
|
1b9d53af2a | ||
|
|
fd85b67a92 | ||
|
|
16eca5f6aa | ||
|
|
c57b238b86 | ||
|
|
5646d04ba9 | ||
|
|
4937ec4800 | ||
|
|
d3be34adc9 | ||
|
|
49febd1e63 | ||
|
|
8737b2b51a | ||
|
|
1876b9bb95 | ||
|
|
f2fcc9d02f | ||
|
|
d0eeae92d3 | ||
|
|
be28d0c3e8 | ||
|
|
b0276eaa7d | ||
|
|
6b690a0218 | ||
|
|
4bcc213f1b | ||
|
|
ff94019b08 | ||
|
|
681e8a2f07 | ||
|
|
5269a610d1 | ||
|
|
5cd34e6fa8 | ||
|
|
752c5fc48b | ||
|
|
a08de7ccc3 | ||
|
|
cb9179c873 | ||
|
|
904c83f341 | ||
|
|
f4253641e1 | ||
|
|
1d1e9bc040 | ||
|
|
f57f22502e | ||
|
|
b376b52ce8 | ||
|
|
36baf6ed24 | ||
|
|
733bd9aa9b | ||
|
|
66a1748573 | ||
|
|
0bac9201ac | ||
|
|
ffb98523e6 | ||
|
|
830ccce303 | ||
|
|
a5d0e4baff | ||
|
|
4066b9b52b | ||
|
|
678775ab9d | ||
|
|
db47040543 | ||
|
|
47b1508f66 | ||
|
|
6cc4990b6e | ||
|
|
d6279757bb | ||
|
|
24f67ffe80 | ||
|
|
0b3a792a51 | ||
|
|
ef2621c917 | ||
|
|
eb4d30ae73 | ||
|
|
9ca523620d | ||
|
|
4f7acf211b | ||
|
|
585ab030b5 | ||
|
|
5ce7857d49 | ||
|
|
5539ff99cb | ||
|
|
c2b5a5f545 | ||
|
|
9c3255d5a4 | ||
|
|
b03be8ecfe | ||
|
|
609205f9fd | ||
|
|
4c56605ca0 | ||
|
|
55ea81f9c7 | ||
|
|
9c2021b947 | ||
|
|
ad1b8b71a5 | ||
|
|
6a766f2467 | ||
|
|
87d05ae487 | ||
|
|
29a7b01937 | ||
|
|
bc06d9ecc1 | ||
|
|
a0d063d93e | ||
|
|
24f994ff2a | ||
|
|
f4bc485408 | ||
|
|
b4a4b540cc | ||
|
|
8add9677a8 |
No files matched your search
@@ -1,2 +1,3 @@
|
||||
github: kennytv
|
||||
patreon: kennytv
|
||||
custom: ['https://florianmichael.de/donate']
|
||||
@@ -19,10 +19,11 @@ body:
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Console Error
|
||||
label: Server/Client Error
|
||||
description: |
|
||||
If you encounter warnings/errors in your console, **paste them with https://mclo.gs/ and put the paste link here**.
|
||||
If the error is small/less than 10 lines, you may put it directly into this field.
|
||||
**Important**: If you are kicked for `Network Protocol Error` or an encoder/decoder exception, please click the `Open Report Directory` button on your client and paste the newest disconnect file contents.
|
||||
value: |
|
||||
```
|
||||
Put the mclo.gs link or text here.
|
||||
@@ -38,7 +39,7 @@ body:
|
||||
Describe the unexpected behavior.
|
||||
If you want to attach screenshots, use the comment field at the bottom of the page.
|
||||
placeholder: |
|
||||
Example: "Placing signs on 1.13.2 causes text to disappear."
|
||||
Example: "Placing signs on 1.16.5 causes text to disappear."
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -49,7 +50,7 @@ body:
|
||||
List the steps on how we can reproduce the issue. Make sure we can easily understand what you mean with each step.
|
||||
placeholder: |
|
||||
Example:
|
||||
1. Login with a 1.13.2 client
|
||||
1. Login with a 1.16.5 client
|
||||
2. Place a sign
|
||||
3. The sign text is displayed wrong
|
||||
validations:
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@@ -6,13 +6,15 @@ jobs:
|
||||
build:
|
||||
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
|
||||
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
@@ -20,4 +22,4 @@ jobs:
|
||||
java-version: 17
|
||||
check-latest: true
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
run: ./gradlew build --refresh-dependencies
|
||||
@@ -8,12 +8,14 @@ on:
|
||||
jobs:
|
||||
publish:
|
||||
if: github.repository_owner == 'ViaVersion'
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
@@ -24,4 +26,4 @@ jobs:
|
||||
env:
|
||||
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
|
||||
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
||||
run: ./gradlew build modrinth publishAllPublicationsToHangar --stacktrace
|
||||
run: ./gradlew build modrinth publishAllPublicationsToHangar --refresh-dependencies --stacktrace
|
||||
@@ -0,0 +1,16 @@
|
||||
name: Update Gradle Wrapper
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "0 0 * * 0"
|
||||
|
||||
jobs:
|
||||
update-gradle-wrapper:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Update Gradle Wrapper
|
||||
uses: gradle-update/update-gradle-wrapper-action@v2
|
||||
@@ -107,3 +107,9 @@ nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
.nb-gradle/
|
||||
|
||||
### MacOS ###
|
||||
.DS_Store
|
||||
|
||||
### Run Folder (ViaProxy) ###
|
||||
common/run/
|
||||
@@ -1,12 +1,12 @@
|
||||
# ViaBackwards
|
||||
|
||||
[](https://github.com/ViaVersion/ViaBackwards/releases)
|
||||
[](https://github.com/ViaVersion/ViaBackwards/actions)
|
||||
[](https://github.com/ViaVersion/ViaBackwards/actions)
|
||||
[](https://viaversion.com/discord)
|
||||
|
||||
**Allows older Minecraft client versions to connect to newer server versions.**
|
||||
**Allows the connection of older clients to newer server versions for Minecraft servers.**
|
||||
|
||||
Requires [ViaVersion](https://hangar.papermc.io/ViaVersion/ViaVersion) to be installed..
|
||||
Requires [ViaVersion](https://hangar.papermc.io/ViaVersion/ViaVersion) to be installed.
|
||||
|
||||
Supported Versions
|
||||
-
|
||||
@@ -14,7 +14,14 @@ As a plugin, ViaBackwards runs on servers on releases 1.10-latest. You can also
|
||||
- in **ViaFabric**, put ViaBackwards into the `mods` folder
|
||||
- in **ViaFabricPlus**, put ViaBackwards into the `ViaFabricPlus/jars` folder
|
||||
|
||||
See [HERE](https://github.com/ViaVersion) for an overview of the different Via* projects.
|
||||
See [HERE](https://viaversion.com) for an overview of the different Via* projects.
|
||||
|
||||
Snapshot support
|
||||
--------
|
||||
**ViaBackwards will only be released a few days *after* a Minecraft update** unless the protocol changes of the update were trivial. If you want early-access, usually days or even weeks before the final release, you can subscribe to either:
|
||||
- [GitHub Sponsors](https://github.com/sponsors/kennytv/sponsorships?sponsor=kennytv&tier_id=385613&preview=false) (preferred option. Use the `/verify` command on this Discord after), or alternatively
|
||||
- [Patreon](https://www.patreon.com/kennytv/membership) (see the highest tier and make sure to link Patreon to your Discord account under Settings->Connections)
|
||||
This also includes access to a private repository with the code, which will be pushed to the public repository after the given delay on a Minecraft update.
|
||||
|
||||
Releases/Dev Builds
|
||||
-
|
||||
@@ -35,7 +42,7 @@ Known issues
|
||||
1.17 will not be able to see or interact with blocks below y=0 and above y=255
|
||||
* <1.17 clients on 1.17+ servers might experience inventory desyncs on certain inventory click actions
|
||||
* Sound mappings are incomplete ([see here](https://github.com/ViaVersion/ViaBackwards/issues/326))
|
||||
* <1.19.4 clients on 1.20+ servers won't be able to use the smithing table, this can be fixed by
|
||||
* <1.19.4 clients on 1.20+ servers won't be able to use the smithing table. This can be fixed by
|
||||
installing [AxSmithing](https://github.com/ViaVersionAddons/AxSmithing)
|
||||
|
||||
Other Links
|
||||
|
||||
@@ -8,5 +8,5 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
// version must be manually kept in sync with the one in root project settings.gradle.kts
|
||||
implementation("com.github.johnrengelman", "shadow", "8.1.1")
|
||||
implementation("com.gradleup.shadow", "shadow-gradle-plugin", "8.3.6")
|
||||
}
|
||||
@@ -1,33 +1,23 @@
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import java.io.ByteArrayOutputStream
|
||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||
|
||||
fun Project.latestCommitHash(): String {
|
||||
val byteOut = ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
|
||||
standardOutput = byteOut
|
||||
}
|
||||
return byteOut.toString(Charsets.UTF_8.name()).trim()
|
||||
return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
|
||||
}
|
||||
|
||||
fun Project.latestCommitMessage(): String {
|
||||
val byteOut = ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine = listOf("git", "log", "-1", "--pretty=%B")
|
||||
standardOutput = byteOut
|
||||
}
|
||||
return byteOut.toString(Charsets.UTF_8.name()).trim()
|
||||
return runGitCommand(listOf("log", "-1", "--pretty=%B"))
|
||||
}
|
||||
|
||||
fun Project.branchName(): String {
|
||||
val byteOut = ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
standardOutput = byteOut
|
||||
}
|
||||
return byteOut.toString(Charsets.UTF_8.name()).trim()
|
||||
return runGitCommand(listOf("rev-parse", "--abbrev-ref", "HEAD"))
|
||||
}
|
||||
|
||||
fun Project.runGitCommand(args: List<String>): String {
|
||||
return providers.exec {
|
||||
commandLine = listOf("git") + args
|
||||
}.standardOutput.asBytes.get().toString(Charsets.UTF_8).trim()
|
||||
}
|
||||
|
||||
fun Project.parseMinecraftSnapshotVersion(version: String): String? {
|
||||
@@ -40,6 +30,5 @@ fun Project.parseMinecraftSnapshotVersion(version: String): String? {
|
||||
}
|
||||
|
||||
fun JavaPluginExtension.javaTarget(version: Int) {
|
||||
sourceCompatibility = JavaVersion.toVersion(version)
|
||||
targetCompatibility = JavaVersion.toVersion(version)
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(version))
|
||||
}
|
||||
@@ -5,8 +5,10 @@ plugins {
|
||||
tasks {
|
||||
// Variable replacements
|
||||
processResources {
|
||||
filesMatching(listOf("plugin.yml", "fabric.mod.json")) {
|
||||
expand("version" to project.version, "description" to project.description, "url" to "https://viaversion.com/backwards")
|
||||
val ver = project.version.toString()
|
||||
val desc = project.description
|
||||
filesMatching(listOf("plugin.yml", "META-INF/sponge_plugins.json", "fabric.mod.json")) {
|
||||
expand("version" to ver, "description" to desc)
|
||||
}
|
||||
}
|
||||
javadoc {
|
||||
@@ -22,4 +24,4 @@ tasks {
|
||||
java {
|
||||
javaTarget(17)
|
||||
withSourcesJar()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.gradle.kotlin.dsl.named
|
||||
plugins {
|
||||
id("vb.base-conventions")
|
||||
id("maven-publish")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ plugins {
|
||||
allprojects {
|
||||
group = "com.viaversion"
|
||||
version = property("projectVersion") as String // from gradle.properties
|
||||
description = "Allows older Minecraft client versions to connect to newer server versions."
|
||||
description = "Allows the connection of older clients to newer server versions for Minecraft servers."
|
||||
}
|
||||
|
||||
val main = setOf(
|
||||
@@ -15,10 +15,10 @@ val main = setOf(
|
||||
projects.viabackwardsBukkit,
|
||||
projects.viabackwardsVelocity,
|
||||
projects.viabackwardsFabric
|
||||
).map { it.dependencyProject }
|
||||
).map { it.path }
|
||||
|
||||
subprojects {
|
||||
when (this) {
|
||||
when (path) {
|
||||
in main -> plugins.apply("vb.shadow-conventions")
|
||||
else -> plugins.apply("vb.base-conventions")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -48,7 +48,10 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
private void enable() {
|
||||
@Override
|
||||
public void enable() {
|
||||
ViaBackwardsPlatform.super.enable();
|
||||
|
||||
final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion();
|
||||
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_17)) {
|
||||
new PlayerItemDropListener(this).register();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
@@ -6,6 +6,6 @@ api-version: 1.13
|
||||
folia-supported: true
|
||||
|
||||
authors: [Matsv, kennytv, Gerrygames, creeper123123321, ForceUpdate1, EnZaXD]
|
||||
website: ${url}
|
||||
website: "https://viaversion.com/backwards"
|
||||
|
||||
depend: [ViaVersion]
|
||||
@@ -24,3 +24,32 @@ dependencies {
|
||||
java {
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
// Task to quickly test/debug code changes using https://github.com/ViaVersion/ViaProxy
|
||||
// For further instructions see the ViaProxy repository README
|
||||
tasks.register<JavaExec>("runViaProxy") {
|
||||
dependsOn(tasks.shadowJar)
|
||||
|
||||
val viaProxyConfiguration = configurations.create("viaProxy")
|
||||
viaProxyConfiguration.dependencies.add(dependencies.create(rootProject.libs.viaProxy.get().copy().setTransitive(false)))
|
||||
|
||||
mainClass.set("net.raphimc.viaproxy.ViaProxy")
|
||||
classpath = viaProxyConfiguration
|
||||
workingDir = file("run")
|
||||
jvmArgs = listOf("-DskipUpdateCheck")
|
||||
|
||||
if (System.getProperty("viaproxy.gui.autoStart") != null) {
|
||||
jvmArgs("-Dviaproxy.gui.autoStart")
|
||||
}
|
||||
|
||||
doFirst {
|
||||
val jarsDir = file("$workingDir/jars")
|
||||
jarsDir.mkdirs()
|
||||
file("$jarsDir/${project.name}.jar").writeBytes(tasks.shadowJar.get().archiveFile.get().asFile.readBytes())
|
||||
}
|
||||
|
||||
doLast {
|
||||
file("$workingDir/jars/${project.name}.jar").delete()
|
||||
file("$workingDir/logs").deleteRecursively()
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -36,6 +36,8 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
||||
private boolean handlePingsAsInvAcknowledgements;
|
||||
private boolean bedrockAtY0;
|
||||
private boolean sculkShriekersToCryingObsidian;
|
||||
private boolean mapDarknessEffect;
|
||||
private boolean mapCustomModelData;
|
||||
private boolean suppressEmulationWarnings;
|
||||
|
||||
public ViaBackwardsConfig(File configFile, Logger logger) {
|
||||
@@ -57,6 +59,8 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
||||
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
|
||||
bedrockAtY0 = getBoolean("bedrock-at-y-0", false);
|
||||
sculkShriekersToCryingObsidian = getBoolean("sculk-shriekers-to-crying-obsidian", false);
|
||||
mapDarknessEffect = getBoolean("map-darkness-effect", true);
|
||||
mapCustomModelData = getBoolean("map-custom-model-data", true);
|
||||
suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false);
|
||||
}
|
||||
|
||||
@@ -100,6 +104,16 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
||||
return sculkShriekersToCryingObsidian;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mapDarknessEffect() {
|
||||
return mapDarknessEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mapCustomModelData() {
|
||||
return mapCustomModelData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean suppressEmulationWarnings() {
|
||||
return suppressEmulationWarnings;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,7 +18,7 @@
|
||||
package com.viaversion.viabackwards.api;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.TranslatableRewriter;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
@@ -66,7 +66,7 @@ public abstract class BackwardsProtocol<CU extends ClientboundPacketType, CM ext
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TranslatableRewriter<CU> getComponentRewriter() {
|
||||
public @Nullable TranslatableRewriter getComponentRewriter() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -78,6 +78,20 @@ public interface ViaBackwardsConfig extends Config {
|
||||
*/
|
||||
boolean sculkShriekerToCryingObsidian();
|
||||
|
||||
/**
|
||||
* Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean mapDarknessEffect();
|
||||
|
||||
/**
|
||||
* If enabled, 1.21.3 clients will receive the first float of 1.21.4+ custom model data as int. Disable if you handle this change yourself.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean mapCustomModelData();
|
||||
|
||||
/**
|
||||
* Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -20,7 +20,7 @@ package com.viaversion.viabackwards.api;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.ViaBackwardsConfig;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.data.TranslatableMappings;
|
||||
import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_11_1to1_11.Protocol1_11_1To1_11;
|
||||
@@ -49,11 +49,15 @@ import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_18_2to1_18.Protocol1_18_2To1_18;
|
||||
import com.viaversion.viabackwards.protocol.v1_19_3to1_19_1.Protocol1_19_3To1_19_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.Protocol1_19_4To1_19_3;
|
||||
import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.Protocol1_21_4To1_21_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_20to1_19_4.Protocol1_20To1_19_4;
|
||||
import com.viaversion.viabackwards.protocol.v1_19_1to1_19.Protocol1_19_1To1_19;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20;
|
||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
|
||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask;
|
||||
import com.viaversion.viabackwards.protocol.v1_21_5to1_21_4.Protocol1_21_5To1_21_4;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
|
||||
@@ -69,7 +73,7 @@ import java.util.logging.Logger;
|
||||
|
||||
public interface ViaBackwardsPlatform {
|
||||
|
||||
String MINIMUM_VV_VERSION = "5.0.2";
|
||||
String MINIMUM_VV_VERSION = "5.3.2";
|
||||
|
||||
/**
|
||||
* Initialize ViaBackwards.
|
||||
@@ -89,7 +93,7 @@ public interface ViaBackwardsPlatform {
|
||||
Via.getManager().getSubPlatforms().add(VersionInfo.getImplementationVersion());
|
||||
|
||||
getLogger().info("Loading translations...");
|
||||
TranslatableRewriter.loadTranslatables();
|
||||
TranslatableMappings.loadTranslatables();
|
||||
|
||||
getLogger().info("Registering protocols...");
|
||||
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
||||
@@ -141,6 +145,16 @@ public interface ViaBackwardsPlatform {
|
||||
protocolManager.registerProtocol(new Protocol1_20_5To1_20_3(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5);
|
||||
|
||||
protocolManager.registerProtocol(new Protocol1_21To1_20_5(), ProtocolVersion.v1_20_5, ProtocolVersion.v1_21);
|
||||
protocolManager.registerProtocol(new Protocol1_21_2To1_21(), ProtocolVersion.v1_21, ProtocolVersion.v1_21_2);
|
||||
protocolManager.registerProtocol(new Protocol1_21_4To1_21_2(), ProtocolVersion.v1_21_2, ProtocolVersion.v1_21_4);
|
||||
protocolManager.registerProtocol(new Protocol1_21_5To1_21_4(), ProtocolVersion.v1_21_4, ProtocolVersion.v1_21_5);
|
||||
}
|
||||
|
||||
default void enable() {
|
||||
final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion();
|
||||
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_21_2)) {
|
||||
Via.getPlatform().runRepeatingSync(new PlayerPacketsTickTask(), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+16
-40
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -15,25 +15,19 @@
|
||||
* 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.viabackwards.api.rewriters;
|
||||
package com.viaversion.viabackwards.api.data;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class TranslatableRewriter<C extends ClientboundPacketType> extends ComponentRewriter<C> {
|
||||
public final class TranslatableMappings {
|
||||
|
||||
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
|
||||
private final Map<String, String> translatables;
|
||||
|
||||
public static void loadTranslatables() {
|
||||
if (!TRANSLATABLES.isEmpty()) {
|
||||
@@ -52,42 +46,24 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
|
||||
}
|
||||
}
|
||||
|
||||
public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type) {
|
||||
this(protocol, type, protocol.getClass().getSimpleName().replace("Protocol", "").split("To")[0].replace("_", "."));
|
||||
public static Map<String, String> translatablesFor(final Protocol<?, ?, ?, ?> protocol) {
|
||||
final String version = protocol.getClass().getSimpleName()
|
||||
.replace("Protocol", "")
|
||||
.split("To")[0]
|
||||
.replace("_", ".");
|
||||
return translatablesFor(version);
|
||||
}
|
||||
|
||||
public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String version) {
|
||||
super(protocol, type);
|
||||
public static Map<String, String> translatablesFor(final String version) {
|
||||
final Map<String, String> translatableMappings = getTranslatableMappings(version);
|
||||
if (translatableMappings == null) {
|
||||
protocol.getLogger().warning("Missing " + version + " translatables!");
|
||||
this.translatables = new HashMap<>();
|
||||
} else {
|
||||
this.translatables = translatableMappings;
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing " + version + " translatables!");
|
||||
return new HashMap<>();
|
||||
}
|
||||
return translatableMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(final JsonObject root, final String translate) {
|
||||
final String newTranslate = mappedTranslationKey(translate);
|
||||
if (newTranslate != null) {
|
||||
root.addProperty("translate", newTranslate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(final UserConnection connection, final CompoundTag parentTag, final StringTag translateTag) {
|
||||
final String newTranslate = mappedTranslationKey(translateTag.getValue());
|
||||
if (newTranslate != null) {
|
||||
parentTag.put("translate", new StringTag(newTranslate));
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable String mappedTranslationKey(final String translationKey) {
|
||||
return translatables.get(translationKey);
|
||||
}
|
||||
|
||||
public static Map<String, String> getTranslatableMappings(final String sectionIdentifier) {
|
||||
public static @Nullable Map<String, String> getTranslatableMappings(final String sectionIdentifier) {
|
||||
return TRANSLATABLES.get(sectionIdentifier);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+6
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -75,7 +75,11 @@ public class EntityPositionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
positionStorage.setCoordinates(x, y, z, relative);
|
||||
if (relative) {
|
||||
positionStorage.addRelativePosition(x, y, z);
|
||||
} else {
|
||||
positionStorage.setPosition(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
public EntityPositionStorage getStorage(UserConnection user, int entityId) {
|
||||
|
||||
+11
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -34,15 +34,15 @@ public abstract class EntityPositionStorage {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setCoordinates(double x, double y, double z, boolean relative) {
|
||||
if (relative) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
} else {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public void setPosition(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void addRelativePosition(double relX, double relY, double relZ) {
|
||||
this.x += relX;
|
||||
this.y += relY;
|
||||
this.z += relZ;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+9
-15
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,8 +18,6 @@
|
||||
package com.viaversion.viabackwards.api.entities.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
public abstract class PlayerPositionStorage implements StorableObject {
|
||||
private double x;
|
||||
@@ -53,19 +51,15 @@ public abstract class PlayerPositionStorage implements StorableObject {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void setCoordinates(PacketWrapper wrapper, boolean relative) {
|
||||
setCoordinates(wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2), relative);
|
||||
public void setPosition(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void setCoordinates(double x, double y, double z, boolean relative) {
|
||||
if (relative) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
} else {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public void addRelativePosition(double relX, double relY, double relZ) {
|
||||
this.x += relX;
|
||||
this.y += relY;
|
||||
this.z += relZ;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+182
-67
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,39 +18,55 @@
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.FloatTag;
|
||||
import com.viaversion.nbt.tag.IntArrayTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.FullMappings;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.EitherHolder;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.CustomModelData1_21_4;
|
||||
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.type.Type;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntFunction;
|
||||
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends StructuredItemRewriter<C, S, T> {
|
||||
|
||||
public BackwardsStructuredItemRewriter(final T protocol, final Type<Item> itemType, final Type<Item[]> itemArrayType) {
|
||||
super(protocol, itemType, itemArrayType);
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
|
||||
public BackwardsStructuredItemRewriter(
|
||||
T protocol,
|
||||
Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType,
|
||||
Type<Item> itemCostType, Type<Item> optionalItemCostType, Type<Item> mappedItemCostType, Type<Item> mappedOptionalItemCostType
|
||||
) {
|
||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, itemCostType, optionalItemCostType, mappedItemCostType, mappedOptionalItemCostType);
|
||||
}
|
||||
|
||||
public BackwardsStructuredItemRewriter(final T protocol, final Type<Item> itemType, final Type<Item[]> itemArrayType, final Type<Item> mappedItemType, final Type<Item[]> mappedItemArrayType) {
|
||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
||||
}
|
||||
|
||||
public BackwardsStructuredItemRewriter(final T protocol, final Type<Item> itemType, final Type<Item[]> itemArrayType) {
|
||||
super(protocol, itemType, itemArrayType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(final UserConnection connection, final Item item) {
|
||||
if (item.isEmpty()) {
|
||||
@@ -58,33 +74,9 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
updateItemDataComponentTypeIds(dataContainer, true);
|
||||
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
if (mappingData != null && mappingData.getDataComponentSerializerMappings() != null) {
|
||||
final FullMappings mappings = mappingData.getDataComponentSerializerMappings();
|
||||
dataContainer.setIdLookup(protocol, true);
|
||||
dataContainer.updateIds(protocol, mappings::getNewId);
|
||||
}
|
||||
|
||||
if (protocol.getComponentRewriter() != null) {
|
||||
// Handle name and lore components
|
||||
updateComponent(connection, item, StructuredDataKey.ITEM_NAME, "item_name");
|
||||
updateComponent(connection, item, StructuredDataKey.CUSTOM_NAME, "custom_name");
|
||||
|
||||
final StructuredData<Tag[]> loreData = dataContainer.getNonEmpty(StructuredDataKey.LORE);
|
||||
if (loreData != null) {
|
||||
for (final Tag tag : loreData.value()) {
|
||||
protocol.getComponentRewriter().processTag(connection, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Int2IntFunction itemIdRewriter = null;
|
||||
Int2IntFunction blockIdRewriter = null;
|
||||
if (mappingData != null) {
|
||||
itemIdRewriter = mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
|
||||
blockIdRewriter = mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null;
|
||||
}
|
||||
|
||||
final MappedItem mappedItem = mappingData != null ? mappingData.getMappedItem(item.identifier()) : null;
|
||||
if (mappedItem == null) {
|
||||
// Just rewrite the id
|
||||
@@ -92,7 +84,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
||||
}
|
||||
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter);
|
||||
updateItemDataComponents(connection, item, true);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -102,17 +94,28 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
item.setIdentifier(mappedItem.id());
|
||||
|
||||
// Add custom model data
|
||||
if (mappedItem.customModelData() != null && !dataContainer.contains(StructuredDataKey.CUSTOM_MODEL_DATA)) {
|
||||
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA, mappedItem.customModelData());
|
||||
if (mappedItem.customModelData() != null) {
|
||||
if (connection.getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_21_4)) {
|
||||
if (!dataContainer.has(StructuredDataKey.CUSTOM_MODEL_DATA1_21_4)) {
|
||||
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA1_21_4, new CustomModelData1_21_4(
|
||||
new float[]{mappedItem.customModelData().floatValue()},
|
||||
new boolean[0],
|
||||
new String[0],
|
||||
EMPTY_INT_ARRAY
|
||||
));
|
||||
}
|
||||
} else if (!dataContainer.has(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5)) {
|
||||
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5, mappedItem.customModelData());
|
||||
}
|
||||
}
|
||||
|
||||
// Set custom name - only done if there is no original one
|
||||
if (!dataContainer.contains(StructuredDataKey.CUSTOM_NAME)) {
|
||||
if (!dataContainer.has(StructuredDataKey.CUSTOM_NAME)) {
|
||||
dataContainer.set(StructuredDataKey.CUSTOM_NAME, mappedItem.tagName());
|
||||
tag.putBoolean(nbtTagName("added_custom_name"), true);
|
||||
}
|
||||
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter);
|
||||
updateItemDataComponents(connection, item, true);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -122,46 +125,27 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
return item;
|
||||
}
|
||||
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
if (mappingData != null) {
|
||||
if (mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
updateItemDataComponentTypeIds(dataContainer, false);
|
||||
|
||||
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings();
|
||||
if (dataComponentMappings != null) {
|
||||
dataContainer.setIdLookup(protocol, false);
|
||||
dataContainer.updateIds(protocol, id -> dataComponentMappings.inverse().getNewId(id));
|
||||
}
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
if (mappingData != null && mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
|
||||
|
||||
final CompoundTag tag = customTag(item);
|
||||
if (tag != null) {
|
||||
final Tag originalId = tag.remove(nbtTagName("id"));
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||
final CompoundTag customData = dataContainer.get(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData != null) {
|
||||
if (customData.remove(nbtTagName("id")) instanceof final IntTag originalTag) {
|
||||
item.setIdentifier(originalTag.asInt());
|
||||
removeCustomTag(dataContainer, customData);
|
||||
}
|
||||
}
|
||||
|
||||
restoreTextComponents(item);
|
||||
|
||||
Int2IntFunction itemIdRewriter = null;
|
||||
Int2IntFunction blockIdRewriter = null;
|
||||
if (mappingData != null) {
|
||||
itemIdRewriter = mappingData.getItemMappings() != null ? mappingData::getOldItemId : null;
|
||||
blockIdRewriter = mappingData.getBlockMappings() != null ? mappingData::getOldBlockId : null;
|
||||
}
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToServer, itemIdRewriter, blockIdRewriter);
|
||||
updateItemDataComponents(connection, item, false);
|
||||
return item;
|
||||
}
|
||||
|
||||
protected @Nullable CompoundTag customTag(final Item item) {
|
||||
final StructuredData<CompoundTag> customData = item.dataContainer().getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
return customData != null ? customData.value() : null;
|
||||
}
|
||||
|
||||
protected void saveListTag(CompoundTag tag, ListTag<?> original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = nbtTagName(name);
|
||||
@@ -204,6 +188,137 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
return new ArrayList<>(data.values());
|
||||
}
|
||||
|
||||
protected Tag holderSetToTag(final HolderSet set) {
|
||||
if (set.hasIds()) {
|
||||
return new IntArrayTag(set.ids());
|
||||
} else {
|
||||
return new StringTag(set.tagKey());
|
||||
}
|
||||
}
|
||||
|
||||
protected HolderSet restoreHolderSet(final CompoundTag tag, final String key) {
|
||||
final Tag savedTag = tag.get(key);
|
||||
if (savedTag == null) {
|
||||
return HolderSet.of(EMPTY_INT_ARRAY);
|
||||
}
|
||||
|
||||
if (savedTag instanceof StringTag tagKey) {
|
||||
return HolderSet.of(tagKey.getValue());
|
||||
} else if (savedTag instanceof IntArrayTag idsTag) {
|
||||
return HolderSet.of(idsTag.getValue());
|
||||
} else {
|
||||
return HolderSet.of(EMPTY_INT_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> Tag holderToTag(final Holder<V> holder, final BiConsumer<V, CompoundTag> valueSaveFunction) {
|
||||
if (holder.hasId()) {
|
||||
return new IntTag(holder.id());
|
||||
} else {
|
||||
final CompoundTag savedTag = new CompoundTag();
|
||||
valueSaveFunction.accept(holder.value(), savedTag);
|
||||
return savedTag;
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> Tag eitherHolderToTag(final EitherHolder<V> holder, final BiConsumer<V, CompoundTag> valueSaveFunction) {
|
||||
if (holder.hasKey()) {
|
||||
return new StringTag(holder.key());
|
||||
} else {
|
||||
return holderToTag(holder.holder(), valueSaveFunction);
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> void saveEitherHolderData(final StructuredDataKey<EitherHolder<V>> key, final StructuredDataContainer data, final CompoundTag backupTag, final BiConsumer<V, CompoundTag> valueSaveFunction) {
|
||||
final EitherHolder<V> holder = data.get(key);
|
||||
if (holder != null) {
|
||||
backupTag.put(key.identifier(), eitherHolderToTag(holder, valueSaveFunction));
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> void saveHolderData(final StructuredDataKey<Holder<V>> key, final StructuredDataContainer data, final CompoundTag backupTag, final BiConsumer<V, CompoundTag> valueSaveFunction) {
|
||||
final Holder<V> holder = data.get(key);
|
||||
if (holder != null) {
|
||||
backupTag.put(key.identifier(), holderToTag(holder, valueSaveFunction));
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> Holder<V> restoreHolder(final CompoundTag tag, final String key, final Function<CompoundTag, V> valueRestoreFunction) {
|
||||
final Tag savedTag = tag.get(key);
|
||||
if (savedTag == null) {
|
||||
return Holder.of(0);
|
||||
}
|
||||
|
||||
if (savedTag instanceof IntTag idTag) {
|
||||
return Holder.of(idTag.asInt());
|
||||
} else if (savedTag instanceof CompoundTag compoundTag) {
|
||||
return Holder.of(valueRestoreFunction.apply(compoundTag));
|
||||
} else {
|
||||
return Holder.of(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> EitherHolder<V> restoreEitherHolder(final CompoundTag tag, final String key, final Function<CompoundTag, V> valueRestoreFunction) {
|
||||
final Tag savedTag = tag.get(key);
|
||||
if (savedTag == null) {
|
||||
return EitherHolder.of(Holder.of(0));
|
||||
}
|
||||
|
||||
if (savedTag instanceof StringTag keyTag) {
|
||||
return EitherHolder.of(keyTag.getValue());
|
||||
} else {
|
||||
return EitherHolder.of(restoreHolder(tag, key, valueRestoreFunction));
|
||||
}
|
||||
}
|
||||
|
||||
protected <V> void restoreHolderData(final StructuredDataKey<Holder<V>> key, final StructuredDataContainer data, final CompoundTag backupTag, final Function<CompoundTag, V> valueRestoreFunction) {
|
||||
if (backupTag.contains(key.identifier())) {
|
||||
data.set(key, restoreHolder(backupTag, key.identifier(), valueRestoreFunction));
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveStringData(final StructuredDataKey<String> key, final StructuredDataContainer data, final CompoundTag backupTag) {
|
||||
final String value = data.get(key);
|
||||
if (value != null) {
|
||||
backupTag.putString(key.identifier(), value);
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreStringData(final StructuredDataKey<String> key, final StructuredDataContainer data, final CompoundTag backupTag) {
|
||||
final String value = backupTag.getString(key.identifier());
|
||||
if (value != null) {
|
||||
data.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveIntData(final StructuredDataKey<Integer> key, final StructuredDataContainer data, final CompoundTag backupTag) {
|
||||
final Integer variant = data.get(key);
|
||||
if (variant != null) {
|
||||
backupTag.putInt(key.identifier(), variant);
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreIntData(final StructuredDataKey<Integer> key, final StructuredDataContainer data, final CompoundTag backupTag) {
|
||||
final IntTag variant = backupTag.getIntTag(key.identifier());
|
||||
if (variant != null) {
|
||||
data.set(key, variant.asInt());
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveFloatData(final StructuredDataKey<Float> key, final StructuredDataContainer data, final CompoundTag backupTag) {
|
||||
final Float variant = data.get(key);
|
||||
if (variant != null) {
|
||||
backupTag.putFloat(key.identifier(), variant);
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreFloatData(final StructuredDataKey<Float> key, final StructuredDataContainer data, final CompoundTag backupTag) {
|
||||
final FloatTag variant = backupTag.getFloatTag(key.identifier());
|
||||
if (variant != null) {
|
||||
data.set(key, variant.asFloat());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nbtTagName() {
|
||||
return "VB|" + protocol.getClass().getSimpleName();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+33
-41
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -24,8 +24,6 @@ import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
|
||||
@@ -41,40 +39,34 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
|
||||
@Override
|
||||
public void registerTrackerWithData(C packetType, EntityType fallingBlockType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // 0 - Entity id
|
||||
map(Types.UUID); // 1 - Entity UUID
|
||||
map(Types.VAR_INT); // 2 - Entity Type
|
||||
map(Types.DOUBLE); // 3 - X
|
||||
map(Types.DOUBLE); // 4 - Y
|
||||
map(Types.DOUBLE); // 5 - Z
|
||||
map(Types.BYTE); // 6 - Pitch
|
||||
map(Types.BYTE); // 7 - Yaw
|
||||
map(Types.INT); // 8 - Data
|
||||
handler(getSpawnTrackerWithDataHandler(fallingBlockType));
|
||||
}
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||
wrapper.passthrough(Types.UUID); // Entity UUID
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity Type
|
||||
wrapper.passthrough(Types.DOUBLE); // X
|
||||
wrapper.passthrough(Types.DOUBLE); // Y
|
||||
wrapper.passthrough(Types.DOUBLE); // Z
|
||||
wrapper.passthrough(Types.BYTE); // Pitch
|
||||
wrapper.passthrough(Types.BYTE); // Yaw
|
||||
wrapper.passthrough(Types.INT); // Data
|
||||
getSpawnTrackerWithDataHandler(fallingBlockType).handle(wrapper);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTrackerWithData1_19(C packetType, EntityType fallingBlockType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.UUID); // Entity UUID
|
||||
map(Types.VAR_INT); // Entity type
|
||||
map(Types.DOUBLE); // X
|
||||
map(Types.DOUBLE); // Y
|
||||
map(Types.DOUBLE); // Z
|
||||
map(Types.BYTE); // Pitch
|
||||
map(Types.BYTE); // Yaw
|
||||
map(Types.BYTE); // Head yaw
|
||||
map(Types.VAR_INT); // Data
|
||||
handler(getSpawnTrackerWithDataHandler1_19(fallingBlockType));
|
||||
}
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity id
|
||||
wrapper.passthrough(Types.UUID); // Entity UUID
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity type
|
||||
wrapper.passthrough(Types.DOUBLE); // X
|
||||
wrapper.passthrough(Types.DOUBLE); // Y
|
||||
wrapper.passthrough(Types.DOUBLE); // Z
|
||||
wrapper.passthrough(Types.BYTE); // Pitch
|
||||
wrapper.passthrough(Types.BYTE); // Yaw
|
||||
wrapper.passthrough(Types.BYTE); // Head yaw
|
||||
wrapper.passthrough(Types.VAR_INT); // Data
|
||||
getSpawnTrackerWithDataHandler1_19(fallingBlockType).handle(wrapper);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,14 +97,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
}
|
||||
|
||||
public void registerSpawnTracker(C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // 0 - Entity ID
|
||||
map(Types.UUID); // 1 - Entity UUID
|
||||
map(Types.VAR_INT); // 2 - Entity Type
|
||||
handler(wrapper -> trackAndMapEntity(wrapper));
|
||||
}
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||
wrapper.passthrough(Types.UUID); // Entity UUID
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity Type
|
||||
trackAndMapEntity(wrapper);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -127,7 +116,6 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
String world = wrapper.get(Types.STRING, 1);
|
||||
if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) {
|
||||
tracker.clearEntities();
|
||||
tracker.trackClientEntity();
|
||||
}
|
||||
tracker.setCurrentWorld(world);
|
||||
};
|
||||
@@ -142,6 +130,10 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
protected EntityType trackAndMapEntity(PacketWrapper wrapper) {
|
||||
int typeId = wrapper.get(Types.VAR_INT, 1);
|
||||
EntityType entityType = typeFromId(typeId);
|
||||
if (entityType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
|
||||
|
||||
int mappedTypeId = newEntityId(entityType.getId());
|
||||
|
||||
+25
-9
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
|
||||
import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
@@ -184,7 +185,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(value));
|
||||
}
|
||||
} else if (type == particleType) {
|
||||
rewriteParticle(event.user(), data.value());
|
||||
protocol.getParticleRewriter().rewriteParticle(event.user(), data.value());
|
||||
} else if (type == optionalComponentType || type == componentType) {
|
||||
JsonElement text = data.value();
|
||||
protocol.getComponentRewriter().processText(event.user(), text);
|
||||
@@ -214,11 +215,11 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(value));
|
||||
}
|
||||
} else if (type == particleType) {
|
||||
rewriteParticle(event.user(), data.value());
|
||||
protocol.getParticleRewriter().rewriteParticle(event.user(), data.value());
|
||||
} else if (type == particlesType) {
|
||||
Particle[] particles = data.value();
|
||||
for (final Particle particle : particles) {
|
||||
rewriteParticle(event.user(), particle);
|
||||
protocol.getParticleRewriter().rewriteParticle(event.user(), particle);
|
||||
}
|
||||
} else if (type == optionalComponentType || type == componentType) {
|
||||
protocol.getComponentRewriter().processTag(event.user(), data.value());
|
||||
@@ -230,7 +231,10 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
protected PacketHandler getTrackerHandler(Type<? extends Number> intType, int typeIndex) {
|
||||
return wrapper -> {
|
||||
Number id = wrapper.get(intType, typeIndex);
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), typeFromId(id.intValue()));
|
||||
EntityType entityType = typeFromId(id.intValue());
|
||||
if (entityType != null) {
|
||||
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -238,15 +242,27 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
return getTrackerHandler(Types.VAR_INT, 1);
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerHandler(EntityType entityType, Type<? extends Number> intType) {
|
||||
return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(intType, 0), entityType);
|
||||
protected PacketHandler getTrackerHandler(EntityType entityType) {
|
||||
return wrapper -> tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
|
||||
}
|
||||
|
||||
protected PacketHandler getPlayerTrackerHandler() {
|
||||
return wrapper -> {
|
||||
final int entityId = wrapper.get(Types.INT, 0);
|
||||
|
||||
final EntityTracker tracker = tracker(wrapper.user());
|
||||
tracker(wrapper.user()).setClientEntityId(entityId);
|
||||
tracker.addEntity(entityId, tracker.playerType());
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getDimensionHandler(int index) {
|
||||
return wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(this.protocol.getClass());
|
||||
int dimensionId = wrapper.get(Types.INT, index);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
if (clientWorld.setEnvironment(dimensionId)) {
|
||||
tracker(wrapper.user()).clearEntities();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+25
-21
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,9 +18,16 @@
|
||||
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.ShortTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.BlockColors1_11_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
@@ -41,17 +48,10 @@ import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.ShortTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
@@ -103,9 +103,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
// Include data
|
||||
short unmappedData = Short.parseShort(key.substring(dataSeparatorIndex + 1));
|
||||
unmappedId = Integer.parseInt(key.substring(0, dataSeparatorIndex));
|
||||
unmappedId = IdAndData.toRawData(unmappedId, unmappedData);
|
||||
unmappedId = compress(unmappedId, unmappedData);
|
||||
} else {
|
||||
unmappedId = IdAndData.toRawData(Integer.parseInt(key), -1);
|
||||
unmappedId = compress(Integer.parseInt(key), -1);
|
||||
}
|
||||
|
||||
mappings.put(unmappedId, new MappedLegacyBlockItem(id, data, name, type));
|
||||
@@ -120,12 +120,12 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
// Special block color handling
|
||||
if (name != null && name.contains("%color%")) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
mappings.put(IdAndData.toRawData(i, -1), new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors1_11_1.get(i - from)), type));
|
||||
mappings.put(compress(i, -1), new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors1_11_1.get(i - from)), type));
|
||||
}
|
||||
} else {
|
||||
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name, type);
|
||||
for (int i = from; i <= to; i++) {
|
||||
mappings.put(IdAndData.toRawData(i, -1), mappedBlockItem);
|
||||
mappings.put(compress(i, -1), mappedBlockItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,10 +226,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
public PacketHandler getFallingBlockHandler() {
|
||||
return wrapper -> {
|
||||
final EntityTypes1_12.ObjectType type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0));
|
||||
final int objectData = wrapper.get(Types.INT, 0);
|
||||
final EntityTypes1_12.ObjectType type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0), objectData);
|
||||
if (type == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
|
||||
final int objectData = wrapper.get(Types.INT, 0);
|
||||
|
||||
final IdAndData block = handleBlock(objectData & 4095, objectData >> 12 & 15);
|
||||
if (block == null) return;
|
||||
|
||||
@@ -360,13 +359,13 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
private @Nullable MappedLegacyBlockItem getMappedBlock(int id, int data) {
|
||||
MappedLegacyBlockItem mapping = blockReplacements.get(IdAndData.toRawData(id, data));
|
||||
return mapping != null ? mapping : blockReplacements.get(IdAndData.toRawData(id, -1));
|
||||
MappedLegacyBlockItem mapping = blockReplacements.get(compress(id, data));
|
||||
return mapping != null ? mapping : blockReplacements.get(compress(id, -1));
|
||||
}
|
||||
|
||||
private @Nullable MappedLegacyBlockItem getMappedItem(int id, int data) {
|
||||
MappedLegacyBlockItem mapping = itemReplacements.get(IdAndData.toRawData(id, data));
|
||||
return mapping != null ? mapping : itemReplacements.get(IdAndData.toRawData(id, -1));
|
||||
MappedLegacyBlockItem mapping = itemReplacements.get(compress(id, data));
|
||||
return mapping != null ? mapping : itemReplacements.get(compress(id, -1));
|
||||
}
|
||||
|
||||
private @Nullable MappedLegacyBlockItem getMappedBlock(int rawId) {
|
||||
@@ -379,6 +378,11 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
return BackwardsMappingDataLoader.INSTANCE.loadFromDataDir(name);
|
||||
}
|
||||
|
||||
protected int compress(final int id, final int data) {
|
||||
// Using IdAndData for the internal storage can cause id overlaps in edge cases and would lead to wrong data
|
||||
return (id << 16) | (data & 0xFFFF);
|
||||
}
|
||||
|
||||
private record Pos(int x, short y, int z) {
|
||||
|
||||
public Pos(int x, int y, int z) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+39
-40
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -36,7 +36,6 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriterBase<C, T> {
|
||||
@@ -66,8 +65,10 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
public void register() {
|
||||
map(Types.INT);
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
clientWorld.setEnvironment(wrapper.get(Types.INT, 0));
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||
if (clientWorld.setEnvironment(wrapper.get(Types.INT, 0))) {
|
||||
tracker(wrapper.user()).clearEntities();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -81,42 +82,24 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Types.INT); // 2 - Dimension
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
clientChunks.setEnvironment(wrapper.get(Types.INT, 1));
|
||||
addTrackedEntity(wrapper, wrapper.get(Types.INT, 0), playerType);
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||
clientWorld.setEnvironment(wrapper.get(Types.INT, 1));
|
||||
|
||||
final int entityId = wrapper.get(Types.INT, 0);
|
||||
addTrackedEntity(wrapper, entityId, playerType);
|
||||
tracker(wrapper.user()).setClientEntityId(entityId);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSetEntityData(C packetType, Type<List<EntityData>> dataType, Type<List<EntityData>> mappedDataType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // 0 - Entity ID
|
||||
if (dataType != null) {
|
||||
map(dataType, mappedDataType);
|
||||
} else {
|
||||
map(mappedDataType);
|
||||
}
|
||||
handler(wrapper -> {
|
||||
List<EntityData> entityDataList = wrapper.get(mappedDataType, 0);
|
||||
handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSetEntityData(C packetType, Type<List<EntityData>> dataType) {
|
||||
registerSetEntityData(packetType, null, dataType);
|
||||
}
|
||||
|
||||
protected PacketHandler getMobSpawnRewriter(Type<List<EntityData>> dataType, IdSetter idSetter) {
|
||||
return wrapper -> {
|
||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||
EntityType type = tracker(wrapper.user()).entityType(entityId);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<EntityData> entityDataList = wrapper.get(dataType, 0);
|
||||
handleEntityData(entityId, entityDataList, wrapper.user());
|
||||
@@ -140,7 +123,16 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
}
|
||||
|
||||
protected PacketHandler getObjectTrackerHandler() {
|
||||
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), objectTypeFromId(wrapper.get(Types.BYTE, 0)));
|
||||
return wrapper -> {
|
||||
int id = wrapper.get(Types.BYTE, 0);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
EntityType type = objectTypeFromId(id, data);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), type);
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getTrackerAndDataHandler(Type<List<EntityData>> dataType, EntityType entityType) {
|
||||
@@ -151,19 +143,20 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGetter) {
|
||||
protected PacketHandler getObjectRewriter(ObjectTypeGetter objectGetter) {
|
||||
return wrapper -> {
|
||||
ObjectType type = objectGetter.apply(wrapper.get(Types.BYTE, 0));
|
||||
int id = wrapper.get(Types.BYTE, 0);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
ObjectType type = objectGetter.get(id, data);
|
||||
if (type == null) {
|
||||
protocol.getLogger().warning("Could not find entity type " + wrapper.get(Types.BYTE, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
EntityReplacement data = getObjectData(type);
|
||||
if (data != null) {
|
||||
wrapper.set(Types.BYTE, 0, (byte) data.replacementId());
|
||||
if (data.objectData() != -1) {
|
||||
wrapper.set(Types.INT, 0, data.objectData());
|
||||
EntityReplacement replacement = getObjectData(type);
|
||||
if (replacement != null) {
|
||||
wrapper.set(Types.BYTE, 0, (byte) replacement.replacementId());
|
||||
if (replacement.objectData() != -1) {
|
||||
wrapper.set(Types.INT, 0, replacement.objectData());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -179,4 +172,10 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
||||
|
||||
void setId(PacketWrapper wrapper, int id);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface ObjectTypeGetter {
|
||||
|
||||
ObjectType get(int id, int data);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+37
-27
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -17,13 +17,47 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
||||
|
||||
public final class MapColorRewriter {
|
||||
|
||||
/**
|
||||
* Rewrite map colors using the provided id rewriter.
|
||||
*
|
||||
* @param wrapper packet wrapper
|
||||
* @param rewriter id rewriter returning mapped colors, or -1 if unmapped
|
||||
* @param iconCount number of icons to read
|
||||
*/
|
||||
public static void rewriteMapColors(PacketWrapper wrapper, IdRewriteFunction rewriter, int iconCount) {
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
wrapper.passthrough(Types.VAR_INT); // Type
|
||||
wrapper.passthrough(Types.BYTE); // X
|
||||
wrapper.passthrough(Types.BYTE); // Z
|
||||
wrapper.passthrough(Types.BYTE); // Direction
|
||||
wrapper.passthrough(Types.OPTIONAL_COMPONENT); // Display Name
|
||||
}
|
||||
|
||||
short columns = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
if (columns < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Rows
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // X
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Z
|
||||
byte[] data = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int color = data[i] & 0xFF;
|
||||
int mappedColor = rewriter.rewrite(color);
|
||||
if (mappedColor != -1) {
|
||||
data[i] = (byte) mappedColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a packethandler to rewrite map data color ids. Reading starts from the icon count.
|
||||
*
|
||||
@@ -31,30 +65,6 @@ public final class MapColorRewriter {
|
||||
* @return packethandler to rewrite map data color ids
|
||||
*/
|
||||
public static PacketHandler getRewriteHandler(IdRewriteFunction rewriter) {
|
||||
return wrapper -> {
|
||||
int iconCount = wrapper.passthrough(Types.VAR_INT);
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
wrapper.passthrough(Types.VAR_INT); // Type
|
||||
wrapper.passthrough(Types.BYTE); // X
|
||||
wrapper.passthrough(Types.BYTE); // Z
|
||||
wrapper.passthrough(Types.BYTE); // Direction
|
||||
wrapper.passthrough(Types.OPTIONAL_COMPONENT); // Display Name
|
||||
}
|
||||
|
||||
short columns = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
if (columns < 1) return;
|
||||
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Rows
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // X
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Z
|
||||
byte[] data = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int color = data[i] & 0xFF;
|
||||
int mappedColor = rewriter.rewrite(color);
|
||||
if (mappedColor != -1) {
|
||||
data[i] = (byte) mappedColor;
|
||||
}
|
||||
}
|
||||
};
|
||||
return wrapper -> rewriteMapColors(wrapper, rewriter, wrapper.passthrough(Types.VAR_INT));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.SoundRewriter<C> {
|
||||
@@ -36,22 +35,14 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
|
||||
}
|
||||
|
||||
public void registerNamedSound(final C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Sound identifier
|
||||
handler(getNamedSoundHandler());
|
||||
}
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
wrapper.passthrough(Types.STRING); // Sound identifier
|
||||
getNamedSoundHandler().handle(wrapper);
|
||||
});
|
||||
}
|
||||
|
||||
public void registerStopSound(final C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(getStopSoundHandler());
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(packetType, wrapper -> getStopSoundHandler().handle(wrapper));
|
||||
}
|
||||
|
||||
public PacketHandler getNamedSoundHandler() {
|
||||
|
||||
+58
-51
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -25,7 +25,6 @@ import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.data.Mappings;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
@@ -60,32 +59,28 @@ public class StructuredEnchantmentRewriter {
|
||||
final String remappedName = mappingData.mappedEnchantmentName(id);
|
||||
return ComponentUtil.jsonStringToTag(ChatUtil.legacyToJsonString("§7" + remappedName, ENCHANTMENT_LEVEL_TRANSLATION.formatted(level), true));
|
||||
};
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, idRewriteFunction, descriptionSupplier, false);
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS, idRewriteFunction, descriptionSupplier, true);
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS1_20_5, idRewriteFunction, descriptionSupplier, false);
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS1_20_5, idRewriteFunction, descriptionSupplier, true);
|
||||
}
|
||||
|
||||
public void handleToServer(final Item item) {
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData == null) {
|
||||
return;
|
||||
final CompoundTag customData = data.get(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData != null) {
|
||||
rewriteEnchantmentsToServer(data, customData, StructuredDataKey.ENCHANTMENTS1_20_5);
|
||||
rewriteEnchantmentsToServer(data, customData, StructuredDataKey.STORED_ENCHANTMENTS1_20_5);
|
||||
}
|
||||
|
||||
final CompoundTag tag = customData.value();
|
||||
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.ENCHANTMENTS);
|
||||
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.STORED_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
public void rewriteEnchantmentsToClient(final StructuredDataContainer data, final StructuredDataKey<Enchantments> key, final IdRewriteFunction rewriteFunction, final DescriptionSupplier descriptionSupplier, final boolean storedEnchant) {
|
||||
final StructuredData<Enchantments> enchantmentsData = data.getNonEmpty(key);
|
||||
if (enchantmentsData == null) {
|
||||
final Enchantments enchantments = data.get(key);
|
||||
if (enchantments == null || enchantments.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
|
||||
final Enchantments enchantments = enchantmentsData.value();
|
||||
final List<Tag> loreToAdd = new ArrayList<>();
|
||||
boolean changed = false;
|
||||
boolean removedEnchantments = false;
|
||||
boolean updatedLore = false;
|
||||
|
||||
final ObjectIterator<Int2IntMap.Entry> iterator = enchantments.enchantments().int2IntEntrySet().iterator();
|
||||
final List<PendingIdChange> updatedIds = new ArrayList<>();
|
||||
@@ -102,17 +97,20 @@ public class StructuredEnchantmentRewriter {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Tag description = descriptionSupplier.get(id, level);
|
||||
if (description != null) {
|
||||
if (!changed) {
|
||||
// Backup original before doing modifications
|
||||
itemRewriter.saveListTag(tag, asTag(enchantments), key.identifier());
|
||||
changed = true;
|
||||
}
|
||||
|
||||
loreToAdd.add(description);
|
||||
iterator.remove();
|
||||
if (!removedEnchantments) {
|
||||
// Backup original before doing modifications
|
||||
final CompoundTag customData = customData(data);
|
||||
itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier());
|
||||
removedEnchantments = true;
|
||||
}
|
||||
|
||||
final Tag description = descriptionSupplier.get(id, level);
|
||||
if (description != null && enchantments.showInTooltip()) {
|
||||
loreToAdd.add(description);
|
||||
updatedLore = true;
|
||||
}
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
// Remove all first, then add the new ones
|
||||
@@ -123,37 +121,46 @@ public class StructuredEnchantmentRewriter {
|
||||
enchantments.add(change.mappedId(), change.level());
|
||||
}
|
||||
|
||||
if (loreToAdd.isEmpty()) {
|
||||
// No removed enchantments
|
||||
return;
|
||||
}
|
||||
|
||||
// Add glint override if there are no enchantments left
|
||||
if (!storedEnchant && enchantments.size() == 0) {
|
||||
final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
if (glintOverride != null) {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value());
|
||||
} else {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("noglint"), true);
|
||||
if (removedEnchantments) {
|
||||
final CompoundTag tag = customData(data);
|
||||
if (!storedEnchant && enchantments.size() == 0) {
|
||||
// Add glint override if there are no enchantments left
|
||||
final Boolean glintOverride = data.get(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
if (glintOverride != null) {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride);
|
||||
} else {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("noglint"), true);
|
||||
}
|
||||
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||
}
|
||||
|
||||
if (enchantments.showInTooltip()) {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
|
||||
}
|
||||
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||
}
|
||||
|
||||
// Save original lore
|
||||
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
|
||||
if (loreData != null) {
|
||||
final List<Tag> loreList = Arrays.asList(loreData.value());
|
||||
itemRewriter.saveGenericTagList(tag, loreList, "lore");
|
||||
loreToAdd.addAll(loreList);
|
||||
} else {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("nolore"), true);
|
||||
if (updatedLore) {
|
||||
// Save original lore
|
||||
final CompoundTag tag = customData(data);
|
||||
final Tag[] lore = data.get(StructuredDataKey.LORE);
|
||||
if (lore != null) {
|
||||
final List<Tag> loreList = Arrays.asList(lore);
|
||||
itemRewriter.saveGenericTagList(tag, loreList, "lore");
|
||||
loreToAdd.addAll(loreList);
|
||||
} else {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("nolore"), true);
|
||||
}
|
||||
data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (enchantments.showInTooltip()) {
|
||||
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
|
||||
private CompoundTag customData(final StructuredDataContainer data) {
|
||||
CompoundTag tag = data.get(StructuredDataKey.CUSTOM_DATA);
|
||||
if (tag == null) {
|
||||
tag = new CompoundTag();
|
||||
data.set(StructuredDataKey.CUSTOM_DATA, tag);
|
||||
}
|
||||
|
||||
data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0]));
|
||||
return tag;
|
||||
}
|
||||
|
||||
private ListTag<CompoundTag> asTag(final Enchantments enchantments) {
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2025 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.viabackwards.api.rewriters.text;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.TranslatableMappings;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class JsonNBTComponentRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter<C> implements TranslatableRewriter {
|
||||
|
||||
private final Map<String, String> translatables;
|
||||
|
||||
public JsonNBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type) {
|
||||
super(protocol, type);
|
||||
this.translatables = TranslatableMappings.translatablesFor(protocol);
|
||||
}
|
||||
|
||||
public JsonNBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String version) {
|
||||
super(protocol, type);
|
||||
this.translatables = TranslatableMappings.translatablesFor(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(final JsonObject root, final String translate) {
|
||||
final String newTranslate = mappedTranslationKey(translate);
|
||||
if (newTranslate != null) {
|
||||
root.addProperty("translate", newTranslate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(final UserConnection connection, final CompoundTag parentTag, final StringTag translateTag) {
|
||||
final String newTranslate = mappedTranslationKey(translateTag.getValue());
|
||||
if (newTranslate != null) {
|
||||
parentTag.put("translate", new StringTag(newTranslate));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String mappedTranslationKey(final String translationKey) {
|
||||
return translatables.get(translationKey);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2025 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.viabackwards.api.rewriters.text;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.TranslatableMappings;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class NBTComponentRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.text.NBTComponentRewriter<C> implements TranslatableRewriter {
|
||||
|
||||
private final Map<String, String> translatables;
|
||||
|
||||
public NBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
this.translatables = TranslatableMappings.translatablesFor(protocol);
|
||||
}
|
||||
|
||||
public NBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final String version) {
|
||||
super(protocol);
|
||||
this.translatables = TranslatableMappings.translatablesFor(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(final JsonObject root, final String translate) {
|
||||
final String newTranslate = mappedTranslationKey(translate);
|
||||
if (newTranslate != null) {
|
||||
root.addProperty("translate", newTranslate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(final UserConnection connection, final CompoundTag parentTag, final StringTag translateTag) {
|
||||
final String newTranslate = mappedTranslationKey(translateTag.getValue());
|
||||
if (newTranslate != null) {
|
||||
parentTag.put("translate", new StringTag(newTranslate));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String mappedTranslationKey(final String translationKey) {
|
||||
return translatables.get(translationKey);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2025 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.viabackwards.api.rewriters.text;
|
||||
|
||||
import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface TranslatableRewriter extends ComponentRewriter {
|
||||
|
||||
@Nullable
|
||||
String mappedTranslationKey(String translationKey);
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2025 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.viabackwards.protocol.template;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_21_5;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21_4;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21_5;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPacket1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPackets1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.rewriter.RecipeDisplayRewriter1_21_5;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter;
|
||||
|
||||
// To replace if needed:
|
||||
// ChunkType1_21_5
|
||||
// RecipeDisplayRewriter
|
||||
// Types1_21_4
|
||||
final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21_2, ServerboundPacket1_21_4, Protocol1_98To1_99> {
|
||||
|
||||
public BlockItemPacketRewriter1_99(final Protocol1_98To1_99 protocol) {
|
||||
super(protocol, Types1_21_4.ITEM, Types1_21_4.ITEM_ARRAY);
|
||||
/*super(protocol,
|
||||
Types1_21_4.ITEM, Types1_21_4.ITEM_ARRAY, Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY,
|
||||
Types1_21_4.ITEM_COST, Types1_21_4.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST
|
||||
);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
final BlockRewriter<ClientboundPacket1_21_2> blockRewriter = BlockRewriter.for1_20_2(protocol);
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE);
|
||||
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001);
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_21_5::new);
|
||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA);
|
||||
|
||||
// registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN);
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, this::passthroughClientboundItem);
|
||||
registerSetPlayerInventory(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY);
|
||||
registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN);
|
||||
registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT);
|
||||
registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT);
|
||||
registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS);
|
||||
registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT);
|
||||
registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS);
|
||||
registerContainerClick1_21_5(ServerboundPackets1_21_4.CONTAINER_CLICK);
|
||||
registerSetCreativeModeSlot1_21_5(ServerboundPackets1_21_4.SET_CREATIVE_MODE_SLOT, Types1_21_5.LENGTH_PREFIXED_ITEM, Types1_21_5.LENGTH_PREFIXED_ITEM); // Change this
|
||||
|
||||
final RecipeDisplayRewriter<ClientboundPacket1_21_2> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
|
||||
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_2.UPDATE_RECIPES);
|
||||
recipeRewriter.registerRecipeBookAdd(ClientboundPackets1_21_2.RECIPE_BOOK_ADD);
|
||||
recipeRewriter.registerPlaceGhostRecipe(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2025 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.viabackwards.protocol.template;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.NBTComponentRewriter;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
|
||||
final class ComponentRewriter1_99 extends NBTComponentRewriter<ClientboundPacket1_21_2> {
|
||||
|
||||
public ComponentRewriter1_99(final BackwardsProtocol<ClientboundPacket1_21_2, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) {
|
||||
super.handleShowItem(connection, itemTag, componentsTag);
|
||||
if (componentsTag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove or update data from componentsTag
|
||||
// Newly added data which is not handled otherwise needs to be removed to prevent errors on the client
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2025 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.viabackwards.protocol.template;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_4;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
||||
|
||||
// Replace if needed
|
||||
// Types1_OLD
|
||||
// Types1_21_4
|
||||
final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_21_2, Protocol1_98To1_99> {
|
||||
|
||||
public EntityPacketRewriter1_99(final Protocol1_98To1_99 protocol) {
|
||||
super(protocol, Types1_21_4.ENTITY_DATA_TYPES.optionalComponentType, Types1_21_4.ENTITY_DATA_TYPES.booleanType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_21_4.FALLING_BLOCK);
|
||||
registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, /*Types1_OLD.ENTITY_DATA_LIST, */Types1_21_4.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
|
||||
registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES);
|
||||
registerPlayerAbilities(ClientboundPackets1_21_2.PLAYER_ABILITIES);
|
||||
registerGameEvent(ClientboundPackets1_21_2.GAME_EVENT);
|
||||
registerLogin1_20_5(ClientboundPackets1_21_2.LOGIN);
|
||||
registerRespawn1_20_5(ClientboundPackets1_21_2.RESPAWN);
|
||||
|
||||
final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol);
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
/*filter().handler((event, data) -> {
|
||||
int id = data.dataType().typeId();
|
||||
if (id >= ac) {
|
||||
return;
|
||||
} else if (id >= ab) {
|
||||
id--;
|
||||
}
|
||||
|
||||
data.setDataType(Types1_21_4.ENTITY_DATA_TYPES.byId(id));
|
||||
});*/
|
||||
|
||||
registerEntityDataTypeHandler1_20_3(
|
||||
Types1_21_4.ENTITY_DATA_TYPES.itemType,
|
||||
Types1_21_4.ENTITY_DATA_TYPES.blockStateType,
|
||||
Types1_21_4.ENTITY_DATA_TYPES.optionalBlockStateType,
|
||||
Types1_21_4.ENTITY_DATA_TYPES.particleType,
|
||||
Types1_21_4.ENTITY_DATA_TYPES.particlesType,
|
||||
Types1_21_4.ENTITY_DATA_TYPES.componentType,
|
||||
Types1_21_4.ENTITY_DATA_TYPES.optionalComponentType
|
||||
);
|
||||
|
||||
// Remove entity data of new entity type
|
||||
// filter().type(EntityTypes1_21_4.SNIFFER).removeIndex(newIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMappingDataLoaded() {
|
||||
// If types changed, uncomment to map them
|
||||
// mapTypes();
|
||||
|
||||
// mapEntityTypeWithData(EntityTypes1_21_4.SNIFFER, EntityTypes1_21_4.RAVAGER).tagName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(final int type) {
|
||||
return EntityTypes1_21_4.getTypeFromId(type);
|
||||
}
|
||||
}
|
||||
+63
-51
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -15,86 +15,93 @@
|
||||
* 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.viabackwards.template.protocol;
|
||||
package com.viaversion.viabackwards.protocol.template;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.template.protocol.rewriter.BlockItemPacketRewriter1_99;
|
||||
import com.viaversion.viabackwards.template.protocol.rewriter.EntityPacketRewriter1_99;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.NBTComponentRewriter;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_4;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21_4;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
|
||||
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.ClientboundPacket1_20_5;
|
||||
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.ServerboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPacket1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPackets1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.rewriter.ParticleRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
|
||||
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
|
||||
|
||||
// Placeholders to replace (in the entire package):
|
||||
// Protocol1_98To_99, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99
|
||||
// Protocol1_20_5To1_20_3 (the ViaVersion protocol class the mappings depend on)
|
||||
// ClientboundPacket1_20_5
|
||||
// ServerboundPacket1_20_5
|
||||
// ClientboundConfigurationPackets1_20_5
|
||||
// Protocol1_98To1_99, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99
|
||||
// Protocol1_20_5To1_21 (the ViaVersion protocol class the mappings depend on)
|
||||
// ClientboundPacket1_21_2
|
||||
// ServerboundPacket1_21_4
|
||||
// ClientboundConfigurationPackets1_21
|
||||
// ServerboundConfigurationPackets1_20_5
|
||||
// EntityTypes1_20_5 (UNMAPPED type)
|
||||
// EntityTypes1_21_4 (UNMAPPED type)
|
||||
// Types1_21_4.PARTICLE
|
||||
// 1.99, 1.98
|
||||
public final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacket1_20_5, ClientboundPacket1_20_5, ServerboundPacket1_20_5, ServerboundPacket1_20_5> {
|
||||
final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacket1_21_2, ClientboundPacket1_21_2, ServerboundPacket1_21_4, ServerboundPacket1_21_4> {
|
||||
|
||||
// ViaBackwards uses its own mappings and also needs a translatablerewriter for translation mappings
|
||||
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.99", "1.98", Protocol1_20_3To1_20_5.class);
|
||||
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.99", "1.98", Protocol1_20_5To1_21.class);
|
||||
private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this);
|
||||
private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this);
|
||||
private final TranslatableRewriter<ClientboundPacket1_20_5> translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT);
|
||||
private final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);
|
||||
private final ParticleRewriter<ClientboundPacket1_21_2> particleRewriter = new ParticleRewriter<>(this, Types1_21_4.PARTICLE/*, Types1_OLD.PARTICLE*/);
|
||||
private final NBTComponentRewriter<ClientboundPacket1_21_2> translatableRewriter = new ComponentRewriter1_99(this);
|
||||
private final TagRewriter<ClientboundPacket1_21_2> tagRewriter = new TagRewriter<>(this);
|
||||
|
||||
public Protocol1_98To1_99() {
|
||||
super(ClientboundPacket1_20_5.class, ClientboundPacket1_20_5.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class);
|
||||
super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_4.class, ServerboundPacket1_21_4.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
super.registerPackets();
|
||||
|
||||
tagRewriter.registerGeneric(ClientboundPackets1_20_5.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundPackets1_21_2.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS);
|
||||
|
||||
final SoundRewriter<ClientboundPacket1_20_5> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_20_5.SOUND);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_20_5.SOUND_ENTITY);
|
||||
soundRewriter.registerStopSound(ClientboundPackets1_20_5.STOP_SOUND);
|
||||
final SoundRewriter<ClientboundPacket1_21_2> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY);
|
||||
soundRewriter.registerStopSound(ClientboundPackets1_21_2.STOP_SOUND);
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.AWARD_STATS);
|
||||
//new AttributeRewriter<>(this).register1_21(ClientboundPackets1_20_5.ENTITY_PROPERTIES);
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
|
||||
//new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES);
|
||||
|
||||
// Registers translatable mappings (missing a whole bunch still)
|
||||
//translatableRewriter.registerOpenWindow(ClientboundPackets1_20_5.OPEN_WINDOW); // Handled by registerOpenWindow in item rewriters
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.SET_ACTION_BAR_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.SET_TITLE_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.SET_SUBTITLE_TEXT);
|
||||
translatableRewriter.registerBossEvent(ClientboundPackets1_20_5.BOSS_EVENT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.DISCONNECT);
|
||||
translatableRewriter.registerTabList(ClientboundPackets1_20_5.TAB_LIST);
|
||||
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_20_5.PLAYER_COMBAT_KILL);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.SYSTEM_CHAT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.DISGUISED_CHAT);
|
||||
//translatableRewriter.registerOpenScreen1_14(ClientboundPackets1_21_2.OPEN_SCREEN); // Handled by registerOpenScreen in item rewriters
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);
|
||||
translatableRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT);
|
||||
translatableRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST);
|
||||
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL);
|
||||
translatableRewriter.registerPlayerInfoUpdate1_21_4(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT);
|
||||
translatableRewriter.registerDisguisedChat(ClientboundPackets1_21_2.DISGUISED_CHAT);
|
||||
translatableRewriter.registerPlayerChat1_21_5(ClientboundPackets1_21_2.PLAYER_CHAT);
|
||||
translatableRewriter.registerPing();
|
||||
|
||||
// If needed for any particle, item, or block changes. Extend ParticleRewriter for particle serializer changes
|
||||
particleRewriter.registerLevelParticles1_21_4(ClientboundPackets1_21_2.LEVEL_PARTICLES);
|
||||
particleRewriter.registerExplode1_21_2(ClientboundPackets1_21_2.EXPLODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final UserConnection user) {
|
||||
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
|
||||
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_21_4.PLAYER));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,22 +120,27 @@ public final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacke
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPacket1_20_5> getComponentRewriter() {
|
||||
public ParticleRewriter<ClientboundPacket1_21_2> getParticleRewriter() {
|
||||
return particleRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTComponentRewriter<ClientboundPacket1_21_2> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagRewriter<ClientboundPacket1_20_5> getTagRewriter() {
|
||||
public TagRewriter<ClientboundPacket1_21_2> getTagRewriter() {
|
||||
return tagRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketTypesProvider<ClientboundPacket1_20_5, ClientboundPacket1_20_5, ServerboundPacket1_20_5, ServerboundPacket1_20_5> createPacketTypesProvider() {
|
||||
protected PacketTypesProvider<ClientboundPacket1_21_2, ClientboundPacket1_21_2, ServerboundPacket1_21_4, ServerboundPacket1_21_4> createPacketTypesProvider() {
|
||||
return new SimplePacketTypesProvider<>(
|
||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
|
||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
|
||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
|
||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-8
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -21,7 +21,7 @@ package com.viaversion.viabackwards.protocol.v1_10to1_9_3;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter.BlockItemPacketRewriter1_10;
|
||||
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter.EntityPacketRewriter1_10;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
@@ -34,7 +34,7 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
|
||||
|
||||
public class Protocol1_10To1_9_3 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
|
||||
|
||||
@@ -92,17 +92,14 @@ public class Protocol1_10To1_9_3 extends BackwardsProtocol<ClientboundPackets1_9
|
||||
}
|
||||
});
|
||||
|
||||
TranslatableRewriter<ClientboundPackets1_9_3> componentRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON);
|
||||
JsonNBTComponentRewriter<ClientboundPackets1_9_3> componentRewriter = new JsonNBTComponentRewriter<>(this, ComponentRewriterBase.ReadType.JSON);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_9_3.CHAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld());
|
||||
}
|
||||
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_10.EntityType.PLAYER));
|
||||
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -50,7 +50,7 @@ public class BlockItemPacketRewriter1_10 extends LegacyBlockItemRewriter<Clientb
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_10To1_9_3.class);
|
||||
|
||||
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
||||
Chunk chunk = wrapper.passthrough(type);
|
||||
|
||||
+7
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -89,6 +89,9 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPa
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||
EntityType type = tracker(wrapper.user()).entityType(entityId);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<EntityData> entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
|
||||
handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
|
||||
@@ -161,11 +164,11 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_10.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_10.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_10.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_10.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -39,11 +39,8 @@ public class Protocol1_11_1To1_11 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld());
|
||||
}
|
||||
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_11.EntityType.PLAYER));
|
||||
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -117,11 +117,11 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter<Clientbound
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_11.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_11.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+7
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -21,7 +21,7 @@ package com.viaversion.viabackwards.protocol.v1_11to1_10;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter.BlockItemPacketRewriter1_11;
|
||||
import com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter.EntityPacketRewriter1_11;
|
||||
import com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter.PlayerPacketRewriter1_11;
|
||||
@@ -30,17 +30,16 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
|
||||
|
||||
public class Protocol1_11To1_10 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
|
||||
|
||||
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.11", "1.10");
|
||||
private final EntityPacketRewriter1_11 entityRewriter = new EntityPacketRewriter1_11(this);
|
||||
private final BlockItemPacketRewriter1_11 itemRewriter = new BlockItemPacketRewriter1_11(this);
|
||||
private TranslatableRewriter<ClientboundPackets1_9_3> componentRewriter;
|
||||
private JsonNBTComponentRewriter<ClientboundPackets1_9_3> componentRewriter;
|
||||
|
||||
public Protocol1_11To1_10() {
|
||||
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
|
||||
@@ -56,17 +55,14 @@ public class Protocol1_11To1_10 extends BackwardsProtocol<ClientboundPackets1_9_
|
||||
soundRewriter.registerNamedSound(ClientboundPackets1_9_3.CUSTOM_SOUND);
|
||||
soundRewriter.registerSound(ClientboundPackets1_9_3.SOUND);
|
||||
|
||||
componentRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON);
|
||||
componentRewriter = new JsonNBTComponentRewriter<>(this, ComponentRewriterBase.ReadType.JSON);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_9_3.CHAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld());
|
||||
}
|
||||
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_11.EntityType.PLAYER));
|
||||
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||
|
||||
if (!user.has(WindowTracker.class)) {
|
||||
user.put(new WindowTracker());
|
||||
@@ -88,7 +84,7 @@ public class Protocol1_11To1_10 extends BackwardsProtocol<ClientboundPackets1_9_
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
public TranslatableRewriter<ClientboundPackets1_9_3> getComponentRewriter() {
|
||||
public JsonNBTComponentRewriter<ClientboundPackets1_9_3> getComponentRewriter() {
|
||||
return componentRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -60,7 +60,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.CONTAINER_SET_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Types.BYTE); // 0 - Window ID
|
||||
map(Types.SHORT); // 1 - Slot ID
|
||||
map(Types.ITEM1_8); // 2 - Slot Value
|
||||
|
||||
@@ -118,7 +118,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
|
||||
protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Types.BYTE); // 0 - Window ID
|
||||
map(Types.SHORT); // 1 - Slot
|
||||
map(Types.BYTE); // 2 - Button
|
||||
map(Types.SHORT); // 3 - Action number
|
||||
@@ -147,7 +147,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_11To1_10.class);
|
||||
|
||||
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed.
|
||||
Chunk chunk = wrapper.passthrough(type);
|
||||
|
||||
+12
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -159,9 +159,15 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
|
||||
map(Types.BYTE); // 1 - Entity Status
|
||||
|
||||
handler(wrapper -> {
|
||||
byte b = wrapper.get(Types.BYTE, 0);
|
||||
final int entityId = wrapper.get(Types.INT, 0);
|
||||
if (entityId != tracker(wrapper.user()).clientEntityId()) {
|
||||
// Entity events are sent for all players, but we only want to apply this for the self player
|
||||
return;
|
||||
}
|
||||
|
||||
if (b == 35) {
|
||||
final byte entityStatus = wrapper.get(Types.BYTE, 0);
|
||||
if (entityStatus == 35) {
|
||||
// TODO spawn particles?
|
||||
wrapper.clearPacket();
|
||||
wrapper.setPacketType(ClientboundPackets1_9_3.GAME_EVENT);
|
||||
wrapper.write(Types.UNSIGNED_BYTE, (short) 10); // Play Elder Guardian animation
|
||||
@@ -358,11 +364,11 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_11.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_11.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_11.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+2
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -71,11 +71,8 @@ public class Protocol1_12To1_11_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld());
|
||||
}
|
||||
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_12.EntityType.PLAYER));
|
||||
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||
|
||||
user.put(new ShoulderTracker(user));
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+36
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.MapColorMappings1_11_1;
|
||||
@@ -38,6 +39,9 @@ import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<ClientboundPackets1_12, ServerboundPackets1_9_3, Protocol1_12To1_11_1> {
|
||||
@@ -91,7 +95,7 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Types.BYTE); // 0 - Window ID
|
||||
map(Types.SHORT); // 1 - Slot
|
||||
map(Types.BYTE); // 2 - Button
|
||||
map(Types.SHORT); // 3 - Action number
|
||||
@@ -108,7 +112,7 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
|
||||
// Apologize (may happen in some cases, maybe if inventory is full?)
|
||||
PacketWrapper confirm = wrapper.create(ServerboundPackets1_12.CONTAINER_ACK);
|
||||
confirm.write(Types.UNSIGNED_BYTE, wrapper.get(Types.UNSIGNED_BYTE, 0));
|
||||
confirm.write(Types.BYTE, wrapper.get(Types.BYTE, 0));
|
||||
confirm.write(Types.SHORT, wrapper.get(Types.SHORT, 1));
|
||||
confirm.write(Types.BOOLEAN, false); // Success - not used
|
||||
|
||||
@@ -127,12 +131,21 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.LEVEL_CHUNK, wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_12To1_11_1.class);
|
||||
|
||||
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed.
|
||||
Chunk chunk = wrapper.passthrough(type);
|
||||
|
||||
handleChunk(chunk);
|
||||
for (final CompoundTag tag : chunk.getBlockEntities()) {
|
||||
final String id = tag.getString("id");
|
||||
if (id == null) {
|
||||
continue;
|
||||
}
|
||||
if (Key.stripMinecraftNamespace(id).equals("sign")) {
|
||||
handleSignText(tag);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@@ -143,9 +156,14 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
map(Types.NAMED_COMPOUND_TAG); // 2 - NBT
|
||||
|
||||
handler(wrapper -> {
|
||||
// Remove bed color
|
||||
if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 11)
|
||||
final short type = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
if (type == 9) {
|
||||
final CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
|
||||
handleSignText(tag);
|
||||
} else if (type == 11) {
|
||||
// Remove bed color
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -170,6 +188,18 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
});
|
||||
}
|
||||
|
||||
private void handleSignText(final CompoundTag tag) {
|
||||
// Push signs through component conversion, fixes https://github.com/ViaVersion/ViaBackwards/issues/835
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final StringTag lineTag = tag.getStringTag("Text" + (i + 1));
|
||||
if (lineTag == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lineTag.setValue(ComponentUtil.convertJsonOrEmpty(lineTag.getValue(), SerializerVersion.V1_12, SerializerVersion.V1_9).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,18 +18,18 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
|
||||
|
||||
public class ComponentRewriter1_12 extends TranslatableRewriter<ClientboundPackets1_12> {
|
||||
public class ComponentRewriter1_12 extends JsonNBTComponentRewriter<ClientboundPackets1_12> {
|
||||
|
||||
public ComponentRewriter1_12(Protocol1_12To1_11_1 protocol) {
|
||||
super(protocol, ComponentRewriter.ReadType.JSON);
|
||||
super(protocol, ComponentRewriterBase.ReadType.JSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
-12
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.storage.ParrotStorage;
|
||||
@@ -31,10 +32,10 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_12;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
|
||||
public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPackets1_12, Protocol1_12To1_11_1> {
|
||||
|
||||
@@ -83,13 +84,13 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
||||
map(Types.SHORT); // 9 - Velocity X
|
||||
map(Types.SHORT); // 10 - Velocity Y
|
||||
map(Types.SHORT); // 11 - Velocity Z
|
||||
map(Types1_12.ENTITY_DATA_LIST); // 12 - Entity data
|
||||
map(Types1_12.ENTITY_DATA_LIST, Types1_9.ENTITY_DATA_LIST); // 12 - Entity data
|
||||
|
||||
// Track entity
|
||||
handler(getTrackerHandler());
|
||||
|
||||
// Rewrite entity type / data
|
||||
handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST));
|
||||
handler(getMobSpawnRewriter1_11(Types1_9.ENTITY_DATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -105,9 +106,9 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
||||
map(Types.DOUBLE); // 4 - Z
|
||||
map(Types.BYTE); // 5 - Yaw
|
||||
map(Types.BYTE); // 6 - Pitch
|
||||
map(Types1_12.ENTITY_DATA_LIST); // 7 - Entity data list
|
||||
map(Types1_12.ENTITY_DATA_LIST, Types1_9.ENTITY_DATA_LIST); // 7 - Entity data list
|
||||
|
||||
handler(getTrackerAndDataHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_12.EntityType.PLAYER));
|
||||
handler(getTrackerAndDataHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_12.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -118,9 +119,8 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
||||
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Types.INT); // 2 - Dimension
|
||||
|
||||
handler(getTrackerHandler(EntityTypes1_12.EntityType.PLAYER, Types.INT));
|
||||
|
||||
handler(getDimensionHandler(1));
|
||||
handler(getPlayerTrackerHandler());
|
||||
|
||||
handler(wrapper -> {
|
||||
ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class);
|
||||
@@ -142,7 +142,7 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
registerRespawn(ClientboundPackets1_12.RESPAWN);
|
||||
registerRemoveEntities(ClientboundPackets1_12.REMOVE_ENTITIES);
|
||||
registerSetEntityData(ClientboundPackets1_12.SET_ENTITY_DATA, Types1_12.ENTITY_DATA_LIST);
|
||||
registerSetEntityData(ClientboundPackets1_12.SET_ENTITY_DATA, Types1_12.ENTITY_DATA_LIST, Types1_9.ENTITY_DATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.UPDATE_ATTRIBUTES, new PacketHandlers() {
|
||||
@Override
|
||||
@@ -285,11 +285,11 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_12.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_12.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_12.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_12.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+15
-9
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -20,7 +20,7 @@ package com.viaversion.viabackwards.protocol.v1_13_1to1_13;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter.CommandRewriter1_13_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter.EntityPacketRewriter1_13_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter.ItemPacketRewriter1_13_1;
|
||||
@@ -40,7 +40,8 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
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_13to1_13_1.Protocol1_13To1_13_1;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
|
||||
import com.viaversion.viaversion.rewriter.ParticleRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
@@ -50,7 +51,8 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.13.2", "1.13", Protocol1_13To1_13_1.class);
|
||||
private final EntityPacketRewriter1_13_1 entityRewriter = new EntityPacketRewriter1_13_1(this);
|
||||
private final ItemPacketRewriter1_13_1 itemRewriter = new ItemPacketRewriter1_13_1(this);
|
||||
private final TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON);
|
||||
private final ParticleRewriter<ClientboundPackets1_13> particleRewriter = new ParticleRewriter<>(this);
|
||||
private final JsonNBTComponentRewriter<ClientboundPackets1_13> translatableRewriter = new JsonNBTComponentRewriter<>(this, ComponentRewriterBase.ReadType.JSON);
|
||||
private final TagRewriter<ClientboundPackets1_13> tagRewriter = new TagRewriter<>(this);
|
||||
|
||||
public Protocol1_13_1To1_13() {
|
||||
@@ -72,6 +74,8 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
new CommandRewriter1_13_1(this).registerDeclareCommands(ClientboundPackets1_13.COMMANDS);
|
||||
|
||||
particleRewriter.registerLevelParticles1_13(ClientboundPackets1_13.LEVEL_PARTICLES, Types.FLOAT);
|
||||
|
||||
registerServerbound(ServerboundPackets1_13.COMMAND_SUGGESTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
@@ -203,10 +207,7 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
user.addEntityTracker(getClass(), new EntityTrackerBase(user, EntityTypes1_13.EntityType.PLAYER));
|
||||
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld());
|
||||
}
|
||||
user.addClientWorld(getClass(), new ClientWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -224,7 +225,12 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
public TranslatableRewriter<ClientboundPackets1_13> translatableRewriter() {
|
||||
@Override
|
||||
public ParticleRewriter<ClientboundPackets1_13> getParticleRewriter() {
|
||||
return particleRewriter;
|
||||
}
|
||||
|
||||
public JsonNBTComponentRewriter<ClientboundPackets1_13> translatableRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+8
-9
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -22,8 +22,8 @@ import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
@@ -55,15 +55,14 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||
byte type = wrapper.get(Types.BYTE, 0);
|
||||
EntityTypes1_13.EntityType entType = EntityTypes1_13.getTypeFromId(type, true);
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
EntityTypes1_13.EntityType entType = EntityTypes1_13.ObjectType.getEntityType(type, data);
|
||||
if (entType == null) {
|
||||
protocol.getLogger().warning("Could not find entity type " + type);
|
||||
return;
|
||||
}
|
||||
|
||||
// Rewrite falling block
|
||||
if (entType.is(EntityTypes1_13.EntityType.FALLING_BLOCK)) {
|
||||
int data = wrapper.get(Types.INT, 0);
|
||||
wrapper.set(Types.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
@@ -138,7 +137,7 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
|
||||
int value = (int) data.getValue();
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(value));
|
||||
} else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.particleType) {
|
||||
rewriteParticle(event.user(), (Particle) data.getValue());
|
||||
protocol.getParticleRewriter().rewriteParticle(event.user(), (Particle) data.getValue());
|
||||
} else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalComponentType || data.dataType() == Types1_13.ENTITY_DATA_TYPES.componentType) {
|
||||
JsonElement element = data.value();
|
||||
protocol.translatableRewriter().processText(event.user(), element);
|
||||
@@ -160,11 +159,11 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<Clientbound
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int typeId) {
|
||||
return EntityTypes1_13.getTypeFromId(typeId, false);
|
||||
return EntityTypes1_13.EntityType.findById(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int typeId) {
|
||||
return EntityTypes1_13.getTypeFromId(typeId, true);
|
||||
public EntityType objectTypeFromId(int typeId, int data) {
|
||||
return EntityTypes1_13.ObjectType.getEntityType(typeId, data);
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
|
||||
@@ -68,7 +67,5 @@ public class ItemPacketRewriter1_13_1 extends ItemRewriter<ClientboundPackets1_1
|
||||
registerSetEquippedItem(ClientboundPackets1_13.SET_EQUIPPED_ITEM);
|
||||
registerContainerClick(ServerboundPackets1_13.CONTAINER_CLICK);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_13.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
registerLevelParticles(ClientboundPackets1_13.LEVEL_PARTICLES, Types.FLOAT);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -34,7 +34,7 @@ public class WorldPacketRewriter1_13_1 {
|
||||
BlockRewriter<ClientboundPackets1_13> blockRewriter = BlockRewriter.legacy(protocol);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13_1To1_13.class);
|
||||
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
|
||||
|
||||
blockRewriter.handleChunk(chunk);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+22
-17
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -18,9 +18,12 @@
|
||||
package com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.Protocol1_13_2To1_13_1;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
|
||||
@@ -47,11 +50,7 @@ public class EntityPacketRewriter1_13_2 {
|
||||
map(Types.SHORT); // 11 - Velocity Z
|
||||
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Entity data
|
||||
|
||||
handler(wrapper -> {
|
||||
for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
|
||||
entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId()));
|
||||
}
|
||||
});
|
||||
handler(EntityPacketRewriter1_13_2::updateEntityData);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -67,11 +66,7 @@ public class EntityPacketRewriter1_13_2 {
|
||||
map(Types.BYTE); // 6 - Pitch
|
||||
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Entity data
|
||||
|
||||
handler(wrapper -> {
|
||||
for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
|
||||
entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId()));
|
||||
}
|
||||
});
|
||||
handler(EntityPacketRewriter1_13_2::updateEntityData);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,13 +76,23 @@ public class EntityPacketRewriter1_13_2 {
|
||||
map(Types.VAR_INT); // 0 - Entity ID
|
||||
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Entity data list
|
||||
|
||||
handler(wrapper -> {
|
||||
for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
|
||||
entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId()));
|
||||
}
|
||||
});
|
||||
handler(EntityPacketRewriter1_13_2::updateEntityData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void updateEntityData(final PacketWrapper wrapper) {
|
||||
for (final EntityData data : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
|
||||
final EntityDataType dataType = Types1_13.ENTITY_DATA_TYPES.byId(data.dataType().typeId());
|
||||
data.setDataType(dataType);
|
||||
|
||||
if (dataType == Types1_13.ENTITY_DATA_TYPES.particleType) {
|
||||
final Particle particle = data.value();
|
||||
if (particle.id() == 27) {
|
||||
final Item item = particle.<Item>getArgument(0).getValue();
|
||||
particle.set(0, Types.ITEM1_13, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -30,7 +30,7 @@ public class ItemPacketRewriter1_13_2 {
|
||||
protocol.registerClientbound(ClientboundPackets1_13.CONTAINER_SET_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Types.BYTE); // 0 - Window ID
|
||||
map(Types.SHORT); // 1 - Slot ID
|
||||
map(Types.ITEM1_13_2, Types.ITEM1_13); // 2 - Slot Value
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class ItemPacketRewriter1_13_2 {
|
||||
protocol.registerServerbound(ServerboundPackets1_13.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Types.BYTE); // 0 - Window ID
|
||||
map(Types.SHORT); // 1 - Slot
|
||||
map(Types.BYTE); // 2 - Button
|
||||
map(Types.SHORT); // 3 - Action number
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+7
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
@@ -20,7 +20,7 @@ package com.viaversion.viabackwards.protocol.v1_13to1_12_2;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.BackwardsMappingData1_13;
|
||||
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.PaintingNames1_13;
|
||||
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.provider.BackwardsBlockEntityProvider;
|
||||
@@ -45,7 +45,7 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.ComponentRewriterBase;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.ProtocolLogger;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -56,7 +56,7 @@ public class Protocol1_13To1_12_2 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public static final ProtocolLogger LOGGER = new ProtocolLogger(Protocol1_13To1_12_2.class);
|
||||
private final EntityPacketRewriter1_13 entityRewriter = new EntityPacketRewriter1_13(this);
|
||||
private final BlockItemPacketRewriter1_13 blockItemPackets = new BlockItemPacketRewriter1_13(this);
|
||||
private final TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON) {
|
||||
private final JsonNBTComponentRewriter<ClientboundPackets1_13> translatableRewriter = new JsonNBTComponentRewriter<>(this, ComponentRewriterBase.ReadType.JSON) {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject root, String translate) {
|
||||
String mappedKey = mappedTranslationKey(translate);
|
||||
@@ -65,7 +65,7 @@ public class Protocol1_13To1_12_2 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
}
|
||||
};
|
||||
private final TranslatableRewriter<ClientboundPackets1_13> translatableToLegacyRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON) {
|
||||
private final JsonNBTComponentRewriter<ClientboundPackets1_13> translatableToLegacyRewriter = new JsonNBTComponentRewriter<>(this, ComponentRewriterBase.ReadType.JSON) {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject root, String translate) {
|
||||
String mappedKey = mappedTranslationKey(translate);
|
||||
@@ -114,11 +114,8 @@ public class Protocol1_13To1_12_2 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld());
|
||||
}
|
||||
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_13.EntityType.PLAYER));
|
||||
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||
|
||||
user.put(new BackwardsBlockStorage());
|
||||
user.put(new TabCompleteStorage());
|
||||
@@ -151,7 +148,7 @@ public class Protocol1_13To1_12_2 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
|
||||
// Don't override the parent method
|
||||
public TranslatableRewriter<ClientboundPackets1_13> translatableRewriter() {
|
||||
public JsonNBTComponentRewriter<ClientboundPackets1_13> translatableRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2016-2025 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
|
||||
|
||||
Loaded 100 of 275 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user