Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
007799734f
|
||
|
|
2a2cfd20a5
|
||
|
|
197288a47e | ||
|
|
44e478ebe7 | ||
|
|
ea548dfd91 | ||
|
|
d0561f2e19 | ||
|
|
2c8189a447 | ||
|
|
48c9e45bcf | ||
|
|
ecb4f4bf00 | ||
|
|
6ea9377622 | ||
|
|
b789fdebb7 | ||
|
|
e7b0606e18 | ||
|
|
14991b61e7 | ||
|
|
bf490c3805 | ||
|
|
7ca7078141 | ||
|
|
9c72c68d11 | ||
|
|
91643b8a53 | ||
|
|
170af55f91 | ||
|
|
00d82f9f2f | ||
|
|
79ef613c15 | ||
|
|
e2fcbafc70 | ||
|
|
9ae46145e5 | ||
|
|
76f90b68b8 | ||
|
|
32a2ee6bfa | ||
|
|
04878b7e34 | ||
|
|
45508ddf4d | ||
|
|
adccdc4b41 | ||
|
|
0accea66f2 | ||
|
|
47535748c4 | ||
|
|
65257be3ee | ||
|
|
880e879dce | ||
|
|
0ccc6a0923 | ||
|
|
7bff361e14 | ||
|
|
c2c28473cc | ||
|
|
048d502998 | ||
|
|
e0c1f53115 | ||
|
|
e5313a466b | ||
|
|
e30633e367 | ||
|
|
a443dd5d11 | ||
|
|
3820426bce | ||
|
|
031ae32f27 | ||
|
|
e83616139e | ||
|
|
7325b733d6 | ||
|
|
e64501eae8 | ||
|
|
2d99607c35 | ||
|
|
4d159189c0 | ||
|
|
2076294856 | ||
|
|
49f7bd22be | ||
|
|
298605874d | ||
|
|
35b94f1878 | ||
|
|
37955059c4 | ||
|
|
af4306bc81 | ||
|
|
98ca00f625 | ||
|
|
598804432b | ||
|
|
92bae0a5c4 | ||
|
|
d50b6a2f89 | ||
|
|
54cc085717 | ||
|
|
bd0d4c31b2 | ||
|
|
705c88f4b3 | ||
|
|
7306a795b9 | ||
|
|
dfdfad4bfc | ||
|
|
c87654848d | ||
|
|
08a7077d10 | ||
|
|
73afaaf493 | ||
|
|
f0f8038b18 | ||
|
|
540c0d0d47 | ||
|
|
d00b0c8afe | ||
|
|
b34385c09e | ||
|
|
ff47845df1 | ||
|
|
fc37b9c0ba | ||
|
|
e3baafa2a2 | ||
|
|
11914da37e | ||
|
|
30fa58af81 | ||
|
|
52b6aed005 | ||
|
|
9d74706e84 | ||
|
|
7d5ad45ffc | ||
|
|
bd3593e15a | ||
|
|
835fb5de08 | ||
|
|
8b2769f19b | ||
|
|
4da08b5a35 | ||
|
|
7da8e62a39 | ||
|
|
31c62f96b9 | ||
|
|
0f866d8b50 | ||
|
|
32d265116a | ||
|
|
b7d1197be3 | ||
|
|
d4363b67b6 | ||
|
|
dcdce8ad52 | ||
|
|
af44f88d6e | ||
|
|
1d1d77abfd | ||
|
|
ae800f16be | ||
|
|
f31d731f34 | ||
|
|
2ddd0d8b66 | ||
|
|
f97884158b | ||
|
|
1e2fcb9c58 | ||
|
|
5110326a90 | ||
|
|
6887556b2c | ||
|
|
66cf650d36 | ||
|
|
1426631c97 | ||
|
|
b6a32823cc | ||
|
|
aff88a6ca3 | ||
|
|
0edfd844b9 | ||
|
|
57a64740aa | ||
|
|
f7903050bf | ||
|
|
3a7ac0765b | ||
|
|
48f500a470 | ||
|
|
c3e19b769b | ||
|
|
561829d952 | ||
|
|
6767379526 | ||
|
|
a10ce1f35f | ||
|
|
49f0c673e6 | ||
|
|
fd2c81a6fd | ||
|
|
901463e095 | ||
|
|
227d37b2b9 | ||
|
|
be5bb6e07c | ||
|
|
064dbee920 | ||
|
|
783006baa5 | ||
|
|
ba93a40d22 | ||
|
|
422f81dd2e | ||
|
|
aa47e3c0a5 | ||
|
|
094298771e | ||
|
|
66133d1ccc | ||
|
|
11011d59aa | ||
|
|
691cbf1b2a | ||
|
|
8d8675a891 | ||
|
|
4fa2f10f3a | ||
|
|
c2e516dcd2 | ||
|
|
153eedd5eb | ||
|
|
2d404608ee | ||
|
|
bbc1d77939 | ||
|
|
fa36428391 | ||
|
|
b6dee43620 | ||
|
|
371c25f9d0 | ||
|
|
a41bbc2d67 | ||
|
|
de84a8fffc | ||
|
|
22ff1416c2 | ||
|
|
00b74ef2dd | ||
|
|
8d5b348318 | ||
|
|
51f001ac3e | ||
|
|
e27caba231 | ||
|
|
07aab015ea | ||
|
|
6bcf8d8895 | ||
|
|
43c42f44f6 | ||
|
|
295d87d49f | ||
|
|
ab97e248da | ||
|
|
276b9ba386 | ||
|
|
351ff79187 | ||
|
|
87ed2160c9 | ||
|
|
668ed3c455 | ||
|
|
3a0c742878 | ||
|
|
bc7b33f28a | ||
|
|
657dcaa682 | ||
|
|
3676906fbf | ||
|
|
dc9dbe9900 | ||
|
|
d8924485ac | ||
|
|
b02a257383 | ||
|
|
a4b666724f | ||
|
|
e92b15c19f | ||
|
|
3fd2da9bf8 | ||
|
|
ff4fbe2029 | ||
|
|
c3d32874a7 | ||
|
|
7b9888c758 | ||
|
|
e0c05df633 | ||
|
|
3af661b256 | ||
|
|
74ebb09ebc | ||
|
|
36396c10b0 | ||
|
|
bc9b84464b | ||
|
|
0ee7c1cf16 | ||
|
|
6d35536862 | ||
|
|
8945193a8a | ||
|
|
546f4b14fa | ||
|
|
e8028cf446 | ||
|
|
6a85860132 | ||
|
|
4b11b8e1bb | ||
|
|
724a6b7a4b | ||
|
|
c785df5fc0 | ||
|
|
de92c06dfd | ||
|
|
31f427a1b6 | ||
|
|
fffcae9c0e | ||
|
|
594dbbcbe9 | ||
|
|
8c4efbbb13 | ||
|
|
5b1dcf63d2 | ||
|
|
beead5773c | ||
|
|
60a5c4ae2f | ||
|
|
d707e20b05 | ||
|
|
14bad1d36f | ||
|
|
7a9bf5f465 | ||
|
|
f290af7b81 | ||
|
|
064d0008f5 | ||
|
|
fbe30d9da5 | ||
|
|
31490069ea | ||
|
|
1b8d5eacc0 | ||
|
|
abdb79598b | ||
|
|
1b5b59317c | ||
|
|
6e4ac65983 | ||
|
|
64cce82140 | ||
|
|
cb79316d6a | ||
|
|
7d34c3838a | ||
|
|
c60152532d | ||
|
|
1894bac11b | ||
|
|
a80ca442e5 | ||
|
|
c69ce24d32 | ||
|
|
e937a886ec | ||
|
|
3e261824ef | ||
|
|
43c3bb11dc | ||
|
|
f57ac05bd4 | ||
|
|
a3c623c202 | ||
|
|
481315f1e6 | ||
|
|
21e50421e5 | ||
|
|
233d52281b | ||
|
|
6807a02de7 | ||
|
|
b34cc42a65 | ||
|
|
7b1f0a8737 | ||
|
|
a171e4013b | ||
|
|
3e3561c18f | ||
|
|
0097a97ab0 | ||
|
|
6e583a0c8e | ||
|
|
780b981c68 | ||
|
|
5df933f0e2 | ||
|
|
750a98cb06 | ||
|
|
1ebfa0a715 | ||
|
|
dc82de8ba2 | ||
|
|
9ecdaa30bf | ||
|
|
ee69005318 | ||
|
|
740a6d9b96 | ||
|
|
b1d680468b | ||
|
|
64c18af7b6 | ||
|
|
6728a8a809 | ||
|
|
0cb70b0a04 | ||
|
|
2f7f108cd8 |
No files matched your search
+14
-2
@@ -1,4 +1,16 @@
|
||||
root = true
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
tab_width = 4
|
||||
|
||||
[*.java]
|
||||
indent_style = tab
|
||||
ij_java_class_count_to_use_import_on_demand = 999999
|
||||
ij_java_names_count_to_use_import_on_demand = 999999
|
||||
ij_java_imports_layout = *, |, $*
|
||||
ij_java_generate_final_locals = true
|
||||
ij_java_generate_final_parameters = true
|
||||
|
||||
[{*.json,*.yml}]
|
||||
indent_size = 2
|
||||
@@ -0,0 +1 @@
|
||||
.gitea/CODEOWNERS linguist-detectable=false
|
||||
@@ -0,0 +1,3 @@
|
||||
# Pull requests request review from the eligible staff team(s).
|
||||
# One approval from either an Admin or Developer satisfies branch protection.
|
||||
* @trueog/Admins @trueog/Developers
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
github: FlorianMichael
|
||||
custom: ['https://florianmichael.de/donate', 'https://viaversion.com/donate', 'https://creeper123123321.github.io/#donate']
|
||||
github: florianreuth
|
||||
custom: [ 'https://florianreuth.de/donate', 'https://creeper123123321.github.io/#donate' ]
|
||||
@@ -1,6 +1,6 @@
|
||||
name: Bug report
|
||||
description: Report a bug or console error
|
||||
labels: [Unconfirmed]
|
||||
labels: [ Unconfirmed ]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
@@ -71,9 +71,9 @@ body:
|
||||
attributes:
|
||||
label: Additional Server Info
|
||||
description: |
|
||||
Do you use a proxy (eg. BungeeCord)? What software do you use and what plugins?
|
||||
Do you use a proxy (eg. Velocity)? What software do you use and what plugins?
|
||||
placeholder: |
|
||||
Example: "I also use BungeeCord with the following plugins: x, y, z"
|
||||
Example: "I also use Velocity with the following plugins: x, y, z"
|
||||
validations:
|
||||
required: false
|
||||
|
||||
@@ -82,7 +82,7 @@ body:
|
||||
label: Checklist
|
||||
description: Make sure you have followed each of the steps outlined here.
|
||||
options:
|
||||
- label: Via plugins are only running on **EITHER** the backend servers (e.g. Paper) **OR** the proxy (e.g. BungeeCord), **not on both**.
|
||||
- label: Via plugins are only running on **EITHER** the backend servers (e.g. Paper) **OR** the proxy (e.g. Velocity), **not on both**.
|
||||
required: true
|
||||
- label: I have included a ViaVersion dump.
|
||||
required: true
|
||||
@@ -91,4 +91,4 @@ body:
|
||||
- label: I have tried the latest build(s) from https://ci.viaversion.com/ and the issue still persists.
|
||||
required: true
|
||||
- label: I have looked at https://www.spigotmc.org/resources/viarewind-legacy-support.52924/ and it does not offer a fix for my problem
|
||||
required: true
|
||||
required: true
|
||||
@@ -5,34 +5,34 @@ labels: [ Feature Request ]
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Problem Description
|
||||
description: |
|
||||
Describe the issue you are facing or why you need the feature to be added.
|
||||
placeholder: |
|
||||
I am always frustrated with...
|
||||
label: Problem Description
|
||||
description: |
|
||||
Describe the issue you are facing or why you need the feature to be added.
|
||||
placeholder: |
|
||||
I am always frustrated with...
|
||||
validations:
|
||||
required: true
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Solution Description
|
||||
description: |
|
||||
Describe the solution you would like to see.
|
||||
label: Solution Description
|
||||
description: |
|
||||
Describe the solution you would like to see.
|
||||
validations:
|
||||
required: true
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Alternatives
|
||||
description: |
|
||||
Describe alternatives you have considered.
|
||||
label: Alternatives
|
||||
description: |
|
||||
Describe alternatives you have considered.
|
||||
validations:
|
||||
required: false
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional Info
|
||||
description: |
|
||||
Does the feature apply to any specific version or environment?
|
||||
label: Additional Info
|
||||
description: |
|
||||
Does the feature apply to any specific version or environment?
|
||||
validations:
|
||||
required: false
|
||||
required: false
|
||||
@@ -0,0 +1,14 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gradle"
|
||||
cooldown:
|
||||
default-days: 7
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
- package-ecosystem: "github-actions"
|
||||
cooldown:
|
||||
default-days: 7
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
+20
-15
@@ -1,28 +1,33 @@
|
||||
name: ViaRewind CI
|
||||
name: Build
|
||||
on: [pull_request, push, workflow_dispatch]
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
# Only run on PRs if the source branch is on a different repo. We do not need to run everything twice.
|
||||
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
|
||||
with:
|
||||
cache-disabled: false
|
||||
cache-provider: basic
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
check-latest: true
|
||||
- name: Cache Dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
- name: Upload Artifacts to GitHub
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: Artifacts
|
||||
path: build/libs/
|
||||
@@ -4,24 +4,40 @@ on:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
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@v1
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
|
||||
with:
|
||||
cache-disabled: false
|
||||
cache-provider: basic
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
check-latest: true
|
||||
- name: Publish
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
- name: Publish to Hangar
|
||||
env:
|
||||
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
|
||||
run: ./gradlew publishAllPublicationsToHangar --stacktrace
|
||||
continue-on-error: true
|
||||
- name: Publish to Modrinth
|
||||
env:
|
||||
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
||||
run: ./gradlew build modrinth publishAllPublicationsToHangar
|
||||
run: ./gradlew modrinth --stacktrace
|
||||
continue-on-error: true
|
||||
+20
-97
@@ -1,113 +1,36 @@
|
||||
### Java files ###
|
||||
*.class
|
||||
# Gradle
|
||||
|
||||
# Package Files
|
||||
#*.jar
|
||||
*.war
|
||||
*.ear
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
.kotlin/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
# Eclipse
|
||||
|
||||
*.launch
|
||||
|
||||
# Idea
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
|
||||
# Ignore project files
|
||||
.idea/
|
||||
!.idea/copyright/*
|
||||
!.idea/scopes/*
|
||||
*.iml
|
||||
|
||||
# Ignore IDEA directory
|
||||
.idea/*
|
||||
|
||||
# Include the project's dictionary
|
||||
!.idea/dictionaries/
|
||||
!.idea/dictionaries/*
|
||||
|
||||
# File-based project format:
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
### Plugin-specific files: ###
|
||||
# IntelliJ
|
||||
/out/
|
||||
# VSCode
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
*.pydevproject
|
||||
.metadata
|
||||
.gradle
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# Eclipse Core
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
# macOS
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
DS_Store
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
# Misc
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
|
||||
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
.nb-gradle/
|
||||
|
||||
|
||||
|
||||
### Git ###
|
||||
# Don't exclude the .gitignore itself
|
||||
!/.gitignore
|
||||
run/
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings>
|
||||
<settings default="viarewind-gpl">
|
||||
<module2copyright>
|
||||
<element module="ViaRewind" copyright="viarewind-gpl" />
|
||||
</module2copyright>
|
||||
@@ -1,16 +1,23 @@
|
||||
# ViaRewind
|
||||
|
||||
[](https://github.com/ViaVersion/ViaRewind/releases)
|
||||
[](https://github.com/ViaVersion/ViaRewind/actions)
|
||||
[](https://viaversion.com/discord)
|
||||
|
||||
**ViaBackwards addon to allow 1.8.x and 1.7.x clients on newer server versions.** <br>
|
||||
**ViaVersion addon to allow 1.8.x and 1.7.x clients on newer server versions.** <br>
|
||||
Runs on 1.9-latest servers or 1.8 clients and lower.
|
||||
|
||||
**You can override the included version in [ViaFabric](https://modrinth.com/mod/viafabric) or [ViaProxy](https://github.com/ViaVersion/ViaProxy):**
|
||||
**You can override the included version in [ViaFabric](https://modrinth.com/mod/viafabric)
|
||||
or [ViaProxy](https://github.com/ViaVersion/ViaProxy):**
|
||||
|
||||
- in **ViaFabric**, put ViaRewind into the `mods` folder
|
||||
- in **ViaProxy**, put ViaRewind into the `jars` folder
|
||||
|
||||
**Requires [ViaVersion](https://hangar.papermc.io/ViaVersion/ViaVersion) and [ViaBackwards](https://hangar.papermc.io/ViaVersion/ViaBackwards) to be installed..**
|
||||
Note: when using ViaFabric <= 1.16.5 or J8 ViaProxy builds, you
|
||||
need [J8 ViaRewind](https://ci.viaversion.com/view/ViaRewind/job/ViaRewind-Java8/) builds.
|
||||
|
||||
**Requires [ViaVersion](https://hangar.papermc.io/ViaVersion/ViaVersion)
|
||||
and [ViaBackwards](https://hangar.papermc.io/ViaVersion/ViaBackwards) to be installed..**
|
||||
|
||||
Releases/Dev Builds
|
||||
-
|
||||
@@ -35,7 +42,9 @@ Other Links
|
||||
Building
|
||||
-
|
||||
After cloning this repository, build the project with Gradle by running `./gradlew build` and take the created jar out
|
||||
of the `universal/build/libs` directory.
|
||||
of the `build/libs` directory.
|
||||
|
||||
You need JDK 17 or newer to build ViaRewind.
|
||||
|
||||
License
|
||||
-
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Security Policy
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you discover a **security vulnerability**, please **do not** open a public issue. Instead, use one of the following
|
||||
**confidential contact methods**:
|
||||
|
||||
* **Email:** [security@viaversion.com](mailto:security@viaversion.com)
|
||||
* **Discord:** Join our [Discord server](https://discord.gg/viaversion) and visit
|
||||
the [#exploit-report](https://discord.com/channels/316206679014244363/1388847764137316485) channel for further
|
||||
instructions.
|
||||
|
||||
If your issue is **not security-related** (e.g., bug reports, feature requests, or usage questions), please use
|
||||
the [GitHub Issues page](https://github.com/ViaVersion/ViaRewind/issues) or contact us via
|
||||
the [Discord server](https://discord.gg/viaversion).
|
||||
@@ -0,0 +1,143 @@
|
||||
import de.florianreuth.baseproject.*
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
eclipse
|
||||
id("io.papermc.hangar-publish-plugin")
|
||||
id("com.modrinth.minotaur")
|
||||
id("de.florianreuth.baseproject")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
setupProject()
|
||||
setupViaPublishing()
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.viaversion.com")
|
||||
maven("https://repo.papermc.io/repository/maven-public")
|
||||
maven("https://maven.fabricmc.net")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.viaversion:viaversion:5.7.2")
|
||||
compileOnly("com.viaversion:viabackwards:5.7.2")
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
val projectVersion = project.version
|
||||
val projectDescription = project.description
|
||||
filesMatching(listOf("plugin.yml", "fabric.mod.json", "META-INF/sponge_plugins.json")) {
|
||||
expand(mapOf("version" to projectVersion, "description" to projectDescription))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
base {
|
||||
archivesName.set("ViaRewind")
|
||||
}
|
||||
|
||||
val shade = configureShadedDependencies(false) // Only shade, don't add them as dependency
|
||||
|
||||
dependencies {
|
||||
subprojects.forEach {
|
||||
shade(it)
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
manifest {
|
||||
attributes("paperweight-mappings-namespace" to "mojang")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val branch = branchName()
|
||||
val baseVersion = version as String
|
||||
val isRelease = !baseVersion.contains('-')
|
||||
val isMainBranch = branch == "master"
|
||||
if (!isRelease || isMainBranch) { // Only publish releases from the main branch
|
||||
val suffixedVersion = if (isRelease) baseVersion else baseVersion + "+" + System.getenv("GITHUB_RUN_NUMBER")
|
||||
val changelogContent = if (isRelease) {
|
||||
"See [GitHub](https://github.com/ViaVersion/ViaRewind) for release notes."
|
||||
} else {
|
||||
val commitHash = latestCommitHash()
|
||||
"[$commitHash](https://github.com/ViaVersion/ViaRewind/commit/$commitHash) ${latestCommitMessage()}"
|
||||
}
|
||||
|
||||
modrinth {
|
||||
val mcVersions: List<String> = (property("minecraft_versions") as String)
|
||||
.split(",")
|
||||
.map { it.trim() }
|
||||
token.set(System.getenv("MODRINTH_TOKEN"))
|
||||
projectId.set("viarewind")
|
||||
versionType.set(if (isRelease) "release" else if (isMainBranch) "beta" else "alpha")
|
||||
versionNumber.set(suffixedVersion)
|
||||
versionName.set(suffixedVersion)
|
||||
changelog.set(changelogContent)
|
||||
uploadFile.set(tasks.jar.flatMap { it.archiveFile })
|
||||
gameVersions.set(mcVersions)
|
||||
loaders.add("fabric")
|
||||
loaders.add("paper")
|
||||
loaders.add("folia")
|
||||
loaders.add("velocity")
|
||||
autoAddDependsOn.set(false)
|
||||
detectLoaders.set(false)
|
||||
dependencies {
|
||||
required.project("viaversion")
|
||||
required.project("viabackwards")
|
||||
optional.project("viafabric")
|
||||
}
|
||||
}
|
||||
tasks.modrinth {
|
||||
notCompatibleWithConfigurationCache("")
|
||||
}
|
||||
|
||||
hangarPublish {
|
||||
publications.register("plugin") {
|
||||
version.set(suffixedVersion)
|
||||
id.set("ViaRewind")
|
||||
channel.set(if (isRelease) "Release" else if (isMainBranch) "Snapshot" else "Alpha")
|
||||
changelog.set(changelogContent)
|
||||
apiKey.set(System.getenv("HANGAR_TOKEN"))
|
||||
platforms {
|
||||
paper {
|
||||
jar.set(tasks.jar.flatMap { it.archiveFile })
|
||||
platformVersions.set(listOf(property("minecraft_version_range") as String))
|
||||
dependencies {
|
||||
hangar("ViaVersion") {
|
||||
required = true
|
||||
}
|
||||
hangar("ViaBackwards") {
|
||||
required = true
|
||||
}
|
||||
}
|
||||
}
|
||||
velocity {
|
||||
jar.set(tasks.jar.flatMap { it.archiveFile })
|
||||
platformVersions.set(listOf(property("velocity_version") as String))
|
||||
dependencies {
|
||||
hangar("ViaVersion") {
|
||||
required = true
|
||||
}
|
||||
hangar("ViaBackwards") {
|
||||
required = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks.named("publishPluginPublicationToHangar") {
|
||||
notCompatibleWithConfigurationCache("")
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
plugins {
|
||||
id "groovy-gradle-plugin"
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
plugins {
|
||||
id "java-library"
|
||||
id "maven-publish"
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = uri("https://repo.viaversion.com")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.maven.apache.org/maven2/")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://maven.fabricmc.net/")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.spongepowered.org/repository/maven-public/")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://nexus.velocitypowered.com/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "com.viaversion:viaversion:${project.viaversion_version}"
|
||||
compileOnly "com.viaversion:viabackwards:${project.viabackwards_version}"
|
||||
compileOnly "io.netty:netty-all:${project.netty_version}"
|
||||
compileOnly "com.google.guava:guava:${project.guava_version}"
|
||||
}
|
||||
|
||||
base {
|
||||
archivesName = project.maven_name
|
||||
group = project.maven_group
|
||||
version = project.maven_version
|
||||
description = "ViaBackwards addon to allow 1.8.x and 1.7.x clients on newer server versions."
|
||||
}
|
||||
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
tasks {
|
||||
// Variable replacements
|
||||
processResources {
|
||||
for (final def file in ["plugin.yml", "bungee.yml", "META-INF/sponge_plugins.json", "fabric.mod.json"]) {
|
||||
filesMatching(file) {
|
||||
expand(
|
||||
"version": project.version,
|
||||
"description": project.description
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "Via"
|
||||
url = "https://repo.viaversion.com/"
|
||||
|
||||
credentials(PasswordCredentials)
|
||||
authentication {
|
||||
basic(BasicAuthentication)
|
||||
}
|
||||
}
|
||||
}
|
||||
publications {
|
||||
main(MavenPublication) {
|
||||
artifactId = project.maven_name
|
||||
groupId = project.maven_group
|
||||
version = project.maven_version
|
||||
|
||||
from(components.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
tasks.withType(Javadoc) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
plugins {
|
||||
id "com.viaversion.java-conventions"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api project(":viarewind-common")
|
||||
|
||||
compileOnly(annotationProcessor("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"))
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
dependencies {
|
||||
compileOnly(project(":viarewind-common"))
|
||||
compileOnly("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT")
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
maven_name=viarewind-bukkit
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,14 +18,22 @@
|
||||
package com.viaversion.viarewind;
|
||||
|
||||
import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.provider.InventoryProvider;
|
||||
import com.viaversion.viarewind.provider.BukkitInventoryProvider;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BukkitPlugin extends JavaPlugin implements ViaRewindPlatform {
|
||||
|
||||
public BukkitPlugin() {
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
public BukkitPlugin() {
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final ViaProviders providers = Via.getManager().getProviders();
|
||||
providers.use(InventoryProvider.class, new BukkitInventoryProvider());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.provider;
|
||||
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.provider.InventoryProvider;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class BukkitInventoryProvider extends InventoryProvider {
|
||||
|
||||
@Override
|
||||
public boolean hasElytra(final UserConnection connection) {
|
||||
final Player player = Bukkit.getPlayer(connection.getProtocolInfo().getUuid());
|
||||
final ItemStack chestplate = player.getInventory().getChestplate();
|
||||
return chestplate != null && chestplate.getType() == Material.ELYTRA;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
name: ViaRewind
|
||||
main: com.viaversion.viarewind.BukkitPlugin
|
||||
authors: [FlorianMichael/EnZaXD, Gerrygames, creeper123321123]
|
||||
authors: [ EnZaXD, Gerrygames, creeper123123321 ]
|
||||
version: ${version}
|
||||
description: ${description}
|
||||
website: https://viaversion.com/rewind
|
||||
api-version: 1.13
|
||||
folia-supported: true
|
||||
load: STARTUP
|
||||
depend: [ViaVersion, ViaBackwards]
|
||||
depend: [ ViaVersion, ViaBackwards ]
|
||||
@@ -1,9 +0,0 @@
|
||||
plugins {
|
||||
id "com.viaversion.java-conventions"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api project(":viarewind-common")
|
||||
|
||||
compileOnly(annotationProcessor("net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT"))
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
maven_name=viarewind-bungee
|
||||
@@ -1,6 +0,0 @@
|
||||
name: ViaRewind
|
||||
main: com.viaversion.viarewind.BungeePlugin
|
||||
authors: [FlorianMichael/EnZaXD, Gerrygames, creeper123321123]
|
||||
version: ${version}
|
||||
depends: [ViaVersion, ViaBackwards]
|
||||
website: https://viaversion.com/rewind
|
||||
@@ -1,28 +0,0 @@
|
||||
plugins {
|
||||
id "com.viaversion.java-conventions"
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "net.raphimc.class-token-replacer" version "1.0.0"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
classTokenReplacer {
|
||||
property("\${version}", rootProject.maven_version)
|
||||
property("\${impl_version}", "git-ViaRewind-${rootProject.maven_version}:${project.latestCommitHash()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String latestCommitHash() {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'rev-parse', '--short', 'HEAD'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().trim()
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import de.florianreuth.baseproject.latestCommitHash
|
||||
|
||||
plugins {
|
||||
id("net.raphimc.class-token-replacer")
|
||||
}
|
||||
|
||||
val viaProxy: Configuration by configurations.creating
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.netty:netty-all:4.0.20.Final")
|
||||
compileOnly("com.google.guava:guava:17.0")
|
||||
compileOnly("com.velocitypowered:velocity-native:3.4.0-SNAPSHOT")
|
||||
|
||||
viaProxy("net.raphimc:ViaProxy:[3.0.0,4.0.0)") {
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.configureEach {
|
||||
classTokenReplacer {
|
||||
replaceInPlace.set(true)
|
||||
|
||||
property("\${version}", project.version)
|
||||
property("\${impl_version}", "git-ViaRewind-${project.version}:${latestCommitHash()}")
|
||||
}
|
||||
}
|
||||
|
||||
// Task to quickly test/debug code changes using https://github.com/ViaVersion/ViaProxy
|
||||
// For further instructions see the ViaProxy repository README
|
||||
val prepareViaProxyFiles by tasks.registering(Copy::class) {
|
||||
dependsOn(project.tasks.jar)
|
||||
|
||||
from(project.tasks.jar.get().archiveFile.get().asFile)
|
||||
into(layout.projectDirectory.dir("run/jars"))
|
||||
|
||||
val projectName = project.name
|
||||
rename { "${projectName}.jar" }
|
||||
}
|
||||
|
||||
val cleanupViaProxyFiles by tasks.registering(Delete::class) {
|
||||
delete(
|
||||
layout.projectDirectory.file("run/jars/${project.name}.jar"),
|
||||
layout.projectDirectory.dir("run/logs")
|
||||
)
|
||||
}
|
||||
|
||||
tasks.register<JavaExec>("runViaProxy") {
|
||||
dependsOn(prepareViaProxyFiles)
|
||||
finalizedBy(cleanupViaProxyFiles)
|
||||
|
||||
mainClass.set("net.raphimc.viaproxy.ViaProxy")
|
||||
classpath = viaProxy
|
||||
workingDir = layout.projectDirectory.dir("run").asFile
|
||||
jvmArgs = listOf("-DskipUpdateCheck")
|
||||
|
||||
if (System.getProperty("viaproxy.gui.autoStart") != null) {
|
||||
jvmArgs("-Dviaproxy.gui.autoStart")
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
maven_name=viarewind-common
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -23,21 +23,21 @@ import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
|
||||
public class ViaRewind {
|
||||
|
||||
private static ViaRewindPlatform platform;
|
||||
private static ViaRewindConfig config;
|
||||
private static ViaRewindPlatform platform;
|
||||
private static ViaRewindConfig config;
|
||||
|
||||
public static void init(ViaRewindPlatform platform, ViaRewindConfig config) {
|
||||
Preconditions.checkArgument(ViaRewind.platform == null, "ViaRewind is already initialized");
|
||||
public static void init(ViaRewindPlatform platform, ViaRewindConfig config) {
|
||||
Preconditions.checkArgument(ViaRewind.platform == null, "ViaRewind is already initialized");
|
||||
|
||||
ViaRewind.platform = platform;
|
||||
ViaRewind.config = config;
|
||||
}
|
||||
ViaRewind.platform = platform;
|
||||
ViaRewind.config = config;
|
||||
}
|
||||
|
||||
public static ViaRewindPlatform getPlatform() {
|
||||
return ViaRewind.platform;
|
||||
}
|
||||
public static ViaRewindPlatform getPlatform() {
|
||||
return ViaRewind.platform;
|
||||
}
|
||||
|
||||
public static ViaRewindConfig getConfig() {
|
||||
return ViaRewind.config;
|
||||
}
|
||||
public static ViaRewindConfig getConfig() {
|
||||
return ViaRewind.config;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,101 +18,115 @@
|
||||
package com.viaversion.viarewind;
|
||||
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ViaRewindConfig extends Config implements com.viaversion.viarewind.api.ViaRewindConfig {
|
||||
|
||||
private CooldownIndicator cooldownIndicator;
|
||||
private boolean replaceAdventureMode;
|
||||
private boolean replaceParticles;
|
||||
private int maxBookPages;
|
||||
private int maxBookPageSize;
|
||||
private boolean emulateWorldBorder;
|
||||
private boolean alwaysShowOriginalMobName;
|
||||
private String worldBorderParticle;
|
||||
private boolean enableOffhand;
|
||||
private String offhandCommand;
|
||||
private CooldownIndicator cooldownIndicator;
|
||||
private boolean replaceAdventureMode;
|
||||
private boolean replaceParticles;
|
||||
private int maxBookPages;
|
||||
private int maxBookPageSize;
|
||||
private boolean emulateWorldBorder;
|
||||
private boolean alwaysShowOriginalMobName;
|
||||
private String worldBorderParticle;
|
||||
private boolean enableOffhand;
|
||||
private String offhandCommand;
|
||||
private boolean emulateLevitationEffect;
|
||||
private boolean handlePlayerCombatPacket;
|
||||
|
||||
public ViaRewindConfig(File configFile) {
|
||||
super(configFile);
|
||||
public ViaRewindConfig(File configFile, Logger logger) {
|
||||
super(configFile, logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
loadFields();
|
||||
}
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
loadFields();
|
||||
}
|
||||
|
||||
private void loadFields() {
|
||||
cooldownIndicator = CooldownIndicator.valueOf(getString("cooldown-indicator", "TITLE").toUpperCase());
|
||||
replaceAdventureMode = getBoolean("replace-adventure", false);
|
||||
replaceParticles = getBoolean("replace-particles", false);
|
||||
maxBookPages = getInt("max-book-pages", 100);
|
||||
maxBookPageSize = getInt("max-book-page-length", 5000);
|
||||
emulateWorldBorder = getBoolean("emulate-world-border", true);
|
||||
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
||||
worldBorderParticle = getString("world-border-particle", "fireworksSpark");
|
||||
enableOffhand = getBoolean("enable-offhand", true);
|
||||
offhandCommand = getString("offhand-command", "/offhand");
|
||||
}
|
||||
private void loadFields() {
|
||||
cooldownIndicator = CooldownIndicator.valueOf(getString("cooldown-indicator", "TITLE").toUpperCase());
|
||||
replaceAdventureMode = getBoolean("replace-adventure", false);
|
||||
replaceParticles = getBoolean("replace-particles", false);
|
||||
maxBookPages = getInt("max-book-pages", 100);
|
||||
maxBookPageSize = getInt("max-book-page-length", 5000);
|
||||
emulateWorldBorder = getBoolean("emulate-world-border", true);
|
||||
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
||||
worldBorderParticle = getString("world-border-particle", "fireworksSpark");
|
||||
enableOffhand = getBoolean("enable-offhand", true);
|
||||
offhandCommand = getString("offhand-command", "/offhand");
|
||||
emulateLevitationEffect = getBoolean("emulate-levitation-effect", true);
|
||||
handlePlayerCombatPacket = getBoolean("handle-player-combat-packet", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public CooldownIndicator getCooldownIndicator() {
|
||||
return cooldownIndicator;
|
||||
return cooldownIndicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceAdventureMode() {
|
||||
return replaceAdventureMode;
|
||||
return replaceAdventureMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceParticles() {
|
||||
return replaceParticles;
|
||||
return replaceParticles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBookPages() {
|
||||
return maxBookPages;
|
||||
return maxBookPages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBookPageSize() {
|
||||
return maxBookPageSize;
|
||||
return maxBookPageSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmulateWorldBorder() {
|
||||
return emulateWorldBorder;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmulateWorldBorder() {
|
||||
return emulateWorldBorder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysShowOriginalMobName() {
|
||||
return alwaysShowOriginalMobName;
|
||||
}
|
||||
@Override
|
||||
public boolean alwaysShowOriginalMobName() {
|
||||
return alwaysShowOriginalMobName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWorldBorderParticle() {
|
||||
return worldBorderParticle;
|
||||
}
|
||||
@Override
|
||||
public String getWorldBorderParticle() {
|
||||
return worldBorderParticle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnableOffhand() {
|
||||
return enableOffhand;
|
||||
}
|
||||
@Override
|
||||
public boolean isEnableOffhand() {
|
||||
return enableOffhand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOffhandCommand() {
|
||||
return offhandCommand;
|
||||
}
|
||||
@Override
|
||||
public String getOffhandCommand() {
|
||||
return offhandCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public boolean emulateLevitationEffect() {
|
||||
return emulateLevitationEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePlayerCombatPacket() {
|
||||
return handlePlayerCombatPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getDefaultConfigURL() {
|
||||
return getClass().getClassLoader().getResource("assets/viarewind/config.yml");
|
||||
}
|
||||
|
||||
+19
-8
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,14 +19,25 @@ package com.viaversion.viarewind;
|
||||
|
||||
import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BungeePlugin extends Plugin implements ViaRewindPlatform {
|
||||
public class ViaRewindPlatformImpl implements ViaRewindPlatform {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
private final Logger logger;
|
||||
|
||||
public ViaRewindPlatformImpl() {
|
||||
logger = Via.getPlatform().createLogger("ViaRewind");
|
||||
init(new File(getDataFolder(), "viarewind.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return Via.getPlatform().getDataFolder();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -24,83 +24,97 @@ import com.viaversion.viaversion.api.configuration.Config;
|
||||
*/
|
||||
public interface ViaRewindConfig extends Config {
|
||||
|
||||
enum CooldownIndicator {
|
||||
TITLE, ACTION_BAR, BOSS_BAR, DISABLED
|
||||
}
|
||||
/**
|
||||
* Specifies how 1.8.x clients should see the cooldown indicator
|
||||
* You can choose between TITLE, ACTION_BAR, BOSS_BAR and DISABLED
|
||||
* ONLY DISABLE IF YOU HAVE 1.9 COOLDOWN DISABLED ON YOUR SERVER
|
||||
* 1.8 PLAYERS MAY ASK WHY PVP IS NOT WORKING OTHERWISE
|
||||
*
|
||||
* @return the cooldown indicator
|
||||
*/
|
||||
CooldownIndicator getCooldownIndicator();
|
||||
|
||||
/**
|
||||
* Specifies how 1.8.x clients should see the cooldown indicator
|
||||
* You can choose between TITLE, ACTION_BAR, BOSS_BAR and DISABLED
|
||||
* ONLY DISABLE IF YOU HAVE 1.9 COOLDOWN DISABLED ON YOUR SERVER
|
||||
* 1.8 PLAYERS MAY ASK WHY PVP IS NOT WORKING OTHERWISE
|
||||
*
|
||||
* @return the cooldown indicator
|
||||
*/
|
||||
CooldownIndicator getCooldownIndicator();
|
||||
/**
|
||||
* Replaces Adventure mode with Survival mode for 1.7.x clients
|
||||
* Enable this option if your server is using the 'CanDestroy'
|
||||
* or 'CanPlaceOn' flags on items
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceAdventureMode();
|
||||
|
||||
/**
|
||||
* Replaces Adventure mode with Survival mode for 1.7.x clients
|
||||
* Enable this option if your server is using the 'CanDestroy'
|
||||
* or 'CanPlaceOn' flags on items
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceAdventureMode();
|
||||
/**
|
||||
* Whether 1.9 particles should be replaced by similar ones in
|
||||
* 1.8 and lower
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceParticles();
|
||||
|
||||
/**
|
||||
* Whether 1.9 particles should be replaced by similar ones in
|
||||
* 1.8 and lower
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceParticles();
|
||||
/**
|
||||
* Max amount of pages for written books before a client gets kicked
|
||||
*
|
||||
* @return the max amount of pages
|
||||
*/
|
||||
int getMaxBookPages();
|
||||
|
||||
/**
|
||||
* Max amount of pages for written books before a client gets kicked
|
||||
*
|
||||
* @return the max amount of pages
|
||||
*/
|
||||
int getMaxBookPages();
|
||||
/**
|
||||
* Max amount of characters in the json (!) string of a book page before a client gets kicked
|
||||
*
|
||||
* @return the max amount of characters
|
||||
*/
|
||||
int getMaxBookPageSize();
|
||||
|
||||
/**
|
||||
* Max amount of characters in the json (!) string of a book page before a client gets kicked
|
||||
*
|
||||
* @return the max amount of characters
|
||||
*/
|
||||
int getMaxBookPageSize();
|
||||
/**
|
||||
* Whether to emulate the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEmulateWorldBorder();
|
||||
|
||||
/**
|
||||
* Whether to emulate the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEmulateWorldBorder();
|
||||
/**
|
||||
* Always shows the original mob's name instead of only when hovering over them with the cursor.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean alwaysShowOriginalMobName();
|
||||
|
||||
/**
|
||||
* Always shows the original mob's name instead of only when hovering over them with the cursor.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean alwaysShowOriginalMobName();
|
||||
/**
|
||||
* The particle to show the world border for the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return the particle name
|
||||
*/
|
||||
String getWorldBorderParticle();
|
||||
|
||||
/**
|
||||
* The particle to show the world border for the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return the particle name (see <a href="https://wiki.vg/index.php?title=Protocol&oldid=7368#Particle_2">Particle registry for Packet</a>)
|
||||
*/
|
||||
String getWorldBorderParticle();
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers can use /offhand to switch items between their main hand and offhand.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEnableOffhand();
|
||||
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers can use /offhand to switch items between their main hand and offhand.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEnableOffhand();
|
||||
/**
|
||||
* Allows to define the offhand command
|
||||
*
|
||||
* @return the offhand command
|
||||
*/
|
||||
String getOffhandCommand();
|
||||
|
||||
/**
|
||||
* Allows to define the offhand command
|
||||
*
|
||||
* @return the offhand command
|
||||
*/
|
||||
String getOffhandCommand();
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers will also experience the levitation effect by sending velocity packets.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean emulateLevitationEffect();
|
||||
|
||||
/**
|
||||
* If enabled, 1.8 players will handle the player combat packet added in 1.9 by showing the custom death message above the hotbar.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean handlePlayerCombatPacket();
|
||||
|
||||
enum CooldownIndicator {
|
||||
TITLE, ACTION_BAR, BOSS_BAR, DISABLED
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,13 +19,12 @@ package com.viaversion.viarewind.api;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.ViaRewindConfig;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.Protocol1_7_2_5To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.Protocol1_7_6_10To1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.Protocol1_8To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolManager;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -34,40 +33,62 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public interface ViaRewindPlatform {
|
||||
|
||||
String VERSION = "${version}";
|
||||
String IMPL_VERSION = "${impl_version}";
|
||||
String VERSION = "${version}";
|
||||
String IMPL_VERSION = "${impl_version}";
|
||||
|
||||
/**
|
||||
* Initialize ViaRewind
|
||||
*/
|
||||
default void init(final File configFile) {
|
||||
ViaRewindConfig config = new ViaRewindConfig(configFile);
|
||||
config.reload();
|
||||
Via.getManager().getConfigurationProvider().register(config);
|
||||
default void init(final File configFile) {
|
||||
init(new ViaRewindConfig(configFile, getLogger()));
|
||||
}
|
||||
|
||||
ViaRewind.init(this, config);
|
||||
/**
|
||||
* Initialize ViaRewind
|
||||
*/
|
||||
default void init(final com.viaversion.viarewind.api.ViaRewindConfig config) {
|
||||
config.reload();
|
||||
Via.getManager().getConfigurationProvider().register(config);
|
||||
|
||||
Via.getManager().getSubPlatforms().add(IMPL_VERSION);
|
||||
ViaRewind.init(this, config);
|
||||
|
||||
getLogger().info("Registering protocols...");
|
||||
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
||||
protocolManager.registerProtocol(new Protocol1_7_2_5To1_7_6_10(), ProtocolVersion.v1_7_2, ProtocolVersion.v1_7_6);
|
||||
protocolManager.registerProtocol(new Protocol1_7_6_10To1_8(), ProtocolVersion.v1_7_6, ProtocolVersion.v1_8);
|
||||
Via.getManager().getSubPlatforms().add(IMPL_VERSION);
|
||||
|
||||
protocolManager.registerProtocol(new Protocol1_8To1_9(), ProtocolVersion.v1_8, ProtocolVersion.v1_9);
|
||||
}
|
||||
getLogger().info("Registering protocols...");
|
||||
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
||||
protocolManager.registerProtocol(new Protocol1_7_6_10To1_7_2_5(), ProtocolVersion.v1_7_2, ProtocolVersion.v1_7_6);
|
||||
protocolManager.registerProtocol(new Protocol1_8To1_7_6_10(), ProtocolVersion.v1_7_6, ProtocolVersion.v1_8);
|
||||
|
||||
/**
|
||||
* Get the platform logger
|
||||
*
|
||||
* @return the logger
|
||||
*/
|
||||
Logger getLogger();
|
||||
protocolManager.registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_8, ProtocolVersion.v1_9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform logger
|
||||
*
|
||||
* @return the logger
|
||||
*/
|
||||
Logger getLogger();
|
||||
|
||||
/**
|
||||
* Returns ViaRewind's data folder.
|
||||
*
|
||||
* @return data folder
|
||||
*/
|
||||
File getDataFolder();
|
||||
|
||||
/**
|
||||
* Returns the platform's compression handler name. Only used in the 1.8 -> 1.7 protocol.
|
||||
*
|
||||
* @return the compression handler name
|
||||
*/
|
||||
default String compressHandlerName() {
|
||||
return "compress";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the platform's decompression handler name. Only used in the 1.8 -> 1.7 protocol.
|
||||
*
|
||||
* @return the decompression handler name
|
||||
*/
|
||||
default String decompressHandlerName() {
|
||||
return "decompress";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ViaRewind's data folder.
|
||||
*
|
||||
* @return data folder
|
||||
*/
|
||||
File getDataFolder();
|
||||
}
|
||||
+15
-16
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,25 +17,24 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.data;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappings;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RewindMappings extends BackwardsMappings {
|
||||
public class RewindMappingData extends BackwardsMappingData {
|
||||
|
||||
public RewindMappings(String unmappedVersion, String mappedVersion) {
|
||||
super(unmappedVersion, mappedVersion);
|
||||
}
|
||||
public RewindMappingData(String unmappedVersion, String mappedVersion) {
|
||||
super(unmappedVersion, mappedVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
@Override
|
||||
protected Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompoundTag readMappingsFile(String name) {
|
||||
return VRMappingDataLoader.INSTANCE.loadNBTFromDir(name);
|
||||
}
|
||||
@Override
|
||||
protected CompoundTag readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadNBTFromDir(name);
|
||||
}
|
||||
}
|
||||
+14
-15
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,26 +19,25 @@ package com.viaversion.viarewind.api.data;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class VRMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
public class RewindMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
|
||||
public static final VRMappingDataLoader INSTANCE = new VRMappingDataLoader();
|
||||
public static final RewindMappingDataLoader INSTANCE = new RewindMappingDataLoader();
|
||||
|
||||
public VRMappingDataLoader() {
|
||||
super(VRMappingDataLoader.class, "assets/viarewind/data/");
|
||||
}
|
||||
public RewindMappingDataLoader() {
|
||||
super(RewindMappingDataLoader.class, "assets/viarewind/data/");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return ViaRewind.getPlatform().getDataFolder();
|
||||
}
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return ViaRewind.getPlatform().getDataFolder();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.entitydata;
|
||||
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
public enum EntityDataTypes1_7_6_10 implements EntityDataType {
|
||||
BYTE(0, Types.BYTE),
|
||||
SHORT(1, Types.SHORT),
|
||||
INT(2, Types.INT),
|
||||
FLOAT(3, Types.FLOAT),
|
||||
STRING(4, Types.STRING),
|
||||
ITEM(5, RewindTypes.COMPRESSED_NBT_ITEM),
|
||||
POSITION(6, Types.VECTOR);
|
||||
|
||||
private final int typeID;
|
||||
private final Type<?> type;
|
||||
|
||||
EntityDataTypes1_7_6_10(int typeID, Type<?> type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static EntityDataTypes1_7_6_10 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return this.typeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<?> type() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -15,22 +15,22 @@
|
||||
* 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.viarewind.utils.math;
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class AABB {
|
||||
Vector3d min;
|
||||
Vector3d max;
|
||||
Vector3d min;
|
||||
Vector3d max;
|
||||
|
||||
public AABB(Vector3d min, Vector3d max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
public AABB(Vector3d min, Vector3d max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Vector3d getMin() {
|
||||
return this.min;
|
||||
}
|
||||
public Vector3d getMin() {
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public Vector3d getMax() {
|
||||
return this.max;
|
||||
}
|
||||
public Vector3d getMax() {
|
||||
return this.max;
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -15,22 +15,22 @@
|
||||
* 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.viarewind.utils.math;
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class Ray3d {
|
||||
Vector3d start;
|
||||
Vector3d dir;
|
||||
Vector3d start;
|
||||
Vector3d dir;
|
||||
|
||||
public Ray3d(Vector3d start, Vector3d dir) {
|
||||
this.start = start;
|
||||
this.dir = dir;
|
||||
}
|
||||
public Ray3d(Vector3d start, Vector3d dir) {
|
||||
this.start = start;
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public Vector3d getStart() {
|
||||
return this.start;
|
||||
}
|
||||
public Vector3d getStart() {
|
||||
return this.start;
|
||||
}
|
||||
|
||||
public Vector3d getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
public Vector3d getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class RayTracing {
|
||||
|
||||
public static Vector3d trace(Ray3d ray, AABB aabb, double distance) {
|
||||
Vector3d invDir = new Vector3d(1f / ray.dir.x, 1f / ray.dir.y, 1f / ray.dir.z);
|
||||
|
||||
boolean signDirX = invDir.x < 0;
|
||||
boolean signDirY = invDir.y < 0;
|
||||
boolean signDirZ = invDir.z < 0;
|
||||
|
||||
Vector3d bbox = signDirX ? aabb.max : aabb.min;
|
||||
double tmin = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirX ? aabb.min : aabb.max;
|
||||
double tmax = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirY ? aabb.max : aabb.min;
|
||||
double tymin = (bbox.y - ray.start.y) * invDir.y;
|
||||
bbox = signDirY ? aabb.min : aabb.max;
|
||||
double tymax = (bbox.y - ray.start.y) * invDir.y;
|
||||
|
||||
if (tmin > tymax || tymin > tmax) return null;
|
||||
|
||||
if (tymin > tmin) tmin = tymin;
|
||||
|
||||
if (tymax < tmax) tmax = tymax;
|
||||
|
||||
bbox = signDirZ ? aabb.max : aabb.min;
|
||||
double tzmin = (bbox.z - ray.start.z) * invDir.z;
|
||||
bbox = signDirZ ? aabb.min : aabb.max;
|
||||
double tzmax = (bbox.z - ray.start.z) * invDir.z;
|
||||
|
||||
if (tmin > tzmax || tzmin > tmax) return null;
|
||||
|
||||
if (tzmin > tmin) tmin = tzmin;
|
||||
|
||||
if (tzmax < tmax) tmax = tzmax;
|
||||
|
||||
return tmin <= distance && tmax > 0 ? ray.start.clone().add(ray.dir.clone().normalize().multiply(tmin)) : null;
|
||||
}
|
||||
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.EntityTracker1_9;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
|
||||
@Deprecated // ?????????
|
||||
public class RelativeMoveUtil {
|
||||
|
||||
public static Vector[] calculateRelativeMoves(UserConnection user, int entityId, int relX, int relY, int relZ) {
|
||||
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Vector offset = tracker.getEntityOffset(entityId);
|
||||
if (offset != null) {
|
||||
relX += offset.blockX();
|
||||
relY += offset.blockY();
|
||||
relZ += offset.blockZ();
|
||||
}
|
||||
|
||||
if (relX > Short.MAX_VALUE) {
|
||||
x = relX - Short.MAX_VALUE;
|
||||
relX = Short.MAX_VALUE;
|
||||
} else if (relX < Short.MIN_VALUE) {
|
||||
x = relX - Short.MIN_VALUE;
|
||||
relX = Short.MIN_VALUE;
|
||||
} else {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (relY > Short.MAX_VALUE) {
|
||||
y = relY - Short.MAX_VALUE;
|
||||
relY = Short.MAX_VALUE;
|
||||
} else if (relY < Short.MIN_VALUE) {
|
||||
y = relY - Short.MIN_VALUE;
|
||||
relY = Short.MIN_VALUE;
|
||||
} else {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (relZ > Short.MAX_VALUE) {
|
||||
z = relZ - Short.MAX_VALUE;
|
||||
relZ = Short.MAX_VALUE;
|
||||
} else if (relZ < Short.MIN_VALUE) {
|
||||
z = relZ - Short.MIN_VALUE;
|
||||
relZ = Short.MIN_VALUE;
|
||||
} else {
|
||||
z = 0;
|
||||
}
|
||||
|
||||
int sentRelX, sentRelY, sentRelZ;
|
||||
Vector[] moves;
|
||||
|
||||
if (relX > Byte.MAX_VALUE * 128 || relX < Byte.MIN_VALUE * 128 || relY > Byte.MAX_VALUE * 128 || relY < Byte.MIN_VALUE * 128 || relZ > Byte.MAX_VALUE * 128 || relZ < Byte.MIN_VALUE * 128) {
|
||||
byte relX1 = (byte) (relX / 256);
|
||||
byte relX2 = (byte) (Math.round((relX - relX1 * 128) / 128f));
|
||||
byte relY1 = (byte) (relY / 256);
|
||||
byte relY2 = (byte) (Math.round((relY - relY1 * 128) / 128f));
|
||||
byte relZ1 = (byte) (relZ / 256);
|
||||
byte relZ2 = (byte) (Math.round((relZ - relZ1 * 128) / 128f));
|
||||
|
||||
sentRelX = relX1 + relX2;
|
||||
sentRelY = relY1 + relY2;
|
||||
sentRelZ = relZ1 + relZ2;
|
||||
|
||||
moves = new Vector[]{new Vector(relX1, relY1, relZ1), new Vector(relX2, relY2, relZ2)};
|
||||
} else {
|
||||
sentRelX = Math.round(relX / 128f);
|
||||
sentRelY = Math.round(relY / 128f);
|
||||
sentRelZ = Math.round(relZ / 128f);
|
||||
|
||||
moves = new Vector[]{new Vector(sentRelX, sentRelY, sentRelZ)};
|
||||
}
|
||||
|
||||
x = x + relX - sentRelX * 128;
|
||||
y = y + relY - sentRelY * 128;
|
||||
z = z + relZ - sentRelZ * 128;
|
||||
|
||||
tracker.setEntityOffset(entityId, new Vector(x, y, z));
|
||||
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Vector3d {
|
||||
double x, y, z;
|
||||
|
||||
public Vector3d(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3d() {
|
||||
}
|
||||
|
||||
public void set(Vector3d vec) {
|
||||
this.x = vec.x;
|
||||
this.y = vec.y;
|
||||
this.z = vec.z;
|
||||
}
|
||||
|
||||
public Vector3d set(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d multiply(double a) {
|
||||
this.x *= a;
|
||||
this.y *= a;
|
||||
this.z *= a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d add(Vector3d vec) {
|
||||
this.x += vec.x;
|
||||
this.y += vec.y;
|
||||
this.z += vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d substract(Vector3d vec) {
|
||||
this.x -= vec.x;
|
||||
this.y -= vec.y;
|
||||
this.z -= vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
public double lengthSquared() {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
public Vector3d normalize() {
|
||||
double length = length();
|
||||
multiply(1.0 / length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3d clone() {
|
||||
return new Vector3d(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Vector3d vector3d = (Vector3d) o;
|
||||
return Double.compare(vector3d.x, x) == 0 && Double.compare(vector3d.y, y) == 0 && Double.compare(vector3d.z, z) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector3d{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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.viarewind.api.netty;
|
||||
package com.viaversion.viarewind.api.minecraft.netty;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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.viarewind.api.netty;
|
||||
package com.viaversion.viarewind.api.minecraft.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -23,8 +23,8 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
public class ForwardMessageToByteEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
|
||||
out.writeBytes(msg);
|
||||
}
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
|
||||
out.writeBytes(msg);
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,24 +19,24 @@ package com.viaversion.viarewind.api.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
|
||||
import com.viaversion.viarewind.api.data.VRMappingDataLoader;
|
||||
import com.viaversion.viarewind.api.data.RewindMappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
public class VRBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType, T extends BackwardsProtocol<C, ?, ?, S>> extends LegacyBlockItemRewriter<C, S, T> {
|
||||
|
||||
protected VRBlockItemRewriter(T protocol, String name) {
|
||||
super(protocol, name);
|
||||
}
|
||||
protected VRBlockItemRewriter(T protocol, String name) {
|
||||
super(protocol, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject readMappingsFile(String name) {
|
||||
return VRMappingDataLoader.INSTANCE.loadFromDataDir(name);
|
||||
}
|
||||
@Override
|
||||
protected JsonObject readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadFromDataDir(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nbtTagName() {
|
||||
return "VR|" + protocol.getClass().getSimpleName();
|
||||
}
|
||||
@Override
|
||||
public String nbtTagName() {
|
||||
return "VR|" + protocol.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -22,50 +22,45 @@ import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
|
||||
public abstract class VREntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends LegacyEntityRewriter<C, T> {
|
||||
|
||||
public VREntityRewriter(T protocol) {
|
||||
super(protocol, MetaType1_8.String, MetaType1_8.Byte);
|
||||
}
|
||||
public VREntityRewriter(T protocol) {
|
||||
super(protocol, EntityDataTypes1_8.STRING, EntityDataTypes1_8.BYTE);
|
||||
}
|
||||
|
||||
public VREntityRewriter(T protocol, MetaType displayType, MetaType displayVisibilityType) {
|
||||
super(protocol, displayType, displayVisibilityType);
|
||||
}
|
||||
public VREntityRewriter(T protocol, EntityDataType displayType, EntityDataType displayVisibilityType) {
|
||||
super(protocol, displayType, displayVisibilityType);
|
||||
}
|
||||
|
||||
protected void registerJoinGame1_8(final C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Type.INT); // Entity id
|
||||
map(Type.UNSIGNED_BYTE); // Game mode
|
||||
map(Type.BYTE); // Dimension
|
||||
handler(playerTrackerHandler());
|
||||
handler(wrapper -> wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Type.BYTE, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
protected void removeEntities(final UserConnection connection, final int[] entities) {
|
||||
final EntityTrackerBase tracker = tracker(connection);
|
||||
for (int entityId : entities) {
|
||||
tracker.removeEntity(entityId);
|
||||
}
|
||||
}
|
||||
|
||||
protected void untrackEntities(final UserConnection connection, final int[] entities) {
|
||||
final EntityTrackerBase tracker = tracker(connection);
|
||||
for (int entityId : entities) {
|
||||
tracker.removeEntity(entityId);
|
||||
}
|
||||
}
|
||||
protected PacketHandler getDimensionHandler() {
|
||||
return wrapper -> {
|
||||
final int dimension = wrapper.get(Types.BYTE, 0);
|
||||
final ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||
clientWorld.setEnvironment(dimension);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getDisplayVisibilityMetaValue() {
|
||||
return (byte) 1;
|
||||
}
|
||||
@Override
|
||||
protected Object getDisplayVisibilityDataValue() {
|
||||
return (byte) 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean alwaysShowOriginalMobName() {
|
||||
return ViaRewind.getConfig().alwaysShowOriginalMobName();
|
||||
}
|
||||
@Override
|
||||
protected boolean alwaysShowOriginalMobName() {
|
||||
return ViaRewind.getConfig().alwaysShowOriginalMobName();
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -15,30 +15,30 @@
|
||||
* 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.viarewind.api.type.primitive;
|
||||
package com.viaversion.viarewind.api.type;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ByteIntArrayType extends Type<int[]> {
|
||||
public class IntArrayType extends Type<int[]> {
|
||||
|
||||
public ByteIntArrayType() {
|
||||
super(int[].class);
|
||||
}
|
||||
public IntArrayType() {
|
||||
super(int[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] read(ByteBuf byteBuf) throws Exception {
|
||||
byte size = byteBuf.readByte();
|
||||
int[] array = new int[size];
|
||||
for (byte i = 0; i < size; i++) {
|
||||
array[i] = byteBuf.readInt();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@Override
|
||||
public int[] read(ByteBuf byteBuf) {
|
||||
byte size = byteBuf.readByte();
|
||||
int[] array = new int[size];
|
||||
for (byte i = 0; i < size; i++) {
|
||||
array[i] = byteBuf.readInt();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, int[] array) throws Exception {
|
||||
byteBuf.writeByte(array.length);
|
||||
for (int i : array) byteBuf.writeInt(i);
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, int[] array) {
|
||||
byteBuf.writeByte(array.length);
|
||||
for (int i : array) byteBuf.writeInt(i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
public class PositionVarYType<T extends Number> extends Type<BlockPosition> {
|
||||
|
||||
private final Type<T> yType;
|
||||
private final IntFunction<T> toY;
|
||||
|
||||
public PositionVarYType(final Type<T> yType, final IntFunction<T> toY) {
|
||||
super(BlockPosition.class);
|
||||
|
||||
this.yType = yType;
|
||||
this.toY = toY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosition read(ByteBuf buffer) {
|
||||
final int x = buffer.readInt();
|
||||
final int y = yType.read(buffer).intValue();
|
||||
final int z = buffer.readInt();
|
||||
|
||||
return new BlockPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, BlockPosition value) {
|
||||
buffer.writeInt(value.x());
|
||||
yType.write(buffer, this.toY.apply(value.y()));
|
||||
buffer.writeInt(value.z());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viarewind.api.type.entitydata.EntityDataListType;
|
||||
import com.viaversion.viarewind.api.type.entitydata.EntityDataType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemArrayType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemType;
|
||||
import com.viaversion.viarewind.api.type.item.NBTType;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Safe to use before protocol loading
|
||||
*/
|
||||
public class RewindTypes {
|
||||
|
||||
public static final Type<int[]> INT_ARRAY = new IntArrayType(); // Integer array with byte as length indicator
|
||||
|
||||
public static final Type<BlockPosition> SHORT_POSITION = new PositionVarYType<>(Types.SHORT, value -> (short) value);
|
||||
public static final Type<BlockPosition> INT_POSITION = new PositionVarYType<>(Types.INT, value -> value);
|
||||
public static final Type<BlockPosition> BYTE_POSITION = new PositionVarYType<>(Types.BYTE, value -> (byte) value);
|
||||
public static final Type<BlockPosition> U_BYTE_POSITION = new PositionVarYType<>(Types.UNSIGNED_BYTE, value -> (short) value);
|
||||
|
||||
public static final Type<CompoundTag> COMPRESSED_NBT = new NBTType();
|
||||
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType();
|
||||
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
public static final Type<EntityData> ENTITY_DATA1_7 = new EntityDataType();
|
||||
public static final Type<List<EntityData>> ENTITY_DATA_LIST1_7 = new EntityDataListType(ENTITY_DATA1_7);
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.api.type;
|
||||
|
||||
import com.viaversion.viarewind.api.type.item.NBTType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemArrayType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemType;
|
||||
import com.viaversion.viarewind.api.type.metadata.MetadataListType;
|
||||
import com.viaversion.viarewind.api.type.metadata.MetadataType;
|
||||
import com.viaversion.viarewind.api.type.primitive.ByteIntArrayType;
|
||||
import com.viaversion.viarewind.api.type.primitive.PositionUYType;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Types1_7_6_10 {
|
||||
|
||||
// Primitives
|
||||
public static final Type<int[]> BYTE_INT_ARRAY = new ByteIntArrayType(); // Integer array with byte as length indicator
|
||||
|
||||
// Positions /shrug
|
||||
public static final Type<Position> SHORT_POSITION = new PositionUYType<>(Type.SHORT, value -> (short) value);
|
||||
public static final Type<Position> INT_POSITION = new PositionUYType<>(Type.INT, value -> value);
|
||||
public static final Type<Position> BYTE_POSITION = new PositionUYType<>(Type.BYTE, value -> (byte) value);
|
||||
public static final Type<Position> U_BYTE_POSITION = new PositionUYType<>(Type.UNSIGNED_BYTE, value -> (short) value);
|
||||
|
||||
// Items
|
||||
public static final Type<CompoundTag> COMPRESSED_NBT = new NBTType();
|
||||
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType();
|
||||
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
// Metadata
|
||||
public static final Type<Metadata> METADATA = new MetadataType();
|
||||
public static final Type<List<Metadata>> METADATA_LIST = new MetadataListType();
|
||||
|
||||
}
|
||||
+73
-61
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,80 +18,92 @@
|
||||
package com.viaversion.viarewind.api.type.chunk;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
public class BulkChunkType1_7_6 extends Type<Chunk[]> {
|
||||
|
||||
public static final BulkChunkType1_7_6 TYPE = new BulkChunkType1_7_6();
|
||||
public static final BulkChunkType1_7_6 TYPE = new BulkChunkType1_7_6();
|
||||
|
||||
public BulkChunkType1_7_6() {
|
||||
super(Chunk[].class);
|
||||
}
|
||||
public BulkChunkType1_7_6() {
|
||||
super(Chunk[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk[] read(ByteBuf byteBuf) throws Exception {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulk1_7_6Type.java
|
||||
}
|
||||
@Override
|
||||
public Chunk[] read(ByteBuf byteBuf) {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulk1_7_6Type.java
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, Chunk[] chunks) throws Exception {
|
||||
final int chunkCount = chunks.length;
|
||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
final int[] chunkX = new int[chunkCount];
|
||||
final int[] chunkZ = new int[chunkCount];
|
||||
final short[] primaryBitMask = new short[chunkCount];
|
||||
final short[] additionalBitMask = new short[chunkCount];
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Chunk[] chunks) {
|
||||
final int chunkCount = chunks.length;
|
||||
final int[] addBitMasks = new int[chunkCount];
|
||||
int totalSize = 0;
|
||||
boolean anySkyLight = false;
|
||||
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
final Chunk chunk = chunks[i];
|
||||
final Pair<byte[], Short> chunkData = ChunkType1_7_6.serialize(chunk);
|
||||
output.write(chunkData.key());
|
||||
chunkX[i] = chunk.getX();
|
||||
chunkZ[i] = chunk.getZ();
|
||||
primaryBitMask[i] = (short) chunk.getBitmask();
|
||||
additionalBitMask[i] = chunkData.value();
|
||||
}
|
||||
final byte[] data = output.toByteArray();
|
||||
for (Chunk chunk : chunks) {
|
||||
if (ChunkType1_7_6.hasSkyLight(chunk)) {
|
||||
anySkyLight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
Chunk chunk = chunks[i];
|
||||
addBitMasks[i] = ChunkType1_7_6.getAddBitMask(chunk);
|
||||
boolean biomes = chunk.isFullChunk() && chunk.getBiomeData() != null;
|
||||
|
||||
byteBuf.writeShort(chunkCount);
|
||||
byteBuf.writeInt(compressedSize);
|
||||
totalSize += ChunkType1_7_6.calcSize(
|
||||
chunk.getBitmask(),
|
||||
addBitMasks[i],
|
||||
anySkyLight,
|
||||
biomes
|
||||
);
|
||||
}
|
||||
|
||||
boolean skyLight = false;
|
||||
for (Chunk chunk : chunks) {
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section != null && section.getLight().hasSkyLight()) {
|
||||
skyLight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final byte[] data = new byte[totalSize];
|
||||
int offset = 0;
|
||||
|
||||
byteBuf.writeBoolean(skyLight); // hasSkyLight
|
||||
byteBuf.writeBytes(compressedData, 0, compressedSize);
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
Chunk chunk = chunks[i];
|
||||
boolean biomes = chunk.isFullChunk() && chunk.getBiomeData() != null;
|
||||
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
byteBuf.writeInt(chunkX[i]);
|
||||
byteBuf.writeInt(chunkZ[i]);
|
||||
byteBuf.writeShort(primaryBitMask[i]);
|
||||
byteBuf.writeShort(additionalBitMask[i]);
|
||||
}
|
||||
}
|
||||
offset = ChunkType1_7_6.serialize(
|
||||
chunk,
|
||||
data,
|
||||
offset,
|
||||
addBitMasks[i],
|
||||
anySkyLight,
|
||||
biomes
|
||||
);
|
||||
}
|
||||
|
||||
buffer.writeShort(chunkCount);
|
||||
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
|
||||
buffer.writeInt(compressedSize);
|
||||
buffer.writeBoolean(anySkyLight);
|
||||
buffer.writeBytes(compressedData, 0, compressedSize);
|
||||
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
Chunk chunk = chunks[i];
|
||||
buffer.writeInt(chunk.getX());
|
||||
buffer.writeInt(chunk.getZ());
|
||||
buffer.writeShort(chunk.getBitmask());
|
||||
buffer.writeShort(addBitMasks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,118 +17,182 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.chunk;
|
||||
|
||||
import com.viaversion.viarewind.utils.ExtendedBlockStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.*;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import static com.viaversion.viaversion.api.minecraft.chunks.ChunkSection.SIZE;
|
||||
import static com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight.LIGHT_LENGTH;
|
||||
|
||||
public class ChunkType1_7_6 extends Type<Chunk> {
|
||||
|
||||
public static final ChunkType1_7_6 TYPE = new ChunkType1_7_6();
|
||||
public static final ChunkType1_7_6 TYPE = new ChunkType1_7_6();
|
||||
|
||||
public ChunkType1_7_6() {
|
||||
super(Chunk.class);
|
||||
}
|
||||
public ChunkType1_7_6() {
|
||||
super(Chunk.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk read(ByteBuf byteBuf) throws Exception {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Chunk1_7_6Type.java
|
||||
}
|
||||
@Override
|
||||
public Chunk read(ByteBuf byteBuf) {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Chunk1_7_6Type.java
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf output, Chunk chunk) throws Exception {
|
||||
final Pair<byte[], Short> chunkData = serialize(chunk);
|
||||
final byte[] data = chunkData.key();
|
||||
final short additionalBitMask = chunkData.value();
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Chunk chunk) {
|
||||
final int bitmask = chunk.getBitmask();
|
||||
final int addBitmask = getAddBitMask(chunk);
|
||||
final boolean hasSkyLight = hasSkyLight(chunk);
|
||||
final boolean biomes = chunk.isFullChunk() && chunk.getBiomeData() != null;
|
||||
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
final int size = calcSize(bitmask, addBitmask, hasSkyLight, biomes);
|
||||
final byte[] data = new byte[size];
|
||||
|
||||
output.writeInt(chunk.getX());
|
||||
output.writeInt(chunk.getZ());
|
||||
output.writeBoolean(chunk.isFullChunk());
|
||||
output.writeShort(chunk.getBitmask());
|
||||
output.writeShort(additionalBitMask);
|
||||
output.writeInt(compressedSize);
|
||||
output.writeBytes(compressedData, 0, compressedSize);
|
||||
}
|
||||
serialize(chunk, data, 0, addBitmask, hasSkyLight, biomes);
|
||||
|
||||
public static Pair<byte[], Short> serialize(final Chunk chunk) throws IOException {
|
||||
final ExtendedBlockStorage[] storageArrays = new ExtendedBlockStorage[16];
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
final ChunkSection section = chunk.getSections()[i];
|
||||
if (section != null) {
|
||||
final ExtendedBlockStorage storage = storageArrays[i] = new ExtendedBlockStorage(section.getLight().hasSkyLight());
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
final int flatBlock = section.palette(PaletteType.BLOCKS).idAt(x, y, z);
|
||||
storage.setBlockId(x, y, z, flatBlock >> 4);
|
||||
storage.setBlockMetadata(x, y, z, flatBlock & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
storage.getBlockLightArray().setHandle(section.getLight().getBlockLight());
|
||||
if (section.getLight().hasSkyLight()) {
|
||||
storage.getSkyLightArray().setHandle(section.getLight().getSkyLight());
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.writeInt(chunk.getX());
|
||||
buffer.writeInt(chunk.getZ());
|
||||
buffer.writeBoolean(chunk.isFullChunk());
|
||||
buffer.writeShort(bitmask);
|
||||
buffer.writeShort(addBitmask);
|
||||
|
||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
output.write(storageArrays[i].getBlockLSBArray());
|
||||
}
|
||||
}
|
||||
buffer.writeInt(compressedSize);
|
||||
buffer.writeBytes(compressedData, 0, compressedSize);
|
||||
}
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
output.write(storageArrays[i].getBlockMetadataArray().getHandle());
|
||||
}
|
||||
}
|
||||
public static int serialize(Chunk chunk, byte[] output, int offset, int addBitmask, boolean writeSkyLight, boolean biomes) {
|
||||
final ChunkSection[] sections = chunk.getSections();
|
||||
final int bitmask = chunk.getBitmask();
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
output.write(storageArrays[i].getBlockLightArray().getHandle());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((bitmask & (1 << i)) != 0) {
|
||||
final ChunkSection section = sections[i];
|
||||
final DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
final int block = palette.idAt(j);
|
||||
output[offset++] = (byte) ((block >> 4) & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0 && storageArrays[i].getSkyLightArray() != null) {
|
||||
output.write(storageArrays[i].getSkyLightArray().getHandle());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((bitmask & (1 << i)) != 0) {
|
||||
final ChunkSection section = sections[i];
|
||||
final DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < ChunkSection.SIZE; j += 2) {
|
||||
final int meta1 = palette.idAt(j) & 0xF;
|
||||
final int meta2 = palette.idAt(j + 1) & 0xF;
|
||||
output[offset++] = (byte) (meta1 | (meta2 << 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
short additionalBitMask = 0;
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0 && storageArrays[i].hasBlockMSBArray()) {
|
||||
additionalBitMask |= (short) (1 << i);
|
||||
output.write(storageArrays[i].getOrCreateBlockMSBArray().getHandle());
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((bitmask & (1 << i)) != 0) {
|
||||
final byte[] blockLight = sections[i].getLight().getBlockLight();
|
||||
System.arraycopy(blockLight, 0, output, offset, LIGHT_LENGTH);
|
||||
offset += LIGHT_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.isFullChunk() && chunk.getBiomeData() != null) {
|
||||
for (int biome : chunk.getBiomeData()) {
|
||||
output.write(biome);
|
||||
}
|
||||
}
|
||||
if (writeSkyLight) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((bitmask & (1 << i)) != 0) {
|
||||
if (sections[i].getLight().hasSkyLight()) {
|
||||
final byte[] skyLight = sections[i].getLight().getSkyLight();
|
||||
System.arraycopy(skyLight, 0, output, offset, LIGHT_LENGTH);
|
||||
}
|
||||
offset += LIGHT_LENGTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Pair<>(output.toByteArray(), additionalBitMask);
|
||||
}
|
||||
if (addBitmask != 0) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((bitmask & (1 << i)) != 0 && (addBitmask & (1 << i)) != 0) {
|
||||
final ChunkSection section = sections[i];
|
||||
final DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < SIZE; j += 2) {
|
||||
final int add1 = (palette.idAt(j) >> 12) & 0xF;
|
||||
final int add2 = (palette.idAt(j + 1) >> 12) & 0xF;
|
||||
output[offset++] = (byte) (add1 | (add2 << 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (biomes && chunk.getBiomeData() != null) {
|
||||
final int[] biomeData = chunk.getBiomeData();
|
||||
for (int biome : biomeData) {
|
||||
output[offset++] = (byte) biome;
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
public static int calcSize(int bitmask, int addBitmask, boolean hasSkyLight, boolean biomes) {
|
||||
int size = 0;
|
||||
int sections = Integer.bitCount(bitmask);
|
||||
|
||||
size += sections * SIZE;
|
||||
size += sections * (SIZE / 2);
|
||||
size += sections * LIGHT_LENGTH;
|
||||
|
||||
if (hasSkyLight) {
|
||||
size += sections * LIGHT_LENGTH;
|
||||
}
|
||||
|
||||
if (addBitmask != 0) {
|
||||
size += Integer.bitCount(addBitmask) * (SIZE / 2);
|
||||
}
|
||||
|
||||
if (biomes) {
|
||||
size += 256;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public static int getAddBitMask(Chunk chunk) {
|
||||
int addBitMask = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((chunk.getBitmask() & (1 << i)) != 0) {
|
||||
final ChunkSection section = chunk.getSections()[i];
|
||||
final DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
final int id = palette.idAt(j);
|
||||
if ((id >> 12) != 0) {
|
||||
addBitMask |= (1 << i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return addBitMask;
|
||||
}
|
||||
|
||||
public static boolean hasSkyLight(Chunk chunk) {
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section != null && section.getLight().hasSkyLight()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.entitydata;
|
||||
|
||||
import com.viaversion.viarewind.api.minecraft.entitydata.EntityDataTypes1_7_6_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.entitydata.EntityDataListTypeTemplate;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityDataListType extends EntityDataListTypeTemplate {
|
||||
|
||||
private final Type<EntityData> type;
|
||||
|
||||
public EntityDataListType(Type<EntityData> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityData> read(ByteBuf buffer) {
|
||||
ArrayList<EntityData> entityData = new ArrayList<>();
|
||||
|
||||
EntityData data;
|
||||
do {
|
||||
data = type.read(buffer);
|
||||
if (data != null) {
|
||||
entityData.add(data);
|
||||
}
|
||||
} while (data != null);
|
||||
|
||||
return entityData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, List<EntityData> entityData) {
|
||||
for (EntityData meta : entityData) {
|
||||
type.write(buffer, meta);
|
||||
}
|
||||
if (entityData.isEmpty()) {
|
||||
type.write(buffer, new EntityData(0, EntityDataTypes1_7_6_10.BYTE, (byte) 0));
|
||||
}
|
||||
buffer.writeByte(127);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.entitydata;
|
||||
|
||||
import com.viaversion.viarewind.api.minecraft.entitydata.EntityDataTypes1_7_6_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.type.types.entitydata.EntityDataTypeTemplate;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class EntityDataType extends EntityDataTypeTemplate {
|
||||
@Override
|
||||
public EntityData read(ByteBuf buffer) {
|
||||
byte item = buffer.readByte();
|
||||
if (item == 127) {
|
||||
return null;
|
||||
} else {
|
||||
int typeID = (item & 224) >> 5;
|
||||
EntityDataTypes1_7_6_10 type = EntityDataTypes1_7_6_10.byId(typeID);
|
||||
int id = item & 31;
|
||||
return new EntityData(id, type, type.type().read(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, EntityData meta) {
|
||||
int item = (meta.dataType().typeId() << 5 | meta.id() & 31) & 255;
|
||||
buffer.writeByte(item);
|
||||
meta.dataType().type().write(buffer, meta.getValue());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,33 +17,34 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.item;
|
||||
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ItemArrayType extends Type<Item[]> {
|
||||
|
||||
public ItemArrayType() {
|
||||
super(Item[].class);
|
||||
}
|
||||
public ItemArrayType() {
|
||||
super(Item[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item[] read(ByteBuf buffer) throws Exception {
|
||||
int amount = Type.SHORT.readPrimitive(buffer);
|
||||
Item[] items = new Item[amount];
|
||||
@Override
|
||||
public Item[] read(ByteBuf buffer) {
|
||||
int amount = Types.SHORT.readPrimitive(buffer);
|
||||
Item[] items = new Item[amount];
|
||||
|
||||
for (int i = 0; i < amount; ++i) {
|
||||
items[i] = Types1_7_6_10.COMPRESSED_NBT_ITEM.read(buffer);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
for (int i = 0; i < amount; ++i) {
|
||||
items[i] = RewindTypes.COMPRESSED_NBT_ITEM.read(buffer);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item[] items) throws Exception {
|
||||
Type.SHORT.writePrimitive(buffer, (short) items.length);
|
||||
for (Item item : items) {
|
||||
Types1_7_6_10.COMPRESSED_NBT_ITEM.write(buffer, item);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item[] items) {
|
||||
Types.SHORT.writePrimitive(buffer, (short) items.length);
|
||||
for (Item item : items) {
|
||||
RewindTypes.COMPRESSED_NBT_ITEM.write(buffer, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.item;
|
||||
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
@@ -25,33 +25,33 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ItemType extends Type<Item> {
|
||||
|
||||
public ItemType() {
|
||||
super(Item.class);
|
||||
}
|
||||
public ItemType() {
|
||||
super(Item.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) throws Exception {
|
||||
short id = buffer.readShort();
|
||||
if (id < 0) {
|
||||
return null;
|
||||
}
|
||||
Item item = new DataItem();
|
||||
item.setIdentifier(id);
|
||||
item.setAmount(buffer.readByte());
|
||||
item.setData(buffer.readShort());
|
||||
item.setTag(Types1_7_6_10.COMPRESSED_NBT.read(buffer));
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) {
|
||||
short id = buffer.readShort();
|
||||
if (id < 0) {
|
||||
return null;
|
||||
}
|
||||
Item item = new DataItem();
|
||||
item.setIdentifier(id);
|
||||
item.setAmount(buffer.readByte());
|
||||
item.setData(buffer.readShort());
|
||||
item.setTag(RewindTypes.COMPRESSED_NBT.read(buffer));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item item) throws Exception {
|
||||
if (item == null) {
|
||||
buffer.writeShort(-1);
|
||||
} else {
|
||||
buffer.writeShort(item.identifier());
|
||||
buffer.writeByte(item.amount());
|
||||
buffer.writeShort(item.data());
|
||||
Types1_7_6_10.COMPRESSED_NBT.write(buffer, item.tag());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item item) {
|
||||
if (item == null) {
|
||||
buffer.writeShort(-1);
|
||||
} else {
|
||||
buffer.writeShort(item.identifier());
|
||||
buffer.writeByte(item.amount());
|
||||
buffer.writeShort(item.data());
|
||||
RewindTypes.COMPRESSED_NBT.write(buffer, item.tag());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 ViaVersion and contributors
|
||||
* Copyright (C) 2018-2026 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,53 +17,56 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.item;
|
||||
|
||||
import com.viaversion.nbt.io.NBTIO;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.io.NBTIO;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class NBTType extends Type<CompoundTag> {
|
||||
public NBTType() {
|
||||
super(CompoundTag.class);
|
||||
}
|
||||
public NBTType() {
|
||||
super(CompoundTag.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag read(ByteBuf buffer) throws IOException {
|
||||
short length = buffer.readShort();
|
||||
if (length <= 0) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public CompoundTag read(ByteBuf buffer) {
|
||||
short length = buffer.readShort();
|
||||
if (length <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteBuf compressed = buffer.readSlice(length);
|
||||
ByteBuf compressed = buffer.readSlice(length);
|
||||
|
||||
try (GZIPInputStream gzipStream = new GZIPInputStream(new ByteBufInputStream(compressed))) {
|
||||
return NBTIO.reader(CompoundTag.class).named().read(gzipStream);
|
||||
}
|
||||
}
|
||||
try (GZIPInputStream gzipStream = new GZIPInputStream(new ByteBufInputStream(compressed))) {
|
||||
return NBTIO.reader(CompoundTag.class).named().read(gzipStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, CompoundTag nbt) throws Exception {
|
||||
if (nbt == null) {
|
||||
buffer.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, CompoundTag nbt) {
|
||||
if (nbt == null) {
|
||||
buffer.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuf compressedBuf = buffer.alloc().buffer();
|
||||
try {
|
||||
try (GZIPOutputStream gzipStream = new GZIPOutputStream(new ByteBufOutputStream(compressedBuf))) {
|
||||
NBTIO.writer().named().write(gzipStream, nbt);
|
||||
}
|
||||
ByteBuf compressedBuf = buffer.alloc().buffer();
|
||||
try {
|
||||
try (GZIPOutputStream gzipStream = new GZIPOutputStream(new ByteBufOutputStream(compressedBuf))) {
|
||||
NBTIO.writer().named().write(gzipStream, nbt);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
buffer.writeShort(compressedBuf.readableBytes());
|
||||
buffer.writeBytes(compressedBuf);
|
||||
} finally {
|
||||
compressedBuf.release();
|
||||
}
|
||||
}
|
||||
buffer.writeShort(compressedBuf.readableBytes());
|
||||
buffer.writeBytes(compressedBuf);
|
||||
} finally {
|
||||
compressedBuf.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.api.type.metadata;
|
||||
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
|
||||
public enum MetaType1_7_6_10 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
Short(1, Type.SHORT),
|
||||
Int(2, Type.INT),
|
||||
Float(3, Type.FLOAT),
|
||||
String(4, Type.STRING),
|
||||
Slot(5, Types1_7_6_10.COMPRESSED_NBT_ITEM),
|
||||
Position(6, Type.VECTOR);
|
||||
|
||||
private final int typeID;
|
||||
private final Type<?> type;
|
||||
|
||||
MetaType1_7_6_10(int typeID, Type<?> type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_7_6_10 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return this.typeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<?> type() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.api.type.metadata;
|
||||
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.type.types.metadata.MetaListTypeTemplate;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataListType extends MetaListTypeTemplate {
|
||||
@Override
|
||||
public List<Metadata> read(ByteBuf buffer) throws Exception {
|
||||
ArrayList<Metadata> list = new ArrayList<>();
|
||||
|
||||
Metadata m;
|
||||
do {
|
||||
m = Types1_7_6_10.METADATA.read(buffer);
|
||||
if (m != null) {
|
||||
list.add(m);
|
||||
}
|
||||
} while (m != null);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, List<Metadata> metadata) throws Exception {
|
||||
for (Metadata meta : metadata) {
|
||||
Types1_7_6_10.METADATA.write(buffer, meta);
|
||||
}
|
||||
if (metadata.isEmpty()) {
|
||||
Types1_7_6_10.METADATA.write(buffer, new Metadata(0, MetaType1_7_6_10.Byte, (byte) 0));
|
||||
}
|
||||
buffer.writeByte(127);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.api.type.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.type.types.metadata.MetaTypeTemplate;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class MetadataType extends MetaTypeTemplate {
|
||||
@Override
|
||||
public Metadata read(ByteBuf buffer) throws Exception {
|
||||
byte item = buffer.readByte();
|
||||
if (item == 127) {
|
||||
return null;
|
||||
} else {
|
||||
int typeID = (item & 224) >> 5;
|
||||
MetaType1_7_6_10 type = MetaType1_7_6_10.byId(typeID);
|
||||
int id = item & 31;
|
||||
return new Metadata(id, type, type.type().read(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Metadata meta) throws Exception {
|
||||
int item = (meta.metaType().typeId() << 5 | meta.id() & 31) & 255;
|
||||
buffer.writeByte(item);
|
||||
meta.metaType().type().write(buffer, meta.getValue());
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.api.type.primitive;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
public class PositionUYType<T extends Number> extends Type<Position> {
|
||||
|
||||
private final Type<T> yType;
|
||||
private final IntFunction<T> toY;
|
||||
|
||||
public PositionUYType(final Type<T> yType, final IntFunction<T> toY) {
|
||||
super(Position.class);
|
||||
|
||||
this.yType = yType;
|
||||
this.toY = toY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position read(ByteBuf buffer) throws Exception {
|
||||
final int x = buffer.readInt();
|
||||
final int y = yType.read(buffer).intValue();
|
||||
final int z = buffer.readInt();
|
||||
|
||||
return new Position(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Position value) throws Exception {
|
||||
buffer.writeInt(value.x());
|
||||
yType.write(buffer, this.toY.apply(value.y()));
|
||||
buffer.writeInt(value.z());
|
||||
}
|
||||
}
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_2_5to1_7_6_10;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
|
||||
public enum ClientboundPackets1_7_2_5 implements ClientboundPacketType {
|
||||
KEEP_ALIVE, // 0x00
|
||||
JOIN_GAME, // 0x01
|
||||
CHAT_MESSAGE, // 0x02
|
||||
TIME_UPDATE, // 0x03
|
||||
ENTITY_EQUIPMENT, // 0x04
|
||||
SPAWN_POSITION, // 0x05
|
||||
UPDATE_HEALTH, // 0x06
|
||||
RESPAWN, // 0x07
|
||||
PLAYER_POSITION, // 0x08
|
||||
HELD_ITEM_CHANGE, // 0x09
|
||||
USE_BED, // 0x0A
|
||||
ENTITY_ANIMATION, // 0x0B
|
||||
SPAWN_PLAYER, // 0x0C
|
||||
COLLECT_ITEM, // 0x0D
|
||||
SPAWN_ENTITY, // 0x0E
|
||||
SPAWN_MOB, // 0x0F
|
||||
SPAWN_PAINTING, // 0x10
|
||||
SPAWN_EXPERIENCE_ORB, // 0x11
|
||||
ENTITY_VELOCITY, // 0x12
|
||||
DESTROY_ENTITIES, // 0x13
|
||||
ENTITY_MOVEMENT, // 0x14
|
||||
ENTITY_POSITION, // 0x15
|
||||
ENTITY_ROTATION, // 0x16
|
||||
ENTITY_POSITION_AND_ROTATION, // 0x17
|
||||
ENTITY_TELEPORT, // 0x18
|
||||
ENTITY_HEAD_LOOK, // 0x19
|
||||
ENTITY_STATUS, // 0x1A
|
||||
ATTACH_ENTITY, // 0x1B
|
||||
ENTITY_METADATA, // 0x1C
|
||||
ENTITY_EFFECT, // 0x1D
|
||||
REMOVE_ENTITY_EFFECT, // 0x1E
|
||||
SET_EXPERIENCE, // 0x1F
|
||||
ENTITY_PROPERTIES, // 0x20
|
||||
CHUNK_DATA, // 0x21
|
||||
MULTI_BLOCK_CHANGE, // 0x22
|
||||
BLOCK_CHANGE, // 0x23
|
||||
BLOCK_ACTION, // 0x24
|
||||
BLOCK_BREAK_ANIMATION, // 0x25
|
||||
MAP_BULK_CHUNK, // 0x26
|
||||
EXPLOSION, // 0x27
|
||||
EFFECT, // 0x28
|
||||
NAMED_SOUND, // 0x29
|
||||
SPAWN_PARTICLE, // 0x2A
|
||||
GAME_EVENT, // 0x2B
|
||||
SPAWN_GLOBAL_ENTITY, // 0x2C
|
||||
OPEN_WINDOW, // 0x2D
|
||||
CLOSE_WINDOW, // 0x2E
|
||||
SET_SLOT, // 0x2F
|
||||
WINDOW_ITEMS, // 0x30
|
||||
WINDOW_PROPERTY, // 0x31
|
||||
WINDOW_CONFIRMATION, // 0x32
|
||||
UPDATE_SIGN, // 0x33
|
||||
MAP_DATA, // 0x34
|
||||
BLOCK_ENTITY_DATA, // 0x35
|
||||
OPEN_SIGN_EDITOR, // 0x36
|
||||
STATISTICS, // 0x37
|
||||
PLAYER_INFO, // 0x38
|
||||
PLAYER_ABILITIES, // 0x39
|
||||
TAB_COMPLETE, // 0x3A
|
||||
SCOREBOARD_OBJECTIVE, // 0x3B
|
||||
UPDATE_SCORE, // 0x3C
|
||||
DISPLAY_SCOREBOARD, // 0x3D
|
||||
TEAMS, // 0x3E
|
||||
PLUGIN_MESSAGE, // 0x3F
|
||||
DISCONNECT; // 0x40
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_2_5to1_7_6_10;
|
||||
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Protocol1_7_2_5To1_7_6_10 extends AbstractProtocol<ClientboundPackets1_7_2_5, ClientboundPackets1_7_2_5, ServerboundPackets1_7_2_5, ServerboundPackets1_7_2_5> {
|
||||
|
||||
public static final ValueTransformer<String, String> REMOVE_DASHES = new ValueTransformer<String, String>(Type.STRING) {
|
||||
@Override
|
||||
public String transform(PacketWrapper wrapper, String s) {
|
||||
return s.replace("-", "");
|
||||
}
|
||||
};
|
||||
|
||||
public Protocol1_7_2_5To1_7_6_10() {
|
||||
super(ClientboundPackets1_7_2_5.class, ClientboundPackets1_7_2_5.class, ServerboundPackets1_7_2_5.class, ServerboundPackets1_7_2_5.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE.getId(), ClientboundLoginPackets.GAME_PROFILE.getId(), new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING, REMOVE_DASHES); // Uuid
|
||||
map(Type.STRING); // Name
|
||||
}
|
||||
});
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7_2_5.SPAWN_PLAYER, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.STRING, REMOVE_DASHES); // Uuid
|
||||
map(Type.STRING); // Name
|
||||
handler(wrapper -> {
|
||||
final int size = wrapper.read(Type.VAR_INT); // Data count
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.read(Type.STRING); // Data name
|
||||
wrapper.read(Type.STRING); // Data value
|
||||
wrapper.read(Type.STRING); // Data signature
|
||||
}
|
||||
});
|
||||
map(Type.INT); // X
|
||||
map(Type.INT); // Y
|
||||
map(Type.INT); // Z
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.BYTE); // Pitch
|
||||
map(Type.SHORT); // Item in hand
|
||||
map(Types1_7_6_10.METADATA_LIST); // Metadata
|
||||
}
|
||||
});
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7_2_5.TEAMS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Team name
|
||||
map(Type.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
final byte mode = wrapper.get(Type.BYTE, 0);
|
||||
if (mode == 0 || mode == 2) { // Team is created or information is updated
|
||||
wrapper.passthrough(Type.STRING); // Team display name
|
||||
wrapper.passthrough(Type.STRING); // Team prefix
|
||||
wrapper.passthrough(Type.STRING); // Team suffix
|
||||
wrapper.passthrough(Type.BYTE); // Friendly fire
|
||||
}
|
||||
if (mode == 0 || mode == 3 || mode == 4) { // Team is created, player is added or player is removed
|
||||
List<String> entryList = new ArrayList<>();
|
||||
final int size = wrapper.read(Type.SHORT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
entryList.add(wrapper.read(Type.STRING));
|
||||
}
|
||||
|
||||
entryList = entryList.stream()
|
||||
.map(it -> it.length() > 16 ? it.substring(0, 16) : it) // trim to 16 characters
|
||||
.distinct() // remove duplicates
|
||||
.collect(Collectors.toList());
|
||||
|
||||
wrapper.write(Type.SHORT, (short) entryList.size());
|
||||
for (String entry : entryList) {
|
||||
wrapper.write(Type.STRING, entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_2_5to1_7_6_10;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
|
||||
public enum ServerboundPackets1_7_2_5 implements ServerboundPacketType {
|
||||
KEEP_ALIVE, // 0x00
|
||||
CHAT_MESSAGE, // 0x01
|
||||
INTERACT_ENTITY, // 0x02
|
||||
PLAYER_MOVEMENT, // 0x03
|
||||
PLAYER_POSITION, // 0x04
|
||||
PLAYER_ROTATION, // 0x05
|
||||
PLAYER_POSITION_AND_ROTATION, // 0x06
|
||||
PLAYER_DIGGING, // 0x07
|
||||
PLAYER_BLOCK_PLACEMENT, // 0x08
|
||||
HELD_ITEM_CHANGE, // 0x09
|
||||
ANIMATION, // 0x0A
|
||||
ENTITY_ACTION, // 0x0B
|
||||
STEER_VEHICLE, // 0x0C
|
||||
CLOSE_WINDOW, // 0x0D
|
||||
CLICK_WINDOW, // 0x0E
|
||||
WINDOW_CONFIRMATION, // 0x0F
|
||||
CREATIVE_INVENTORY_ACTION, // 0x10
|
||||
CLICK_WINDOW_BUTTON, // 0x11
|
||||
UPDATE_SIGN, // 0x12
|
||||
PLAYER_ABILITIES, // 0x13
|
||||
TAB_COMPLETE, // 0x14
|
||||
CLIENT_SETTINGS, // 0x15
|
||||
CLIENT_STATUS, // 0x16
|
||||
PLUGIN_MESSAGE; // 0x17
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
-162
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.data.RewindMappings;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ServerboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.metadata.MetadataRewriter1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.packets.*;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.provider.CompressionHandlerProvider;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.provider.compression.TrackingCompressionHandlerProvider;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.*;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.task.WorldBorderUpdateTask;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Protocol1_7_6_10To1_8 extends BackwardsProtocol<ClientboundPackets1_8, ClientboundPackets1_7_2_5, ServerboundPackets1_8, ServerboundPackets1_7_2_5> {
|
||||
|
||||
public static final RewindMappings MAPPINGS = new RewindMappings("1.8", "1.7.10");
|
||||
|
||||
private final BlockItemPackets1_8 itemRewriter = new BlockItemPackets1_8(this);
|
||||
private final MetadataRewriter1_7_6_10To1_8 metadataRewriter = new MetadataRewriter1_7_6_10To1_8(this);
|
||||
|
||||
public Protocol1_7_6_10To1_8() {
|
||||
super(ClientboundPackets1_8.class, ClientboundPackets1_7_2_5.class, ServerboundPackets1_8.class, ServerboundPackets1_7_2_5.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
itemRewriter.register();
|
||||
metadataRewriter.register();
|
||||
|
||||
EntityPackets1_8.register(this);
|
||||
PlayerPackets1_8.register(this);
|
||||
ScoreboardPackets1_8.register(this);
|
||||
WorldPackets1_8.register(this);
|
||||
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // server hash
|
||||
map(Type.BYTE_ARRAY_PRIMITIVE, Type.SHORT_BYTE_ARRAY); // public key
|
||||
map(Type.BYTE_ARRAY_PRIMITIVE, Type.SHORT_BYTE_ARRAY); // verification token
|
||||
}
|
||||
});
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_COMPRESSION.getId(), ClientboundLoginPackets.LOGIN_COMPRESSION.getId(), new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int threshold = wrapper.read(Type.VAR_INT);
|
||||
|
||||
Via.getManager().getProviders().get(CompressionHandlerProvider.class).onHandleLoginCompressionPacket(wrapper.user(), threshold);
|
||||
wrapper.cancel();
|
||||
});
|
||||
}
|
||||
});
|
||||
this.cancelClientbound(ClientboundPackets1_8.SET_COMPRESSION); // unused
|
||||
this.registerClientbound(ClientboundPackets1_8.KEEP_ALIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // id
|
||||
}
|
||||
});
|
||||
|
||||
this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE); // shared secret
|
||||
map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE); // verification token
|
||||
}
|
||||
});
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_7_2_5.KEEP_ALIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT, Type.VAR_INT); // id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||
Via.getManager().getProviders().get(CompressionHandlerProvider.class).onTransformPacket(packetWrapper.user());
|
||||
|
||||
super.transform(direction, state, packetWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
connection.addEntityTracker(this.getClass(), new EntityTracker1_8(connection));
|
||||
|
||||
connection.put(new InventoryTracker(connection));
|
||||
connection.put(new PlayerSessionStorage(connection));
|
||||
connection.put(new GameProfileStorage(connection));
|
||||
connection.put(new Scoreboard(connection));
|
||||
connection.put(new CompressionStatusTracker(connection));
|
||||
connection.put(new WorldBorderEmulator(connection));
|
||||
|
||||
if (!connection.has(ClientWorld.class)) {
|
||||
connection.put(new ClientWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ViaProviders providers) {
|
||||
providers.register(CompressionHandlerProvider.class, new TrackingCompressionHandlerProvider());
|
||||
|
||||
if (ViaRewind.getConfig().isEmulateWorldBorder()) {
|
||||
Via.getManager().getScheduler().scheduleRepeating(new WorldBorderUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RewindMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_8 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataRewriter1_7_6_10To1_8 getEntityRewriter() {
|
||||
return metadataRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public enum ParticleIndex1_7_6_10 {
|
||||
EXPLOSION_NORMAL("explode"),
|
||||
EXPLOSION_LARGE("largeexplode"),
|
||||
EXPLOSION_HUGE("hugeexplosion"),
|
||||
FIREWORKS_SPARK("fireworksSpark"),
|
||||
WATER_BUBBLE("bubble"),
|
||||
WATER_SPLASH("splash"),
|
||||
WATER_WAKE("wake"),
|
||||
SUSPENDED("suspended"),
|
||||
SUSPENDED_DEPTH("depthsuspend"),
|
||||
CRIT("crit"),
|
||||
CRIT_MAGIC("magicCrit"),
|
||||
SMOKE_NORMAL("smoke"),
|
||||
SMOKE_LARGE("largesmoke"),
|
||||
SPELL("spell"),
|
||||
SPELL_INSTANT("instantSpell"),
|
||||
SPELL_MOB("mobSpell"),
|
||||
SPELL_MOB_AMBIENT("mobSpellAmbient"),
|
||||
SPELL_WITCH("witchMagic"),
|
||||
DRIP_WATER("dripWater"),
|
||||
DRIP_LAVA("dripLava"),
|
||||
VILLAGER_ANGRY("angryVillager"),
|
||||
VILLAGER_HAPPY("happyVillager"),
|
||||
TOWN_AURA("townaura"),
|
||||
NOTE("note"),
|
||||
PORTAL("portal"),
|
||||
ENCHANTMENT_TABLE("enchantmenttable"),
|
||||
FLAME("flame"),
|
||||
LAVA("lava"),
|
||||
FOOTSTEP("footstep"),
|
||||
CLOUD("cloud"),
|
||||
REDSTONE("reddust"),
|
||||
SNOWBALL("snowballpoof"),
|
||||
SNOW_SHOVEL("snowshovel"),
|
||||
SLIME("slime"),
|
||||
HEART("heart"),
|
||||
BARRIER("barrier"),
|
||||
ICON_CRACK("iconcrack", 2),
|
||||
BLOCK_CRACK("blockcrack", 1),
|
||||
BLOCK_DUST("blockdust", 1),
|
||||
WATER_DROP("droplet"),
|
||||
ITEM_TAKE("take"),
|
||||
MOB_APPEARANCE("mobappearance");
|
||||
|
||||
public final String name;
|
||||
public final int extra;
|
||||
private static final HashMap<String, ParticleIndex1_7_6_10> particleMap = new HashMap<>();
|
||||
|
||||
ParticleIndex1_7_6_10(String name) {
|
||||
this(name, 0);
|
||||
}
|
||||
|
||||
ParticleIndex1_7_6_10(String name, int extra) {
|
||||
this.name = name;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public static ParticleIndex1_7_6_10 find(String part) {
|
||||
return particleMap.get(part);
|
||||
}
|
||||
|
||||
public static ParticleIndex1_7_6_10 find(int id) {
|
||||
if (id < 0) return null;
|
||||
ParticleIndex1_7_6_10[] values = ParticleIndex1_7_6_10.values();
|
||||
return id >= values.length ? null : values[id];
|
||||
}
|
||||
|
||||
static {
|
||||
ParticleIndex1_7_6_10[] particles = values();
|
||||
|
||||
for (ParticleIndex1_7_6_10 particle : particles) {
|
||||
particleMap.put(particle.name, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
-330
@@ -1,330 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.data;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.metadata.MetaIndex;
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.api.type.metadata.MetaType1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.metadata.MetadataRewriter1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.utils.math.AABB;
|
||||
import com.viaversion.viarewind.utils.math.Vector3d;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.TrackedEntityImpl;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEventImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VirtualHologramEntity {
|
||||
private final List<Metadata> metadataTracker = new ArrayList<>();
|
||||
private double locX, locY, locZ;
|
||||
|
||||
private final UserConnection user;
|
||||
private final int entityId;
|
||||
|
||||
private int[] entityIds = null;
|
||||
private State currentState = null;
|
||||
private String name = null;
|
||||
private float yaw, pitch;
|
||||
private float headYaw;
|
||||
private boolean small = false;
|
||||
private boolean marker = false;
|
||||
|
||||
public VirtualHologramEntity(final UserConnection user, final int entityId) {
|
||||
this.user = user;
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public void setPosition(final double x, final double y, final double z) throws Exception {
|
||||
if (x == this.locX && y == this.locY && z == this.locZ) return;
|
||||
this.locX = x;
|
||||
this.locY = y;
|
||||
this.locZ = z;
|
||||
|
||||
updateLocation(false);
|
||||
}
|
||||
|
||||
public void setRelativePosition(final double x, final double y, final double z) throws Exception {
|
||||
if (x == 0.0 && y == 0.0 && z == 0.0) return;
|
||||
this.locX += x;
|
||||
this.locY += y;
|
||||
this.locZ += z;
|
||||
|
||||
updateLocation(false);
|
||||
}
|
||||
|
||||
public void setRotation(final float yaw, final float pitch) throws Exception {
|
||||
if (this.yaw == yaw || this.headYaw == yaw || this.pitch == pitch) return;
|
||||
this.yaw = yaw;
|
||||
this.headYaw = yaw;
|
||||
this.pitch = pitch;
|
||||
|
||||
updateLocation(false);
|
||||
}
|
||||
|
||||
public void setHeadYaw(float yaw) throws Exception {
|
||||
if (this.headYaw == yaw) return;
|
||||
this.headYaw = yaw;
|
||||
|
||||
updateLocation(false);
|
||||
}
|
||||
|
||||
public void syncState(final MetadataRewriter1_7_6_10To1_8 entityRewriter, final List<Metadata> metadataList) throws Exception {
|
||||
// Merge metadata updates into current tracker
|
||||
for (Metadata metadata : metadataList) {
|
||||
metadataTracker.removeIf(m -> m.id() == metadata.id());
|
||||
metadataTracker.add(metadata);
|
||||
}
|
||||
|
||||
// Filter armor stand data to calculate emulation
|
||||
byte flags = 0;
|
||||
byte armorStandFlags = 0;
|
||||
for (Metadata metadata : metadataTracker) {
|
||||
if (metadata.id() == 0 && metadata.metaType() == MetaType1_8.Byte) {
|
||||
flags = ((Number) metadata.getValue()).byteValue();
|
||||
} else if (metadata.id() == 2 && metadata.metaType() == MetaType1_8.String) {
|
||||
name = metadata.getValue().toString();
|
||||
if (name != null && name.isEmpty()) name = null;
|
||||
} else if (metadata.id() == 10 && metadata.metaType() == MetaType1_8.Byte) {
|
||||
armorStandFlags = ((Number) metadata.getValue()).byteValue();
|
||||
}
|
||||
}
|
||||
final boolean invisible = (flags & 0x20) != 0;
|
||||
small = (armorStandFlags & 0x01) != 0;
|
||||
marker = (armorStandFlags & 0x10) != 0;
|
||||
|
||||
State prevState = currentState;
|
||||
if (invisible && name != null) {
|
||||
currentState = State.HOLOGRAM;
|
||||
} else {
|
||||
currentState = State.ZOMBIE;
|
||||
}
|
||||
|
||||
if (currentState != prevState) {
|
||||
deleteEntity();
|
||||
sendSpawnPacket(entityRewriter);
|
||||
} else {
|
||||
sendMetadataUpdate(entityRewriter);
|
||||
updateLocation(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLocation(final boolean remount) throws Exception {
|
||||
if (entityIds == null) {
|
||||
return;
|
||||
}
|
||||
if (currentState == State.ZOMBIE) {
|
||||
teleportEntity(entityId, locX, locY, locZ, yaw, pitch);
|
||||
|
||||
final PacketWrapper entityHeadLook = PacketWrapper.create(ClientboundPackets1_7_2_5.ENTITY_HEAD_LOOK, user);
|
||||
|
||||
entityHeadLook.write(Type.INT, entityId);
|
||||
entityHeadLook.write(Type.BYTE, (byte) ((headYaw / 360f) * 256));
|
||||
|
||||
entityHeadLook.send(Protocol1_7_6_10To1_8.class);
|
||||
} else if (currentState == State.HOLOGRAM) {
|
||||
if (remount) {
|
||||
PacketWrapper detach = PacketWrapper.create(ClientboundPackets1_7_2_5.ATTACH_ENTITY, user);
|
||||
detach.write(Type.INT, entityIds[1]);
|
||||
detach.write(Type.INT, -1);
|
||||
detach.write(Type.BOOLEAN, false);
|
||||
detach.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
// Don't ask me where this offset is coming from
|
||||
teleportEntity(entityIds[0], locX, (locY + (marker ? 54.85 : small ? 56 : 57) - 0.16), locZ, 0, 0); // Skull
|
||||
|
||||
if (remount) {
|
||||
teleportEntity(entityIds[1], locX, locY + 56.75, locZ, 0, 0); // Horse
|
||||
|
||||
PacketWrapper attach = PacketWrapper.create(ClientboundPackets1_7_2_5.ATTACH_ENTITY, null, user);
|
||||
attach.write(Type.INT, entityIds[1]);
|
||||
attach.write(Type.INT, entityIds[0]);
|
||||
attach.write(Type.BOOLEAN, false);
|
||||
attach.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void teleportEntity(final int entityId, final double x, final double y, final double z, final float yaw, final float pitch) throws Exception {
|
||||
final PacketWrapper entityTeleport = PacketWrapper.create(ClientboundPackets1_7_2_5.ENTITY_TELEPORT, user);
|
||||
|
||||
entityTeleport.write(Type.INT, entityId); // entity id
|
||||
entityTeleport.write(Type.INT, (int) (x * 32.0)); // x
|
||||
entityTeleport.write(Type.INT, (int) (y * 32.0)); // y
|
||||
entityTeleport.write(Type.INT, (int) (z * 32.0)); // z
|
||||
entityTeleport.write(Type.BYTE, (byte) ((yaw / 360f) * 256)); // yaw
|
||||
entityTeleport.write(Type.BYTE, (byte) ((pitch / 360f) * 256)); // pitch
|
||||
|
||||
entityTeleport.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
protected void spawnEntity(final int entityId, final int type, final double locX, final double locY, final double locZ) throws Exception {
|
||||
final PacketWrapper spawnMob = PacketWrapper.create(ClientboundPackets1_7_2_5.SPAWN_MOB, null, user);
|
||||
|
||||
spawnMob.write(Type.VAR_INT, entityId); // entity id
|
||||
spawnMob.write(Type.UNSIGNED_BYTE, (short) type); // type
|
||||
spawnMob.write(Type.INT, (int) (locX * 32.0)); // x
|
||||
spawnMob.write(Type.INT, (int) (locY * 32.0)); // y
|
||||
spawnMob.write(Type.INT, (int) (locZ * 32.0)); // z
|
||||
spawnMob.write(Type.BYTE, (byte) 0); // yaw
|
||||
spawnMob.write(Type.BYTE, (byte) 0); // pitch
|
||||
spawnMob.write(Type.BYTE, (byte) 0); // head pitch
|
||||
spawnMob.write(Type.SHORT, (short) 0); // velocity x
|
||||
spawnMob.write(Type.SHORT, (short) 0); // velocity y
|
||||
spawnMob.write(Type.SHORT, (short) 0); // velocity z
|
||||
spawnMob.write(Types1_7_6_10.METADATA_LIST, new ArrayList<>()); // metadata
|
||||
|
||||
spawnMob.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
public void sendMetadataUpdate(final MetadataRewriter1_7_6_10To1_8 entityRewriter) throws Exception {
|
||||
if (entityIds == null) {
|
||||
return;
|
||||
}
|
||||
final PacketWrapper metadataPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.ENTITY_METADATA, user);
|
||||
|
||||
if (currentState == State.ZOMBIE) {
|
||||
writeZombieMeta(entityRewriter, metadataPacket);
|
||||
} else if (currentState == State.HOLOGRAM) {
|
||||
writeHologramMeta(metadataPacket);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
metadataPacket.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
private void writeZombieMeta(final MetadataRewriter1_7_6_10To1_8 entityRewriter, PacketWrapper wrapper) {
|
||||
wrapper.write(Type.INT, entityIds[0]);
|
||||
|
||||
// Filter metadata sent by the server and convert them together with our custom metadata
|
||||
final List<Metadata> metadataList = new ArrayList<>();
|
||||
for (Metadata metadata : metadataTracker) {
|
||||
// Remove non existent metadata
|
||||
if (metadata.id() < 0 || metadata.id() > 9) {
|
||||
continue;
|
||||
}
|
||||
metadataList.add(new Metadata(metadata.id(), metadata.metaType(), metadata.getValue()));
|
||||
}
|
||||
if (small) {
|
||||
metadataList.add(new Metadata(12, MetaType1_8.Byte, (byte) 1));
|
||||
}
|
||||
|
||||
// Push metadata from the server through metadata conversion 1.7->1.8
|
||||
for (Metadata metadata : metadataList.toArray(new Metadata[0])) {
|
||||
final MetaHandlerEvent event = new MetaHandlerEventImpl(wrapper.user(), new TrackedEntityImpl(EntityTypes1_10.EntityType.ZOMBIE), -1, metadata, metadataList);
|
||||
try {
|
||||
entityRewriter.handleMetadata(event, metadata);
|
||||
} catch (Exception e) {
|
||||
metadataList.remove(metadata);
|
||||
break;
|
||||
}
|
||||
if (event.cancelled()) {
|
||||
metadataList.remove(metadata);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wrapper.write(Types1_7_6_10.METADATA_LIST, metadataList);
|
||||
}
|
||||
|
||||
private void writeHologramMeta(PacketWrapper wrapper) {
|
||||
wrapper.write(Type.INT, entityIds[1]);
|
||||
|
||||
// Directly write 1.7 metadata here since we are making them up
|
||||
final List<Metadata> metadataList = new ArrayList<>();
|
||||
metadataList.add(new Metadata(MetaIndex.ENTITY_AGEABLE_AGE.getIndex(), MetaType1_7_6_10.Int, -1700000));
|
||||
metadataList.add(new Metadata(MetaIndex.ENTITY_LIVING_NAME_TAG.getIndex(), MetaType1_7_6_10.String, name));
|
||||
metadataList.add(new Metadata(MetaIndex.ENTITY_LIVING_NAME_TAG_VISIBILITY.getIndex(), MetaType1_7_6_10.Byte, (byte) 1));
|
||||
|
||||
wrapper.write(Types1_7_6_10.METADATA_LIST, metadataList);
|
||||
}
|
||||
|
||||
public void sendSpawnPacket(final MetadataRewriter1_7_6_10To1_8 entityRewriter) throws Exception {
|
||||
if (entityIds != null) {
|
||||
deleteEntity();
|
||||
}
|
||||
if (currentState == State.ZOMBIE) {
|
||||
spawnEntity(entityId, 54, locX, locY, locZ);
|
||||
|
||||
entityIds = new int[]{entityId};
|
||||
} else if (currentState == State.HOLOGRAM) {
|
||||
final int[] entityIds = { entityId, additionalEntityId() };
|
||||
|
||||
final PacketWrapper spawnSkull = PacketWrapper.create(ClientboundPackets1_7_2_5.SPAWN_ENTITY, user);
|
||||
spawnSkull.write(Type.VAR_INT, entityIds[0]);
|
||||
spawnSkull.write(Type.BYTE, (byte) 66);
|
||||
spawnSkull.write(Type.INT, (int) (locX * 32.0));
|
||||
spawnSkull.write(Type.INT, (int) (locY * 32.0));
|
||||
spawnSkull.write(Type.INT, (int) (locZ * 32.0));
|
||||
spawnSkull.write(Type.BYTE, (byte) 0);
|
||||
spawnSkull.write(Type.BYTE, (byte) 0);
|
||||
spawnSkull.write(Type.INT, 0);
|
||||
spawnSkull.send(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
spawnEntity(entityIds[1], 100, locX, locY, locZ); // Horse
|
||||
|
||||
this.entityIds = entityIds;
|
||||
}
|
||||
|
||||
sendMetadataUpdate(entityRewriter);
|
||||
updateLocation(true);
|
||||
}
|
||||
|
||||
public AABB getBoundingBox() {
|
||||
final double width = this.small ? 0.25 : 0.5;
|
||||
final double height = this.small ? 0.9875 : 1.975;
|
||||
|
||||
final Vector3d min = new Vector3d(this.locX - width / 2, this.locY, this.locZ - width / 2);
|
||||
final Vector3d max = new Vector3d(this.locX + width / 2, this.locY + height, this.locZ + width / 2);
|
||||
|
||||
return new AABB(min, max);
|
||||
}
|
||||
|
||||
private int additionalEntityId() {
|
||||
return Integer.MAX_VALUE - 16000 - entityId;
|
||||
}
|
||||
|
||||
public void deleteEntity() throws Exception {
|
||||
if (entityIds == null) {
|
||||
return;
|
||||
}
|
||||
final PacketWrapper despawn = PacketWrapper.create(ClientboundPackets1_7_2_5.DESTROY_ENTITIES, user);
|
||||
despawn.write(Type.BYTE, (byte) entityIds.length);
|
||||
for (int id : entityIds) {
|
||||
despawn.write(Type.INT, id);
|
||||
}
|
||||
entityIds = null;
|
||||
despawn.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
private enum State {
|
||||
HOLOGRAM, ZOMBIE
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
}
|
||||
-216
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.metadata;
|
||||
|
||||
import com.viaversion.viarewind.api.type.metadata.MetaType1_7_6_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum MetaIndex {
|
||||
|
||||
ENTITY_FLAGS(EntityTypes1_10.EntityType.ENTITY, 0, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
ENTITY_AIR(EntityTypes1_10.EntityType.ENTITY, 1, MetaType1_7_6_10.Short, MetaType1_8.Short),
|
||||
ENTITY_NAME_TAG(EntityTypes1_10.EntityType.ENTITY, -1, null, 2, MetaType1_8.String),
|
||||
ENTITY_NAME_TAG_VISIBILITY(EntityTypes1_10.EntityType.ENTITY, -1, null, 3, MetaType1_8.Byte),
|
||||
ENTITY_SILENT(EntityTypes1_10.EntityType.ENTITY, -1, null, 4, MetaType1_8.Byte),
|
||||
|
||||
ENTITY_LIVING_HEALTH(EntityTypes1_10.EntityType.ENTITY_LIVING, 6, MetaType1_7_6_10.Float, MetaType1_8.Float),
|
||||
ENTITY_LIVING_POTION_EFFECT_COLOR(EntityTypes1_10.EntityType.ENTITY_LIVING, 7, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
ENTITY_LIVING_IS_POTION_EFFECT_AMBIENT(EntityTypes1_10.EntityType.ENTITY_LIVING, 8, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
ENTITY_LIVING_ARROWS(EntityTypes1_10.EntityType.ENTITY_LIVING, 9, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
ENTITY_LIVING_NAME_TAG(EntityTypes1_10.EntityType.ENTITY_LIVING, 10, MetaType1_7_6_10.String, 2, MetaType1_8.String),
|
||||
ENTITY_LIVING_NAME_TAG_VISIBILITY(EntityTypes1_10.EntityType.ENTITY_LIVING, 11, MetaType1_7_6_10.Byte, 3, MetaType1_8.Byte),
|
||||
ENTITY_LIVING_AI(EntityTypes1_10.EntityType.ENTITY_LIVING, -1, null, 15, MetaType1_8.Byte),
|
||||
|
||||
ENTITY_AGEABLE_AGE(EntityTypes1_10.EntityType.ENTITY_AGEABLE, 12, MetaType1_7_6_10.Int, MetaType1_8.Byte),
|
||||
|
||||
ARMOR_STAND_FLAGS(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 10, MetaType1_8.Byte),
|
||||
ARMOR_STAND_HEAD_POSITION(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 11, MetaType1_8.Rotation),
|
||||
ARMOR_STAND_BODY_POSITION(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 12, MetaType1_8.Rotation),
|
||||
ARMOR_STAND_LEFT_ARM_POSITION(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 13, MetaType1_8.Rotation),
|
||||
ARMOR_STAND_RIGHT_ARM_POSITION(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 14, MetaType1_8.Rotation),
|
||||
ARMOR_STAND_LEFT_LEG_POSITION(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 15, MetaType1_8.Rotation),
|
||||
ARMOR_STAND_RIGHT_LEG_POSITION(EntityTypes1_10.EntityType.ARMOR_STAND, -1, null, 16, MetaType1_8.Rotation),
|
||||
|
||||
HUMAN_SKIN_FLAGS(EntityTypes1_10.EntityType.ENTITY_HUMAN, 16, MetaType1_7_6_10.Byte, 10, MetaType1_8.Byte),
|
||||
HUMAN_UNUSED(EntityTypes1_10.EntityType.ENTITY_HUMAN, -1, null, 16, MetaType1_8.Byte),
|
||||
HUMAN_ABSORPTION_HEATS(EntityTypes1_10.EntityType.ENTITY_HUMAN, 17, MetaType1_7_6_10.Float, MetaType1_8.Float),
|
||||
HUMAN_SCORE(EntityTypes1_10.EntityType.ENTITY_HUMAN, 18, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
|
||||
HORSE_FLAGS(EntityTypes1_10.EntityType.HORSE, 16, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
HORSE_TYPE(EntityTypes1_10.EntityType.HORSE, 19, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
HORSE_COLOR(EntityTypes1_10.EntityType.HORSE, 20, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
HORSE_OWNER(EntityTypes1_10.EntityType.HORSE, 21, MetaType1_7_6_10.String, MetaType1_8.String),
|
||||
HORSE_ARMOR(EntityTypes1_10.EntityType.HORSE, 22, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
|
||||
BAT_HANGING(EntityTypes1_10.EntityType.BAT, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
TAMEABLE_FLAGS(EntityTypes1_10.EntityType.ENTITY_TAMEABLE_ANIMAL, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
TAMEABLE_OWNER(EntityTypes1_10.EntityType.ENTITY_TAMEABLE_ANIMAL, 17, MetaType1_7_6_10.String, MetaType1_8.String),
|
||||
|
||||
OCELOT_TYPE(EntityTypes1_10.EntityType.OCELOT, 18, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
WOLF_FLAGS(EntityTypes1_10.EntityType.WOLF, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
WOLF_HEALTH(EntityTypes1_10.EntityType.WOLF, 18, MetaType1_7_6_10.Float, MetaType1_8.Float),
|
||||
WOLF_BEGGING(EntityTypes1_10.EntityType.WOLF, 19, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
WOLF_COLLAR_COLOR(EntityTypes1_10.EntityType.WOLF, 20, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
PIG_SADDLE(EntityTypes1_10.EntityType.PIG, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
SHEEP_COLOR_OR_SHEARED(EntityTypes1_10.EntityType.SHEEP, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
VILLAGER_TYPE(EntityTypes1_10.EntityType.VILLAGER, 16, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
|
||||
ENDERMAN_CARRIED_BLOCK(EntityTypes1_10.EntityType.ENDERMAN, 16, null, MetaType1_8.Short),
|
||||
ENDERMAN_CARRIED_BLOCK_DATA(EntityTypes1_10.EntityType.ENDERMAN, 17, null, MetaType1_8.Byte),
|
||||
ENDERMAN_IS_SCREAMING(EntityTypes1_10.EntityType.ENDERMAN, 18, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
ZOMBIE_CHILD(EntityTypes1_10.EntityType.ZOMBIE, 12, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
ZOMBIE_VILLAGER(EntityTypes1_10.EntityType.ZOMBIE, 13, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
ZOMBIE_CONVERTING(EntityTypes1_10.EntityType.ZOMBIE, 14, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
BLAZE_ON_FIRE(EntityTypes1_10.EntityType.BLAZE, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
SPIDER_CLIMBING(EntityTypes1_10.EntityType.SPIDER, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
CREEPER_STATE(EntityTypes1_10.EntityType.CREEPER, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
CREEPER_POWERED(EntityTypes1_10.EntityType.CREEPER, 17, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
CREEPER_IGNITED(EntityTypes1_10.EntityType.CREEPER, 18, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
GHAST_STATE(EntityTypes1_10.EntityType.GHAST, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
GHAST_IS_POWERED(EntityTypes1_10.EntityType.GHAST, 17, null, MetaType1_8.Byte),
|
||||
|
||||
SLIME_SIZE(EntityTypes1_10.EntityType.SLIME, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
SKELETON_TYPE(EntityTypes1_10.EntityType.SKELETON, 13, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
WITCH_AGGRESSIVE(EntityTypes1_10.EntityType.WITCH, 21, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
IRON_GOLEM_IS_PLAYER_CREATED(EntityTypes1_10.EntityType.IRON_GOLEM, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
WITHER_WATCHED_TARGET_1(EntityTypes1_10.EntityType.WITHER, 17, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
WITHER_WATCHED_TARGET_2(EntityTypes1_10.EntityType.WITHER, 18, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
WITHER_WATCHED_TARGET_3(EntityTypes1_10.EntityType.WITHER, 19, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
WITHER_INVULNERABLE_TIME(EntityTypes1_10.EntityType.WITHER, 20, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
|
||||
GUARDIAN_FLAGS(EntityTypes1_10.EntityType.GUARDIAN, 16, null, MetaType1_8.Byte),
|
||||
GUARDIAN_TARGET(EntityTypes1_10.EntityType.GUARDIAN, 17, null, MetaType1_8.Int),
|
||||
|
||||
BOAT_TIME_SINCE_HIT(EntityTypes1_10.EntityType.BOAT, 17, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
BOAT_FORWARD_DIRECTION(EntityTypes1_10.EntityType.BOAT, 18, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
BOAT_DAMAGE_TAKEN(EntityTypes1_10.EntityType.BOAT, 19, MetaType1_7_6_10.Float, MetaType1_8.Float),
|
||||
|
||||
MINECART_SHAKING_POWER(EntityTypes1_10.EntityType.MINECART_ABSTRACT, 17, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
MINECART_SHAKING_DIRECTION(EntityTypes1_10.EntityType.MINECART_ABSTRACT, 18, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
MINECART_DAMAGE_TAKEN(EntityTypes1_10.EntityType.MINECART_ABSTRACT, 19, MetaType1_7_6_10.Float, MetaType1_8.Float),
|
||||
MINECART_BLOCK_INSIDE(EntityTypes1_10.EntityType.MINECART_ABSTRACT, 20, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
MINECART_BLOCK_Y(EntityTypes1_10.EntityType.MINECART_ABSTRACT, 21, MetaType1_7_6_10.Int, MetaType1_8.Int),
|
||||
MINECART_SHOW_BLOCK(EntityTypes1_10.EntityType.MINECART_ABSTRACT, 22, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
FURNACE_MINECART_IS_POWERED(EntityTypes1_10.EntityType.MINECART_FURNACE, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
ITEM_ITEM(EntityTypes1_10.EntityType.DROPPED_ITEM, 10, MetaType1_7_6_10.Slot, MetaType1_8.Slot),
|
||||
|
||||
ARROW_IS_CRITICAL(EntityTypes1_10.EntityType.ARROW, 16, MetaType1_7_6_10.Byte, MetaType1_8.Byte),
|
||||
|
||||
FIREWORK_INFO(EntityTypes1_10.EntityType.FIREWORK, 8, MetaType1_7_6_10.Slot, MetaType1_8.Slot),
|
||||
|
||||
ITEM_FRAME_ITEM(EntityTypes1_10.EntityType.ITEM_FRAME, 2, MetaType1_7_6_10.Slot, 8, MetaType1_8.Slot),
|
||||
ITEM_FRAME_ROTATION(EntityTypes1_10.EntityType.ITEM_FRAME, 3, MetaType1_7_6_10.Byte, 9, MetaType1_8.Byte),
|
||||
|
||||
ENDER_CRYSTAL_HEALTH(EntityTypes1_10.EntityType.ENDER_CRYSTAL, 8, MetaType1_7_6_10.Int, 9, MetaType1_8.Int);
|
||||
|
||||
private static final HashMap<Pair<EntityTypes1_10.EntityType, Integer>, MetaIndex> metadataRewrites = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (MetaIndex index : MetaIndex.values()) {
|
||||
metadataRewrites.put(new Pair<>(index.getClazz(), index.getNewIndex()), index);
|
||||
}
|
||||
}
|
||||
|
||||
private final EntityTypes1_10.EntityType clazz;
|
||||
private final int newIndex;
|
||||
private final MetaType1_8 newType;
|
||||
private final MetaType1_7_6_10 oldType;
|
||||
private final int index;
|
||||
|
||||
MetaIndex(EntityTypes1_10.EntityType type, int index, MetaType1_7_6_10 oldType, MetaType1_8 newType) {
|
||||
this.clazz = type;
|
||||
this.index = index;
|
||||
this.newIndex = index;
|
||||
this.oldType = oldType;
|
||||
this.newType = newType;
|
||||
}
|
||||
|
||||
MetaIndex(EntityTypes1_10.EntityType type, int index, MetaType1_7_6_10 oldType, int newIndex, MetaType1_8 newType) {
|
||||
this.clazz = type;
|
||||
this.index = index;
|
||||
this.oldType = oldType;
|
||||
this.newIndex = newIndex;
|
||||
this.newType = newType;
|
||||
}
|
||||
|
||||
private static Optional<MetaIndex> getIndex(EntityType type, int index) {
|
||||
Pair<EntityType, Integer> pair = new Pair<>(type, index);
|
||||
if (metadataRewrites.containsKey(pair)) {
|
||||
return Optional.of(metadataRewrites.get(pair));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public EntityTypes1_10.EntityType getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public int getNewIndex() {
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
public MetaType1_8 getNewType() {
|
||||
return newType;
|
||||
}
|
||||
|
||||
public MetaType1_7_6_10 getOldType() {
|
||||
return oldType;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public static MetaIndex searchIndex(EntityType type, int index) {
|
||||
EntityType currentType = type;
|
||||
do {
|
||||
Optional<MetaIndex> optMeta = getIndex(currentType, index);
|
||||
|
||||
if (optMeta.isPresent()) {
|
||||
return optMeta.get();
|
||||
}
|
||||
|
||||
currentType = currentType.getParent();
|
||||
} while (currentType != null);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-435
@@ -1,435 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.metadata;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.rewriter.VREntityRewriter;
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.api.type.metadata.MetaType1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.data.VirtualHologramEntity;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.EntityTracker1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.GameProfileStorage;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.Scoreboard;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
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.version.Types1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MetadataRewriter1_7_6_10To1_8 extends VREntityRewriter<ClientboundPackets1_8, Protocol1_7_6_10To1_8> {
|
||||
|
||||
public MetadataRewriter1_7_6_10To1_8(Protocol1_7_6_10To1_8 protocol) {
|
||||
super(protocol, MetaType1_7_6_10.String, MetaType1_7_6_10.Byte);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.JOIN_GAME, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // Entity id
|
||||
map(Type.UNSIGNED_BYTE); // Game mode
|
||||
map(Type.BYTE); // Dimension
|
||||
map(Type.UNSIGNED_BYTE); // Difficulty
|
||||
map(Type.UNSIGNED_BYTE); // Max players
|
||||
map(Type.STRING); // Level type
|
||||
read(Type.BOOLEAN); // Reduced debug info
|
||||
|
||||
handler(playerTrackerHandler());
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.INT, 0);
|
||||
|
||||
if (ViaRewind.getConfig().isReplaceAdventureMode()) {
|
||||
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 2) { // adventure
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) 0); // survival
|
||||
}
|
||||
}
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
tracker.addPlayer(entityId, wrapper.user().getProtocolInfo().getUuid());
|
||||
tracker.setClientEntityGameMode(wrapper.get(Type.UNSIGNED_BYTE, 0));
|
||||
|
||||
wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Type.BYTE, 0));
|
||||
|
||||
// Reset on Velocity server change
|
||||
wrapper.user().put(new Scoreboard(wrapper.user()));
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.DESTROY_ENTITIES, wrapper -> {
|
||||
final int[] entities = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
|
||||
untrackEntities(wrapper.user(), entities);
|
||||
|
||||
wrapper.cancel();
|
||||
|
||||
// Split entity destroy packets into smaller packets because 1.8 can handle more entities at once then 1.7 can.
|
||||
final List<List<Integer>> parts = Lists.partition(Ints.asList(entities), Byte.MAX_VALUE);
|
||||
|
||||
for (List<Integer> part : parts) {
|
||||
final PacketWrapper destroy = PacketWrapper.create(ClientboundPackets1_7_2_5.DESTROY_ENTITIES, wrapper.user());
|
||||
destroy.write(Types1_7_6_10.BYTE_INT_ARRAY, part.stream().mapToInt(Integer::intValue).toArray());
|
||||
destroy.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_METADATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // Entity id
|
||||
map(Types1_8.METADATA_LIST, Types1_7_6_10.METADATA_LIST); // Metadata
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.INT, 0);
|
||||
final List<Metadata> metadata = wrapper.get(Types1_7_6_10.METADATA_LIST, 0);
|
||||
handleMetadata(entityId, metadata, wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SPAWN_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.BYTE); // Type id
|
||||
map(Type.INT); // X
|
||||
map(Type.INT); // Y
|
||||
map(Type.INT); // Z
|
||||
map(Type.BYTE); // Pitch
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.INT); // Data
|
||||
|
||||
// Track entity
|
||||
handler(getObjectTrackerHandler());
|
||||
handler(getObjectRewriter(id -> EntityTypes1_10.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
final EntityTypes1_10.EntityType type = EntityTypes1_10.getTypeFromId(wrapper.get(Type.BYTE, 0), true);
|
||||
|
||||
int x = wrapper.get(Type.INT, 0);
|
||||
int y = wrapper.get(Type.INT, 1);
|
||||
int z = wrapper.get(Type.INT, 2);
|
||||
|
||||
byte pitch = wrapper.get(Type.BYTE, 1);
|
||||
byte yaw = wrapper.get(Type.BYTE, 2);
|
||||
|
||||
int data = wrapper.get(Type.INT, 3);
|
||||
|
||||
if (type == EntityTypes1_10.ObjectType.ITEM_FRAME.getType()) {
|
||||
switch (yaw) {
|
||||
case -128:
|
||||
z += 32;
|
||||
yaw = 0;
|
||||
break;
|
||||
case -64:
|
||||
x -= 32;
|
||||
yaw = -64;
|
||||
break;
|
||||
case 0:
|
||||
z -= 32;
|
||||
yaw = -128;
|
||||
break;
|
||||
case 64:
|
||||
x += 32;
|
||||
yaw = 64;
|
||||
break;
|
||||
}
|
||||
} else if (type == EntityTypes1_10.ObjectType.ARMOR_STAND.getType()) {
|
||||
wrapper.cancel();
|
||||
|
||||
final EntityTracker1_8 tracker = tracker(wrapper.user());
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(entityId);
|
||||
hologram.setPosition(x / 32.0, y / 32.0, z / 32.0);
|
||||
hologram.setRotation(yaw * 360f / 256, pitch * 360f / 256);
|
||||
hologram.setHeadYaw(yaw * 360f / 256);
|
||||
} else if (type != null && type.isOrHasParent(EntityTypes1_10.EntityType.FALLING_BLOCK)) {
|
||||
int blockId = data & 0xFFF;
|
||||
int blockData = data >> 12 & 0xF;
|
||||
final IdAndData replace = protocol.getItemRewriter().handleBlock(blockId, blockData);
|
||||
if (replace != null) {
|
||||
blockId = replace.getId();
|
||||
blockData = replace.getData();
|
||||
}
|
||||
wrapper.set(Type.INT, 3, data = (blockId | blockData << 16));
|
||||
}
|
||||
|
||||
wrapper.set(Type.INT, 0, x);
|
||||
wrapper.set(Type.INT, 1, y);
|
||||
wrapper.set(Type.INT, 2, z);
|
||||
wrapper.set(Type.BYTE, 2, yaw);
|
||||
|
||||
if (data > 0) {
|
||||
wrapper.passthrough(Type.SHORT); // Velocity x
|
||||
wrapper.passthrough(Type.SHORT); // Velocity y
|
||||
wrapper.passthrough(Type.SHORT); // Velocity z
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerTracker(ClientboundPackets1_8.SPAWN_EXPERIENCE_ORB, EntityType.EXPERIENCE_ORB);
|
||||
registerTracker(ClientboundPackets1_8.SPAWN_GLOBAL_ENTITY, EntityType.LIGHTNING);
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SPAWN_PAINTING, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.STRING); // Title
|
||||
map(Type.POSITION1_8, Types1_7_6_10.INT_POSITION); // Position
|
||||
map(Type.UNSIGNED_BYTE, Type.INT); // Rotation
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
final Position position = wrapper.get(Types1_7_6_10.INT_POSITION, 0);
|
||||
final int rotation = wrapper.get(Type.INT, 0);
|
||||
int modX = 0;
|
||||
int modZ = 0;
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
modZ = -1;
|
||||
break;
|
||||
case 1:
|
||||
modX = 1;
|
||||
break;
|
||||
case 2:
|
||||
modZ = 1;
|
||||
break;
|
||||
case 3:
|
||||
modX = -1;
|
||||
break;
|
||||
}
|
||||
wrapper.set(Types1_7_6_10.INT_POSITION, 0, new Position(position.x() + modX, position.y(), position.z() + modZ));
|
||||
addTrackedEntity(wrapper, entityId, EntityTypes1_10.EntityType.PAINTING);
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SPAWN_MOB, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.UNSIGNED_BYTE); // Entity type
|
||||
map(Type.INT); // X
|
||||
map(Type.INT); // Y
|
||||
map(Type.INT); // Z
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.BYTE); // Pitch
|
||||
map(Type.BYTE); // Head yaw
|
||||
map(Type.SHORT); // Velocity x
|
||||
map(Type.SHORT); // Velocity y
|
||||
map(Type.SHORT); // Velocity z
|
||||
map(Types1_8.METADATA_LIST, Types1_7_6_10.METADATA_LIST); // Metadata
|
||||
|
||||
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
|
||||
handler(getMobSpawnRewriter(Types1_7_6_10.METADATA_LIST));
|
||||
|
||||
// Handle holograms
|
||||
handler(wrapper -> {
|
||||
final short typeId = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
|
||||
final EntityTypes1_10.EntityType type = EntityTypes1_10.getTypeFromId(typeId, false);
|
||||
if (type == EntityTypes1_10.EntityType.ARMOR_STAND) {
|
||||
wrapper.cancel();
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
final int x = wrapper.get(Type.INT, 0);
|
||||
final int y = wrapper.get(Type.INT, 1);
|
||||
final int z = wrapper.get(Type.INT, 2);
|
||||
|
||||
final byte pitch = wrapper.get(Type.BYTE, 1);
|
||||
final byte yaw = wrapper.get(Type.BYTE, 0);
|
||||
final byte headYaw = wrapper.get(Type.BYTE, 2);
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(entityId);
|
||||
|
||||
hologram.setPosition(x / 32.0, y / 32.0, z / 32.0);
|
||||
hologram.setRotation(yaw * 360f / 256, pitch * 360f / 256);
|
||||
hologram.setHeadYaw(headYaw * 360f / 256);
|
||||
hologram.syncState(protocol().getEntityRewriter(), wrapper.get(Types1_7_6_10.METADATA_LIST, 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SPAWN_PLAYER, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // entity id
|
||||
handler(wrapper -> {
|
||||
final UUID uuid = wrapper.read(Type.UUID);
|
||||
wrapper.write(Type.STRING, uuid.toString()); // map to string
|
||||
|
||||
final GameProfileStorage gameProfileStorage = wrapper.user().get(GameProfileStorage.class);
|
||||
|
||||
GameProfileStorage.GameProfile gameProfile = gameProfileStorage.get(uuid);
|
||||
if (gameProfile == null) {
|
||||
wrapper.write(Type.STRING, ""); // name
|
||||
wrapper.write(Type.VAR_INT, 0); // properties count
|
||||
} else {
|
||||
wrapper.write(Type.STRING, gameProfile.name.length() > 16 ? gameProfile.name.substring(0, 16) : gameProfile.name); // name
|
||||
wrapper.write(Type.VAR_INT, gameProfile.properties.size()); // properties count
|
||||
|
||||
for (GameProfileStorage.Property property : gameProfile.properties) {
|
||||
wrapper.write(Type.STRING, property.name); // property name
|
||||
wrapper.write(Type.STRING, property.value); // property value
|
||||
wrapper.write(Type.STRING, property.signature == null ? "" : property.signature); // property signature
|
||||
}
|
||||
}
|
||||
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (gameProfile != null && gameProfile.gamemode == 3) { // Spectator mode
|
||||
for (short i = 0; i < 5; i++) {
|
||||
final PacketWrapper entityEquipment = PacketWrapper.create(ClientboundPackets1_7_2_5.ENTITY_EQUIPMENT, wrapper.user());
|
||||
entityEquipment.write(Type.INT, entityId);
|
||||
entityEquipment.write(Type.SHORT, i);
|
||||
entityEquipment.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, i == 4 ? gameProfile.getSkull() : null);
|
||||
|
||||
entityEquipment.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
|
||||
tracker.addPlayer(entityId, uuid);
|
||||
});
|
||||
map(Type.INT); // x
|
||||
map(Type.INT); // y
|
||||
map(Type.INT); // z
|
||||
map(Type.BYTE); // yaw
|
||||
map(Type.BYTE); // pitch
|
||||
map(Type.SHORT); // Current item
|
||||
map(Types1_8.METADATA_LIST, Types1_7_6_10.METADATA_LIST); // metadata
|
||||
|
||||
handler(getTrackerAndMetaHandler(Types1_7_6_10.METADATA_LIST, EntityTypes1_10.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Handle new entities
|
||||
mapEntityTypeWithData(EntityType.GUARDIAN, EntityType.SQUID).plainName();
|
||||
mapEntityTypeWithData(EntityType.ENDERMITE, EntityType.SQUID).plainName();
|
||||
mapEntityTypeWithData(EntityType.RABBIT, EntityType.CHICKEN).plainName();
|
||||
|
||||
// Metadata rewrite
|
||||
filter().handler((event, meta) -> {
|
||||
try {
|
||||
handleMetadata(event, meta);
|
||||
} catch (Exception e) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "An error occurred with entity metadata: " + meta, e);
|
||||
}
|
||||
event.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleMetadata(MetaHandlerEvent event, Metadata metadata) throws Exception {
|
||||
if (event.entityType() == EntityType.ARMOR_STAND) {
|
||||
final EntityTracker1_8 tracker = tracker(event.user());
|
||||
tracker.getHolograms().get(event.entityId()).syncState(this, event.metadataList());
|
||||
event.cancel(); // We are rewriting metadata manually
|
||||
return;
|
||||
}
|
||||
|
||||
final MetaIndex metaIndex = MetaIndex.searchIndex(event.entityType(), metadata.id());
|
||||
if (metaIndex == null) {
|
||||
// Almost certainly bad data, remove it
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (metaIndex.getOldType() == null) {
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
final Object value = metadata.getValue();
|
||||
metadata.setTypeAndValue(metaIndex.getNewType(), value);
|
||||
metadata.setMetaTypeUnsafe(metaIndex.getOldType());
|
||||
metadata.setId(metaIndex.getIndex());
|
||||
|
||||
switch (metaIndex.getOldType()) {
|
||||
case Int:
|
||||
if (metaIndex.getNewType() == MetaType1_8.Byte) {
|
||||
metadata.setValue(((Byte) value).intValue());
|
||||
if (metaIndex == MetaIndex.ENTITY_AGEABLE_AGE) {
|
||||
if ((Integer) metadata.getValue() < 0) {
|
||||
metadata.setValue(-25000);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (metaIndex.getNewType() == MetaType1_8.Short) {
|
||||
metadata.setValue(((Short) value).intValue());
|
||||
}
|
||||
if (metaIndex.getNewType() == MetaType1_8.Int) {
|
||||
metadata.setValue(value);
|
||||
}
|
||||
break;
|
||||
case Byte:
|
||||
if (metaIndex.getNewType() == MetaType1_8.Int) {
|
||||
metadata.setValue(((Integer) value).byteValue());
|
||||
}
|
||||
if (metaIndex.getNewType() == MetaType1_8.Byte) {
|
||||
if (metaIndex == MetaIndex.ITEM_FRAME_ROTATION) {
|
||||
metadata.setValue(Integer.valueOf((Byte) value % 4).byteValue());
|
||||
} else {
|
||||
metadata.setValue(value);
|
||||
}
|
||||
}
|
||||
if (metaIndex == MetaIndex.HUMAN_SKIN_FLAGS) {
|
||||
byte flags = (byte) value;
|
||||
boolean cape = (flags & 0x01) != 0;
|
||||
flags = (byte) (cape ? 0x00 : 0x02);
|
||||
metadata.setValue(flags);
|
||||
}
|
||||
break;
|
||||
case Slot:
|
||||
metadata.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) value));
|
||||
break;
|
||||
case Float:
|
||||
case String:
|
||||
case Short:
|
||||
case Position:
|
||||
metadata.setValue(value);
|
||||
break;
|
||||
default:
|
||||
event.cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityTypes1_10.EntityType typeFromId(int type) {
|
||||
return EntityTypes1_10.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityTypes1_10.EntityType objectTypeFromId(int type) {
|
||||
return EntityTypes1_10.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
-330
@@ -1,330 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
|
||||
import com.viaversion.viarewind.api.rewriter.VRBlockItemRewriter;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ServerboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.EntityTracker1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.GameProfileStorage;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.InventoryTracker;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.PlayerSessionStorage;
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BlockItemPackets1_8 extends VRBlockItemRewriter<ClientboundPackets1_8, ServerboundPackets1_7_2_5, Protocol1_7_6_10To1_8> {
|
||||
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
|
||||
public BlockItemPackets1_8(Protocol1_7_6_10To1_8 protocol) {
|
||||
super(protocol, "1.8");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.OPEN_WINDOW, wrapper -> {
|
||||
final InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE); // window id
|
||||
final short windowTypeId = InventoryTracker.getInventoryType(wrapper.read(Type.STRING)); // window type
|
||||
|
||||
windowTracker.getWindowTypeMap().put(windowId, windowTypeId);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, windowTypeId); // window type id
|
||||
|
||||
final JsonElement titleComponent = wrapper.read(Type.COMPONENT); // Title
|
||||
String title = ChatUtil.jsonToLegacy(wrapper.user(), titleComponent);
|
||||
title = ChatUtil.removeUnusedColor(title, '8');
|
||||
if (title.length() > 32) {
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
wrapper.write(Type.STRING, title); // window title
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // slots count
|
||||
wrapper.write(Type.BOOLEAN, true); // use provided window title
|
||||
|
||||
if (windowTypeId == 11) { // Horse
|
||||
wrapper.passthrough(Type.INT); // entity id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CLOSE_WINDOW, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE); // window id
|
||||
|
||||
wrapper.user().get(InventoryTracker.class).remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.UNSIGNED_BYTE); // window id
|
||||
map(Type.SHORT); // slot
|
||||
|
||||
handler(wrapper -> {
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(wrapper.get(Type.UNSIGNED_BYTE, 0));
|
||||
final short slot = wrapper.get(Type.SHORT, 0);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
if (slot == 1) {
|
||||
wrapper.cancel();
|
||||
} else if (slot >= 2) {
|
||||
wrapper.set(Type.SHORT, 0, (short) (slot - 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
map(Type.ITEM1_8, Types1_7_6_10.COMPRESSED_NBT_ITEM); // item
|
||||
|
||||
// remap item
|
||||
handler(wrapper -> {
|
||||
final Item item = wrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0);
|
||||
handleItemToClient(wrapper.user(), item);
|
||||
|
||||
wrapper.set(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0, item);
|
||||
});
|
||||
|
||||
handler(wrapper -> {
|
||||
final short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
if (windowId != 0) return;
|
||||
|
||||
final short slot = wrapper.get(Type.SHORT, 0);
|
||||
if (slot < 5 || slot > 8) return;
|
||||
|
||||
final PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
final Item item = wrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0);
|
||||
playerSession.setPlayerEquipment(wrapper.user().getProtocolInfo().getUuid(), item, 8 - slot);
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (tracker.isSpectator()) { // Spectator mode didn't exist in 1.7.10
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.WINDOW_ITEMS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.UNSIGNED_BYTE); // window id
|
||||
|
||||
// remap enchantment table items
|
||||
handler(wrapper -> {
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(wrapper.get(Type.UNSIGNED_BYTE, 0));
|
||||
|
||||
Item[] items = wrapper.read(Type.ITEM1_8_SHORT_ARRAY);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
Item[] old = items;
|
||||
items = new Item[old.length - 1];
|
||||
items[0] = old[0];
|
||||
System.arraycopy(old, 2, items, 1, old.length - 3);
|
||||
}
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
wrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM_ARRAY, items); // items
|
||||
});
|
||||
|
||||
handler(wrapper -> {
|
||||
final short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
if (windowId != 0) return;
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
final UUID userId = wrapper.user().getProtocolInfo().getUuid();
|
||||
|
||||
final Item[] items = wrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM_ARRAY, 0);
|
||||
for (int i = 5; i < 9; i++) {
|
||||
wrapper.user().get(PlayerSessionStorage.class).setPlayerEquipment(userId, items[i], 8 - i);
|
||||
if (tracker.isSpectator()) {
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
if (tracker.isSpectator()) {
|
||||
final GameProfileStorage.GameProfile profile = wrapper.user().get(GameProfileStorage.class).get(userId);
|
||||
if (profile != null) {
|
||||
items[5] = profile.getSkull();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.WINDOW_PROPERTY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.UNSIGNED_BYTE); // window id
|
||||
map(Type.SHORT); // progress bar id
|
||||
map(Type.SHORT); // progress bar value
|
||||
|
||||
handler(wrapper -> {
|
||||
final InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
|
||||
final short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
final short windowType = windowTracker.get(windowId);
|
||||
|
||||
final short progressBarId = wrapper.get(Type.SHORT, 0);
|
||||
short progress = wrapper.get(Type.SHORT, 1);
|
||||
|
||||
if (windowType == 2) { // Furnace
|
||||
// TODO | Proper methods (getOrCreate)=
|
||||
final InventoryTracker.FurnaceData furnace = windowTracker.getFurnaceData().computeIfAbsent(windowId, x -> new InventoryTracker.FurnaceData());
|
||||
if (progressBarId == 0 || progressBarId == 1) {
|
||||
if (progressBarId == 0) {
|
||||
furnace.fuelLeft = progress;
|
||||
} else {
|
||||
furnace.maxFuel = progress;
|
||||
}
|
||||
if (furnace.maxFuel == 0) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
progress = (short) (200 * furnace.fuelLeft / furnace.maxFuel);
|
||||
wrapper.set(Type.SHORT, 0, (short) 1);
|
||||
wrapper.set(Type.SHORT, 1, progress);
|
||||
} else if (progressBarId == 2 || progressBarId == 3) {
|
||||
if (progressBarId == 2) {
|
||||
furnace.progress = progress;
|
||||
} else {
|
||||
furnace.maxProgress = progress;
|
||||
}
|
||||
if (furnace.maxProgress == 0) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
progress = (short) (200 * furnace.progress / furnace.maxProgress);
|
||||
wrapper.set(Type.SHORT, 0, (short) 0);
|
||||
wrapper.set(Type.SHORT, 1, progress);
|
||||
}
|
||||
} else if (windowType == 4 && progressBarId > 2) { // Enchanting Table
|
||||
wrapper.cancel();
|
||||
} else if (windowType == 8) { // Anvil
|
||||
windowTracker.levelCost = progress;
|
||||
windowTracker.anvilId = windowId;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CLOSE_WINDOW, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
||||
wrapper.user().get(InventoryTracker.class).remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CLICK_WINDOW, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.BYTE, Type.UNSIGNED_BYTE); // window id
|
||||
map(Type.SHORT); // slot
|
||||
handler(wrapper -> {
|
||||
final short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0); //Window Id
|
||||
final short slot = wrapper.get(Type.SHORT, 0);
|
||||
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(windowId);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
if (slot > 0) {
|
||||
wrapper.set(Type.SHORT, 0, (short) (slot + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
map(Type.BYTE); // button
|
||||
map(Type.SHORT); // action number
|
||||
map(Type.BYTE); // mode
|
||||
map(Types1_7_6_10.COMPRESSED_NBT_ITEM, Type.ITEM1_8); // clicked item
|
||||
|
||||
// remap item
|
||||
handler(wrapper -> {
|
||||
final Item item = wrapper.get(Type.ITEM1_8, 0);
|
||||
handleItemToServer(wrapper.user(), item);
|
||||
wrapper.set(Type.ITEM1_8, 0, item);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CREATIVE_INVENTORY_ACTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.SHORT); // slot
|
||||
map(Types1_7_6_10.COMPRESSED_NBT_ITEM, Type.ITEM1_8); // item
|
||||
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName(), false);
|
||||
enchantmentRewriter.registerEnchantment(8, "§7Depth Strider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
}
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
|
||||
if (item.identifier() == 387) {
|
||||
final ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages == null) return item;
|
||||
|
||||
final ListTag<StringTag> oldPages = new ListTag<>(StringTag.class);
|
||||
tag.put(nbtTagName() + "|pages", oldPages);
|
||||
|
||||
for (StringTag page : pages) {
|
||||
final String value = page.getValue();
|
||||
oldPages.add(new StringTag(value));
|
||||
page.setValue(ChatUtil.jsonToLegacy(connection, value));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(connection, item);
|
||||
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
|
||||
if (item.identifier() == 387) {
|
||||
final ListTag<StringTag> oldPages = tag.get(nbtTagName() + "|pages");
|
||||
if (oldPages != null) {
|
||||
tag.remove("pages");
|
||||
tag.put("pages", oldPages);
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
-315
@@ -1,315 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.packets;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.data.VirtualHologramEntity;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.EntityTracker1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.GameProfileStorage;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.PlayerSessionStorage;
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class EntityPackets1_8 {
|
||||
|
||||
public static void register(Protocol1_7_6_10To1_8 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_EQUIPMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.SHORT); // slot
|
||||
map(Type.ITEM1_8, Types1_7_6_10.COMPRESSED_NBT_ITEM); // item
|
||||
|
||||
// remap item
|
||||
handler(wrapper -> {
|
||||
final Item item = wrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0);
|
||||
protocol.getItemRewriter().handleItemToClient(wrapper.user(), item);
|
||||
wrapper.set(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0, item);
|
||||
});
|
||||
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
final int id = wrapper.get(Type.INT, 0);
|
||||
int limit = tracker.clientEntityId() == id ? 3 : 4;
|
||||
if (wrapper.get(Type.SHORT, 0) > limit) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
final short slot = wrapper.get(Type.SHORT, 0);
|
||||
final UUID uuid = tracker.getPlayerUUID(wrapper.get(Type.INT, 0));
|
||||
if (uuid == null) return;
|
||||
|
||||
final Item item = wrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0);
|
||||
wrapper.user().get(PlayerSessionStorage.class).setPlayerEquipment(uuid, item, slot);
|
||||
|
||||
final GameProfileStorage storage = wrapper.user().get(GameProfileStorage.class);
|
||||
GameProfileStorage.GameProfile profile = storage.get(uuid);
|
||||
if (profile != null && profile.gamemode == 3) { // spectator mode didn't exist in 1.7.10
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.USE_BED, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.POSITION1_8, Types1_7_6_10.U_BYTE_POSITION); // position
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.COLLECT_ITEM, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // collected entity id
|
||||
map(Type.VAR_INT, Type.INT); // collector entity id
|
||||
|
||||
handler(wrapper -> wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class).removeEntity(wrapper.get(Type.INT, 0)));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_VELOCITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_MOVEMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.BYTE); // x
|
||||
map(Type.BYTE); // y
|
||||
map(Type.BYTE); // z
|
||||
read(Type.BOOLEAN); // on ground
|
||||
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(wrapper.get(Type.INT, 0));
|
||||
if (hologram != null) {
|
||||
wrapper.cancel();
|
||||
final int x = wrapper.get(Type.BYTE, 0);
|
||||
final int y = wrapper.get(Type.BYTE, 1);
|
||||
final int z = wrapper.get(Type.BYTE, 2);
|
||||
|
||||
hologram.setRelativePosition(x / 32.0, y / 32.0, z / 32.0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_ROTATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.BYTE); // yaw
|
||||
map(Type.BYTE); // pitch
|
||||
read(Type.BOOLEAN); // on ground
|
||||
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(wrapper.get(Type.INT, 0));
|
||||
if (hologram != null) {
|
||||
wrapper.cancel();
|
||||
final int yaw = wrapper.get(Type.BYTE, 0);
|
||||
final int pitch = wrapper.get(Type.BYTE, 1);
|
||||
|
||||
hologram.setRotation(yaw * 360f / 256, pitch * 360f / 256);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_POSITION_AND_ROTATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.BYTE); // x
|
||||
map(Type.BYTE); // y
|
||||
map(Type.BYTE); // z
|
||||
map(Type.BYTE); // yaw
|
||||
map(Type.BYTE); // pitch
|
||||
read(Type.BOOLEAN); // on ground
|
||||
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(wrapper.get(Type.INT, 0));
|
||||
if (hologram != null) {
|
||||
wrapper.cancel();
|
||||
final int x = wrapper.get(Type.BYTE, 0);
|
||||
final int y = wrapper.get(Type.BYTE, 1);
|
||||
final int z = wrapper.get(Type.BYTE, 2);
|
||||
|
||||
final int yaw = wrapper.get(Type.BYTE, 3);
|
||||
final int pitch = wrapper.get(Type.BYTE, 4);
|
||||
|
||||
hologram.setRelativePosition(x / 32.0, y / 32.0, z / 32.0);
|
||||
hologram.setRotation(yaw * 360f / 256, pitch * 360f / 256);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_TELEPORT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.INT); // x
|
||||
map(Type.INT); // y
|
||||
map(Type.INT); // z
|
||||
map(Type.BYTE); // yaw
|
||||
map(Type.BYTE); // pitch
|
||||
read(Type.BOOLEAN); // on ground
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.INT, 0);
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (tracker.entityType(entityId) == EntityTypes1_10.EntityType.MINECART_ABSTRACT) { // TODO | Realign all entities?
|
||||
int y = wrapper.get(Type.INT, 2);
|
||||
y += 12;
|
||||
wrapper.set(Type.INT, 2, y);
|
||||
}
|
||||
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(entityId);
|
||||
if (hologram != null) {
|
||||
wrapper.cancel();
|
||||
final int x = wrapper.get(Type.INT, 1);
|
||||
final int y = wrapper.get(Type.INT, 2);
|
||||
final int z = wrapper.get(Type.INT, 3);
|
||||
|
||||
final int yaw = wrapper.get(Type.BYTE, 0);
|
||||
final int pitch = wrapper.get(Type.BYTE, 1);
|
||||
|
||||
hologram.setPosition(x / 32.0, y / 32.0, z / 32.0);
|
||||
hologram.setRotation(yaw * 360f / 256, pitch * 360f / 256);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_HEAD_LOOK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.BYTE); // head yaw
|
||||
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
final VirtualHologramEntity hologram = tracker.getHolograms().get(wrapper.get(Type.INT, 0));
|
||||
if (hologram != null) {
|
||||
wrapper.cancel();
|
||||
final int yaw = wrapper.get(Type.BYTE, 0);
|
||||
|
||||
hologram.setHeadYaw(yaw * 360f / 256);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ATTACH_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // riding entity id
|
||||
map(Type.INT); // vehicle entity id
|
||||
map(Type.BOOLEAN); // leash state
|
||||
handler(wrapper -> {
|
||||
final boolean leash = wrapper.get(Type.BOOLEAN, 0);
|
||||
if (!leash) {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
final int passenger = wrapper.get(Type.INT, 0);
|
||||
final int vehicle = wrapper.get(Type.INT, 1);
|
||||
|
||||
tracker.setPassenger(vehicle, passenger);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_EFFECT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.BYTE); // effect id
|
||||
map(Type.BYTE); // amplifier
|
||||
map(Type.VAR_INT, Type.SHORT); // duration
|
||||
read(Type.BYTE); // hide particles
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.REMOVE_ENTITY_EFFECT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
map(Type.BYTE); // effect id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_PROPERTIES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT, Type.INT); // entity id
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (tracker.getHolograms().containsKey(wrapper.get(Type.INT, 0))) { // Don't handle properties for hologram emulation
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
final int amount = wrapper.passthrough(Type.INT);
|
||||
for (int i = 0; i < amount; i++) {
|
||||
wrapper.passthrough(Type.STRING); // id
|
||||
wrapper.passthrough(Type.DOUBLE); // value
|
||||
|
||||
int modifierLength = wrapper.read(Type.VAR_INT);
|
||||
wrapper.write(Type.SHORT, (short) modifierLength);
|
||||
for (int j = 0; j < modifierLength; j++) {
|
||||
wrapper.passthrough(Type.UUID); // modifier uuid
|
||||
wrapper.passthrough(Type.DOUBLE); // modifier amount
|
||||
wrapper.passthrough(Type.BYTE); // modifier operation
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.UPDATE_ENTITY_NBT);
|
||||
}
|
||||
}
|
||||
-876
@@ -1,876 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.packets;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ServerboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.provider.TitleRenderProvider;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.*;
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viarewind.utils.math.AABB;
|
||||
import com.viaversion.viarewind.utils.math.Ray3d;
|
||||
import com.viaversion.viarewind.utils.math.RayTracing;
|
||||
import com.viaversion.viarewind.utils.math.Vector3d;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
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.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerPackets1_8 {
|
||||
|
||||
public static void register(Protocol1_7_6_10To1_8 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CHAT_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.COMPONENT); // chat message
|
||||
handler(wrapper -> {
|
||||
final int position = wrapper.read(Type.BYTE);
|
||||
if (position == 2) { // above hotbar
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SPAWN_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8, Types1_7_6_10.INT_POSITION); // spawn position
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.UPDATE_HEALTH, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.FLOAT); // health
|
||||
map(Type.VAR_INT, Type.SHORT); // food
|
||||
map(Type.FLOAT); // food saturation
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.RESPAWN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // dimension
|
||||
map(Type.UNSIGNED_BYTE); // difficulty
|
||||
map(Type.UNSIGNED_BYTE); // game mode
|
||||
handler(wrapper -> {
|
||||
if (ViaRewind.getConfig().isReplaceAdventureMode()) {
|
||||
if (wrapper.get(Type.UNSIGNED_BYTE, 1) == 2) {
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 1, (short) 0);
|
||||
}
|
||||
}
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
tracker.setClientEntityGameMode(wrapper.get(Type.UNSIGNED_BYTE, 1));
|
||||
|
||||
final Environment dimension = Environment.getEnvironmentById(wrapper.get(Type.INT, 0));
|
||||
|
||||
final ClientWorld world = wrapper.user().get(ClientWorld.class);
|
||||
if (world.getEnvironment() != dimension) {
|
||||
// Clear entities on dimension change and re-track player
|
||||
world.setEnvironment(dimension.id());
|
||||
tracker.clearEntities();
|
||||
tracker.addEntity(tracker.clientEntityId(), EntityTypes1_10.EntityType.PLAYER);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.DOUBLE); // x
|
||||
map(Type.DOUBLE); // y
|
||||
map(Type.DOUBLE); // z
|
||||
map(Type.FLOAT); // yaw
|
||||
map(Type.FLOAT); // pitch
|
||||
handler(wrapper -> {
|
||||
final double x = wrapper.get(Type.DOUBLE, 0);
|
||||
double y = wrapper.get(Type.DOUBLE, 1);
|
||||
final double z = wrapper.get(Type.DOUBLE, 2);
|
||||
|
||||
final float yaw = wrapper.get(Type.FLOAT, 0);
|
||||
final float pitch = wrapper.get(Type.FLOAT, 1);
|
||||
|
||||
final PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
final int flags = wrapper.read(Type.BYTE);
|
||||
|
||||
// x, y, and z
|
||||
if ((flags & 0x01) == 0x01) wrapper.set(Type.DOUBLE, 0, x + playerSession.getPosX());
|
||||
if ((flags & 0x02) == 0x02) y += playerSession.getPosY();
|
||||
|
||||
playerSession.receivedPosY = y;
|
||||
wrapper.set(Type.DOUBLE, 1, y + 1.62F);
|
||||
|
||||
if ((flags & 0x04) == 0x04) wrapper.set(Type.DOUBLE, 2, z + playerSession.getPosZ());
|
||||
|
||||
// yaw and pitch
|
||||
if ((flags & 0x08) == 0x08) wrapper.set(Type.FLOAT, 0, yaw + playerSession.yaw);
|
||||
if ((flags & 0x10) == 0x10) wrapper.set(Type.FLOAT, 1, pitch + playerSession.pitch);
|
||||
|
||||
wrapper.write(Type.BOOLEAN, playerSession.onGround);
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (tracker.spectatingClientEntityId != tracker.clientEntityId()) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_EXPERIENCE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.FLOAT); // experience bar
|
||||
map(Type.VAR_INT, Type.SHORT); // level
|
||||
map(Type.VAR_INT, Type.SHORT); // total experience
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.GAME_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.UNSIGNED_BYTE); // reason
|
||||
map(Type.FLOAT); // value
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Type.UNSIGNED_BYTE, 0) != 3) return; // Change game mode
|
||||
int gameMode = wrapper.get(Type.FLOAT, 0).intValue();
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (gameMode == 3 || tracker.isSpectator()) {
|
||||
UUID myId = wrapper.user().getProtocolInfo().getUuid();
|
||||
Item[] equipment = new Item[4];
|
||||
if (gameMode == 3) {
|
||||
GameProfileStorage.GameProfile profile = wrapper.user().get(GameProfileStorage.class).get(myId);
|
||||
equipment[3] = profile == null ? null : profile.getSkull();
|
||||
} else {
|
||||
for (int i = 0; i < equipment.length; i++) {
|
||||
equipment[i] = wrapper.user().get(PlayerSessionStorage.class).getPlayerEquipment(myId, i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < equipment.length; i++) {
|
||||
PacketWrapper setSlot = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_SLOT, wrapper.user());
|
||||
setSlot.write(Type.BYTE, (byte) 0);
|
||||
setSlot.write(Type.SHORT, (short) (8 - i));
|
||||
setSlot.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, equipment[i]);
|
||||
setSlot.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
|
||||
if (gameMode == 2 && ViaRewind.getConfig().isReplaceAdventureMode()) {
|
||||
gameMode = 0;
|
||||
wrapper.set(Type.FLOAT, 0, 0.0f);
|
||||
}
|
||||
tracker.setClientEntityGameMode(gameMode);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.OPEN_SIGN_EDITOR, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8, Types1_7_6_10.INT_POSITION); // position
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.PLAYER_INFO, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
int action = wrapper.read(Type.VAR_INT);
|
||||
int count = wrapper.read(Type.VAR_INT);
|
||||
GameProfileStorage gameProfileStorage = wrapper.user().get(GameProfileStorage.class);
|
||||
for (int i = 0; i < count; i++) {
|
||||
UUID uuid = wrapper.read(Type.UUID);
|
||||
if (action == 0) {
|
||||
String name = wrapper.read(Type.STRING);
|
||||
|
||||
GameProfileStorage.GameProfile gameProfile = gameProfileStorage.get(uuid);
|
||||
if (gameProfile == null) gameProfile = gameProfileStorage.put(uuid, name);
|
||||
|
||||
int propertyCount = wrapper.read(Type.VAR_INT);
|
||||
while (propertyCount-- > 0) {
|
||||
String propertyName = wrapper.read(Type.STRING);
|
||||
String propertyValue = wrapper.read(Type.STRING);
|
||||
String propertySignature = wrapper.read(Type.OPTIONAL_STRING);
|
||||
gameProfile.properties.add(new GameProfileStorage.Property(propertyName, propertyValue, propertySignature));
|
||||
}
|
||||
|
||||
int gamemode = wrapper.read(Type.VAR_INT);
|
||||
int ping = wrapper.read(Type.VAR_INT);
|
||||
gameProfile.ping = ping;
|
||||
gameProfile.gamemode = gamemode;
|
||||
JsonElement displayName = wrapper.read(Type.OPTIONAL_COMPONENT);
|
||||
if (displayName != null) {
|
||||
gameProfile.setDisplayName(ChatUtil.jsonToLegacy(wrapper.user(), displayName));
|
||||
}
|
||||
|
||||
PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_7_2_5.PLAYER_INFO, null, wrapper.user());
|
||||
packet.write(Type.STRING, gameProfile.getDisplayName());
|
||||
packet.write(Type.BOOLEAN, true);
|
||||
packet.write(Type.SHORT, (short) ping);
|
||||
packet.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
} else if (action == 1) {
|
||||
int gamemode = wrapper.read(Type.VAR_INT);
|
||||
|
||||
GameProfileStorage.GameProfile gameProfile = gameProfileStorage.get(uuid);
|
||||
if (gameProfile == null || gameProfile.gamemode == gamemode) continue;
|
||||
|
||||
if (gamemode == 3 || gameProfile.gamemode == 3) {
|
||||
EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
int entityId = tracker.getPlayerEntityId(uuid);
|
||||
boolean isOwnPlayer = entityId == tracker.clientEntityId();
|
||||
if (entityId != -1) {
|
||||
// Weirdly, PlayerEntity has only 4 slots instead of 5
|
||||
Item[] equipment = new Item[isOwnPlayer ? 4 : 5];
|
||||
if (gamemode == 3) {
|
||||
equipment[isOwnPlayer ? 3 : 4] = gameProfile.getSkull();
|
||||
} else {
|
||||
for (int j = 0; j < equipment.length; j++) {
|
||||
equipment[j] = wrapper.user().get(PlayerSessionStorage.class).getPlayerEquipment(uuid, j);
|
||||
}
|
||||
}
|
||||
|
||||
for (short slot = 0; slot < equipment.length; slot++) {
|
||||
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.ENTITY_EQUIPMENT, wrapper.user());
|
||||
equipmentPacket.write(Type.INT, entityId);
|
||||
equipmentPacket.write(Type.SHORT, slot);
|
||||
equipmentPacket.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, equipment[slot]);
|
||||
equipmentPacket.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gameProfile.gamemode = gamemode;
|
||||
} else if (action == 2) {
|
||||
int ping = wrapper.read(Type.VAR_INT);
|
||||
|
||||
GameProfileStorage.GameProfile gameProfile = gameProfileStorage.get(uuid);
|
||||
if (gameProfile == null) continue;
|
||||
|
||||
PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_7_2_5.PLAYER_INFO, null, wrapper.user());
|
||||
packet.write(Type.STRING, gameProfile.getDisplayName());
|
||||
packet.write(Type.BOOLEAN, false);
|
||||
packet.write(Type.SHORT, (short) gameProfile.ping);
|
||||
packet.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
gameProfile.ping = ping;
|
||||
|
||||
packet = PacketWrapper.create(ClientboundPackets1_7_2_5.PLAYER_INFO, null, wrapper.user());
|
||||
packet.write(Type.STRING, gameProfile.getDisplayName());
|
||||
packet.write(Type.BOOLEAN, true);
|
||||
packet.write(Type.SHORT, (short) ping);
|
||||
packet.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
} else if (action == 3) {
|
||||
JsonElement displayNameComponent = wrapper.read(Type.OPTIONAL_COMPONENT);
|
||||
String displayName = displayNameComponent != null ? ChatUtil.jsonToLegacy(wrapper.user(), displayNameComponent) : null;
|
||||
|
||||
GameProfileStorage.GameProfile gameProfile = gameProfileStorage.get(uuid);
|
||||
if (gameProfile == null || gameProfile.displayName == null && displayName == null) continue;
|
||||
|
||||
PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_7_2_5.PLAYER_INFO, null, wrapper.user());
|
||||
packet.write(Type.STRING, gameProfile.getDisplayName());
|
||||
packet.write(Type.BOOLEAN, false);
|
||||
packet.write(Type.SHORT, (short) gameProfile.ping);
|
||||
packet.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
if (gameProfile.displayName == null && displayName != null || gameProfile.displayName != null && displayName == null || !gameProfile.displayName.equals(displayName)) {
|
||||
gameProfile.setDisplayName(displayName);
|
||||
}
|
||||
|
||||
packet = PacketWrapper.create(ClientboundPackets1_7_2_5.PLAYER_INFO, null, wrapper.user());
|
||||
packet.write(Type.STRING, gameProfile.getDisplayName());
|
||||
packet.write(Type.BOOLEAN, true);
|
||||
packet.write(Type.SHORT, (short) gameProfile.ping);
|
||||
packet.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
} else if (action == 4) {
|
||||
GameProfileStorage.GameProfile gameProfile = gameProfileStorage.remove(uuid);
|
||||
if (gameProfile == null) continue;
|
||||
|
||||
PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_7_2_5.PLAYER_INFO, null, wrapper.user());
|
||||
packet.write(Type.STRING, gameProfile.getDisplayName());
|
||||
packet.write(Type.BOOLEAN, false);
|
||||
packet.write(Type.SHORT, (short) gameProfile.ping);
|
||||
packet.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.PLAYER_ABILITIES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.BYTE);
|
||||
map(Type.FLOAT);
|
||||
map(Type.FLOAT);
|
||||
handler(wrapper -> {
|
||||
byte flags = wrapper.get(Type.BYTE, 0);
|
||||
float flySpeed = wrapper.get(Type.FLOAT, 0);
|
||||
float walkSpeed = wrapper.get(Type.FLOAT, 1);
|
||||
PlayerSessionStorage abilities = wrapper.user().get(PlayerSessionStorage.class);
|
||||
abilities.invincible = (flags & 8) == 8;
|
||||
abilities.allowFly = (flags & 4) == 4;
|
||||
abilities.flying = (flags & 2) == 2;
|
||||
abilities.creative = (flags & 1) == 1;
|
||||
abilities.flySpeed = flySpeed;
|
||||
abilities.walkSpeed = walkSpeed;
|
||||
|
||||
if (abilities.sprinting && abilities.flying) {
|
||||
wrapper.set(Type.FLOAT, 0, abilities.flySpeed * 2.0f);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = wrapper.get(Type.STRING, 0);
|
||||
if (channel.equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); //Window Id
|
||||
|
||||
int size;
|
||||
if (wrapper.isReadable(Type.BYTE, 0)) {
|
||||
size = wrapper.passthrough(Type.BYTE);
|
||||
} else {
|
||||
size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Item item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8));
|
||||
wrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item); //Buy Item 1
|
||||
|
||||
item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8));
|
||||
wrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item); //Buy Item 3
|
||||
|
||||
boolean has3Items = wrapper.passthrough(Type.BOOLEAN);
|
||||
if (has3Items) {
|
||||
item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8));
|
||||
wrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item); //Buy Item 2
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); //Unavailable
|
||||
wrapper.read(Type.INT); //Uses
|
||||
wrapper.read(Type.INT); //Max Uses
|
||||
}
|
||||
} else if (channel.equals("MC|Brand")) {
|
||||
wrapper.write(Type.REMAINING_BYTES, wrapper.read(Type.STRING).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
wrapper.cancel();
|
||||
wrapper.setPacketType(null);
|
||||
ByteBuf newPacketBuf = Unpooled.buffer();
|
||||
wrapper.writeToBuffer(newPacketBuf);
|
||||
PacketWrapper newWrapper = PacketWrapper.create(ClientboundPackets1_7_2_5.PLUGIN_MESSAGE, newPacketBuf, wrapper.user());
|
||||
newWrapper.passthrough(Type.STRING);
|
||||
if (newPacketBuf.readableBytes() <= Short.MAX_VALUE) {
|
||||
newWrapper.write(Type.SHORT, (short) newPacketBuf.readableBytes());
|
||||
newWrapper.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CAMERA, null, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
final int entityId = wrapper.read(Type.VAR_INT);
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (tracker.spectatingClientEntityId != entityId) {
|
||||
tracker.setSpectating(entityId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Title
|
||||
protocol.registerClientbound(ClientboundPackets1_8.TITLE, null, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
TitleRenderProvider titleRenderProvider = Via.getManager().getProviders().get(TitleRenderProvider.class);
|
||||
if (titleRenderProvider == null) return;
|
||||
int action = wrapper.read(Type.VAR_INT);
|
||||
UUID uuid = wrapper.user().getProtocolInfo().getUuid();
|
||||
switch (action) {
|
||||
case 0:
|
||||
titleRenderProvider.setTitle(uuid, wrapper.read(Type.STRING));
|
||||
break;
|
||||
case 1:
|
||||
titleRenderProvider.setSubTitle(uuid, wrapper.read(Type.STRING));
|
||||
break;
|
||||
case 2:
|
||||
titleRenderProvider.setTimings(uuid, wrapper.read(Type.INT), wrapper.read(Type.INT), wrapper.read(Type.INT));
|
||||
break;
|
||||
case 3:
|
||||
titleRenderProvider.clear(uuid);
|
||||
break;
|
||||
case 4:
|
||||
titleRenderProvider.reset(uuid);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Player List Header And Footer
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.TAB_LIST);
|
||||
|
||||
//Resource Pack Send
|
||||
protocol.registerClientbound(ClientboundPackets1_8.RESOURCE_PACK, ClientboundPackets1_7_2_5.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
create(Type.STRING, "MC|RPack");
|
||||
handler(wrapper -> {
|
||||
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer();
|
||||
try {
|
||||
// Url
|
||||
Type.STRING.write(buf, wrapper.read(Type.STRING));
|
||||
|
||||
wrapper.write(Type.SHORT_BYTE_ARRAY, Type.REMAINING_BYTES.read(buf));
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
});
|
||||
read(Type.STRING); // Hash
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CHAT_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
String msg = wrapper.get(Type.STRING, 0);
|
||||
if (tracker.isSpectator() && msg.toLowerCase().startsWith("/stp ")) { // TODO add setting
|
||||
String username = msg.split(" ")[1];
|
||||
GameProfileStorage storage = wrapper.user().get(GameProfileStorage.class);
|
||||
GameProfileStorage.GameProfile profile = storage.get(username, true);
|
||||
if (profile != null && profile.uuid != null) {
|
||||
wrapper.cancel();
|
||||
|
||||
PacketWrapper teleportPacket = PacketWrapper.create(0x18, null, wrapper.user());
|
||||
teleportPacket.write(Type.UUID, profile.uuid);
|
||||
|
||||
teleportPacket.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.INTERACT_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT, Type.VAR_INT);
|
||||
map(Type.BYTE, Type.VAR_INT);
|
||||
handler(wrapper -> {
|
||||
int mode = wrapper.get(Type.VAR_INT, 1);
|
||||
if (mode != 0) {
|
||||
return;
|
||||
}
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
final PlayerSessionStorage position = wrapper.user().get(PlayerSessionStorage.class);
|
||||
|
||||
if (tracker.getHolograms().containsKey(entityId)) {
|
||||
final AABB boundingBox = tracker.getHolograms().get(entityId).getBoundingBox();
|
||||
|
||||
Vector3d pos = new Vector3d(position.getPosX(), position.getPosY() + 1.8, position.getPosZ());
|
||||
double yaw = Math.toRadians(position.yaw);
|
||||
double pitch = Math.toRadians(position.pitch);
|
||||
|
||||
Vector3d dir = new Vector3d(-Math.cos(pitch) * Math.sin(yaw), -Math.sin(pitch), Math.cos(pitch) * Math.cos(yaw));
|
||||
Ray3d ray = new Ray3d(pos, dir);
|
||||
Vector3d intersection = RayTracing.trace(ray, boundingBox, 5.0);
|
||||
|
||||
if (intersection == null) {
|
||||
return;
|
||||
}
|
||||
intersection.substract(boundingBox.getMin());
|
||||
|
||||
mode = 2;
|
||||
wrapper.set(Type.VAR_INT, 1, mode);
|
||||
wrapper.write(Type.FLOAT, (float) intersection.getX());
|
||||
wrapper.write(Type.FLOAT, (float) intersection.getY());
|
||||
wrapper.write(Type.FLOAT, (float) intersection.getZ());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_MOVEMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.BOOLEAN);
|
||||
handler(wrapper -> {
|
||||
PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
playerSession.onGround = wrapper.get(Type.BOOLEAN, 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.DOUBLE); //X
|
||||
map(Type.DOUBLE); //Y
|
||||
read(Type.DOUBLE);
|
||||
map(Type.DOUBLE); //Z
|
||||
map(Type.BOOLEAN); //OnGround
|
||||
handler(wrapper -> {
|
||||
double x = wrapper.get(Type.DOUBLE, 0);
|
||||
double feetY = wrapper.get(Type.DOUBLE, 1);
|
||||
double z = wrapper.get(Type.DOUBLE, 2);
|
||||
|
||||
PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
|
||||
playerSession.onGround = wrapper.get(Type.BOOLEAN, 0);
|
||||
playerSession.setPos(x, feetY, z);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_ROTATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.FLOAT);
|
||||
map(Type.FLOAT);
|
||||
map(Type.BOOLEAN);
|
||||
handler(wrapper -> {
|
||||
PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
playerSession.yaw = wrapper.get(Type.FLOAT, 0);
|
||||
playerSession.pitch = wrapper.get(Type.FLOAT, 1);
|
||||
playerSession.onGround = wrapper.get(Type.BOOLEAN, 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_POSITION_AND_ROTATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.DOUBLE); //X
|
||||
map(Type.DOUBLE); //Y
|
||||
read(Type.DOUBLE);
|
||||
map(Type.DOUBLE); //Z
|
||||
map(Type.FLOAT); //Yaw
|
||||
map(Type.FLOAT); //Pitch
|
||||
map(Type.BOOLEAN); //OnGround
|
||||
handler(wrapper -> {
|
||||
double x = wrapper.get(Type.DOUBLE, 0);
|
||||
double feetY = wrapper.get(Type.DOUBLE, 1);
|
||||
double z = wrapper.get(Type.DOUBLE, 2);
|
||||
|
||||
float yaw = wrapper.get(Type.FLOAT, 0);
|
||||
float pitch = wrapper.get(Type.FLOAT, 1);
|
||||
|
||||
PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
|
||||
playerSession.onGround = wrapper.get(Type.BOOLEAN, 0);
|
||||
playerSession.setPos(x, feetY, z);
|
||||
playerSession.yaw = yaw;
|
||||
playerSession.pitch = pitch;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_DIGGING, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); //Status
|
||||
handler(wrapper -> {
|
||||
int x = wrapper.read(Type.INT);
|
||||
int y = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
int z = wrapper.read(Type.INT);
|
||||
wrapper.write(Type.POSITION1_8, new Position(x, y, z));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_BLOCK_PLACEMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
int x = wrapper.read(Type.INT);
|
||||
int y = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
int z = wrapper.read(Type.INT);
|
||||
wrapper.write(Type.POSITION1_8, new Position(x, y, z));
|
||||
|
||||
wrapper.passthrough(Type.BYTE); //Direction
|
||||
Item item = wrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM);
|
||||
item = protocol.getItemRewriter().handleItemToServer(wrapper.user(), item);
|
||||
wrapper.write(Type.ITEM1_8, item);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
wrapper.passthrough(Type.BYTE);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.ANIMATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
int entityId = wrapper.read(Type.INT);
|
||||
int animation = wrapper.read(Type.BYTE); //Animation
|
||||
if (animation == 1) return;
|
||||
wrapper.cancel();
|
||||
//1.7 vanilla client is not sending this packet with animation!=1
|
||||
switch (animation) {
|
||||
case 104:
|
||||
animation = 0;
|
||||
break;
|
||||
case 105:
|
||||
animation = 1;
|
||||
break;
|
||||
case 3:
|
||||
animation = 2;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
PacketWrapper entityAction = PacketWrapper.create(0x0B, null, wrapper.user());
|
||||
entityAction.write(Type.VAR_INT, entityId);
|
||||
entityAction.write(Type.VAR_INT, animation);
|
||||
entityAction.write(Type.VAR_INT, 0);
|
||||
entityAction.send(Protocol1_7_6_10To1_8.class);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.ENTITY_ACTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT, Type.VAR_INT); //Entity Id
|
||||
handler(wrapper -> wrapper.write(Type.VAR_INT, wrapper.read(Type.BYTE) - 1)); //Action Id
|
||||
map(Type.INT, Type.VAR_INT); //Action Parameter
|
||||
handler(wrapper -> {
|
||||
int action = wrapper.get(Type.VAR_INT, 1);
|
||||
if (action == 3 || action == 4) {
|
||||
PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
playerSession.sprinting = action == 3;
|
||||
PacketWrapper abilitiesPacket = PacketWrapper.create(0x39, null, wrapper.user());
|
||||
abilitiesPacket.write(Type.BYTE, playerSession.combineAbilities());
|
||||
abilitiesPacket.write(Type.FLOAT, playerSession.sprinting ? playerSession.flySpeed * 2.0f : playerSession.flySpeed);
|
||||
abilitiesPacket.write(Type.FLOAT, playerSession.walkSpeed);
|
||||
abilitiesPacket.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.STEER_VEHICLE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.FLOAT); //Sideways
|
||||
map(Type.FLOAT); //Forwards
|
||||
handler(wrapper -> {
|
||||
boolean jump = wrapper.read(Type.BOOLEAN);
|
||||
boolean unmount = wrapper.read(Type.BOOLEAN);
|
||||
short flags = 0;
|
||||
if (jump) flags += 0x01;
|
||||
if (unmount) flags += 0x02;
|
||||
wrapper.write(Type.UNSIGNED_BYTE, flags);
|
||||
|
||||
if (unmount) {
|
||||
EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_7_6_10To1_8.class);
|
||||
if (tracker.spectatingClientEntityId != tracker.clientEntityId()) {
|
||||
PacketWrapper sneakPacket = PacketWrapper.create(0x0B, null, wrapper.user());
|
||||
sneakPacket.write(Type.VAR_INT, tracker.clientEntityId());
|
||||
sneakPacket.write(Type.VAR_INT, 0); //Start sneaking
|
||||
sneakPacket.write(Type.VAR_INT, 0); //Action Parameter
|
||||
|
||||
PacketWrapper unsneakPacket = PacketWrapper.create(0x0B, null, wrapper.user());
|
||||
unsneakPacket.write(Type.VAR_INT, tracker.clientEntityId());
|
||||
unsneakPacket.write(Type.VAR_INT, 1); //Stop sneaking
|
||||
unsneakPacket.write(Type.VAR_INT, 0); //Action Parameter
|
||||
|
||||
sneakPacket.scheduleSendToServer(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.UPDATE_SIGN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
int x = wrapper.read(Type.INT);
|
||||
int y = wrapper.read(Type.SHORT);
|
||||
int z = wrapper.read(Type.INT);
|
||||
wrapper.write(Type.POSITION1_8, new Position(x, y, z));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final String line = wrapper.read(Type.STRING);
|
||||
|
||||
wrapper.write(Type.COMPONENT, ComponentUtil.legacyToJson(line));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLAYER_ABILITIES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.BYTE);
|
||||
map(Type.FLOAT);
|
||||
map(Type.FLOAT);
|
||||
handler(wrapper -> {
|
||||
PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
if (playerSession.allowFly) {
|
||||
byte flags = wrapper.get(Type.BYTE, 0);
|
||||
playerSession.flying = (flags & 2) == 2;
|
||||
}
|
||||
wrapper.set(Type.FLOAT, 0, playerSession.flySpeed);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.TAB_COMPLETE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
create(Type.OPTIONAL_POSITION1_8, null);
|
||||
handler(wrapper -> {
|
||||
String msg = wrapper.get(Type.STRING, 0);
|
||||
if (msg.toLowerCase().startsWith("/stp ")) {
|
||||
wrapper.cancel();
|
||||
String[] args = msg.split(" ");
|
||||
if (args.length <= 2) {
|
||||
String prefix = args.length == 1 ? "" : args[1];
|
||||
GameProfileStorage storage = wrapper.user().get(GameProfileStorage.class);
|
||||
List<GameProfileStorage.GameProfile> profiles = storage.getAllWithPrefix(prefix, true);
|
||||
|
||||
PacketWrapper tabComplete = PacketWrapper.create(0x3A, null, wrapper.user());
|
||||
tabComplete.write(Type.VAR_INT, profiles.size());
|
||||
for (GameProfileStorage.GameProfile profile : profiles) {
|
||||
tabComplete.write(Type.STRING, profile.name);
|
||||
}
|
||||
|
||||
tabComplete.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Client Settings
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CLIENT_SETTINGS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
map(Type.BYTE);
|
||||
map(Type.BYTE);
|
||||
map(Type.BOOLEAN);
|
||||
read(Type.BYTE);
|
||||
handler(wrapper -> {
|
||||
boolean cape = wrapper.read(Type.BOOLEAN);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) (cape ? 127 : 126));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
read(Type.SHORT); // Length
|
||||
handler(wrapper -> {
|
||||
String channel = wrapper.get(Type.STRING, 0);
|
||||
|
||||
switch (channel) {
|
||||
case "MC|TrSel": {
|
||||
wrapper.passthrough(Type.INT);
|
||||
wrapper.read(Type.REMAINING_BYTES); // unused data ???
|
||||
break;
|
||||
}
|
||||
case "MC|ItemName": {
|
||||
byte[] data = wrapper.read(Type.REMAINING_BYTES);
|
||||
String name = new String(data, StandardCharsets.UTF_8);
|
||||
|
||||
wrapper.write(Type.STRING, name);
|
||||
|
||||
InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
PacketWrapper updateCost = PacketWrapper.create(0x31, null, wrapper.user());
|
||||
updateCost.write(Type.UNSIGNED_BYTE, windowTracker.anvilId);
|
||||
updateCost.write(Type.SHORT, (short) 0);
|
||||
updateCost.write(Type.SHORT, windowTracker.levelCost);
|
||||
|
||||
updateCost.send(Protocol1_7_6_10To1_8.class);
|
||||
break;
|
||||
}
|
||||
case "MC|BEdit":
|
||||
case "MC|BSign": {
|
||||
Item book = wrapper.read(Types1_7_6_10.COMPRESSED_NBT_ITEM);
|
||||
CompoundTag tag = book.tag();
|
||||
if (tag != null && tag.contains("pages")) {
|
||||
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
for (int i = 0; i < pages.size(); i++) {
|
||||
StringTag page = pages.get(i);
|
||||
String value = page.getValue();
|
||||
value = ComponentUtil.legacyToJsonString(value);
|
||||
page.setValue(value);
|
||||
}
|
||||
}
|
||||
wrapper.write(Type.ITEM1_8, book);
|
||||
break;
|
||||
}
|
||||
case "MC|Brand": {
|
||||
wrapper.write(Type.STRING, new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
-253
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.packets;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.Scoreboard;
|
||||
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.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ScoreboardPackets1_8 {
|
||||
|
||||
public static void register(Protocol1_7_6_10To1_8 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SCOREBOARD_OBJECTIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.passthrough(Type.STRING);
|
||||
if (name.length() > 16) {
|
||||
wrapper.set(Type.STRING, 0, name = name.substring(0, 16));
|
||||
}
|
||||
byte mode = wrapper.read(Type.BYTE);
|
||||
|
||||
Scoreboard scoreboard = wrapper.user().get(Scoreboard.class);
|
||||
if (mode == 0) {
|
||||
if (scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
scoreboard.addObjective(name);
|
||||
} else if (mode == 1) {
|
||||
if (!scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
if (scoreboard.getColorIndependentSidebar() != null) {
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent()) {
|
||||
String sidebar = scoreboard.getColorDependentSidebar().get(color.get());
|
||||
if (name.equals(sidebar)) {
|
||||
PacketWrapper sidebarPacket = PacketWrapper.create(0x3D, null, wrapper.user());
|
||||
sidebarPacket.write(Type.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Type.STRING, scoreboard.getColorIndependentSidebar());
|
||||
sidebarPacket.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
scoreboard.removeObjective(name);
|
||||
} else if (mode == 2) {
|
||||
if (!scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
String displayName = wrapper.passthrough(Type.STRING);
|
||||
if (displayName.length() > 32) {
|
||||
wrapper.set(Type.STRING, 1, displayName.substring(0, 32));
|
||||
}
|
||||
wrapper.read(Type.STRING);
|
||||
} else {
|
||||
wrapper.write(Type.STRING, "");
|
||||
}
|
||||
wrapper.write(Type.BYTE, mode);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SCORE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Name
|
||||
map(Type.VAR_INT, Type.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
Scoreboard scoreboard = wrapper.user().get(Scoreboard.class);
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
byte mode = wrapper.get(Type.BYTE, 0);
|
||||
|
||||
if (mode == 1) {
|
||||
name = scoreboard.removeTeamForScore(name);
|
||||
} else {
|
||||
name = scoreboard.sendTeamForScore(name);
|
||||
}
|
||||
|
||||
if (name.length() > 16) {
|
||||
name = ChatColorUtil.stripColor(name);
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
}
|
||||
wrapper.set(Type.STRING, 0, name);
|
||||
|
||||
String objective = wrapper.read(Type.STRING);
|
||||
if (objective.length() > 16) {
|
||||
objective = objective.substring(0, 16);
|
||||
}
|
||||
|
||||
if (mode != 1) {
|
||||
int score = wrapper.read(Type.VAR_INT);
|
||||
wrapper.write(Type.STRING, objective);
|
||||
wrapper.write(Type.INT, score);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.DISPLAY_SCOREBOARD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.BYTE); // Position
|
||||
map(Type.STRING); // Score name
|
||||
handler(wrapper -> {
|
||||
byte position = wrapper.get(Type.BYTE, 0);
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
Scoreboard scoreboard = wrapper.user().get(Scoreboard.class);
|
||||
if (position > 2) { // team specific sidebar
|
||||
byte receiverTeamColor = (byte) (position - 3);
|
||||
scoreboard.getColorDependentSidebar().put(receiverTeamColor, name);
|
||||
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent() && color.get() == receiverTeamColor) {
|
||||
position = 1;
|
||||
} else {
|
||||
position = -1;
|
||||
}
|
||||
} else if (position == 1) { // team independent sidebar
|
||||
scoreboard.setColorIndependentSidebar(name);
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent() && scoreboard.getColorDependentSidebar().containsKey(color.get())) {
|
||||
position = -1;
|
||||
}
|
||||
}
|
||||
if (position == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.set(Type.BYTE, 0, position);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.TEAMS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
handler(wrapper -> {
|
||||
String team = wrapper.get(Type.STRING, 0);
|
||||
if (team == null) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
byte mode = wrapper.passthrough(Type.BYTE);
|
||||
|
||||
Scoreboard scoreboard = wrapper.user().get(Scoreboard.class);
|
||||
|
||||
if (mode != 0 && !scoreboard.teamExists(team)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
} else if (mode == 0 && scoreboard.teamExists(team)) {
|
||||
scoreboard.removeTeam(team);
|
||||
|
||||
PacketWrapper remove = PacketWrapper.create(0x3E, null, wrapper.user());
|
||||
remove.write(Type.STRING, team);
|
||||
remove.write(Type.BYTE, (byte) 1);
|
||||
remove.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
if (mode == 0) {
|
||||
scoreboard.addTeam(team);
|
||||
} else if (mode == 1) {
|
||||
scoreboard.removeTeam(team);
|
||||
}
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
wrapper.passthrough(Type.STRING); // Display name
|
||||
wrapper.passthrough(Type.STRING); // prefix
|
||||
wrapper.passthrough(Type.STRING); // suffix
|
||||
wrapper.passthrough(Type.BYTE); // friendly fire
|
||||
wrapper.read(Type.STRING); // name tag visibility
|
||||
byte color = wrapper.read(Type.BYTE);
|
||||
if (mode == 2 && scoreboard.getTeamColor(team).get() != color) {
|
||||
String sidebar = scoreboard.getColorDependentSidebar().get(color);
|
||||
PacketWrapper sidebarPacket = wrapper.create(0x3D);
|
||||
sidebarPacket.write(Type.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Type.STRING, sidebar == null ? "" : sidebar);
|
||||
sidebarPacket.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
scoreboard.setTeamColor(team, color);
|
||||
}
|
||||
if (mode == 0 || mode == 3 || mode == 4) {
|
||||
byte color = scoreboard.getTeamColor(team).get();
|
||||
String[] entries = wrapper.read(Type.STRING_ARRAY);
|
||||
List<String> entryList = new ArrayList<>();
|
||||
|
||||
for (String entry : entries) {
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
|
||||
if (mode == 4) {
|
||||
if (!scoreboard.isPlayerInTeam(entry, team)) continue;
|
||||
scoreboard.removePlayerFromTeam(entry, team);
|
||||
if (entry.equals(username)) {
|
||||
PacketWrapper sidebarPacket = wrapper.create(0x3D);
|
||||
sidebarPacket.write(Type.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Type.STRING, scoreboard.getColorIndependentSidebar() == null ? "" : scoreboard.getColorIndependentSidebar());
|
||||
sidebarPacket.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
} else {
|
||||
scoreboard.addPlayerToTeam(entry, team);
|
||||
if (entry.equals(username) && scoreboard.getColorDependentSidebar().containsKey(color)) {
|
||||
PacketWrapper displayObjective = wrapper.create(0x3D);
|
||||
displayObjective.write(Type.BYTE, (byte) 1);
|
||||
displayObjective.write(Type.STRING, scoreboard.getColorDependentSidebar().get(color));
|
||||
displayObjective.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
entryList.add(entry);
|
||||
}
|
||||
|
||||
wrapper.write(Type.SHORT, (short) entryList.size());
|
||||
for (String entry : entryList) {
|
||||
wrapper.write(Type.STRING, entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-291
@@ -1,291 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.packets;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.WorldBorderEmulator;
|
||||
import com.viaversion.viarewind.api.type.chunk.ChunkType1_7_6;
|
||||
import com.viaversion.viarewind.api.type.chunk.BulkChunkType1_7_6;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.data.ParticleIndex1_7_6_10;
|
||||
import com.viaversion.viarewind.api.type.Types1_7_6_10;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
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.FixedByteArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.BulkChunkType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
|
||||
public class WorldPackets1_8 {
|
||||
|
||||
public static void register(Protocol1_7_6_10To1_8 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CHUNK_DATA, wrapper -> {
|
||||
final ClientWorld world = wrapper.user().get(ClientWorld.class);
|
||||
final Chunk chunk = wrapper.read(ChunkType1_8.forEnvironment(world.getEnvironment()));
|
||||
protocol.getItemRewriter().handleChunk(chunk);
|
||||
|
||||
wrapper.write(ChunkType1_7_6.TYPE, chunk);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Type.POSITION1_8, Types1_7_6_10.U_BYTE_POSITION); // position
|
||||
handler(wrapper -> {
|
||||
int data = wrapper.read(Type.VAR_INT); // block data
|
||||
data = protocol.getItemRewriter().handleBlockId(data);
|
||||
|
||||
wrapper.write(Type.VAR_INT, IdAndData.getId(data)); // block id
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) IdAndData.getData(data)); // block data
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MULTI_BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // chunk x
|
||||
map(Type.INT); // chunk z
|
||||
|
||||
handler(wrapper -> {
|
||||
final BlockChangeRecord[] records = wrapper.read(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
||||
|
||||
wrapper.write(Type.SHORT, (short) records.length); // record count
|
||||
wrapper.write(Type.INT, records.length * 4); // data array length (position + block id)
|
||||
|
||||
for (BlockChangeRecord record : records) {
|
||||
wrapper.write(Type.SHORT, (short) (record.getSectionX() << 12 | record.getSectionZ() << 8 | record.getY())); // position
|
||||
wrapper.write(Type.SHORT, (short) protocol.getItemRewriter().handleBlockId(record.getBlockId())); // block id
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ACTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8, Types1_7_6_10.SHORT_POSITION); // position
|
||||
map(Type.UNSIGNED_BYTE); // type
|
||||
map(Type.UNSIGNED_BYTE); // data
|
||||
map(Type.VAR_INT); // block id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_BREAK_ANIMATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // entity id
|
||||
map(Type.POSITION1_8, Types1_7_6_10.INT_POSITION); // position
|
||||
map(Type.BYTE); // progress
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MAP_BULK_CHUNK, wrapper -> {
|
||||
final Chunk[] chunks = wrapper.read(BulkChunkType1_8.TYPE);
|
||||
for (Chunk chunk : chunks) {
|
||||
protocol.getItemRewriter().handleChunk(chunk);
|
||||
}
|
||||
|
||||
wrapper.write(BulkChunkType1_7_6.TYPE, chunks);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.EFFECT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // effect id
|
||||
map(Type.POSITION1_8, Types1_7_6_10.BYTE_POSITION); // position
|
||||
map(Type.INT); // data
|
||||
map(Type.BOOLEAN); // disable relative volume
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SPAWN_PARTICLE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int particleId = wrapper.read(Type.INT); // particle id
|
||||
ParticleIndex1_7_6_10 particle = ParticleIndex1_7_6_10.find(particleId);
|
||||
if (particle == null) particle = ParticleIndex1_7_6_10.CRIT;
|
||||
wrapper.write(Type.STRING, particle.name); // particle name
|
||||
|
||||
});
|
||||
read(Type.BOOLEAN); // long distance
|
||||
map(Type.FLOAT); // x
|
||||
map(Type.FLOAT); // y
|
||||
map(Type.FLOAT); // z
|
||||
map(Type.FLOAT); // offset x
|
||||
map(Type.FLOAT); // offset y
|
||||
map(Type.FLOAT); // offset z
|
||||
map(Type.FLOAT); // particle data
|
||||
map(Type.INT); // particle count
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
ParticleIndex1_7_6_10 particle = ParticleIndex1_7_6_10.find(name);
|
||||
|
||||
if (particle == ParticleIndex1_7_6_10.ICON_CRACK || particle == ParticleIndex1_7_6_10.BLOCK_CRACK || particle == ParticleIndex1_7_6_10.BLOCK_DUST) {
|
||||
int id = wrapper.read(Type.VAR_INT);
|
||||
int data = particle == ParticleIndex1_7_6_10.ICON_CRACK ? wrapper.read(Type.VAR_INT) : id / 4096;
|
||||
id %= 4096;
|
||||
if (id >= 256 && id <= 422 || id >= 2256 && id <= 2267) { //item
|
||||
particle = ParticleIndex1_7_6_10.ICON_CRACK;
|
||||
} else if (id >= 0 && id <= 164 || id >= 170 && id <= 175) {
|
||||
if (particle == ParticleIndex1_7_6_10.ICON_CRACK)
|
||||
particle = ParticleIndex1_7_6_10.BLOCK_CRACK;
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
name = particle.name + "_" + id + "_" + data;
|
||||
}
|
||||
|
||||
wrapper.set(Type.STRING, 0, name);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SIGN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8, Types1_7_6_10.SHORT_POSITION); // position
|
||||
handler(wrapper -> {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String line = wrapper.read(Type.STRING);
|
||||
line = ChatUtil.jsonToLegacy(wrapper.user(), line);
|
||||
line = ChatUtil.removeUnusedColor(line, '0');
|
||||
|
||||
if (line.length() > 15) {
|
||||
line = ChatColorUtil.stripColor(line);
|
||||
if (line.length() > 15) line = line.substring(0, 15);
|
||||
}
|
||||
wrapper.write(Type.STRING, line);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MAP_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
final int id = wrapper.read(Type.VAR_INT);
|
||||
final byte scale = wrapper.read(Type.BYTE);
|
||||
|
||||
final int iconCount = wrapper.read(Type.VAR_INT);
|
||||
byte[] icons = new byte[iconCount * 4];
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
final int directionAndType = wrapper.read(Type.BYTE);
|
||||
|
||||
icons[i * 4] = (byte) (directionAndType >> 4 & 0xF);
|
||||
icons[i * 4 + 1] = wrapper.read(Type.BYTE); // x
|
||||
icons[i * 4 + 2] = wrapper.read(Type.BYTE); // z
|
||||
icons[i * 4 + 3] = (byte) (directionAndType & 0xF);
|
||||
}
|
||||
final short columns = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
if (columns > 0) {
|
||||
final short rows = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
final short x = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
final short z = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
|
||||
final byte[] data = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int column = 0; column < columns; column++) {
|
||||
byte[] columnData = new byte[rows + 3];
|
||||
columnData[0] = 0;
|
||||
columnData[1] = (byte) (x + column);
|
||||
columnData[2] = (byte) z;
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
columnData[i + 3] = data[column + i * columns];
|
||||
}
|
||||
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_DATA, wrapper.user());
|
||||
mapData.write(Type.VAR_INT, id); // map id
|
||||
mapData.write(Type.SHORT, (short) columnData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(columnData.length), columnData); // data
|
||||
|
||||
mapData.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
}
|
||||
|
||||
if (iconCount > 0) {
|
||||
final byte[] iconData = new byte[iconCount * 3 + 1];
|
||||
iconData[0] = 1;
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
iconData[i * 3 + 1] = (byte) (icons[i * 4] << 4 | icons[i * 4 + 3] & 0xF);
|
||||
iconData[i * 3 + 2] = icons[i * 4 + 1];
|
||||
iconData[i * 3 + 3] = icons[i * 4 + 2];
|
||||
}
|
||||
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_DATA, wrapper.user());
|
||||
mapData.write(Type.VAR_INT, id); // map id
|
||||
mapData.write(Type.SHORT, (short) iconData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(iconData.length), iconData); // data
|
||||
|
||||
mapData.send(Protocol1_7_6_10To1_8.class);
|
||||
}
|
||||
|
||||
// Update scale
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_DATA, wrapper.user());
|
||||
mapData.write(Type.VAR_INT, id); // map id
|
||||
mapData.write(Type.SHORT, (short) 2); // data length
|
||||
mapData.write(new FixedByteArrayType(2), new byte[]{2, scale}); // data
|
||||
|
||||
mapData.send(Protocol1_7_6_10To1_8.class);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8, Types1_7_6_10.SHORT_POSITION); // position
|
||||
map(Type.UNSIGNED_BYTE); // action
|
||||
map(Type.NAMED_COMPOUND_TAG, Types1_7_6_10.COMPRESSED_NBT); // nbt
|
||||
}
|
||||
});
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.SERVER_DIFFICULTY);
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.COMBAT_EVENT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.WORLD_BORDER, null, wrapper -> {
|
||||
final WorldBorderEmulator emulator = wrapper.user().get(WorldBorderEmulator.class);
|
||||
wrapper.cancel();
|
||||
|
||||
final int action = wrapper.read(Type.VAR_INT);
|
||||
if (action == 0) { // set size
|
||||
emulator.setSize(wrapper.read(Type.DOUBLE)); // radius
|
||||
} else if (action == 1) { // lerp size
|
||||
emulator.lerpSize(wrapper.read(Type.DOUBLE), wrapper.read(Type.DOUBLE), wrapper.read(Type.VAR_LONG)); // old radius, new radius, speed
|
||||
} else if (action == 2) { // set center
|
||||
emulator.setCenter(wrapper.read(Type.DOUBLE), wrapper.read(Type.DOUBLE)); // x, z
|
||||
} else if (action == 3) { // initialize
|
||||
emulator.init(
|
||||
wrapper.read(Type.DOUBLE), wrapper.read(Type.DOUBLE), // x, z
|
||||
wrapper.read(Type.DOUBLE), wrapper.read(Type.DOUBLE), // old radius, new radius
|
||||
wrapper.read(Type.VAR_LONG) // speed
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.provider;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.CompressionStatusTracker;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
|
||||
public abstract class CompressionHandlerProvider implements Provider {
|
||||
|
||||
public abstract void onHandleLoginCompressionPacket(UserConnection user, int threshold);
|
||||
public abstract void onTransformPacket(UserConnection user);
|
||||
|
||||
public abstract ChannelHandler getEncoder(int threshold);
|
||||
public abstract ChannelHandler getDecoder(int threshold);
|
||||
|
||||
public boolean isCompressionEnabled(UserConnection user) {
|
||||
return user.get(CompressionStatusTracker.class).removeCompression;
|
||||
}
|
||||
|
||||
public void setCompressionEnabled(UserConnection user, boolean enabled) {
|
||||
user.get(CompressionStatusTracker.class).removeCompression = enabled;
|
||||
}
|
||||
}
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class TitleRenderProvider implements Provider {
|
||||
protected Map<UUID, Integer> fadeIn = new HashMap<>();
|
||||
protected Map<UUID, Integer> stay = new HashMap<>();
|
||||
protected Map<UUID, Integer> fadeOut = new HashMap<>();
|
||||
protected Map<UUID, String> titles = new HashMap<>();
|
||||
protected Map<UUID, String> subTitles = new HashMap<>();
|
||||
protected Map<UUID, AtomicInteger> times = new HashMap<>();
|
||||
|
||||
public void setTimings(UUID uuid, int fadeIn, int stay, int fadeOut) {
|
||||
setFadeIn(uuid, fadeIn);
|
||||
setStay(uuid, stay);
|
||||
setFadeOut(uuid, fadeOut);
|
||||
|
||||
AtomicInteger time = getTime(uuid);
|
||||
if (time.get() > 0) time.set(getFadeIn(uuid) + getStay(uuid) + getFadeOut(uuid));
|
||||
}
|
||||
|
||||
public void reset(UUID uuid) {
|
||||
this.titles.remove(uuid);
|
||||
this.subTitles.remove(uuid);
|
||||
getTime(uuid).set(0);
|
||||
fadeIn.remove(uuid);
|
||||
stay.remove(uuid);
|
||||
fadeOut.remove(uuid);
|
||||
}
|
||||
|
||||
public void setTitle(UUID uuid, String title) {
|
||||
this.titles.put(uuid, title);
|
||||
getTime(uuid).set(getFadeIn(uuid) + getStay(uuid) + getFadeOut(uuid));
|
||||
}
|
||||
|
||||
public void setSubTitle(UUID uuid, String subTitle) {
|
||||
this.subTitles.put(uuid, subTitle);
|
||||
}
|
||||
|
||||
public void clear(UUID uuid) {
|
||||
this.titles.remove(uuid);
|
||||
this.subTitles.remove(uuid);
|
||||
getTime(uuid).set(0);
|
||||
}
|
||||
|
||||
public AtomicInteger getTime(UUID uuid) {
|
||||
return times.computeIfAbsent(uuid, key -> new AtomicInteger(0));
|
||||
}
|
||||
|
||||
public int getFadeIn(UUID uuid) {
|
||||
return fadeIn.getOrDefault(uuid, 10);
|
||||
}
|
||||
|
||||
public int getStay(UUID uuid) {
|
||||
return stay.getOrDefault(uuid, 70);
|
||||
}
|
||||
|
||||
public int getFadeOut(UUID uuid) {
|
||||
return fadeOut.getOrDefault(uuid, 20);
|
||||
}
|
||||
|
||||
public void setFadeIn(UUID uuid, int fadeIn) {
|
||||
if (fadeIn >= 0) this.fadeIn.put(uuid, fadeIn);
|
||||
else this.fadeIn.remove(uuid);
|
||||
}
|
||||
|
||||
public void setStay(UUID uuid, int stay) {
|
||||
if (stay >= 0) this.stay.put(uuid, stay);
|
||||
else this.stay.remove(uuid);
|
||||
}
|
||||
|
||||
public void setFadeOut(UUID uuid, int fadeOut) {
|
||||
if (fadeOut >= 0) this.fadeOut.put(uuid, fadeOut);
|
||||
else this.fadeOut.remove(uuid);
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.provider.compression;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
// https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionDecoder.java
|
||||
public class CompressionDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
private final Inflater inflater = new Inflater();
|
||||
|
||||
private final int threshold;
|
||||
|
||||
public CompressionDecoder(final int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (!in.isReadable()) return;
|
||||
|
||||
int outLength = Type.VAR_INT.readPrimitive(in);
|
||||
if (outLength == 0) {
|
||||
out.add(in.readBytes(in.readableBytes()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (outLength < this.threshold) {
|
||||
throw new DecoderException("Badly compressed packet - size of " + outLength + " is below server threshold of " + this.threshold);
|
||||
} else if (outLength > 2097152) {
|
||||
throw new DecoderException("Badly compressed packet - size of " + outLength + " is larger than protocol maximum of " + 2097152);
|
||||
}
|
||||
|
||||
ByteBuf temp = in;
|
||||
if (!in.hasArray()) {
|
||||
temp = ByteBufAllocator.DEFAULT.heapBuffer().writeBytes(in);
|
||||
} else {
|
||||
in.retain();
|
||||
}
|
||||
ByteBuf output = ByteBufAllocator.DEFAULT.heapBuffer(outLength, outLength);
|
||||
try {
|
||||
this.inflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
|
||||
output.writerIndex(output.writerIndex() + this.inflater.inflate(output.array(), output.arrayOffset(), outLength));
|
||||
out.add(output.retain());
|
||||
} finally {
|
||||
output.release();
|
||||
temp.release();
|
||||
this.inflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.provider.compression;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
// https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionEncoder.java
|
||||
public class CompressionEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
private final Deflater deflater = new Deflater();
|
||||
|
||||
private final int threshold;
|
||||
|
||||
public CompressionEncoder(final int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
|
||||
int frameLength = in.readableBytes();
|
||||
if (frameLength < this.threshold) {
|
||||
out.writeByte(0); // VarInt
|
||||
out.writeBytes(in);
|
||||
return;
|
||||
}
|
||||
|
||||
Type.VAR_INT.writePrimitive(out, frameLength);
|
||||
|
||||
ByteBuf temp = in;
|
||||
if (!in.hasArray()) {
|
||||
temp = ByteBufAllocator.DEFAULT.heapBuffer().writeBytes(in);
|
||||
} else {
|
||||
in.retain();
|
||||
}
|
||||
ByteBuf output = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||
try {
|
||||
this.deflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
|
||||
deflater.finish();
|
||||
|
||||
while (!deflater.finished()) {
|
||||
output.ensureWritable(4096);
|
||||
output.writerIndex(output.writerIndex() + this.deflater.deflate(output.array(), output.arrayOffset() + output.writerIndex(), output.writableBytes()));
|
||||
}
|
||||
out.writeBytes(output);
|
||||
} finally {
|
||||
output.release();
|
||||
temp.release();
|
||||
this.deflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.provider.compression;
|
||||
|
||||
import com.viaversion.viarewind.api.netty.EmptyChannelHandler;
|
||||
import com.viaversion.viarewind.api.netty.ForwardMessageToByteEncoder;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.provider.CompressionHandlerProvider;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
|
||||
public class TrackingCompressionHandlerProvider extends CompressionHandlerProvider {
|
||||
public static final String COMPRESS_HANDLER_NAME = "compress";
|
||||
public static final String DECOMPRESS_HANDLER_NAME = "decompress";
|
||||
|
||||
@Override
|
||||
public void onHandleLoginCompressionPacket(UserConnection user, int threshold) {
|
||||
final ChannelPipeline pipeline = user.getChannel().pipeline();
|
||||
if (user.isClientSide()) {
|
||||
pipeline.addBefore(Via.getManager().getInjector().getEncoderName(), COMPRESS_HANDLER_NAME, getEncoder(threshold));
|
||||
pipeline.addBefore(Via.getManager().getInjector().getDecoderName(), DECOMPRESS_HANDLER_NAME, getDecoder(threshold));
|
||||
} else {
|
||||
setCompressionEnabled(user, true); // We need to remove compression for 1.7 clients
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformPacket(UserConnection user) {
|
||||
if (isCompressionEnabled(user)) {
|
||||
final ChannelPipeline pipeline = user.getChannel().pipeline();
|
||||
|
||||
String compressor = null;
|
||||
String decompressor = null;
|
||||
if (pipeline.get(COMPRESS_HANDLER_NAME) != null) { // ViaVersion
|
||||
compressor = COMPRESS_HANDLER_NAME;
|
||||
decompressor = DECOMPRESS_HANDLER_NAME;
|
||||
} else if (pipeline.get("compression-encoder") != null) { // Velocity
|
||||
compressor = "compression-encoder";
|
||||
decompressor = "compression-decoder";
|
||||
}
|
||||
|
||||
if (compressor != null) { // We can neutralize the effect of compressor to the client
|
||||
pipeline.replace(decompressor, decompressor, new EmptyChannelHandler());
|
||||
pipeline.replace(compressor, compressor, new ForwardMessageToByteEncoder());
|
||||
} else {
|
||||
throw new IllegalStateException("Couldn't remove compression for 1.7!");
|
||||
}
|
||||
|
||||
setCompressionEnabled(user, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelHandler getEncoder(int threshold) {
|
||||
return new CompressionEncoder(threshold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelHandler getDecoder(int threshold) {
|
||||
return new CompressionDecoder(threshold);
|
||||
}
|
||||
}
|
||||
-183
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.storage;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ServerboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.data.VirtualHologramEntity;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntArrayMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectArrayMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EntityTracker1_8 extends EntityTrackerBase {
|
||||
|
||||
private final Int2ObjectMap<VirtualHologramEntity> holograms = new Int2ObjectArrayMap<>();
|
||||
private final Int2IntMap vehicles = new Int2IntArrayMap();
|
||||
private final Int2ObjectMap<UUID> entityIdToUUID = new Int2ObjectArrayMap<>();
|
||||
private final Object2IntMap<UUID> entityUUIDToId = new Object2IntOpenHashMap<>();
|
||||
|
||||
public int spectatingClientEntityId = -1;
|
||||
private int clientEntityGameMode;
|
||||
|
||||
public EntityTracker1_8(UserConnection connection) {
|
||||
super(connection, EntityTypes1_10.EntityType.ENTITY_HUMAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEntity(int id, EntityType type) {
|
||||
super.addEntity(id, type);
|
||||
if (type == EntityTypes1_10.EntityType.ARMOR_STAND) {
|
||||
holograms.put(id, new VirtualHologramEntity(user(), id));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int entityId) {
|
||||
super.removeEntity(entityId);
|
||||
|
||||
if (entityIdToUUID.containsKey(entityId)) {
|
||||
final UUID playerId = entityIdToUUID.remove(entityId);
|
||||
|
||||
entityUUIDToId.removeInt(playerId);
|
||||
user().get(PlayerSessionStorage.class).getPlayerEquipment().remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntities() {
|
||||
super.clearEntities();
|
||||
vehicles.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientEntityId(int entityId) {
|
||||
if (this.spectatingClientEntityId == this.clientEntityId()) {
|
||||
this.spectatingClientEntityId = entityId;
|
||||
}
|
||||
super.setClientEntityId(entityId);
|
||||
}
|
||||
|
||||
public void addPlayer(final int entityId, final UUID uuid) {
|
||||
entityUUIDToId.put(uuid, entityId);
|
||||
entityIdToUUID.put(entityId, uuid);
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID(final int entityId) {
|
||||
return entityIdToUUID.get(entityId);
|
||||
}
|
||||
|
||||
public int getPlayerEntityId(final UUID uuid) {
|
||||
return entityUUIDToId.getOrDefault(uuid, -1);
|
||||
}
|
||||
|
||||
public int getVehicle(final int passengerId) {
|
||||
for (Map.Entry<Integer, Integer> vehicle : vehicles.entrySet()) {
|
||||
if (vehicle.getValue() == passengerId) {
|
||||
return vehicle.getValue();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getPassenger(int vehicleId) {
|
||||
return vehicles.getOrDefault(vehicleId, -1);
|
||||
}
|
||||
|
||||
protected void startSneaking() {
|
||||
try {
|
||||
final PacketWrapper entityAction = PacketWrapper.create(ServerboundPackets1_7_2_5.ENTITY_ACTION, user());
|
||||
entityAction.write(Type.VAR_INT, this.clientEntityId()); // Entity id
|
||||
entityAction.write(Type.VAR_INT, 0); // Action id
|
||||
entityAction.write(Type.VAR_INT, 0); // Jump boost
|
||||
|
||||
entityAction.sendToServer(Protocol1_7_6_10To1_8.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send sneak packet", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPassenger(final int vehicleId, final int passengerId) {
|
||||
if (vehicleId == this.spectatingClientEntityId && this.spectatingClientEntityId != this.clientEntityId()) {
|
||||
startSneaking();
|
||||
setSpectating(this.clientEntityId());
|
||||
}
|
||||
|
||||
if (vehicleId == -1) {
|
||||
vehicles.remove(getVehicle(passengerId));
|
||||
} else if (passengerId == -1) {
|
||||
vehicles.remove(vehicleId);
|
||||
} else {
|
||||
vehicles.put(vehicleId, passengerId);
|
||||
}
|
||||
}
|
||||
|
||||
protected void attachEntity(final int target) {
|
||||
try {
|
||||
final PacketWrapper attachEntity = PacketWrapper.create(ClientboundPackets1_8.ATTACH_ENTITY, user());
|
||||
attachEntity.write(Type.INT, this.clientEntityId()); // vehicle id
|
||||
attachEntity.write(Type.INT, target); // passenger id
|
||||
attachEntity.write(Type.BOOLEAN, false); // leash
|
||||
|
||||
attachEntity.scheduleSend(Protocol1_7_6_10To1_8.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send attach packet", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpectating(int spectating) {
|
||||
if (spectating != this.clientEntityId() && getPassenger(spectating) != -1) {
|
||||
startSneaking();
|
||||
setSpectating(this.clientEntityId());
|
||||
return;
|
||||
}
|
||||
if (this.spectatingClientEntityId != spectating && this.spectatingClientEntityId != this.clientEntityId()) {
|
||||
attachEntity(-1);
|
||||
}
|
||||
this.spectatingClientEntityId = spectating;
|
||||
if (spectating != this.clientEntityId()) {
|
||||
attachEntity(this.spectatingClientEntityId);
|
||||
}
|
||||
}
|
||||
|
||||
public Int2ObjectMap<VirtualHologramEntity> getHolograms() {
|
||||
return holograms;
|
||||
}
|
||||
|
||||
public boolean isSpectator() {
|
||||
return clientEntityGameMode == 3;
|
||||
}
|
||||
|
||||
public void setClientEntityGameMode(int clientEntityGameMode) {
|
||||
this.clientEntityGameMode = clientEntityGameMode;
|
||||
}
|
||||
}
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.storage;
|
||||
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GameProfileStorage extends StoredObject {
|
||||
private final Map<UUID, GameProfile> properties = new HashMap<>();
|
||||
|
||||
public GameProfileStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public GameProfile put(UUID uuid, String name) {
|
||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||
properties.put(uuid, gameProfile);
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public GameProfile get(UUID uuid) {
|
||||
return properties.get(uuid);
|
||||
}
|
||||
|
||||
public GameProfile get(String name, boolean ignoreCase) {
|
||||
if (ignoreCase) name = name.toLowerCase();
|
||||
|
||||
for (GameProfile profile : properties.values()) {
|
||||
if (profile.name == null) continue;
|
||||
|
||||
String n = ignoreCase ? profile.name.toLowerCase() : profile.name;
|
||||
|
||||
if (n.equals(name)) {
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<GameProfile> getAllWithPrefix(String prefix, boolean ignoreCase) {
|
||||
if (ignoreCase) prefix = prefix.toLowerCase();
|
||||
|
||||
ArrayList<GameProfile> profiles = new ArrayList<>();
|
||||
|
||||
for (GameProfile profile : properties.values()) {
|
||||
if (profile.name == null) continue;
|
||||
|
||||
String n = ignoreCase ? profile.name.toLowerCase() : profile.name;
|
||||
|
||||
if (n.startsWith(prefix)) profiles.add(profile);
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public GameProfile remove(UUID uuid) {
|
||||
return properties.remove(uuid);
|
||||
}
|
||||
|
||||
|
||||
public static class GameProfile {
|
||||
public final String name;
|
||||
public final UUID uuid;
|
||||
public String displayName;
|
||||
public int ping;
|
||||
public List<Property> properties = new ArrayList<>();
|
||||
public int gamemode = 0;
|
||||
|
||||
public GameProfile(UUID uuid, String name) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Item getSkull() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
CompoundTag ownerTag = new CompoundTag();
|
||||
tag.put("SkullOwner", ownerTag);
|
||||
ownerTag.put("Id", new StringTag(uuid.toString()));
|
||||
CompoundTag properties = new CompoundTag();
|
||||
ownerTag.put("Properties", properties);
|
||||
ListTag textures = new ListTag(CompoundTag.class);
|
||||
properties.put("textures", textures);
|
||||
for (Property property : this.properties) {
|
||||
if (property.name.equals("textures")) {
|
||||
CompoundTag textureTag = new CompoundTag();
|
||||
textureTag.put("Value", new StringTag(property.value));
|
||||
if (property.signature != null) {
|
||||
textureTag.put("Signature", new StringTag(property.signature));
|
||||
}
|
||||
textures.add(textureTag);
|
||||
}
|
||||
}
|
||||
|
||||
return new DataItem(397, (byte) 1, (short) 3, tag);
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
String displayName = this.displayName == null ? name : this.displayName;
|
||||
if (displayName.length() > 16) displayName = ChatUtil.removeUnusedColor(displayName, 'f');
|
||||
if (displayName.length() > 16) displayName = ChatColorUtil.stripColor(displayName);
|
||||
if (displayName.length() > 16) displayName = displayName.substring(0, 16);
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
public final String name;
|
||||
public final String value;
|
||||
public final String signature;
|
||||
|
||||
public Property(String name, String value, String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
}
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InventoryTracker extends StoredObject {
|
||||
public static final Map<String, Integer> WINDOW_TYPE_REGISTRY = new HashMap<>();
|
||||
|
||||
static {
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:container", 0);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:chest", 0);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:crafting_table", 1);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:furnace", 2);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:dispenser", 3);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:enchanting_table", 4);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:brewing_stand", 5);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:villager", 6);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:beacon", 7);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:anvil", 8);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:hopper", 9);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:dropper", 10);
|
||||
WINDOW_TYPE_REGISTRY.put("EntityHorse", 11);
|
||||
}
|
||||
|
||||
private final HashMap<Short, Short> windowTypeMap = new HashMap<>();
|
||||
private final HashMap<Short, FurnaceData> furnaceData = new HashMap<>();
|
||||
|
||||
public short levelCost = 0;
|
||||
public short anvilId = -1;
|
||||
|
||||
public InventoryTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public short get(short windowId) {
|
||||
return windowTypeMap.getOrDefault(windowId, (short) -1);
|
||||
}
|
||||
|
||||
public void remove(short windowId) {
|
||||
windowTypeMap.remove(windowId);
|
||||
furnaceData.remove(windowId);
|
||||
}
|
||||
|
||||
public static short getInventoryType(String name) {
|
||||
return WINDOW_TYPE_REGISTRY.getOrDefault(name, -1).shortValue();
|
||||
}
|
||||
|
||||
public HashMap<Short, Short> getWindowTypeMap() {
|
||||
return windowTypeMap;
|
||||
}
|
||||
|
||||
public HashMap<Short, FurnaceData> getFurnaceData() {
|
||||
return furnaceData;
|
||||
}
|
||||
|
||||
public static class FurnaceData {
|
||||
|
||||
public short fuelLeft = 0;
|
||||
public short maxFuel = 0;
|
||||
public short progress = 0;
|
||||
public short maxProgress = 200;
|
||||
}
|
||||
|
||||
}
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerSessionStorage extends StoredObject {
|
||||
|
||||
// Player abilities
|
||||
public boolean sprinting, allowFly, flying, invincible, creative;
|
||||
public float flySpeed, walkSpeed;
|
||||
|
||||
// Player position, rotation and data
|
||||
private double posX, posY, posZ;
|
||||
public double receivedPosY;
|
||||
public float yaw, pitch;
|
||||
public boolean onGround;
|
||||
|
||||
// Player inventory
|
||||
private final Map<UUID, Item[]> playerEquipment = new HashMap<>();
|
||||
|
||||
public PlayerSessionStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public byte combineAbilities() {
|
||||
byte flags = 0;
|
||||
|
||||
if (invincible) flags |= 8;
|
||||
if (allowFly) flags |= 4;
|
||||
if (flying) flags |= 2;
|
||||
if (creative) flags |= 1;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public double getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public double getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
public double getPosZ() {
|
||||
return posZ;
|
||||
}
|
||||
|
||||
public void setPos(double x, double y, double z) {
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
}
|
||||
|
||||
public Item getPlayerEquipment(final UUID uuid, final int slot) {
|
||||
final Item[] items = playerEquipment.get(uuid);
|
||||
if (items == null || slot < 0 || slot >= items.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return items[slot];
|
||||
}
|
||||
|
||||
public void setPlayerEquipment(final UUID uuid, final Item equipment, final int slot) {
|
||||
final Item[] items = playerEquipment.computeIfAbsent(uuid, it -> new Item[5]);
|
||||
if (slot < 0 || slot >= items.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
items[slot] = equipment;
|
||||
}
|
||||
|
||||
public Map<UUID, Item[]> getPlayerEquipment() {
|
||||
return playerEquipment;
|
||||
}
|
||||
}
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.storage;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Scoreboard extends StoredObject {
|
||||
private final HashMap<String, List<String>> teams = new HashMap<>();
|
||||
private final HashSet<String> objectives = new HashSet<>();
|
||||
private final HashMap<String, ScoreTeam> scoreTeams = new HashMap<>();
|
||||
private final HashMap<String, Byte> teamColors = new HashMap<>();
|
||||
private final HashSet<String> scoreTeamNames = new HashSet<>();
|
||||
private String colorIndependentSidebar;
|
||||
private final HashMap<Byte, String> colorDependentSidebar = new HashMap<>();
|
||||
|
||||
public Scoreboard(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void addPlayerToTeam(String player, String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>()).add(player);
|
||||
}
|
||||
|
||||
public void setTeamColor(String team, Byte color) {
|
||||
teamColors.put(team, color);
|
||||
}
|
||||
|
||||
public Optional<Byte> getTeamColor(String team) {
|
||||
return Optional.ofNullable(teamColors.get(team));
|
||||
}
|
||||
|
||||
public void addTeam(String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>());
|
||||
}
|
||||
|
||||
public void removeTeam(String team) {
|
||||
teams.remove(team);
|
||||
scoreTeams.remove(team);
|
||||
teamColors.remove(team);
|
||||
}
|
||||
|
||||
public boolean teamExists(String team) {
|
||||
return teams.containsKey(team);
|
||||
}
|
||||
|
||||
public void removePlayerFromTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
if (teamPlayers != null) teamPlayers.remove(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
return teamPlayers != null && teamPlayers.contains(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(String player) {
|
||||
for (List<String> teamPlayers : teams.values()) {
|
||||
if (teamPlayers.contains(player)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Optional<Byte> getPlayerTeamColor(String player) {
|
||||
Optional<String> team = getTeam(player);
|
||||
return team.isPresent() ? getTeamColor(team.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<String> getTeam(String player) {
|
||||
for (Map.Entry<String, List<String>> entry : teams.entrySet())
|
||||
if (entry.getValue().contains(player))
|
||||
return Optional.of(entry.getKey());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void addObjective(String name) {
|
||||
objectives.add(name);
|
||||
}
|
||||
|
||||
public void removeObjective(String name) {
|
||||
objectives.remove(name);
|
||||
colorDependentSidebar.values().remove(name);
|
||||
if (name.equals(colorIndependentSidebar)) {
|
||||
colorIndependentSidebar = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean objectiveExists(String name) {
|
||||
return objectives.contains(name);
|
||||
}
|
||||
|
||||
public String sendTeamForScore(String score) throws Exception {
|
||||
if (score.length() <= 16) return score;
|
||||
if (scoreTeams.containsKey(score)) return scoreTeams.get(score).name;
|
||||
int l = 16;
|
||||
int i = Math.min(16, score.length() - 16);
|
||||
String name = score.substring(i, i + l);
|
||||
while (scoreTeamNames.contains(name) || teams.containsKey(name)) {
|
||||
i--;
|
||||
while (score.length() - l - i > 16) {
|
||||
l--;
|
||||
if (l < 1) return score;
|
||||
i = Math.min(16, score.length() - l);
|
||||
}
|
||||
name = score.substring(i, i + l);
|
||||
}
|
||||
String prefix = score.substring(0, i);
|
||||
String suffix = i + l >= score.length() ? "" : score.substring(i + l);
|
||||
|
||||
ScoreTeam scoreTeam = new ScoreTeam(name, prefix, suffix);
|
||||
scoreTeams.put(score, scoreTeam);
|
||||
scoreTeamNames.add(name);
|
||||
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.TEAMS, getUser());
|
||||
teamPacket.write(Type.STRING, name);
|
||||
teamPacket.write(Type.BYTE, (byte) 0);
|
||||
teamPacket.write(Type.STRING, "ViaRewind");
|
||||
teamPacket.write(Type.STRING, prefix);
|
||||
teamPacket.write(Type.STRING, suffix);
|
||||
teamPacket.write(Type.BYTE, (byte) 0);
|
||||
teamPacket.write(Type.SHORT, (short) 1);
|
||||
teamPacket.write(Type.STRING, name);
|
||||
teamPacket.send(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public String removeTeamForScore(String score) throws Exception {
|
||||
ScoreTeam scoreTeam = scoreTeams.remove(score);
|
||||
if (scoreTeam == null) return score;
|
||||
scoreTeamNames.remove(scoreTeam.name);
|
||||
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.TEAMS, getUser());
|
||||
teamPacket.write(Type.STRING, scoreTeam.name);
|
||||
teamPacket.write(Type.BYTE, (byte) 1);
|
||||
teamPacket.send(Protocol1_7_6_10To1_8.class);
|
||||
|
||||
return scoreTeam.name;
|
||||
}
|
||||
|
||||
public String getColorIndependentSidebar() {
|
||||
return this.colorIndependentSidebar;
|
||||
}
|
||||
|
||||
public HashMap<Byte, String> getColorDependentSidebar() {
|
||||
return this.colorDependentSidebar;
|
||||
}
|
||||
|
||||
public void setColorIndependentSidebar(String colorIndependentSidebar) {
|
||||
this.colorIndependentSidebar = colorIndependentSidebar;
|
||||
}
|
||||
|
||||
private static class ScoreTeam {
|
||||
private final String prefix;
|
||||
private final String suffix;
|
||||
private final String name;
|
||||
|
||||
public ScoreTeam(String name, String prefix, String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public class WorldBorderEmulator extends StoredObject {
|
||||
private double x, z;
|
||||
private double oldDiameter, newDiameter;
|
||||
|
||||
private long lerpTime;
|
||||
private long lerpStartTime;
|
||||
|
||||
private boolean init = false;
|
||||
|
||||
public WorldBorderEmulator(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void init(double x, double z, double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
|
||||
this.lerpTime = lerpTime;
|
||||
|
||||
init = true;
|
||||
}
|
||||
|
||||
public void setCenter(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void lerpSize(double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
this.lerpTime = lerpTime;
|
||||
this.lerpStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setSize(double size) {
|
||||
this.oldDiameter = size;
|
||||
this.newDiameter = size;
|
||||
|
||||
this.lerpTime = 0;
|
||||
}
|
||||
|
||||
public double getSize() {
|
||||
if (lerpTime == 0) {
|
||||
return newDiameter;
|
||||
}
|
||||
|
||||
double percent = ((double) (System.currentTimeMillis() - lerpStartTime) / (double) (lerpTime));
|
||||
|
||||
// Clamp value
|
||||
if (percent > 1.0D) percent = 1.0d;
|
||||
else if (percent < 0.0D) percent = 0.0d;
|
||||
|
||||
return oldDiameter + (newDiameter - oldDiameter) * percent;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean isInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
public enum Side {
|
||||
NORTH(0, -1),
|
||||
EAST(1, 0),
|
||||
SOUTH(0, 1),
|
||||
WEST(-1, 0);
|
||||
|
||||
public final int modX;
|
||||
public final int modZ;
|
||||
|
||||
Side(int modX, int modZ) {
|
||||
this.modX = modX;
|
||||
this.modZ = modZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_7_6_10to1_8.task;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.PlayerSessionStorage;
|
||||
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.storage.WorldBorderEmulator;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldBorderUpdateTask implements Runnable {
|
||||
public static final int VIEW_DISTANCE = 16;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
final WorldBorderEmulator worldBorderEmulatorTracker = connection.get(WorldBorderEmulator.class);
|
||||
if (!worldBorderEmulatorTracker.isInit()) continue;
|
||||
|
||||
final PlayerSessionStorage playerSession = connection.get(PlayerSessionStorage.class);
|
||||
|
||||
double radius = worldBorderEmulatorTracker.getSize() / 2.0;
|
||||
|
||||
for (WorldBorderEmulator.Side side : WorldBorderEmulator.Side.values()) {
|
||||
double d;
|
||||
double pos;
|
||||
double center;
|
||||
if (side.modX != 0) {
|
||||
pos = playerSession.getPosZ();
|
||||
center = worldBorderEmulatorTracker.getZ();
|
||||
d = Math.abs(worldBorderEmulatorTracker.getX() + radius * side.modX - playerSession.getPosX());
|
||||
} else {
|
||||
center = worldBorderEmulatorTracker.getX();
|
||||
pos = playerSession.getPosX();
|
||||
d = Math.abs(worldBorderEmulatorTracker.getZ() + radius * side.modZ - playerSession.getPosZ());
|
||||
}
|
||||
if (d >= VIEW_DISTANCE) continue;
|
||||
|
||||
double r = Math.sqrt(VIEW_DISTANCE * VIEW_DISTANCE - d * d);
|
||||
|
||||
double minH = Math.ceil(pos - r);
|
||||
double maxH = Math.floor(pos + r);
|
||||
double minV = Math.ceil(playerSession.getPosY() - r);
|
||||
double maxV = Math.floor(playerSession.getPosY() + r);
|
||||
|
||||
if (minH < center - radius) minH = Math.ceil(center - radius);
|
||||
if (maxH > center + radius) maxH = Math.floor(center + radius);
|
||||
if (minV < 0.0) minV = 0.0;
|
||||
|
||||
double centerH = (minH + maxH) / 2.0;
|
||||
double centerV = (minV + maxV) / 2.0;
|
||||
|
||||
double particleOffset = 2.5;
|
||||
|
||||
final PacketWrapper spawnParticle = PacketWrapper.create(ClientboundPackets1_8.SPAWN_PARTICLE, connection);
|
||||
spawnParticle.write(Type.STRING, ViaRewind.getConfig().getWorldBorderParticle()); // particle name
|
||||
spawnParticle.write(Type.FLOAT, (float) (side.modX != 0 ? worldBorderEmulatorTracker.getX() + (radius * side.modX) : centerH)); // x
|
||||
spawnParticle.write(Type.FLOAT, (float) centerV); // y
|
||||
spawnParticle.write(Type.FLOAT, (float) (side.modX == 0 ? worldBorderEmulatorTracker.getZ() + (radius * side.modZ) : centerH)); // z
|
||||
spawnParticle.write(Type.FLOAT, (float) (side.modX != 0 ? 0f : (maxH - minH) / particleOffset)); // offset x
|
||||
spawnParticle.write(Type.FLOAT, (float) ((maxV - minV) / particleOffset)); // offset y
|
||||
spawnParticle.write(Type.FLOAT, (float) (side.modX == 0 ? 0f : (maxH - minH) / particleOffset)); // offset z
|
||||
spawnParticle.write(Type.FLOAT, 0F); // particle data
|
||||
spawnParticle.write(Type.INT, (int) Math.floor((maxH - minH) * (maxV - minV) * 0.5));
|
||||
|
||||
try {
|
||||
spawnParticle.send(Protocol1_7_6_10To1_8.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send world border particle", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.data.RewindMappings;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.metadata.MetadataRewriter1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.packets.*;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.*;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.task.CooldownIndicatorTask;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.task.LevitationUpdateTask;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Protocol1_8To1_9 extends BackwardsProtocol<ClientboundPackets1_9, ClientboundPackets1_8, ServerboundPackets1_9, ServerboundPackets1_8> {
|
||||
|
||||
public static final ValueTransformer<Double, Integer> DOUBLE_TO_INT_TIMES_32 = new ValueTransformer<Double, Integer>(Type.INT) {
|
||||
@Override
|
||||
public Integer transform(PacketWrapper wrapper, Double inputValue) {
|
||||
return (int) (inputValue * 32.0D);
|
||||
}
|
||||
};
|
||||
public static final ValueTransformer<Float, Byte> DEGREES_TO_ANGLE = new ValueTransformer<Float, Byte>(Type.BYTE) {
|
||||
@Override
|
||||
public Byte transform(PacketWrapper packetWrapper, Float degrees) {
|
||||
return (byte) ((degrees / 360F) * 256);
|
||||
}
|
||||
};
|
||||
|
||||
public static final RewindMappings MAPPINGS = new RewindMappings();
|
||||
|
||||
private final BlockItemPackets1_9 itemRewriter = new BlockItemPackets1_9(this);
|
||||
private final MetadataRewriter1_8To1_9 metadataRewriter = new MetadataRewriter1_8To1_9(this);
|
||||
|
||||
public Protocol1_8To1_9() {
|
||||
super(ClientboundPackets1_9.class, ClientboundPackets1_8.class, ServerboundPackets1_9.class, ServerboundPackets1_8.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
metadataRewriter.register();
|
||||
itemRewriter.register();
|
||||
|
||||
EntityPackets1_9.register(this);
|
||||
PlayerPackets1_9.register(this);
|
||||
WorldPackets1_9.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
connection.addEntityTracker(this.getClass(), new EntityTracker1_9(connection));
|
||||
|
||||
connection.put(new WindowTracker(connection));
|
||||
connection.put(new LevitationStorage());
|
||||
connection.put(new PlayerPositionTracker());
|
||||
connection.put(new CooldownStorage());
|
||||
connection.put(new BlockPlaceDestroyTracker());
|
||||
connection.put(new BossBarStorage(connection));
|
||||
|
||||
if (!connection.has(ClientWorld.class)) {
|
||||
connection.put(new ClientWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ViaProviders providers) {
|
||||
Via.getManager().getScheduler().scheduleRepeating(new LevitationUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
Via.getManager().getScheduler().scheduleRepeating(new CooldownIndicatorTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RewindMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_9 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataRewriter1_8To1_9 getEntityRewriter() {
|
||||
return metadataRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EffectMappings {
|
||||
|
||||
private static final HashMap<Integer, Integer> effects = new HashMap<>();
|
||||
|
||||
static {
|
||||
effects.put(1003, 1002);
|
||||
effects.put(1005, 1003);
|
||||
effects.put(1006, 1003);
|
||||
effects.put(1007, 1003);
|
||||
effects.put(1008, 1003);
|
||||
effects.put(1009, 1004);
|
||||
effects.put(1010, 1005);
|
||||
effects.put(1011, 1006);
|
||||
effects.put(1012, 1006);
|
||||
effects.put(1013, 1006);
|
||||
effects.put(1014, 1006);
|
||||
effects.put(1015, 1007);
|
||||
effects.put(1016, 1008);
|
||||
effects.put(1017, 1008);
|
||||
effects.put(1018, 1009);
|
||||
effects.put(1019, 1010);
|
||||
effects.put(1020, 1011);
|
||||
effects.put(1021, 1012);
|
||||
effects.put(1022, 1012);
|
||||
effects.put(1023, 1013);
|
||||
effects.put(1024, 1014);
|
||||
effects.put(1025, 1015);
|
||||
effects.put(1026, 1016);
|
||||
effects.put(1027, 1017);
|
||||
effects.put(1028, 1018);
|
||||
effects.put(1029, 1020);
|
||||
effects.put(1030, 1021);
|
||||
effects.put(1031, 1022);
|
||||
effects.put(1032, -1);
|
||||
effects.put(1033, -1);
|
||||
effects.put(1034, -1);
|
||||
effects.put(1035, -1);
|
||||
effects.put(1036, 1003);
|
||||
effects.put(1037, 1006);
|
||||
|
||||
effects.put(3000, -1);
|
||||
effects.put(3001, -1);
|
||||
}
|
||||
|
||||
public static int getOldId(int id) {
|
||||
return effects.getOrDefault(id, id);
|
||||
}
|
||||
}
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.data;
|
||||
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// TODO | Check if this is correct???
|
||||
public class PotionMappings {
|
||||
public static final Map<String, String> POTION_NAME_INDEX = new HashMap<>();
|
||||
public static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
||||
|
||||
static {
|
||||
POTION_NAME_TO_ID.putAll(ItemRewriter.POTION_NAME_TO_ID);
|
||||
POTION_NAME_TO_ID.put("luck", 8203);
|
||||
|
||||
POTION_NAME_INDEX.put("water", "§rWater Bottle");
|
||||
POTION_NAME_INDEX.put("mundane", "§rMundane Potion");
|
||||
POTION_NAME_INDEX.put("thick", "§rThick Potion");
|
||||
POTION_NAME_INDEX.put("awkward", "§rAwkward Potion");
|
||||
POTION_NAME_INDEX.put("water_splash", "§rSplash Water Bottle");
|
||||
POTION_NAME_INDEX.put("mundane_splash", "§rMundane Splash Potion");
|
||||
POTION_NAME_INDEX.put("thick_splash", "§rThick Splash Potion");
|
||||
POTION_NAME_INDEX.put("awkward_splash", "§rAwkward Splash Potion");
|
||||
POTION_NAME_INDEX.put("water_lingering", "§rLingering Water Bottle");
|
||||
POTION_NAME_INDEX.put("mundane_lingering", "§rMundane Lingering Potion");
|
||||
POTION_NAME_INDEX.put("thick_lingering", "§rThick Lingering Potion");
|
||||
POTION_NAME_INDEX.put("awkward_lingering", "§rAwkward Lingering Potion");
|
||||
POTION_NAME_INDEX.put("night_vision_lingering", "§rLingering Potion of Night Vision");
|
||||
POTION_NAME_INDEX.put("long_night_vision_lingering", "§rLingering Potion of Night Vision");
|
||||
POTION_NAME_INDEX.put("invisibility_lingering", "§rLingering Potion of Invisibility");
|
||||
POTION_NAME_INDEX.put("long_invisibility_lingering", "§rLingering Potion of Invisibility");
|
||||
POTION_NAME_INDEX.put("leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("long_leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("strong_leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("fire_resistance_lingering", "§rLingering Potion of Fire Resistance");
|
||||
POTION_NAME_INDEX.put("long_fire_resistance_lingering", "§rLingering Potion of Fire Resistance");
|
||||
POTION_NAME_INDEX.put("swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("long_swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("strong_swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("slowness_lingering", "§rLingering Potion of Slowness");
|
||||
POTION_NAME_INDEX.put("long_slowness_lingering", "§rLingering Potion of Slowness");
|
||||
POTION_NAME_INDEX.put("water_breathing_lingering", "§rLingering Potion of Water Breathing");
|
||||
POTION_NAME_INDEX.put("long_water_breathing_lingering", "§rLingering Potion of Water Breathing");
|
||||
POTION_NAME_INDEX.put("healing_lingering", "§rLingering Potion of Healing");
|
||||
POTION_NAME_INDEX.put("strong_healing_lingering", "§rLingering Potion of Healing");
|
||||
POTION_NAME_INDEX.put("harming_lingering", "§rLingering Potion of Harming");
|
||||
POTION_NAME_INDEX.put("strong_harming_lingering", "§rLingering Potion of Harming");
|
||||
POTION_NAME_INDEX.put("poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("long_poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("strong_poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("long_regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("strong_regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("long_strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("strong_strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("weakness_lingering", "§rLingering Potion of Weakness");
|
||||
POTION_NAME_INDEX.put("long_weakness_lingering", "§rLingering Potion of Weakness");
|
||||
POTION_NAME_INDEX.put("luck_lingering", "§rLingering Potion of Luck");
|
||||
POTION_NAME_INDEX.put("luck", "§rPotion of Luck");
|
||||
POTION_NAME_INDEX.put("luck_splash", "§rSplash Potion of Luck");
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.data;
|
||||
|
||||
import com.viaversion.viarewind.api.data.VRMappingDataLoader;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.ObjectArrayList;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.ObjectList;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
public final class RewindMappings extends com.viaversion.viarewind.api.data.RewindMappings {
|
||||
|
||||
private final ObjectList<String> sounds = new ObjectArrayList<>();
|
||||
|
||||
public RewindMappings() {
|
||||
super("1.9.4", "1.8");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadExtras(CompoundTag data) {
|
||||
super.loadExtras(data);
|
||||
|
||||
final JsonArray sounds = VRMappingDataLoader.INSTANCE.loadData("sounds-1.9.json").getAsJsonArray("sounds");
|
||||
for (final JsonElement sound : sounds) {
|
||||
this.sounds.add(sound.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public String soundName(final int soundId) {
|
||||
return sounds.get(soundId);
|
||||
}
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.emulation;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
|
||||
public class ActionBarVisualization implements CooldownVisualization {
|
||||
private final UserConnection user;
|
||||
|
||||
public ActionBarVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
sendActionBar(CooldownVisualization.buildProgressText("■", progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
sendActionBar("§r");
|
||||
}
|
||||
|
||||
private void sendActionBar(String bar) throws Exception {
|
||||
PacketWrapper actionBarPacket = PacketWrapper.create(ClientboundPackets1_8.CHAT_MESSAGE, user);
|
||||
actionBarPacket.write(Type.COMPONENT, new JsonPrimitive(bar));
|
||||
actionBarPacket.write(Type.BYTE, (byte) 2); // Position - above hotbar
|
||||
actionBarPacket.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.emulation;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BossBarVisualization implements CooldownVisualization {
|
||||
private final UserConnection user;
|
||||
private UUID bossUUID;
|
||||
|
||||
public BossBarVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.BOSSBAR, user);
|
||||
if (bossUUID == null) {
|
||||
bossUUID = UUID.randomUUID();
|
||||
wrapper.write(Type.UUID, bossUUID);
|
||||
wrapper.write(Type.VAR_INT, 0); // Action - add
|
||||
wrapper.write(Type.COMPONENT, new JsonPrimitive(" ")); // Title
|
||||
wrapper.write(Type.FLOAT, (float) progress); // Health
|
||||
wrapper.write(Type.VAR_INT, 0); // Color
|
||||
wrapper.write(Type.VAR_INT, 0); // Division
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 0); // Flags
|
||||
} else {
|
||||
wrapper.write(Type.UUID, bossUUID);
|
||||
wrapper.write(Type.VAR_INT, 2); // Action - update health
|
||||
wrapper.write(Type.FLOAT, (float) progress); // Health
|
||||
}
|
||||
wrapper.send(Protocol1_8To1_9.class, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
if (bossUUID == null) {
|
||||
return;
|
||||
}
|
||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.BOSSBAR, null, user);
|
||||
wrapper.write(Type.UUID, bossUUID);
|
||||
wrapper.write(Type.VAR_INT, 1); // Action - remove
|
||||
wrapper.send(Protocol1_8To1_9.class, false);
|
||||
bossUUID = null;
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.emulation;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.ViaRewindConfig.CooldownIndicator;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public interface CooldownVisualization {
|
||||
void show(double progress) throws Exception;
|
||||
|
||||
void hide() throws Exception;
|
||||
|
||||
|
||||
int MAX_PROGRESS_TEXT_LENGTH = 10;
|
||||
|
||||
static String buildProgressText(String symbol, double cooldown) {
|
||||
int green = (int) Math.floor(((double) MAX_PROGRESS_TEXT_LENGTH) * cooldown);
|
||||
int grey = MAX_PROGRESS_TEXT_LENGTH - green;
|
||||
StringBuilder builder = new StringBuilder("§8");
|
||||
while (green-- > 0) builder.append(symbol);
|
||||
builder.append("§7");
|
||||
while (grey-- > 0) builder.append(symbol);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
interface Factory {
|
||||
CooldownVisualization create(UserConnection user);
|
||||
|
||||
static Factory fromConfiguration() {
|
||||
try {
|
||||
return fromIndicator(ViaRewind.getConfig().getCooldownIndicator());
|
||||
} catch (IllegalArgumentException e) {
|
||||
ViaRewind.getPlatform().getLogger().warning("Invalid cooldown-indicator setting");
|
||||
return DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
static Factory fromIndicator(CooldownIndicator indicator) {
|
||||
switch (indicator) {
|
||||
case TITLE:
|
||||
return TitleCooldownVisualization::new;
|
||||
case BOSS_BAR:
|
||||
return BossBarVisualization::new;
|
||||
case ACTION_BAR:
|
||||
return ActionBarVisualization::new;
|
||||
case DISABLED:
|
||||
return DISABLED;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected: " + indicator);
|
||||
}
|
||||
}
|
||||
|
||||
Factory DISABLED = user -> new DisabledCooldownVisualization();
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.emulation;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TitleCooldownVisualization implements CooldownVisualization {
|
||||
private final UserConnection user;
|
||||
|
||||
public TitleCooldownVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
String text = CooldownVisualization.buildProgressText("˙", progress);
|
||||
sendTitle("", text, 0, 2, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
sendTitlePacket(ACTION_HIDE, wrapper -> {});
|
||||
}
|
||||
|
||||
private static final int ACTION_SET_TITLE = 0;
|
||||
private static final int ACTION_SET_SUBTITLE = 1;
|
||||
private static final int ACTION_SET_TIMES_AND_DISPLAY = 2;
|
||||
private static final int ACTION_HIDE = 3;
|
||||
|
||||
private void sendTitle(String titleText, String subTitleText, int fadeIn, int stay, int fadeOut) throws Exception {
|
||||
sendTitlePacket(
|
||||
ACTION_SET_TITLE,
|
||||
packet -> packet.write(Type.COMPONENT, new JsonPrimitive(titleText))
|
||||
);
|
||||
sendTitlePacket(
|
||||
ACTION_SET_SUBTITLE,
|
||||
packet -> packet.write(Type.COMPONENT, new JsonPrimitive(subTitleText))
|
||||
);
|
||||
sendTitlePacket(
|
||||
ACTION_SET_TIMES_AND_DISPLAY,
|
||||
packet -> {
|
||||
packet.write(Type.INT, fadeIn);
|
||||
packet.write(Type.INT, stay);
|
||||
packet.write(Type.INT, fadeOut);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void sendTitlePacket(int action, Consumer<PacketWrapper> writer) throws Exception {
|
||||
PacketWrapper titlePacket = PacketWrapper.create(ClientboundPackets1_8.TITLE, user);
|
||||
titlePacket.write(Type.VAR_INT, action);
|
||||
writer.accept(titlePacket);
|
||||
titlePacket.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
}
|
||||
-271
@@ -1,271 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.emulation;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.legacy.bossbar.BossBar;
|
||||
import com.viaversion.viaversion.api.legacy.bossbar.BossColor;
|
||||
import com.viaversion.viaversion.api.legacy.bossbar.BossFlag;
|
||||
import com.viaversion.viaversion.api.legacy.bossbar.BossStyle;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_8;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WitherBossBar implements BossBar {
|
||||
private static int highestId = Integer.MAX_VALUE - 10000;
|
||||
|
||||
private final UUID uuid;
|
||||
private String title;
|
||||
private float health;
|
||||
private boolean visible = false;
|
||||
|
||||
private final UserConnection connection;
|
||||
|
||||
private final int entityId = highestId++;
|
||||
private double locX, locY, locZ;
|
||||
|
||||
public WitherBossBar(UserConnection connection, UUID uuid, String title, float health) {
|
||||
this.connection = connection;
|
||||
this.uuid = uuid;
|
||||
this.title = title;
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setTitle(String title) {
|
||||
this.title = title;
|
||||
if (this.visible) {
|
||||
try {
|
||||
updateMetadata();
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to update wither boss bar title", e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setHealth(float health) {
|
||||
this.health = health;
|
||||
if (this.health <= 0) {
|
||||
this.health = 0.0001f;
|
||||
}
|
||||
if (this.visible) {
|
||||
try {
|
||||
updateMetadata();
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to update wither boss bar health", e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossColor getColor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setColor(BossColor bossColor) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support color");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossStyle getStyle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setStyle(BossStyle bossStyle) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support styles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addPlayer(UUID uuid) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addConnection(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removePlayer(UUID uuid) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removeConnection(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addFlag(BossFlag bossFlag) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support flags");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removeFlag(BossFlag bossFlag) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support flags");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFlag(BossFlag bossFlag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return Collections.singleton(connection.getProtocolInfo().getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar show() {
|
||||
if (!this.visible) {
|
||||
this.visible = true;
|
||||
try {
|
||||
spawnWither();
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to spawn wither boss bar", e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar hide() {
|
||||
if (this.visible) {
|
||||
this.visible = false;
|
||||
try {
|
||||
despawnWither();
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to despawn wither boss bar", e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setLocation(double x, double y, double z) throws Exception {
|
||||
locX = x;
|
||||
locY = y;
|
||||
locZ = z;
|
||||
updateLocation();
|
||||
}
|
||||
|
||||
private void spawnWither() throws Exception {
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x0F, null, this.connection);
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 64);
|
||||
wrapper.write(Type.INT, (int) (locX * 32d));
|
||||
wrapper.write(Type.INT, (int) (locY * 32d));
|
||||
wrapper.write(Type.INT, (int) (locZ * 32d));
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
wrapper.write(Type.SHORT, (short) 0);
|
||||
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata(0, MetaType1_8.Byte, (byte) 0x20));
|
||||
metadata.add(new Metadata(2, MetaType1_8.String, title));
|
||||
metadata.add(new Metadata(3, MetaType1_8.Byte, (byte) 1));
|
||||
metadata.add(new Metadata(6, MetaType1_8.Float, health * 300f));
|
||||
|
||||
wrapper.write(Types1_8.METADATA_LIST, metadata);
|
||||
|
||||
wrapper.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
|
||||
private void updateLocation() throws Exception {
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x18, null, this.connection);
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Type.INT, (int) (locX * 32d));
|
||||
wrapper.write(Type.INT, (int) (locY * 32d));
|
||||
wrapper.write(Type.INT, (int) (locZ * 32d));
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.write(Type.BOOLEAN, false);
|
||||
|
||||
wrapper.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
|
||||
private void updateMetadata() throws Exception {
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x1C, null, this.connection);
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata(2, MetaType1_8.String, title));
|
||||
metadata.add(new Metadata(6, MetaType1_8.Float, health * 300f));
|
||||
|
||||
wrapper.write(Types1_8.METADATA_LIST, metadata);
|
||||
|
||||
wrapper.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
|
||||
private void despawnWither() throws Exception {
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x13, null, this.connection);
|
||||
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{entityId});
|
||||
|
||||
wrapper.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
|
||||
public void setPlayerLocation(double posX, double posY, double posZ, float yaw, float pitch) throws Exception {
|
||||
double yawR = Math.toRadians(yaw);
|
||||
double pitchR = Math.toRadians(pitch);
|
||||
|
||||
posX -= Math.cos(pitchR) * Math.sin(yawR) * 48;
|
||||
posY -= Math.sin(pitchR) * 48;
|
||||
posZ += Math.cos(pitchR) * Math.cos(yawR) * 48;
|
||||
|
||||
setLocation(posX, posY, posZ);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.metadata;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetaIndex;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MetaIndex1_8to1_9 {
|
||||
|
||||
private static final HashMap<Pair<EntityTypes1_10.EntityType, Integer>, MetaIndex> metadataRewrites = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (MetaIndex index : MetaIndex.values()) {
|
||||
metadataRewrites.put(new Pair<>(index.getClazz(), index.getNewIndex()), index);
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<MetaIndex> getIndex(final EntityType type, final int index) {
|
||||
final Pair<EntityType, Integer> pair = new Pair<>(type, index);
|
||||
if (metadataRewrites.containsKey(pair)) {
|
||||
return Optional.of(metadataRewrites.get(pair));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public static MetaIndex searchIndex(final EntityType type, final int index) {
|
||||
EntityType currentType = type;
|
||||
do {
|
||||
final Optional<MetaIndex> optMeta = getIndex(currentType, index);
|
||||
if (optMeta.isPresent()) {
|
||||
return optMeta.get();
|
||||
}
|
||||
currentType = currentType.getParent();
|
||||
} while (currentType != null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-337
@@ -1,337 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.metadata;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.rewriter.VREntityRewriter;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.EntityTracker1_9;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.EulerAngle;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
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.version.Types1_8;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetaIndex;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MetadataRewriter1_8To1_9 extends VREntityRewriter<ClientboundPackets1_9, Protocol1_8To1_9> {
|
||||
|
||||
private static final byte HAND_ACTIVE_BIT = 0;
|
||||
private static final byte STATUS_USE_BIT = 4;
|
||||
|
||||
public MetadataRewriter1_8To1_9(Protocol1_8To1_9 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerJoinGame1_8(ClientboundPackets1_9.JOIN_GAME);
|
||||
registerRemoveEntities(ClientboundPackets1_9.DESTROY_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_9.ENTITY_METADATA, Types1_9.METADATA_LIST, Types1_8.METADATA_LIST);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
read(Type.UUID); // Entity UUID
|
||||
map(Type.BYTE); // Entity type
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
map(Type.BYTE); // Pitch
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.INT); // Data
|
||||
|
||||
// Track entity
|
||||
handler(getObjectTrackerHandler());
|
||||
handler(getObjectRewriter(id -> EntityTypes1_10.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
final int entityType = wrapper.get(Type.BYTE, 0);
|
||||
final EntityTypes1_10.EntityType type = EntityTypes1_10.getTypeFromId(entityType, true);
|
||||
|
||||
// Cancel new entities which can't be handled properly
|
||||
if (type == EntityTypes1_10.EntityType.AREA_EFFECT_CLOUD || type == EntityTypes1_10.EntityType.SPECTRAL_ARROW || type == EntityTypes1_10.EntityType.DRAGON_FIREBALL) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.is(EntityTypes1_10.EntityType.BOAT)) {
|
||||
byte yaw = wrapper.get(Type.BYTE, 1);
|
||||
yaw -= 64;
|
||||
wrapper.set(Type.BYTE, 1, yaw);
|
||||
|
||||
int y = wrapper.get(Type.INT, 1);
|
||||
y += 10;
|
||||
wrapper.set(Type.INT, 1, y);
|
||||
}
|
||||
|
||||
int data = wrapper.get(Type.INT, 3);
|
||||
|
||||
if (type.isOrHasParent(EntityTypes1_10.EntityType.ARROW) && data != 0) {
|
||||
wrapper.set(Type.INT, 3, --data);
|
||||
}
|
||||
if (type.is(EntityTypes1_10.EntityType.FALLING_BLOCK)) {
|
||||
int blockId = data & 0xFFF;
|
||||
int blockData = data >> 12 & 0xF;
|
||||
IdAndData replace = protocol.getItemRewriter().handleBlock(blockId, blockData);
|
||||
if (replace != null) {
|
||||
wrapper.set(Type.INT, 3, replace.getId() | replace.getData() << 12);
|
||||
}
|
||||
}
|
||||
|
||||
if (data > 0) {
|
||||
wrapper.passthrough(Type.SHORT); // Velocity x
|
||||
wrapper.passthrough(Type.SHORT); // Velocity y
|
||||
wrapper.passthrough(Type.SHORT); // Velocity z
|
||||
} else {
|
||||
final short velocityX = wrapper.read(Type.SHORT);
|
||||
final short velocityY = wrapper.read(Type.SHORT);
|
||||
final short velocityZ = wrapper.read(Type.SHORT);
|
||||
|
||||
final PacketWrapper velocityPacket = PacketWrapper.create(ClientboundPackets1_8.ENTITY_VELOCITY, wrapper.user());
|
||||
velocityPacket.write(Type.VAR_INT, entityId);
|
||||
velocityPacket.write(Type.SHORT, velocityX);
|
||||
velocityPacket.write(Type.SHORT, velocityY);
|
||||
velocityPacket.write(Type.SHORT, velocityZ);
|
||||
velocityPacket.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_EXPERIENCE_ORB, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
map(Type.SHORT); // Count
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.user().getEntityTracker(Protocol1_8To1_9.class).addEntity(entityId, EntityTypes1_10.EntityType.EXPERIENCE_ORB);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_GLOBAL_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.BYTE); // Type
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.user().getEntityTracker(Protocol1_8To1_9.class).addEntity(entityId, EntityTypes1_10.EntityType.LIGHTNING);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_MOB, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
read(Type.UUID); // Entity UUID
|
||||
map(Type.UNSIGNED_BYTE); // Entity type
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.BYTE); // Pitch
|
||||
map(Type.BYTE); // Head pitch
|
||||
map(Type.SHORT); // Velocity x
|
||||
map(Type.SHORT); // Velocity y
|
||||
map(Type.SHORT); // Velocity z
|
||||
map(Types1_9.METADATA_LIST, Types1_8.METADATA_LIST); // Metadata
|
||||
|
||||
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
|
||||
handler(getMobSpawnRewriter(Types1_8.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_PAINTING, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
read(Type.UUID); // Entity UUID
|
||||
map(Type.STRING); // Title
|
||||
map(Type.POSITION1_8); // Position
|
||||
map(Type.BYTE, Type.UNSIGNED_BYTE); // Direction
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.user().getEntityTracker(Protocol1_8To1_9.class).addEntity(entityId, EntityTypes1_10.EntityType.PAINTING);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_PLAYER, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.UUID); // Player UUID
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.BYTE); // Pitch
|
||||
create(Type.SHORT, (short) 0); // Current item
|
||||
map(Types1_9.METADATA_LIST, Types1_8.METADATA_LIST); // Metadata
|
||||
|
||||
handler(getTrackerAndMetaHandler(Types1_8.METADATA_LIST, EntityTypes1_10.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Handle new entities
|
||||
mapEntityTypeWithData(EntityType.SHULKER, EntityType.MAGMA_CUBE).plainName();
|
||||
mapEntityTypeWithData(EntityType.SHULKER_BULLET, EntityType.WITCH).plainName();
|
||||
|
||||
// Metadata rewrite
|
||||
filter().handler((event, meta) -> {
|
||||
try {
|
||||
handleMetadata(event, meta);
|
||||
} catch (Exception e) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "An error occurred with entity metadata: " + meta, e);
|
||||
}
|
||||
event.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleMetadata(MetaHandlerEvent event, Metadata metadata) {
|
||||
final EntityTracker1_9 tracker = tracker(event.user());
|
||||
if (metadata.id() == MetaIndex.ENTITY_STATUS.getIndex()) {
|
||||
tracker.getStatus().put(event.entityId(), (Byte) metadata.value());
|
||||
}
|
||||
final MetaIndex metaIndex = MetaIndex1_8to1_9.searchIndex(event.entityType(), metadata.id());
|
||||
if (metaIndex == null) {
|
||||
// Almost certainly bad data, remove it
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (metaIndex.getOldType() == null || metaIndex.getNewType() == null) {
|
||||
if (metaIndex == MetaIndex.PLAYER_HAND) { // Player eating/aiming/drinking
|
||||
byte status = (byte) tracker.getStatus().getOrDefault(event.entityId(), 0);
|
||||
if ((((byte) metadata.value()) & 1 << HAND_ACTIVE_BIT) != 0) {
|
||||
status = (byte) (status | 1 << STATUS_USE_BIT);
|
||||
} else {
|
||||
status = (byte) (status & ~(1 << STATUS_USE_BIT));
|
||||
}
|
||||
event.createExtraMeta(new Metadata(MetaIndex.ENTITY_STATUS.getIndex(), MetaType1_8.Byte, status));
|
||||
}
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
metadata.setId(metaIndex.getIndex());
|
||||
metadata.setMetaTypeUnsafe(metaIndex.getOldType());
|
||||
|
||||
final Object value = metadata.getValue();
|
||||
switch (metaIndex.getNewType()) {
|
||||
case Byte:
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
metadata.setValue(value);
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Int) {
|
||||
metadata.setValue(((Byte) value).intValue());
|
||||
}
|
||||
break;
|
||||
case OptUUID:
|
||||
if (metaIndex.getOldType() != MetaType1_8.String) {
|
||||
event.cancel();
|
||||
break;
|
||||
}
|
||||
final UUID owner = (UUID) value;
|
||||
metadata.setValue(owner != null ? owner.toString() : "");
|
||||
break;
|
||||
case BlockID:
|
||||
event.cancel();
|
||||
event.createExtraMeta(new Metadata(metaIndex.getIndex(), MetaType1_8.Short, ((Integer) value).shortValue()));
|
||||
break;
|
||||
case VarInt:
|
||||
if (metaIndex.getOldType() == MetaType1_8.Byte) {
|
||||
metadata.setValue(((Integer) value).byteValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||
metadata.setValue(((Integer) value).shortValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_8.Int) {
|
||||
metadata.setValue(value);
|
||||
}
|
||||
break;
|
||||
case Float:
|
||||
case String:
|
||||
case Chat:
|
||||
metadata.setValue(value);
|
||||
break;
|
||||
case Boolean:
|
||||
final boolean bool = (Boolean) value;
|
||||
if (metaIndex == MetaIndex.AGEABLE_CREATURE_AGE) {
|
||||
metadata.setValue((byte) (bool ? -1 : 0));
|
||||
} else {
|
||||
metadata.setValue((byte) (bool ? 1 : 0));
|
||||
}
|
||||
break;
|
||||
case Slot:
|
||||
metadata.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) value));
|
||||
break;
|
||||
case Position:
|
||||
final Vector vector = (Vector) value;
|
||||
metadata.setValue(vector);
|
||||
break;
|
||||
case Vector3F:
|
||||
final EulerAngle angle = (EulerAngle) value;
|
||||
metadata.setValue(angle);
|
||||
break;
|
||||
default:
|
||||
event.cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(int type) {
|
||||
return EntityTypes1_10.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType objectTypeFromId(int type) {
|
||||
return EntityTypes1_10.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
-346
@@ -1,346 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
|
||||
import com.viaversion.viarewind.api.rewriter.VRBlockItemRewriter;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.data.PotionMappings;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.WindowTracker;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonParser;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter.potionNameFromDamage;
|
||||
|
||||
public class BlockItemPackets1_9 extends VRBlockItemRewriter<ClientboundPackets1_9, ServerboundPackets1_8, Protocol1_8To1_9> {
|
||||
|
||||
public final Set<String> VALID_ATTRIBUTES = new HashSet<>();
|
||||
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
|
||||
public BlockItemPackets1_9(Protocol1_8To1_9 protocol) {
|
||||
super(protocol, "1.9");
|
||||
|
||||
VALID_ATTRIBUTES.add("generic.maxHealth");
|
||||
VALID_ATTRIBUTES.add("generic.followRange");
|
||||
VALID_ATTRIBUTES.add("generic.knockbackResistance");
|
||||
VALID_ATTRIBUTES.add("generic.movementSpeed");
|
||||
VALID_ATTRIBUTES.add("generic.attackDamage");
|
||||
VALID_ATTRIBUTES.add("horse.jumpStrength");
|
||||
VALID_ATTRIBUTES.add("zombie.spawnReinforcements");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerBlockChange(ClientboundPackets1_9.BLOCK_CHANGE);
|
||||
registerMultiBlockChange(ClientboundPackets1_9.MULTI_BLOCK_CHANGE);
|
||||
registerCreativeInvAction(ServerboundPackets1_8.CREATIVE_INVENTORY_ACTION);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CLOSE_WINDOW, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
||||
final WindowTracker tracker = wrapper.user().get(WindowTracker.class);
|
||||
|
||||
final String windowType = tracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:enchanting_table")) {
|
||||
tracker.clearEnchantmentProperties();
|
||||
}
|
||||
tracker.remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.OPEN_WINDOW, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
final String windowType = wrapper.passthrough(Type.STRING);
|
||||
final JsonElement windowTitle = wrapper.passthrough(Type.COMPONENT);
|
||||
|
||||
wrapper.user().get(WindowTracker.class).put(windowId, windowType);
|
||||
|
||||
// TODO check
|
||||
if (windowType.equalsIgnoreCase("minecraft:shulker_box")) {
|
||||
wrapper.set(Type.STRING, 0, "minecraft:container");
|
||||
}
|
||||
if (windowTitle.toString().equalsIgnoreCase("{\"translate\":\"container.shulkerBox\"}")) {
|
||||
wrapper.set(Type.COMPONENT, 0, JsonParser.parseString("{\"text\":\"Shulker Box\"}"));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.WINDOW_ITEMS, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
|
||||
Item[] items = wrapper.read(Type.ITEM1_8_SHORT_ARRAY);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
|
||||
if (windowId == 0 && items.length == 46) {
|
||||
Item[] old = items;
|
||||
items = new Item[45];
|
||||
System.arraycopy(old, 0, items, 0, 45);
|
||||
} else {
|
||||
final String type = wrapper.user().get(WindowTracker.class).get(windowId);
|
||||
if (type != null && type.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
System.arraycopy(items, 0, wrapper.user().get(WindowTracker.class).getBrewingItems(windowId), 0, 4);
|
||||
WindowTracker.updateBrewingStand(wrapper.user(), items[4], windowId);
|
||||
Item[] old = items;
|
||||
items = new Item[old.length - 1];
|
||||
System.arraycopy(old, 0, items, 0, 4);
|
||||
System.arraycopy(old, 5, items, 4, old.length - 5);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.write(Type.ITEM1_8_SHORT_ARRAY, items);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SET_SLOT, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Type.UNSIGNED_BYTE).byteValue();
|
||||
final short slot = wrapper.passthrough(Type.SHORT);
|
||||
final Item item = wrapper.passthrough(Type.ITEM1_8);
|
||||
|
||||
handleItemToClient(wrapper.user(), item);
|
||||
if (windowId == 0 && slot == 45) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
final WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
|
||||
final String windowType = windowTracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
if (slot > 4) {
|
||||
wrapper.set(Type.SHORT, 0, (short) (slot - 1));
|
||||
} else if (slot == 4) {
|
||||
wrapper.cancel();
|
||||
WindowTracker.updateBrewingStand(wrapper.user(), wrapper.get(Type.ITEM1_8, 0), windowId);
|
||||
} else {
|
||||
windowTracker.getBrewingItems(windowId)[slot] = wrapper.get(Type.ITEM1_8, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CLOSE_WINDOW, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
wrapper.user().get(WindowTracker.class).remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CLICK_WINDOW, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.UNSIGNED_BYTE); // Window id
|
||||
map(Type.SHORT); // Slot
|
||||
map(Type.BYTE); // Button
|
||||
map(Type.SHORT); // Action number
|
||||
map(Type.BYTE, Type.VAR_INT); // Mode
|
||||
map(Type.ITEM1_8); // Clicked item
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
|
||||
handler(wrapper -> {
|
||||
final short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
final String windowType = wrapper.user().get(WindowTracker.class).get(windowId);
|
||||
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
final short slot = wrapper.get(Type.SHORT, 0);
|
||||
if (slot > 3) {
|
||||
wrapper.set(Type.SHORT, 0, (short) (slot + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.WINDOW_PROPERTY, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
short key = wrapper.read(Type.SHORT);
|
||||
short value = wrapper.read(Type.SHORT);
|
||||
|
||||
final WindowTracker tracker = wrapper.user().get(WindowTracker.class);
|
||||
final String windowType = tracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:enchanting_table")) {
|
||||
if (key >= 4 && key <= 6) { // Store enchantment ids
|
||||
tracker.putEnchantmentProperty(key, value);
|
||||
wrapper.cancel();
|
||||
} else if (key >= 7 && key <= 9) { // Mix levels with tracked ids
|
||||
key -= 3;
|
||||
final short property = tracker.getEnchantmentValue(key);
|
||||
value = (short) (property | (value << 8));
|
||||
}
|
||||
}
|
||||
wrapper.write(Type.SHORT, key);
|
||||
wrapper.write(Type.SHORT, value);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(9, "§7Frost Walker");
|
||||
enchantmentRewriter.registerEnchantment(70, "§7Mending");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
}
|
||||
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
|
||||
CompoundTag displayTag = tag.get("display");
|
||||
if (item.data() != 0 && tag.contains("Unbreakable")) {
|
||||
final ByteTag unbreakableTag = tag.get("Unbreakable");
|
||||
if (unbreakableTag != null && unbreakableTag.asByte() != 0) {
|
||||
tag.put(nbtTagName() + "|Unbreakable", new ByteTag(unbreakableTag.asByte()));
|
||||
tag.remove("Unbreakable");
|
||||
|
||||
if (displayTag == null) { // Remove the display tag again if it was only added to emulate unbreakable
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag());
|
||||
}
|
||||
|
||||
ListTag<StringTag> loreTag = displayTag.getListTag("Lore", StringTag.class);
|
||||
if (loreTag == null) {
|
||||
displayTag.put("Lore", loreTag = new ListTag<>(StringTag.class));
|
||||
}
|
||||
loreTag.add(new StringTag("§9Unbreakable"));
|
||||
}
|
||||
}
|
||||
|
||||
if (item.identifier() == 383 && item.data() == 0) { // Spawn eggs
|
||||
int data = 0;
|
||||
final CompoundTag entityTag = tag.getCompoundTag("EntityTag");
|
||||
if (entityTag != null) {
|
||||
final StringTag idTag = entityTag.getStringTag("id");
|
||||
if (idTag != null) {
|
||||
final String id = idTag.getValue();
|
||||
if (ItemRewriter.ENTITY_NAME_TO_ID.containsKey(id)) {
|
||||
data = ItemRewriter.ENTITY_NAME_TO_ID.get(id);
|
||||
} else if (displayTag == null) {
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag());
|
||||
displayTag.put("Name", new StringTag("§rSpawn " + id));
|
||||
}
|
||||
}
|
||||
}
|
||||
item.setData((short) data);
|
||||
}
|
||||
|
||||
// Potion, splash potion, lingering potion
|
||||
final boolean potion = item.identifier() == 373;
|
||||
final boolean splashPotion = item.identifier() == 438;
|
||||
final boolean lingeringPotion = item.identifier() == 441;
|
||||
|
||||
if (potion || splashPotion || lingeringPotion) {
|
||||
int data = 0;
|
||||
final StringTag potionTag = tag.getStringTag("Potion");
|
||||
if (potionTag != null) {
|
||||
String potionName = Key.stripMinecraftNamespace(potionTag.getValue());
|
||||
if (PotionMappings.POTION_NAME_TO_ID.containsKey(potionName)) {
|
||||
data = PotionMappings.POTION_NAME_TO_ID.get(potionName);
|
||||
}
|
||||
if (splashPotion) {
|
||||
potionName += "_splash";
|
||||
} else if (lingeringPotion) {
|
||||
potionName += "_lingering";
|
||||
}
|
||||
// Don't override custom name
|
||||
if ((displayTag == null || !displayTag.contains("Name")) && PotionMappings.POTION_NAME_INDEX.containsKey(potionName)) {
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag());
|
||||
displayTag.put("Name", new StringTag(PotionMappings.POTION_NAME_INDEX.get(potionName)));
|
||||
}
|
||||
}
|
||||
if (splashPotion || lingeringPotion) { // Convert splash and lingering potions to normal potions
|
||||
item.setIdentifier(373);
|
||||
data += 8192;
|
||||
}
|
||||
|
||||
item.setData((short) data);
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> attributeModifiers = tag.getListTag("AttributeModifiers", CompoundTag.class);
|
||||
if (attributeModifiers != null) {
|
||||
tag.put(nbtTagName() + "|AttributeModifiers", attributeModifiers.copy());
|
||||
attributeModifiers.getValue().removeIf(entries -> {
|
||||
final StringTag nameTag = entries.getStringTag("AttributeName");
|
||||
return nameTag != null && !VALID_ATTRIBUTES.contains(nameTag.getValue());
|
||||
});
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
}
|
||||
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
|
||||
if (item.identifier() == 383 && item.data() != 0) { // Spawn eggs
|
||||
if (!tag.contains("EntityTag") && ItemRewriter.ENTITY_ID_TO_NAME.containsKey((int) item.data())) {
|
||||
final CompoundTag entityTag = new CompoundTag();
|
||||
entityTag.put("id", new StringTag(ItemRewriter.ENTITY_ID_TO_NAME.get((int) item.data())));
|
||||
tag.put("EntityTag", entityTag);
|
||||
}
|
||||
item.setData((short) 0);
|
||||
}
|
||||
|
||||
if (item.identifier() == 373 && !tag.contains("Potion")) { // Potions
|
||||
if (item.data() >= 16384) {
|
||||
item.setIdentifier(438);
|
||||
item.setData((short) (item.data() - 8192));
|
||||
}
|
||||
|
||||
final String name = item.data() == 8192 ? "water" : potionNameFromDamage(item.data());
|
||||
tag.put("Potion", new StringTag("minecraft:" + name));
|
||||
item.setData((short) 0);
|
||||
}
|
||||
|
||||
final Tag noDisplayTag = tag.remove(nbtTagName() + "|noDisplay");
|
||||
if (noDisplayTag != null) {
|
||||
tag.remove("display");
|
||||
}
|
||||
final Tag unbreakableTag = tag.remove(nbtTagName() + "|Unbreakable");
|
||||
if (unbreakableTag != null) {
|
||||
tag.put("Unbreakable", unbreakableTag);
|
||||
}
|
||||
final Tag attributeModifiersTag = tag.remove(nbtTagName() + "|AttributeModifiers");
|
||||
if (attributeModifiersTag != null) {
|
||||
tag.put("AttributeModifiers", attributeModifiersTag);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
-333
@@ -1,333 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.packets;
|
||||
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.CooldownStorage;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.EntityTracker1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.LevitationStorage;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.PlayerPositionTracker;
|
||||
import com.viaversion.viarewind.utils.math.RelativeMoveUtil;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
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.libs.fastutil.ints.IntArrayList;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntList;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EntityPackets1_9 {
|
||||
|
||||
public static void register(final Protocol1_8To1_9 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_STATUS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // Entity id
|
||||
handler(wrapper -> {
|
||||
final byte status = wrapper.read(Type.BYTE);
|
||||
if (status > 23) { // Remove op permission level 0-4 (24-28)
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.write(Type.BYTE, status);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_POSITION, wrapper -> {
|
||||
final int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
final int deltaX = wrapper.read(Type.SHORT);
|
||||
final int deltaY = wrapper.read(Type.SHORT);
|
||||
final int deltaZ = wrapper.read(Type.SHORT);
|
||||
|
||||
final Vector[] moves = RelativeMoveUtil.calculateRelativeMoves(wrapper.user(), entityId, deltaX, deltaY, deltaZ);
|
||||
|
||||
wrapper.write(Type.BYTE, (byte) moves[0].blockX());
|
||||
wrapper.write(Type.BYTE, (byte) moves[0].blockY());
|
||||
wrapper.write(Type.BYTE, (byte) moves[0].blockZ());
|
||||
|
||||
final boolean onGround = wrapper.passthrough(Type.BOOLEAN);
|
||||
|
||||
if (moves.length > 1) {
|
||||
final PacketWrapper secondPacket = PacketWrapper.create(ClientboundPackets1_8.ENTITY_POSITION, wrapper.user());
|
||||
secondPacket.write(Type.VAR_INT, entityId);
|
||||
secondPacket.write(Type.BYTE, (byte) moves[1].blockX());
|
||||
secondPacket.write(Type.BYTE, (byte) moves[1].blockY());
|
||||
secondPacket.write(Type.BYTE, (byte) moves[1].blockZ());
|
||||
secondPacket.write(Type.BOOLEAN, onGround);
|
||||
|
||||
secondPacket.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_POSITION_AND_ROTATION, wrapper -> {
|
||||
final int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
final int deltaX = wrapper.read(Type.SHORT);
|
||||
final int deltaY = wrapper.read(Type.SHORT);
|
||||
final int deltaZ = wrapper.read(Type.SHORT);
|
||||
|
||||
final Vector[] moves = RelativeMoveUtil.calculateRelativeMoves(wrapper.user(), entityId, deltaX, deltaY, deltaZ);
|
||||
|
||||
wrapper.write(Type.BYTE, (byte) moves[0].blockX());
|
||||
wrapper.write(Type.BYTE, (byte) moves[0].blockY());
|
||||
wrapper.write(Type.BYTE, (byte) moves[0].blockZ());
|
||||
|
||||
byte yaw = wrapper.passthrough(Type.BYTE);
|
||||
final byte pitch = wrapper.passthrough(Type.BYTE);
|
||||
final boolean onGround = wrapper.passthrough(Type.BOOLEAN);
|
||||
|
||||
EntityType type = wrapper.user().getEntityTracker(Protocol1_8To1_9.class).entityType(entityId);
|
||||
if (type == EntityTypes1_10.EntityType.BOAT) {
|
||||
yaw -= 64;
|
||||
wrapper.set(Type.BYTE, 3, yaw);
|
||||
}
|
||||
|
||||
if (moves.length > 1) {
|
||||
final PacketWrapper secondPacket = PacketWrapper.create(ClientboundPackets1_8.ENTITY_POSITION_AND_ROTATION, wrapper.user());
|
||||
secondPacket.write(Type.VAR_INT, entityId);
|
||||
secondPacket.write(Type.BYTE, (byte) moves[1].blockX());
|
||||
secondPacket.write(Type.BYTE, (byte) moves[1].blockY());
|
||||
secondPacket.write(Type.BYTE, (byte) moves[1].blockZ());
|
||||
secondPacket.write(Type.BYTE, yaw);
|
||||
secondPacket.write(Type.BYTE, pitch);
|
||||
secondPacket.write(Type.BOOLEAN, onGround);
|
||||
|
||||
secondPacket.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_ROTATION, wrapper -> {
|
||||
final int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
final EntityType type = wrapper.user().getEntityTracker(Protocol1_8To1_9.class).entityType(entityId);
|
||||
if (type == EntityTypes1_10.EntityType.BOAT) {
|
||||
byte yaw = wrapper.read(Type.BYTE);
|
||||
yaw -= 64;
|
||||
wrapper.write(Type.BYTE, yaw);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.VEHICLE_MOVE, ClientboundPackets1_8.ENTITY_TELEPORT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
final int vehicle = tracker.getVehicle(tracker.clientEntityId());
|
||||
if (vehicle == -1) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, vehicle);
|
||||
});
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
map(Type.FLOAT, Protocol1_8To1_9.DEGREES_TO_ANGLE); // Yaw
|
||||
map(Type.FLOAT, Protocol1_8To1_9.DEGREES_TO_ANGLE); // Pitch
|
||||
handler(wrapper -> {
|
||||
if (wrapper.isCancelled()) return;
|
||||
final PlayerPositionTracker position = wrapper.user().get(PlayerPositionTracker.class);
|
||||
double x = wrapper.get(Type.INT, 0) / 32d;
|
||||
double y = wrapper.get(Type.INT, 1) / 32d;
|
||||
double z = wrapper.get(Type.INT, 2) / 32d;
|
||||
position.setPos(x, y, z);
|
||||
});
|
||||
create(Type.BOOLEAN, true);
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
final EntityType type = wrapper.user().getEntityTracker(Protocol1_8To1_9.class).entityType(entityId);
|
||||
if (type == EntityTypes1_10.EntityType.BOAT) {
|
||||
byte yaw = wrapper.get(Type.BYTE, 1);
|
||||
yaw -= 64;
|
||||
wrapper.set(Type.BYTE, 0, yaw);
|
||||
int y = wrapper.get(Type.INT, 1);
|
||||
y += 10;
|
||||
wrapper.set(Type.INT, 1, y);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.REMOVE_ENTITY_EFFECT, wrapper -> {
|
||||
final int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
final int effectId = wrapper.passthrough(Type.BYTE);
|
||||
if (effectId > 23) { // Throw away new effects
|
||||
wrapper.cancel();
|
||||
}
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
if (effectId == 25 && entityId == tracker.clientEntityId()) {
|
||||
wrapper.user().get(LevitationStorage.class).setActive(false);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ATTACH_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // Attached entity id
|
||||
map(Type.INT); // Holding entity id
|
||||
create(Type.BOOLEAN, true); // Leash
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_EQUIPMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
handler(wrapper -> {
|
||||
// todo check if this is correct for the own player
|
||||
int slot = wrapper.read(Type.VAR_INT);
|
||||
if (slot == 1) {
|
||||
wrapper.cancel();
|
||||
} else if (slot > 1) {
|
||||
slot -= 1;
|
||||
}
|
||||
wrapper.write(Type.SHORT, (short) slot);
|
||||
});
|
||||
map(Type.ITEM1_8); // Item
|
||||
handler(wrapper -> protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SET_PASSENGERS, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
final int vehicle = wrapper.read(Type.VAR_INT);
|
||||
final IntList oldPassengers = tracker.getPassengers(vehicle);
|
||||
|
||||
final int count = wrapper.read(Type.VAR_INT);
|
||||
final IntList passengers = new IntArrayList();
|
||||
for (int i = 0; i < count; i++) {
|
||||
passengers.add(wrapper.read(Type.VAR_INT));
|
||||
}
|
||||
tracker.setPassengers(vehicle, passengers);
|
||||
|
||||
if (!oldPassengers.isEmpty()) {
|
||||
for (Integer passenger : oldPassengers) {
|
||||
final PacketWrapper detach = PacketWrapper.create(ClientboundPackets1_8.ATTACH_ENTITY, wrapper.user());
|
||||
detach.write(Type.INT, passenger); // Attached entity id
|
||||
detach.write(Type.INT, -1); // Holding entity id
|
||||
detach.write(Type.BOOLEAN, false); // Leash
|
||||
detach.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
final int attachedEntityId = passengers.getInt(i);
|
||||
final int holdingEntityId = i == 0 ? vehicle : passengers.getInt(i - 1);
|
||||
|
||||
final PacketWrapper attach = PacketWrapper.create(ClientboundPackets1_8.ATTACH_ENTITY, wrapper.user());
|
||||
attach.write(Type.INT, attachedEntityId);
|
||||
attach.write(Type.INT, holdingEntityId);
|
||||
attach.write(Type.BOOLEAN, false); // Leash
|
||||
attach.scheduleSend(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_TELEPORT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Entity id
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // X
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Y
|
||||
map(Type.DOUBLE, Protocol1_8To1_9.DOUBLE_TO_INT_TIMES_32); // Z
|
||||
map(Type.BYTE); // Yaw
|
||||
map(Type.BYTE); // Pitch
|
||||
map(Type.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
final int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
if (tracker.entityType(entityId) == EntityTypes1_10.EntityType.BOAT) {
|
||||
byte yaw = wrapper.get(Type.BYTE, 1);
|
||||
yaw -= 64;
|
||||
wrapper.set(Type.BYTE, 0, yaw);
|
||||
|
||||
int y = wrapper.get(Type.INT, 1);
|
||||
y += 10;
|
||||
wrapper.set(Type.INT, 1, y);
|
||||
}
|
||||
tracker.resetEntityOffset(entityId);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_PROPERTIES, wrapper -> {
|
||||
final int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
final boolean player = entityId == tracker.clientEntityId();
|
||||
|
||||
// Throw away new attributes and track attack speed
|
||||
int removed = 0;
|
||||
final int size = wrapper.passthrough(Type.INT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
final String key = wrapper.read(Type.STRING);
|
||||
final double value = wrapper.read(Type.DOUBLE);
|
||||
final int modifierSize = wrapper.read(Type.VAR_INT);
|
||||
|
||||
final boolean valid = protocol.getItemRewriter().VALID_ATTRIBUTES.contains(key);
|
||||
if (valid) {
|
||||
wrapper.write(Type.STRING, key);
|
||||
wrapper.write(Type.DOUBLE, value);
|
||||
wrapper.write(Type.VAR_INT, modifierSize);
|
||||
}
|
||||
|
||||
final List<Pair<Byte, Double>> modifiers = new ArrayList<>();
|
||||
for (int j = 0; j < modifierSize; j++) {
|
||||
final UUID modifierId = wrapper.read(Type.UUID); // UUID
|
||||
final double amount = wrapper.read(Type.DOUBLE); // Amount
|
||||
final byte operation = wrapper.read(Type.BYTE); // Operation
|
||||
if (valid) {
|
||||
wrapper.write(Type.UUID, modifierId);
|
||||
wrapper.write(Type.DOUBLE, amount);
|
||||
wrapper.write(Type.BYTE, operation);
|
||||
}
|
||||
modifiers.add(new Pair<>(operation, amount));
|
||||
}
|
||||
if (!valid) {
|
||||
if (player && key.equals("generic.attackSpeed")) {
|
||||
wrapper.user().get(CooldownStorage.class).setAttackSpeed(value, modifiers);
|
||||
}
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
wrapper.set(Type.INT, 0, size - removed);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.ENTITY_EFFECT, wrapper -> {
|
||||
final int entityId = wrapper.passthrough(Type.VAR_INT);
|
||||
final int effectId = wrapper.passthrough(Type.BYTE);
|
||||
final byte amplifier = wrapper.passthrough(Type.BYTE);
|
||||
if (effectId > 23) { // Throw away new effects
|
||||
wrapper.cancel();
|
||||
}
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
if (effectId == 25 && entityId == tracker.clientEntityId()) {
|
||||
final LevitationStorage levitation = wrapper.user().get(LevitationStorage.class);
|
||||
levitation.setActive(true);
|
||||
levitation.setAmplifier(amplifier);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-537
@@ -1,537 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.packets;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.storage.*;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_8;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerPackets1_9 {
|
||||
|
||||
public static void register(final Protocol1_8To1_9 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BOSSBAR, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
final BossBarStorage bossbar = wrapper.user().get(BossBarStorage.class);
|
||||
|
||||
final UUID uuid = wrapper.read(Type.UUID);
|
||||
final int action = wrapper.read(Type.VAR_INT);
|
||||
if (action == 0 /* add */) {
|
||||
final JsonElement title = wrapper.read(Type.COMPONENT);
|
||||
final float health = wrapper.read(Type.FLOAT);
|
||||
wrapper.read(Type.VAR_INT); // Color
|
||||
wrapper.read(Type.VAR_INT); // Division
|
||||
wrapper.read(Type.UNSIGNED_BYTE); // Flags
|
||||
|
||||
bossbar.add(uuid, ChatUtil.jsonToLegacy(wrapper.user(), title), health);
|
||||
} else if (action == 1 /* remove */) {
|
||||
bossbar.remove(uuid);
|
||||
} else if (action == 2 /* update health */) {
|
||||
final float health = wrapper.read(Type.FLOAT);
|
||||
bossbar.updateHealth(uuid, health);
|
||||
} else if (action == 3 /* update title */) {
|
||||
final JsonElement title = wrapper.read(Type.COMPONENT);
|
||||
bossbar.updateTitle(uuid, ChatUtil.jsonToLegacy(wrapper.user(), title));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.TEAMS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Team name
|
||||
map(Type.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
final byte mode = wrapper.get(Type.BYTE, 0);
|
||||
if (mode == 0 /* create team */ || mode == 2 /* update team info */) {
|
||||
wrapper.passthrough(Type.STRING); // Display name
|
||||
wrapper.passthrough(Type.STRING); // Prefix
|
||||
wrapper.passthrough(Type.STRING); // Suffix
|
||||
wrapper.passthrough(Type.BYTE); // Friendly fire
|
||||
wrapper.passthrough(Type.STRING); // Name tag visibility
|
||||
wrapper.read(Type.STRING); // Collision rule
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_9.COOLDOWN);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Type.STRING, 0);
|
||||
if (channel.equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Window id
|
||||
|
||||
int size;
|
||||
if (wrapper.isReadable(Type.BYTE, 0)) {
|
||||
size = wrapper.passthrough(Type.BYTE);
|
||||
} else {
|
||||
size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
final ItemRewriter<?> itemRewriter = protocol.getItemRewriter();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.write(Type.ITEM1_8, itemRewriter.handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Buy item 1
|
||||
wrapper.write(Type.ITEM1_8, itemRewriter.handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Buy item 3
|
||||
|
||||
boolean has3Items = wrapper.passthrough(Type.BOOLEAN);
|
||||
if (has3Items) {
|
||||
wrapper.write(Type.ITEM1_8, itemRewriter.handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Buy item 2
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); //Unavailable
|
||||
wrapper.passthrough(Type.INT); //Uses
|
||||
wrapper.passthrough(Type.INT); //Max Uses
|
||||
}
|
||||
} else if (channel.equals("MC|BOpen")) {
|
||||
wrapper.read(Type.VAR_INT);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.DOUBLE); // X
|
||||
map(Type.DOUBLE); // Feet y
|
||||
map(Type.DOUBLE); // Z
|
||||
map(Type.FLOAT); // Yaw
|
||||
map(Type.FLOAT); // Pitch
|
||||
map(Type.BYTE); // Relative arguments
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
|
||||
pos.setConfirmId(wrapper.read(Type.VAR_INT));
|
||||
|
||||
byte flags = wrapper.get(Type.BYTE, 0);
|
||||
double x = wrapper.get(Type.DOUBLE, 0);
|
||||
double y = wrapper.get(Type.DOUBLE, 1);
|
||||
double z = wrapper.get(Type.DOUBLE, 2);
|
||||
float yaw = wrapper.get(Type.FLOAT, 0);
|
||||
float pitch = wrapper.get(Type.FLOAT, 1);
|
||||
|
||||
wrapper.set(Type.BYTE, 0, (byte) 0);
|
||||
|
||||
if (flags != 0) {
|
||||
if ((flags & 0x01) != 0) {
|
||||
x += pos.getPosX();
|
||||
wrapper.set(Type.DOUBLE, 0, x);
|
||||
}
|
||||
if ((flags & 0x02) != 0) {
|
||||
y += pos.getPosY();
|
||||
wrapper.set(Type.DOUBLE, 1, y);
|
||||
}
|
||||
if ((flags & 0x04) != 0) {
|
||||
z += pos.getPosZ();
|
||||
wrapper.set(Type.DOUBLE, 2, z);
|
||||
}
|
||||
if ((flags & 0x08) != 0) {
|
||||
yaw += pos.getYaw();
|
||||
wrapper.set(Type.FLOAT, 0, yaw);
|
||||
}
|
||||
if ((flags & 0x10) != 0) {
|
||||
pitch += pos.getPitch();
|
||||
wrapper.set(Type.FLOAT, 1, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
pos.setPos(x, y, z);
|
||||
pos.setYaw(yaw);
|
||||
pos.setPitch(pitch);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.RESPAWN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // Dimension
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).reset());
|
||||
handler(wrapper -> {
|
||||
final ClientWorld world = wrapper.user().get(ClientWorld.class);
|
||||
world.setEnvironment(wrapper.get(Type.INT, 0));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CHAT_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Message
|
||||
handler(wrapper -> {
|
||||
if (!ViaRewind.getConfig().isEnableOffhand()) {
|
||||
return;
|
||||
}
|
||||
final String msg = wrapper.get(Type.STRING, 0);
|
||||
if (msg.toLowerCase().trim().startsWith(ViaRewind.getConfig().getOffhandCommand())) {
|
||||
wrapper.cancel();
|
||||
final PacketWrapper swapItems = PacketWrapper.create(ServerboundPackets1_9.PLAYER_DIGGING, wrapper.user());
|
||||
swapItems.write(Type.VAR_INT, 6);
|
||||
swapItems.write(Type.POSITION1_8, new Position(0, 0, 0));
|
||||
swapItems.write(Type.BYTE, (byte) 255);
|
||||
|
||||
swapItems.sendToServer(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.INTERACT_ENTITY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT); // Target
|
||||
map(Type.VAR_INT); // Type
|
||||
handler(wrapper -> {
|
||||
final int type = wrapper.get(Type.VAR_INT, 1);
|
||||
if (type == 2 /* attack */) {
|
||||
wrapper.passthrough(Type.FLOAT); // Target x
|
||||
wrapper.passthrough(Type.FLOAT); // Target y
|
||||
wrapper.passthrough(Type.FLOAT); // Target z
|
||||
}
|
||||
if (type == 2 /* attack */ || type == 0 /* interact */) {
|
||||
wrapper.write(Type.VAR_INT, 0); // Hand
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_MOVEMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(PlayerPositionTracker.class).sendAnimations();
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
if (tracker.isInsideVehicle(tracker.clientEntityId())) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.DOUBLE); // X
|
||||
map(Type.DOUBLE); // Feet y
|
||||
map(Type.DOUBLE); // Z
|
||||
map(Type.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(PlayerPositionTracker.class).sendAnimations();
|
||||
|
||||
final PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
if (pos.getConfirmId() != -1) {
|
||||
return;
|
||||
}
|
||||
pos.setPos(wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2));
|
||||
pos.setOnGround(wrapper.get(Type.BOOLEAN, 0));
|
||||
});
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).updateLocation());
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_ROTATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.FLOAT);
|
||||
map(Type.FLOAT);
|
||||
map(Type.BOOLEAN);
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(PlayerPositionTracker.class).sendAnimations();
|
||||
|
||||
PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
if (pos.getConfirmId() != -1) return;
|
||||
pos.setYaw(wrapper.get(Type.FLOAT, 0));
|
||||
pos.setPitch(wrapper.get(Type.FLOAT, 1));
|
||||
pos.setOnGround(wrapper.get(Type.BOOLEAN, 0));
|
||||
});
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).updateLocation());
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_POSITION_AND_ROTATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.DOUBLE);
|
||||
map(Type.DOUBLE);
|
||||
map(Type.DOUBLE);
|
||||
map(Type.FLOAT);
|
||||
map(Type.FLOAT);
|
||||
map(Type.BOOLEAN);
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(PlayerPositionTracker.class).sendAnimations();
|
||||
|
||||
double x = wrapper.get(Type.DOUBLE, 0);
|
||||
double y = wrapper.get(Type.DOUBLE, 1);
|
||||
double z = wrapper.get(Type.DOUBLE, 2);
|
||||
float yaw = wrapper.get(Type.FLOAT, 0);
|
||||
float pitch = wrapper.get(Type.FLOAT, 1);
|
||||
boolean onGround = wrapper.get(Type.BOOLEAN, 0);
|
||||
|
||||
PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
if (pos.getConfirmId() != -1) {
|
||||
if (pos.getPosX() == x && pos.getPosY() == y && pos.getPosZ() == z
|
||||
&& pos.getYaw() == yaw && pos.getPitch() == pitch) {
|
||||
PacketWrapper confirmTeleport = wrapper.create(0x00);
|
||||
confirmTeleport.write(Type.VAR_INT, pos.getConfirmId());
|
||||
confirmTeleport.sendToServer(Protocol1_8To1_9.class);
|
||||
|
||||
pos.setConfirmId(-1);
|
||||
}
|
||||
} else {
|
||||
pos.setPos(x, y, z);
|
||||
pos.setYaw(yaw);
|
||||
pos.setPitch(pitch);
|
||||
pos.setOnGround(onGround);
|
||||
wrapper.user().get(BossBarStorage.class).updateLocation();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_DIGGING, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.POSITION1_8);
|
||||
handler(wrapper -> {
|
||||
int state = wrapper.get(Type.VAR_INT, 0);
|
||||
if (state == 0) {
|
||||
wrapper.user().get(BlockPlaceDestroyTracker.class).setMining();
|
||||
} else if (state == 2) {
|
||||
BlockPlaceDestroyTracker tracker = wrapper.user().get(BlockPlaceDestroyTracker.class);
|
||||
tracker.setMining();
|
||||
tracker.setLastMining(System.currentTimeMillis() + 100);
|
||||
wrapper.user().get(CooldownStorage.class).setLastHit(0);
|
||||
} else if (state == 1) {
|
||||
BlockPlaceDestroyTracker tracker = wrapper.user().get(BlockPlaceDestroyTracker.class);
|
||||
tracker.setMining();
|
||||
tracker.setLastMining(0);
|
||||
wrapper.user().get(CooldownStorage.class).hit();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_BLOCK_PLACEMENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8);
|
||||
map(Type.BYTE, Type.VAR_INT);
|
||||
read(Type.ITEM1_8);
|
||||
create(Type.VAR_INT, 0); //Main Hand
|
||||
map(Type.BYTE, Type.UNSIGNED_BYTE);
|
||||
map(Type.BYTE, Type.UNSIGNED_BYTE);
|
||||
map(Type.BYTE, Type.UNSIGNED_BYTE);
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Type.VAR_INT, 0) == -1) {
|
||||
wrapper.cancel();
|
||||
PacketWrapper useItem = PacketWrapper.create(0x1D, null, wrapper.user());
|
||||
useItem.write(Type.VAR_INT, 0);
|
||||
|
||||
useItem.sendToServer(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.HELD_ITEM_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> wrapper.user().get(CooldownStorage.class).hit());
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.ANIMATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
|
||||
/* We have to add ArmAnimation to a queue to be sent on PacketPlayInFlying. In 1.9,
|
||||
* PacketPlayInArmAnimation is sent after PacketPlayInUseEntity, not before like it used to be.
|
||||
* However, all packets are sent before PacketPlayInFlying. We'd just do a normal delay, but
|
||||
* it would cause the packet to be sent after PacketPlayInFlying, potentially false flagging
|
||||
* anticheats that check for this behavior from clients. Since all packets are sent before
|
||||
* PacketPlayInFlying, if we queue it to be sent right before PacketPlayInFlying is processed,
|
||||
* we can be certain it will be sent after PacketPlayInUseEntity */
|
||||
wrapper.cancel();
|
||||
final PacketWrapper delayedPacket = PacketWrapper.create(0x1A, null, wrapper.user());
|
||||
delayedPacket.write(Type.VAR_INT, 0); //Main Hand
|
||||
|
||||
wrapper.user().get(PlayerPositionTracker.class).queueAnimation(delayedPacket);
|
||||
});
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(BlockPlaceDestroyTracker.class).updateMining();
|
||||
wrapper.user().get(CooldownStorage.class).hit();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.ENTITY_ACTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.VAR_INT);
|
||||
map(Type.VAR_INT);
|
||||
handler(wrapper -> {
|
||||
int action = wrapper.get(Type.VAR_INT, 1);
|
||||
if (action == 6) {
|
||||
wrapper.set(Type.VAR_INT, 1, 7);
|
||||
} else if (action == 0) {
|
||||
PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
if (!pos.isOnGround()) {
|
||||
PacketWrapper elytra = PacketWrapper.create(0x14, null, wrapper.user());
|
||||
elytra.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
|
||||
elytra.write(Type.VAR_INT, 8);
|
||||
elytra.write(Type.VAR_INT, 0);
|
||||
elytra.scheduleSendToServer(Protocol1_8To1_9.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.STEER_VEHICLE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.FLOAT);
|
||||
map(Type.FLOAT);
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
handler(wrapper -> {
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
|
||||
final int vehicle = tracker.getVehicle(tracker.clientEntityId());
|
||||
if (vehicle != -1 && tracker.entityType(vehicle) == EntityTypes1_10.EntityType.BOAT) {
|
||||
PacketWrapper steerBoat = PacketWrapper.create(0x11, null, wrapper.user());
|
||||
float left = wrapper.get(Type.FLOAT, 0);
|
||||
float forward = wrapper.get(Type.FLOAT, 1);
|
||||
steerBoat.write(Type.BOOLEAN, forward != 0.0f || left < 0.0f);
|
||||
steerBoat.write(Type.BOOLEAN, forward != 0.0f || left > 0.0f);
|
||||
steerBoat.scheduleSendToServer(Protocol1_8To1_9.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.UPDATE_SIGN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8);
|
||||
handler(wrapper -> {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
wrapper.write(Type.STRING, ChatUtil.jsonToLegacy(wrapper.user(), wrapper.read(Type.COMPONENT)));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.TAB_COMPLETE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
create(Type.BOOLEAN, false);
|
||||
map(Type.OPTIONAL_POSITION1_8);
|
||||
}
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CLIENT_SETTINGS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
map(Type.BYTE);
|
||||
map(Type.BYTE, Type.VAR_INT);
|
||||
map(Type.BOOLEAN);
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
create(Type.VAR_INT, 1);
|
||||
handler(wrapper -> {
|
||||
short flags = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
|
||||
PacketWrapper updateSkin = PacketWrapper.create(0x1C, null, wrapper.user());
|
||||
updateSkin.write(Type.VAR_INT, wrapper.user().getEntityTracker(Protocol1_8To1_9.class).clientEntityId());
|
||||
|
||||
ArrayList<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata(10, MetaType1_8.Byte, (byte) flags));
|
||||
|
||||
updateSkin.write(Types1_8.METADATA_LIST, metadata);
|
||||
|
||||
updateSkin.scheduleSend(Protocol1_8To1_9.class);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = wrapper.get(Type.STRING, 0);
|
||||
if (channel.equals("MC|BEdit") || channel.equals("MC|BSign")) {
|
||||
Item book = wrapper.passthrough(Type.ITEM);
|
||||
book.setIdentifier(386);
|
||||
CompoundTag tag = book.tag();
|
||||
if (tag.contains("pages")) {
|
||||
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages.size() > ViaRewind.getConfig().getMaxBookPages()) {
|
||||
wrapper.user().disconnect("Too many book pages");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < pages.size(); i++) {
|
||||
StringTag page = pages.get(i);
|
||||
String value = page.getValue();
|
||||
if (value.length() > ViaRewind.getConfig().getMaxBookPageSize()) {
|
||||
wrapper.user().disconnect("Book page too large");
|
||||
return;
|
||||
}
|
||||
value = ChatUtil.jsonToLegacy(wrapper.user(), value);
|
||||
page.setValue(value);
|
||||
}
|
||||
}
|
||||
} else if (channel.equals("MC|AdvCdm")) {
|
||||
wrapper.set(Type.STRING, 0, "MC|AdvCmd");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-272
@@ -1,272 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
|
||||
* Copyright (C) 2018-2024 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.viarewind.protocol.protocol1_8to1_9.packets;
|
||||
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viarewind.protocol.protocol1_8to1_9.data.EffectMappings;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
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.chunk.ChunkType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WorldPackets1_9 {
|
||||
|
||||
public static void register(Protocol1_8To1_9 protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8); // Position
|
||||
map(Type.UNSIGNED_BYTE); // Action
|
||||
map(Type.NAMED_COMPOUND_TAG); // Tag
|
||||
handler(wrapper -> {
|
||||
final CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
|
||||
final CompoundTag spawnData = tag.remove("SpawnData");
|
||||
if (spawnData != null) {
|
||||
final StringTag id = spawnData.remove("id");
|
||||
if (id != null) {
|
||||
tag.put("EntityId", id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BLOCK_ACTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8);
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
map(Type.VAR_INT);
|
||||
handler(wrapper -> {
|
||||
int block = wrapper.get(Type.VAR_INT, 0);
|
||||
if (block >= 219 && block <= 234) {
|
||||
wrapper.set(Type.VAR_INT, 0, 130);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.NAMED_SOUND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING);
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
name = protocol.getMappingData().getMappedNamedSound(name);
|
||||
if (name == null) {
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.set(Type.STRING, 0, name);
|
||||
}
|
||||
});
|
||||
read(Type.VAR_INT);
|
||||
map(Type.INT);
|
||||
map(Type.INT);
|
||||
map(Type.INT);
|
||||
map(Type.FLOAT);
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.UNLOAD_CHUNK, ClientboundPackets1_8.CHUNK_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final Environment environment = wrapper.user().get(ClientWorld.class).getEnvironment();
|
||||
|
||||
final int chunkX = wrapper.read(Type.INT);
|
||||
final int chunkZ = wrapper.read(Type.INT);
|
||||
|
||||
wrapper.write(ChunkType1_8.forEnvironment(environment), new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>()));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CHUNK_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final Environment environment = wrapper.user().get(ClientWorld.class).getEnvironment();
|
||||
|
||||
Chunk chunk = wrapper.read(ChunkType1_9_1.forEnvironment(environment));
|
||||
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) continue;
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int block = palette.idByIndex(i);
|
||||
int replacedBlock = protocol.getItemRewriter().handleBlockId(block);
|
||||
palette.setIdByIndex(i, replacedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.isFullChunk() && chunk.getBitmask() == 0) { //This would be an unload packet for 1.8 clients. Just set one air section
|
||||
boolean skylight = environment == Environment.NORMAL;
|
||||
ChunkSection[] sections = new ChunkSection[16];
|
||||
ChunkSection section = new ChunkSectionImpl(true);
|
||||
sections[0] = section;
|
||||
section.palette(PaletteType.BLOCKS).addId(0);
|
||||
if (skylight) section.getLight().setSkyLight(new byte[2048]);
|
||||
chunk = new BaseChunk(chunk.getX(), chunk.getZ(), true, false, 1, sections, chunk.getBiomeData(), chunk.getBlockEntities());
|
||||
}
|
||||
|
||||
wrapper.write(ChunkType1_8.forEnvironment(environment), chunk);
|
||||
|
||||
final UserConnection user = wrapper.user();
|
||||
chunk.getBlockEntities().forEach(nbt -> {
|
||||
if (!nbt.contains("x") || !nbt.contains("y") || !nbt.contains("z") || !nbt.contains("id"))
|
||||
return;
|
||||
Position position = new Position((int) nbt.get("x").getValue(), (int) nbt.get("y").getValue(), (int) nbt.get("z").getValue());
|
||||
String id = (String) nbt.get("id").getValue();
|
||||
|
||||
short action;
|
||||
switch (id) {
|
||||
case "minecraft:mob_spawner":
|
||||
action = 1;
|
||||
break;
|
||||
case "minecraft:command_block":
|
||||
action = 2;
|
||||
break;
|
||||
case "minecraft:beacon":
|
||||
action = 3;
|
||||
break;
|
||||
case "minecraft:skull":
|
||||
action = 4;
|
||||
break;
|
||||
case "minecraft:flower_pot":
|
||||
action = 5;
|
||||
break;
|
||||
case "minecraft:banner":
|
||||
action = 6;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
PacketWrapper updateTileEntity = PacketWrapper.create(0x09, null, user);
|
||||
updateTileEntity.write(Type.POSITION1_8, position);
|
||||
updateTileEntity.write(Type.UNSIGNED_BYTE, action);
|
||||
updateTileEntity.write(Type.NBT, nbt);
|
||||
|
||||
try {
|
||||
updateTileEntity.scheduleSend(Protocol1_8To1_9.class, false);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().warning("Error sending tile entity update packet: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.EFFECT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT);
|
||||
map(Type.POSITION1_8);
|
||||
map(Type.INT);
|
||||
map(Type.BOOLEAN);
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
id = EffectMappings.getOldId(id);
|
||||
if (id == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.set(Type.INT, 0, id);
|
||||
if (id == 2001) {
|
||||
int replacedBlock = protocol.getItemRewriter().handleBlockId(wrapper.get(Type.INT, 1));
|
||||
wrapper.set(Type.INT, 1, replacedBlock);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SPAWN_PARTICLE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT);
|
||||
handler(wrapper -> {
|
||||
int type = wrapper.get(Type.INT, 0);
|
||||
if (type > 41 && !ViaRewind.getConfig().isReplaceParticles()) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
if (type == 42) { // Dragon Breath
|
||||
wrapper.set(Type.INT, 0, 24); // Portal
|
||||
} else if (type == 43) { // End Rod
|
||||
wrapper.set(Type.INT, 0, 3); // Firework Spark
|
||||
} else if (type == 44) { // Damage Indicator
|
||||
wrapper.set(Type.INT, 0, 34); // Heart
|
||||
} else if (type == 45) { // Sweep Attack
|
||||
wrapper.set(Type.INT, 0, 1); // Large Explosion
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.MAP_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.BYTE);
|
||||
read(Type.BOOLEAN);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SOUND, ClientboundPackets1_8.NAMED_SOUND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int soundId = wrapper.read(Type.VAR_INT);
|
||||
final String soundName = protocol.getMappingData().soundName(soundId);
|
||||
if (soundName == null) {
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.write(Type.STRING, protocol.getMappingData().getMappedNamedSound(soundName));
|
||||
}
|
||||
});
|
||||
read(Type.VAR_INT);
|
||||
map(Type.INT);
|
||||
map(Type.INT);
|
||||
map(Type.INT);
|
||||
map(Type.FLOAT);
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loaded 100 of 193 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user