Initial commit

This commit is contained in:
RaphiMC 2023-01-03 23:54:35 +01:00
parent 67bf1469af
commit d8f7c62aa4
337 changed files with 70965 additions and 0 deletions

9
.gitattributes vendored Normal file
View File

@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf
# These are Windows script files and should use crlf
*.bat text eol=crlf

6
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "daily"

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
# Compiled class file
*.class
# Log file
*.log
*.log.gz
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Project files
/.idea/
/.gradle/
/build/
/out/

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# ViaLegacy
ViaVersion addon to add support for EVERY minecraft server version (Classic, Alpha, Beta, Release, April Fools).
## Supported Server versions
- Classic (c0.0.15 - c0.30 including [CPE](https://wiki.vg/Classic_Protocol_Extension))
- Alpha (a1.0.15 - a1.2.6)
- Beta (b1.0 - b1.8.1)
- Release (1.0.0 - 1.7.10)
- April Fools (3D Shareware, 20w14infinite)
- Combat Snapshots (Combat Test 8c)
## Releases
### Gradle/Maven
To use ViaLegacy with Gradle/Maven you can use this [Maven server](https://maven.lenni0451.net/#/releases/net/raphimc/ViaLegacy) or [Jitpack](https://jitpack.io/#RaphiMC/ViaLegacy).
You can also find instructions how to implement it into your build script there.
### Jar File
If you just want the latest jar file you can download it from this [Jenkins](https://build.lenni0451.net/job/ViaLegacy/).
## Usage
TODO

63
build.gradle Normal file
View File

@ -0,0 +1,63 @@
plugins {
id "java-library"
id "maven-publish"
}
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
compileJava.options.encoding = "UTF-8"
group = project.maven_group
archivesBaseName = project.maven_name
version = project.maven_version
repositories {
mavenCentral()
maven {
name = "Lenni0451"
url "https://maven.lenni0451.net/releases"
}
maven {
name = "ViaVersion"
url "https://repo.viaversion.com"
}
}
dependencies {
compileOnly "com.viaversion:viaversion:4.5.2-SNAPSHOT"
compileOnly("com.viaversion:viabackwards-common:4.5.2-SNAPSHOT") {
exclude group: "com.viaversion", module: "viaversion"
}
compileOnly "org.yaml:snakeyaml:1.33"
//api "net.lenni0451.mcstructs:all:1.4.0" // Not yet used
}
java {
withSourcesJar()
withJavadocJar()
}
javadoc {
failOnError = false
}
publishing {
repositories {
maven {
name = "reposilite"
url = "https://maven.lenni0451.net/releases"
credentials(PasswordCredentials)
authentication {
basic(BasicAuthentication)
}
}
}
publications {
maven(MavenPublication) {
groupId = project.maven_group
artifactId = project.maven_name
version = project.maven_version
from components.java
}
}
}

9
gradle.properties Normal file
View File

@ -0,0 +1,9 @@
# Gradle properties
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
# Project properties
maven_name=ViaLegacy
maven_group=net.raphimc
maven_version=2.0.0

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

240
gradlew vendored Normal file
View File

@ -0,0 +1,240 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

91
gradlew.bat vendored Normal file
View File

@ -0,0 +1,91 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

8
settings.gradle Normal file
View File

@ -0,0 +1,8 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "ViaLegacy"

View File

@ -0,0 +1,29 @@
package net.raphimc.vialegacy;
import net.raphimc.vialegacy.platform.ViaLegacyConfig;
import net.raphimc.vialegacy.platform.ViaLegacyPlatform;
public class ViaLegacy {
private static ViaLegacyPlatform platform;
private static ViaLegacyConfig config;
private ViaLegacy() {
}
public static void init(final ViaLegacyPlatform platform, final ViaLegacyConfig config) {
if (ViaLegacy.platform != null) throw new IllegalStateException("ViaLegacy is already initialized");
ViaLegacy.platform = platform;
ViaLegacy.config = config;
}
public static ViaLegacyPlatform getPlatform() {
return ViaLegacy.platform;
}
public static ViaLegacyConfig getConfig() {
return ViaLegacy.config;
}
}

View File

@ -0,0 +1,102 @@
package net.raphimc.vialegacy;
import com.viaversion.viaversion.util.Config;
import java.io.File;
import java.net.URL;
import java.util.*;
public class ViaLegacyConfig extends Config implements net.raphimc.vialegacy.platform.ViaLegacyConfig {
private boolean dynamicOnground;
private boolean ignoreLongChannelNames;
private boolean legacySkullLoading;
private boolean legacySkinLoading;
private boolean soundEmulation;
private boolean oldBiomes;
private boolean remapBasedOnColor;
private int classicChunkRange;
private int chunksPerTick;
public ViaLegacyConfig(final File configFile) {
super(configFile);
}
@Override
public void reloadConfig() {
super.reloadConfig();
this.loadFields();
}
private void loadFields() {
this.dynamicOnground = this.getBoolean("dynamic-onground", true);
this.ignoreLongChannelNames = this.getBoolean("ignore-long-1_8-channel-names", true);
this.legacySkullLoading = this.getBoolean("legacy-skull-loading", true);
this.legacySkinLoading = this.getBoolean("legacy-skin-loading", false);
this.soundEmulation = this.getBoolean("sound-emulation", true);
this.oldBiomes = this.getBoolean("old-biomes", true);
this.remapBasedOnColor = this.getBoolean("remap-based-on-color", true);
this.classicChunkRange = this.getInt("classic-chunk-range", 10);
this.chunksPerTick = this.getInt("chunks-per-tick", -1);
}
@Override
public URL getDefaultConfigURL() {
return this.getClass().getClassLoader().getResource("assets/vialegacy/vialegacy.yml");
}
@Override
protected void handleConfig(Map<String, Object> map) {
}
@Override
public List<String> getUnsupportedOptions() {
return Collections.emptyList();
}
@Override
public boolean isDynamicOnground() {
return this.dynamicOnground;
}
@Override
public boolean isIgnoreLong1_8ChannelNames() {
return this.ignoreLongChannelNames;
}
@Override
public boolean isLegacySkullLoading() {
return this.legacySkullLoading;
}
@Override
public boolean isLegacySkinLoading() {
return this.legacySkinLoading;
}
@Override
public boolean isSoundEmulation() {
return this.soundEmulation;
}
@Override
public boolean isOldBiomes() {
return this.oldBiomes;
}
@Override
public boolean isRemapBasedOnColor() {
return this.remapBasedOnColor;
}
@Override
public int getClassicChunkRange() {
return this.classicChunkRange;
}
@Override
public int getChunksPerTick() {
return this.chunksPerTick;
}
}

View File

@ -0,0 +1,53 @@
package net.raphimc.vialegacy.api;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.chunks.*;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
public abstract class AbstractBlockRemapper {
private final Int2IntMap REPLACEMENTS = new Int2IntOpenHashMap();
protected void registerReplacement(final int from, final int to) {
this.REPLACEMENTS.put(from, to);
}
protected void registerReplacement(final IdAndData from, final IdAndData to) {
this.REPLACEMENTS.put(from.toCompressedData(), to.toCompressedData());
}
public void remapChunk(final Chunk chunk) {
for (int i = 0; i < chunk.getSections().length; i++) {
final ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
final DataPalette palette = section.palette(PaletteType.BLOCKS);
for (Int2IntMap.Entry entry : this.REPLACEMENTS.int2IntEntrySet()) {
palette.replaceId(entry.getIntKey(), entry.getIntValue());
}
}
}
public void remapBlockChangeRecords(final BlockChangeRecord[] blockChangeRecords) {
for (final BlockChangeRecord record : blockChangeRecords) {
final int id = record.getBlockId();
if (this.REPLACEMENTS.containsKey(id)) {
record.setBlockId(this.REPLACEMENTS.get(id));
}
}
}
public void remapBlock(final IdAndData block) {
if (this.REPLACEMENTS.containsKey(block.toCompressedData())) {
final int replacement = this.REPLACEMENTS.get(block.toCompressedData());
block.id = replacement >> 4;
block.data = replacement & 15;
}
}
public int remapBlock(final int id) {
return this.REPLACEMENTS.getOrDefault(id, id);
}
}

View File

@ -0,0 +1,201 @@
package net.raphimc.vialegacy.api;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.*;
import com.viaversion.viaversion.libs.fastutil.ints.*;
import java.util.*;
public abstract class AbstractChunkTracker extends StoredObject {
private final Map<ChunkCoord, Chunk> chunks = new HashMap<>();
private final IntSet toTrack = new IntOpenHashSet();
private final boolean trackAll;
private final Int2IntMap replacements = new Int2IntOpenHashMap();
public AbstractChunkTracker(final UserConnection user, final int... toTrack) {
super(user);
for (final int trackedBlock : toTrack) {
this.toTrack.add(trackedBlock);
}
this.trackAll = this.toTrack.contains(0);
}
public void trackAndRemap(final Chunk chunk) {
final ChunkCoord chunkCoord = new ChunkCoord(chunk.getX(), chunk.getZ());
if (chunk.isFullChunk() && chunk.getBitmask() == 0) {
this.chunks.remove(chunkCoord);
return;
}
final Chunk copyChunk = new BaseChunk(chunk.getX(), chunk.getZ(), true, false, 0xFFFF, new ChunkSection[chunk.getSections().length], null, new ArrayList<>());
if (!chunk.isFullChunk()) {
if (this.chunks.containsKey(chunkCoord)) {
copyChunk.setSections(this.chunks.get(chunkCoord).getSections());
} else {
return;
}
} else {
this.chunks.put(chunkCoord, copyChunk);
}
// Track
if (!this.toTrack.isEmpty()) {
for (int i = 0; i < chunk.getSections().length; i++) {
final ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
copyChunk.getSections()[i] = null;
final DataPalette palette = section.palette(PaletteType.BLOCKS);
if (!this.hasRemappableBlocks(palette)) continue;
final ChunkSection copySection = copyChunk.getSections()[i] = new ChunkSectionImpl(false);
final DataPalette copyPalette = copySection.palette(PaletteType.BLOCKS);
copyPalette.addId(0);
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
final int flatBlock = palette.idAt(x, y, z);
if (this.trackAll || this.toTrack.contains(flatBlock >> 4)) {
copyPalette.setIdAt(x, y, z, flatBlock);
}
}
}
}
}
}
// Remap
for (int i = 0; i < chunk.getSections().length; i++) {
final ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
final DataPalette palette = section.palette(PaletteType.BLOCKS);
for (Int2IntMap.Entry entry : this.replacements.int2IntEntrySet()) {
palette.replaceId(entry.getIntKey(), entry.getIntValue());
}
if (!this.hasRemappableBlocks(palette)) continue;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
final int flatBlock = palette.idAt(x, y, z);
if (this.trackAll || this.toTrack.contains(flatBlock >> 4)) {
final IdAndData block = IdAndData.fromCompressedData(flatBlock);
this.remapBlock(block, x + (chunk.getX() << 4), y + (i * 16), z + (chunk.getZ() << 4));
final int newFlatBlock = block.toCompressedData();
if (newFlatBlock != flatBlock) {
palette.setIdAt(x, y, z, newFlatBlock);
}
}
}
}
}
this.postRemap(palette);
}
}
public void trackAndRemap(final Position position, final IdAndData block) {
final int x = position.x();
final int y = position.y();
final int z = position.z();
final Chunk chunk = this.chunks.get(new ChunkCoord(x >> 4, z >> 4));
if (chunk != null && y >= 0 && y >> 4 < chunk.getSections().length) {
ChunkSection section = chunk.getSections()[y >> 4];
if (this.trackAll || this.toTrack.contains(block.id)) {
if (section == null) {
section = chunk.getSections()[y >> 4] = new ChunkSectionImpl(false);
section.palette(PaletteType.BLOCKS).addId(0);
}
section.palette(PaletteType.BLOCKS).setIdAt(x & 15, y & 15, z & 15, block.toCompressedData());
} else if (section != null) {
section.palette(PaletteType.BLOCKS).setIdAt(x & 15, y & 15, z & 15, 0);
}
}
if (this.replacements.containsKey(block.toCompressedData())) {
final int newFlatBlock = this.replacements.get(block.toCompressedData());
block.id = newFlatBlock >> 4;
block.data = newFlatBlock & 15;
}
if (this.trackAll || this.toTrack.contains(block.id)) {
this.remapBlock(block, x, y, z);
}
}
public void remapBlockParticle(final IdAndData block) {
if (this.replacements.containsKey(block.toCompressedData())) {
final int newFlatBlock = this.replacements.get(block.toCompressedData());
block.id = newFlatBlock >> 4;
block.data = newFlatBlock & 15;
}
if (this.trackAll || this.toTrack.contains(block.id)) {
this.remapBlock(block, 0, -16, 0);
}
}
public void clear() {
this.chunks.clear();
}
public boolean isChunkLoaded(final int chunkX, final int chunkZ) {
return this.chunks.containsKey(new ChunkCoord(chunkX, chunkZ));
}
public IdAndData getBlockNotNull(final Position position) {
return this.getBlockNotNull(position.x(), position.y(), position.z());
}
public IdAndData getBlockNotNull(final int x, final int y, final int z) {
IdAndData block = this.getBlock(x, y, z);
if (block == null) block = new IdAndData(0, 0);
return block;
}
public IdAndData getBlock(final Position position) {
return this.getBlock(position.x(), position.y(), position.z());
}
public IdAndData getBlock(final int x, final int y, final int z) {
final Chunk chunk = this.chunks.get(new ChunkCoord(x >> 4, z >> 4));
if (chunk != null) {
if (y < 0 || y >> 4 > chunk.getSections().length - 1) return null;
final ChunkSection section = chunk.getSections()[y >> 4];
if (section != null) {
return IdAndData.fromCompressedData(section.palette(PaletteType.BLOCKS).idAt(x & 15, y & 15, z & 15));
}
}
return null;
}
protected void registerReplacement(final IdAndData from, final IdAndData to) {
this.replacements.put(from.toCompressedData(), to.toCompressedData());
}
protected void remapBlock(final IdAndData block, final int x, final int y, final int z) {
}
protected void postRemap(final DataPalette palette) {
}
private boolean hasRemappableBlocks(final DataPalette palette) {
if (this.trackAll) return true;
if (this.toTrack.isEmpty()) return false;
boolean hasTrackableBlocks = false;
for (int i = 0; i < palette.size(); i++) {
if (this.toTrack.contains(palette.idByIndex(i) >> 4)) {
hasTrackableBlocks = true;
}
}
return hasTrackableBlocks;
}
}

View File

@ -0,0 +1,171 @@
package net.raphimc.vialegacy.api;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.fastutil.objects.ObjectArrayList;
import com.viaversion.viaversion.libs.fastutil.objects.ObjectList;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
import java.util.List;
public abstract class AbstractItemRewriter {
private final ObjectList<RewriteEntry> REWRITE_ENTRIES = new ObjectArrayList<>();
protected final String HACK_TAG_NAME;
protected final String protocolName;
private final boolean jsonName;
public AbstractItemRewriter(final String protocolName, final boolean jsonName) {
this.HACK_TAG_NAME = protocolName.replace(".", "_") + "_ProtocolHack_" + System.currentTimeMillis();
this.protocolName = protocolName;
this.jsonName = jsonName;
}
protected void registerRemappedItem(final int oldItemId, final int newItemId, final String newItemName) {
registerRemappedItem(oldItemId, newItemId, -1, newItemName);
}
protected void registerRemappedItem(final int oldItemId, final int newItemId, final int newItemMeta, final String newItemName) {
registerRemappedItem(oldItemId, -1, newItemId, newItemMeta, newItemName);
}
protected void registerRemappedItem(final int oldItemId, final int oldItemMeta, final int newItemId, final int newItemMeta, final String newItemName) {
REWRITE_ENTRIES.add(new RewriteEntry(oldItemId, (short) oldItemMeta, newItemId, (short) newItemMeta, newItemName));
}
public void rewriteRead(final Item item) {
if (item == null) return;
for (RewriteEntry rewriteEntry : REWRITE_ENTRIES) {
if (rewriteEntry.rewrites(item)) {
setRemappedNameRead(item, rewriteEntry.newItemName);
if (rewriteEntry.newItemMeta != -1) {
item.setData(rewriteEntry.newItemMeta);
}
item.setIdentifier(rewriteEntry.newItemID);
}
}
}
public void rewriteWrite(final Item item) {
if (item == null) return;
setRemappedTagWrite(item);
}
private void setRemappedNameRead(final Item item, final String name) {
//Set protocol hack tag for later remapping
CompoundTag protocolHackTag = (item.tag() != null && item.tag().contains(HACK_TAG_NAME) ? item.tag().get(HACK_TAG_NAME) : new CompoundTag());
if (item.tag() == null || !item.tag().contains(HACK_TAG_NAME)) {
protocolHackTag.put("Id", new IntTag(item.identifier()));
protocolHackTag.put("Meta", new ShortTag(item.data()));
}
//Get Item tag
CompoundTag tag = item.tag();
if (tag == null) {
tag = new CompoundTag();
item.setTag(tag);
protocolHackTag.put("RemoveTag", new IntTag(0));
}
tag.put(HACK_TAG_NAME, protocolHackTag);
//Set name/lore of item
CompoundTag display = tag.get("display");
if (display == null) {
display = new CompoundTag();
tag.put("display", display);
protocolHackTag.put("RemoveDisplayTag", new IntTag(0));
}
if (display.contains("Name")) {
ListTag lore = display.get("Lore");
if (lore == null) {
lore = new ListTag();
display.put("Lore", lore);
protocolHackTag.put("RemoveLore", new IntTag(0));
}
if (this.jsonName) {
lore.add(new StringTag(this.messageToJson("§r " + this.protocolName + " Item ID: " + item.identifier() + " (" + name + ")").toString()));
} else {
lore.add(new StringTag("§r " + this.protocolName + " Item ID: " + item.identifier() + " (" + name + ")"));
}
protocolHackTag.put("RemoveLastLore", new IntTag(0));
} else {
if (this.jsonName) {
display.put("Name", new StringTag(this.messageToJson("§r" + this.protocolName + " " + name).toString()));
} else {
display.put("Name", new StringTag("§r" + this.protocolName + " " + name));
}
protocolHackTag.put("RemoveDisplayName", new IntTag(0));
}
}
private void setRemappedTagWrite(final Item item) {
if (item.tag() == null) return;
if (!item.tag().contains(HACK_TAG_NAME)) return;
CompoundTag tag = item.tag();
CompoundTag protocolHackTag = tag.get(HACK_TAG_NAME);
tag.remove(HACK_TAG_NAME);
item.setIdentifier(((IntTag) protocolHackTag.get("Id")).asInt());
item.setData(((ShortTag) protocolHackTag.get("Meta")).asShort());
if (protocolHackTag.contains("RemoveLastLore")) {
ListTag lore = ((CompoundTag) tag.get("display")).get("Lore");
List<Tag> tags = lore.getValue();
tags.remove(lore.size() - 1);
lore.setValue(tags);
}
if (protocolHackTag.contains("RemoveLore")) {
((CompoundTag) tag.get("display")).remove("Lore");
}
if (protocolHackTag.contains("RemoveDisplayName")) {
((CompoundTag) tag.get("display")).remove("Name");
}
if (protocolHackTag.contains("RemoveDisplayTag")) {
tag.remove("display");
}
if (protocolHackTag.contains("RemoveTag")) {
item.setTag(null);
}
}
private JsonObject messageToJson(final String s) {
JsonObject ob = new JsonObject();
ob.addProperty("text", s);
return ob;
}
public static class RewriteEntry {
private final int oldItemID;
private final short oldItemMeta;
private final int newItemID;
private final short newItemMeta;
private final String newItemName;
public RewriteEntry(final int oldItemID, final short oldItemMeta, final int newItemID, final short newItemMeta, final String newItemName) {
this.oldItemID = oldItemID;
this.oldItemMeta = oldItemMeta;
this.newItemID = newItemID;
this.newItemMeta = newItemMeta;
this.newItemName = newItemName;
}
public int getOldItemID() {
return this.oldItemID;
}
public short getOldItemMeta() {
return this.oldItemMeta;
}
public boolean rewrites(final Item item) {
return item.identifier() == this.oldItemID && (this.oldItemMeta == -1 || this.oldItemMeta == item.data());
}
}
}

View File

@ -0,0 +1,207 @@
package net.raphimc.vialegacy.api;
import com.google.common.collect.Lists;
import java.util.List;
public class BlockList1_6 {
public static final List<Block1_6> blockList = Lists.newArrayList();
public static final Block1_6 stone = new Block1_6(1, "stone");
public static final Block1_6 grass = new Block1_6(2, "grass");
public static final Block1_6 dirt = new Block1_6(3, "dirt");
public static final Block1_6 cobblestone = new Block1_6(4, "stonebrick");
public static final Block1_6 planks = new Block1_6(5, "wood");
public static final Block1_6 sapling = new Block1_6(6, "sapling");
public static final Block1_6 bedrock = new Block1_6(7, "bedrock");
public static final Block1_6 waterMoving = new Block1_6(8, "water");
public static final Block1_6 waterStill = new Block1_6(9, "water");
public static final Block1_6 lavaMoving = new Block1_6(10, "lava");
public static final Block1_6 lavaStill = new Block1_6(11, "lava");
public static final Block1_6 sand = new Block1_6(12, "sand");
public static final Block1_6 gravel = new Block1_6(13, "gravel");
public static final Block1_6 oreGold = new Block1_6(14, "oreGold");
public static final Block1_6 oreIron = new Block1_6(15, "oreIron");
public static final Block1_6 oreCoal = new Block1_6(16, "oreCoal");
public static final Block1_6 wood = new Block1_6(17, "log");
public static final Block1_6 leaves = new Block1_6(18, "leaves");
public static final Block1_6 sponge = new Block1_6(19, "sponge");
public static final Block1_6 glass = new Block1_6(20, "glass");
public static final Block1_6 oreLapis = new Block1_6(21, "oreLapis");
public static final Block1_6 blockLapis = new Block1_6(22, "blockLapis");
public static final Block1_6 dispenser = new Block1_6(23, "dispenser");
public static final Block1_6 sandStone = new Block1_6(24, "sandStone");
public static final Block1_6 music = new Block1_6(25, "musicBlock");
public static final Block1_6 bed = new Block1_6(26, "bed");
public static final Block1_6 railPowered = new Block1_6(27, "goldenRail");
public static final Block1_6 railDetector = new Block1_6(28, "detectorRail");
public static final Block1_6 pistonStickyBase = new Block1_6(29, "pistonStickyBase");
public static final Block1_6 web = new Block1_6(30, "web");
public static final Block1_6 tallGrass = new Block1_6(31, "tallgrass");
public static final Block1_6 deadBush = new Block1_6(32, "deadbush");
public static final Block1_6 pistonBase = new Block1_6(33, "pistonBase");
public static final Block1_6 pistonExtension = new Block1_6(34, "null");
public static final Block1_6 cloth = new Block1_6(35, "cloth");
public static final Block1_6 pistonMoving = new Block1_6(36, "null");
public static final Block1_6 plantYellow = new Block1_6(37, "flower");
public static final Block1_6 plantRed = new Block1_6(38, "rose");
public static final Block1_6 mushroomBrown = new Block1_6(39, "mushroom");
public static final Block1_6 mushroomRed = new Block1_6(40, "mushroom");
public static final Block1_6 blockGold = new Block1_6(41, "blockGold");
public static final Block1_6 blockIron = new Block1_6(42, "blockIron");
public static final Block1_6 stoneDoubleSlab = new Block1_6(43, "stoneSlab");
public static final Block1_6 stoneSingleSlab = new Block1_6(44, "stoneSlab");
public static final Block1_6 brick = new Block1_6(45, "brick");
public static final Block1_6 tnt = new Block1_6(46, "tnt");
public static final Block1_6 bookShelf = new Block1_6(47, "bookshelf");
public static final Block1_6 cobblestoneMossy = new Block1_6(48, "stoneMoss");
public static final Block1_6 obsidian = new Block1_6(49, "obsidian");
public static final Block1_6 torchWood = new Block1_6(50, "torch");
public static final Block1_6 fire = new Block1_6(51, "fire");
public static final Block1_6 mobSpawner = new Block1_6(52, "mobSpawner");
public static final Block1_6 stairsWoodOak = new Block1_6(53, "stairsWood");
public static final Block1_6 chest = new Block1_6(54, "chest");
public static final Block1_6 redstoneWire = new Block1_6(55, "redstoneDust");
public static final Block1_6 oreDiamond = new Block1_6(56, "oreDiamond");
public static final Block1_6 blockDiamond = new Block1_6(57, "blockDiamond");
public static final Block1_6 workbench = new Block1_6(58, "workbench");
public static final Block1_6 crops = new Block1_6(59, "crops");
public static final Block1_6 tilledField = new Block1_6(60, "farmland");
public static final Block1_6 furnaceIdle = new Block1_6(61, "furnace");
public static final Block1_6 furnaceBurning = new Block1_6(62, "furnace");
public static final Block1_6 signPost = new Block1_6(63, "sign");
public static final Block1_6 doorWood = new Block1_6(64, "doorWood");
public static final Block1_6 ladder = new Block1_6(65, "ladder");
public static final Block1_6 rail = new Block1_6(66, "rail");
public static final Block1_6 stairsCobblestone = new Block1_6(67, "stairsStone");
public static final Block1_6 signWall = new Block1_6(68, "sign");
public static final Block1_6 lever = new Block1_6(69, "lever");
public static final Block1_6 pressurePlateStone = new Block1_6(70, "pressurePlate");
public static final Block1_6 doorIron = new Block1_6(71, "doorIron");
public static final Block1_6 pressurePlatePlanks = new Block1_6(72, "pressurePlate");
public static final Block1_6 oreRedstone = new Block1_6(73, "oreRedstone");
public static final Block1_6 oreRedstoneGlowing = new Block1_6(74, "oreRedstone");
public static final Block1_6 torchRedstoneIdle = new Block1_6(75, "notGate");
public static final Block1_6 torchRedstoneActive = new Block1_6(76, "notGate");
public static final Block1_6 stoneButton = new Block1_6(77, "button");
public static final Block1_6 snow = new Block1_6(78, "snow");
public static final Block1_6 ice = new Block1_6(79, "ice");
public static final Block1_6 blockSnow = new Block1_6(80, "snow");
public static final Block1_6 cactus = new Block1_6(81, "cactus");
public static final Block1_6 blockClay = new Block1_6(82, "clay");
public static final Block1_6 reed = new Block1_6(83, "reeds");
public static final Block1_6 jukebox = new Block1_6(84, "jukebox");
public static final Block1_6 fence = new Block1_6(85, "fence");
public static final Block1_6 pumpkin = new Block1_6(86, "pumpkin");
public static final Block1_6 netherrack = new Block1_6(87, "hellrock");
public static final Block1_6 slowSand = new Block1_6(88, "hellsand");
public static final Block1_6 glowStone = new Block1_6(89, "lightgem");
public static final Block1_6 portal = new Block1_6(90, "portal");
public static final Block1_6 pumpkinLantern = new Block1_6(91, "litpumpkin");
public static final Block1_6 cake = new Block1_6(92, "cake");
public static final Block1_6 redstoneRepeaterIdle = new Block1_6(93, "diode");
public static final Block1_6 redstoneRepeaterActive = new Block1_6(94, "diode");
public static final Block1_6 lockedChest = new Block1_6(95, "lockedchest");
public static final Block1_6 trapdoor = new Block1_6(96, "trapdoor");
public static final Block1_6 silverfish = new Block1_6(97, "monsterStoneEgg");
public static final Block1_6 stoneBrick = new Block1_6(98, "stonebricksmooth");
public static final Block1_6 mushroomCapBrown = new Block1_6(99, "mushroom");
public static final Block1_6 mushroomCapRed = new Block1_6(100, "mushroom");
public static final Block1_6 fenceIron = new Block1_6(101, "fenceIron");
public static final Block1_6 thinGlass = new Block1_6(102, "thinGlass");
public static final Block1_6 melon = new Block1_6(103, "melon");
public static final Block1_6 pumpkinStem = new Block1_6(104, "pumpkinStem");
public static final Block1_6 melonStem = new Block1_6(105, "pumpkinStem");
public static final Block1_6 vine = new Block1_6(106, "vine");
public static final Block1_6 fenceGate = new Block1_6(107, "fenceGate");
public static final Block1_6 stairsBrick = new Block1_6(108, "stairsBrick");
public static final Block1_6 stairsStoneBrick = new Block1_6(109, "stairsStoneBrickSmooth");
public static final Block1_6 mycelium = new Block1_6(110, "mycel");
public static final Block1_6 waterlily = new Block1_6(111, "waterlily");
public static final Block1_6 netherBrick = new Block1_6(112, "netherBrick");
public static final Block1_6 netherFence = new Block1_6(113, "netherFence");
public static final Block1_6 stairsNetherBrick = new Block1_6(114, "stairsNetherBrick");
public static final Block1_6 netherStalk = new Block1_6(115, "netherStalk");
public static final Block1_6 enchantmentTable = new Block1_6(116, "enchantmentTable");
public static final Block1_6 brewingStand = new Block1_6(117, "brewingStand");
public static final Block1_6 cauldron = new Block1_6(118, "cauldron");
public static final Block1_6 endPortal = new Block1_6(119, "null");
public static final Block1_6 endPortalFrame = new Block1_6(120, "endPortalFrame");
public static final Block1_6 whiteStone = new Block1_6(121, "whiteStone");
public static final Block1_6 dragonEgg = new Block1_6(122, "dragonEgg");
public static final Block1_6 redstoneLampIdle = new Block1_6(123, "redstoneLight");
public static final Block1_6 redstoneLampActive = new Block1_6(124, "redstoneLight");
public static final Block1_6 woodDoubleSlab = new Block1_6(125, "woodSlab");
public static final Block1_6 woodSingleSlab = new Block1_6(126, "woodSlab");
public static final Block1_6 cocoaPlant = new Block1_6(127, "cocoa");
public static final Block1_6 stairsSandStone = new Block1_6(128, "stairsSandStone");
public static final Block1_6 oreEmerald = new Block1_6(129, "oreEmerald");
public static final Block1_6 enderChest = new Block1_6(130, "enderChest");
public static final Block1_6 tripWireSource = new Block1_6(131, "tripWireSource");
public static final Block1_6 tripWire = new Block1_6(132, "tripWire");
public static final Block1_6 blockEmerald = new Block1_6(133, "blockEmerald");
public static final Block1_6 stairsWoodSpruce = new Block1_6(134, "stairsWoodSpruce");
public static final Block1_6 stairsWoodBirch = new Block1_6(135, "stairsWoodBirch");
public static final Block1_6 stairsWoodJungle = new Block1_6(136, "stairsWoodJungle");
public static final Block1_6 commandBlock = new Block1_6(137, "commandBlock");
public static final Block1_6 beacon = new Block1_6(138, "beacon");
public static final Block1_6 cobblestoneWall = new Block1_6(139, "cobbleWall");
public static final Block1_6 flowerPot = new Block1_6(140, "flowerPot");
public static final Block1_6 carrot = new Block1_6(141, "carrots");
public static final Block1_6 potato = new Block1_6(142, "potatoes");
public static final Block1_6 woodenButton = new Block1_6(143, "button");
public static final Block1_6 skull = new Block1_6(144, "skull");
public static final Block1_6 anvil = new Block1_6(145, "anvil");
public static final Block1_6 chestTrapped = new Block1_6(146, "chestTrap");
public static final Block1_6 pressurePlateGold = new Block1_6(147, "weightedPlate_light");
public static final Block1_6 pressurePlateIron = new Block1_6(148, "weightedPlate_heavy");
public static final Block1_6 redstoneComparatorIdle = new Block1_6(149, "comparator");
public static final Block1_6 redstoneComparatorActive = new Block1_6(150, "comparator");
public static final Block1_6 daylightSensor = new Block1_6(151, "daylightDetector");
public static final Block1_6 blockRedstone = new Block1_6(152, "blockRedstone");
public static final Block1_6 oreNetherQuartz = new Block1_6(153, "netherquartz");
public static final Block1_6 hopperBlock = new Block1_6(154, "hopper");
public static final Block1_6 blockNetherQuartz = new Block1_6(155, "quartzBlock");
public static final Block1_6 stairsNetherQuartz = new Block1_6(156, "stairsQuartz");
public static final Block1_6 railActivator = new Block1_6(157, "activatorRail");
public static final Block1_6 dropper = new Block1_6(158, "dropper");
public static final Block1_6 stainedClay = new Block1_6(159, "clayHardenedStained");
public static final Block1_6 hay = new Block1_6(170, "hayBlock");
public static final Block1_6 carpet = new Block1_6(171, "woolCarpet");
public static final Block1_6 hardenedClay = new Block1_6(172, "clayHardened");
public static final Block1_6 coalBlock = new Block1_6(173, "blockCoal");
public static Block1_6 getByID(final int id) {
for (Block1_6 block : blockList) {
if(block.blockID == id) {
return block;
}
}
return null;
}
public static Block1_6 getByName(final String name) {
for (Block1_6 block : blockList) {
if(block.name.equalsIgnoreCase(name)) {
return block;
}
}
return null;
}
public static class Block1_6 {
public final int blockID;
public final String name;
public Block1_6(final int blockID, final String name) {
this.blockID = blockID;
this.name = name;
blockList.add(this);
}
}
}

View File

@ -0,0 +1,50 @@
package net.raphimc.vialegacy.api;
import java.util.Objects;
public class ChunkCoord {
public int chunkX;
public int chunkZ;
public ChunkCoord(final int chunkX, final int chunkZ) {
this.chunkX = chunkX;
this.chunkZ = chunkZ;
}
public ChunkCoord(final long pos) {
this.chunkX = (int) pos;
this.chunkZ = (int) (pos >> 32);
}
public long toLong() {
return toLong(this.chunkX, this.chunkZ);
}
public static long toLong(final int chunkX, final int chunkZ) {
return (long) chunkX & 4294967295L | ((long) chunkZ & 4294967295L) << 32;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChunkCoord that = (ChunkCoord) o;
return chunkX == that.chunkX &&
chunkZ == that.chunkZ;
}
@Override
public int hashCode() {
return Objects.hash(chunkX, chunkZ);
}
@Override
public String toString() {
return "ChunkCoord{" +
"chunkX=" + chunkX +
", chunkZ=" + chunkZ +
'}';
}
}

View File

@ -0,0 +1,50 @@
package net.raphimc.vialegacy.api;
import java.util.Objects;
public class IdAndData {
public int id;
public int data;
public IdAndData(final int id, final int data) {
if (data < 0 || data > 15) throw new IllegalArgumentException("Block data out of bounds (id:" + id + " data:" + data + ")");
this.id = id;
this.data = data;
}
public static IdAndData fromCompressedData(final int idAndData) {
return new IdAndData(idAndData >> 4, idAndData & 15);
}
public static int toCompressedData(final int id, final int data) {
return id << 4 | data & 15;
}
public int toCompressedData() {
return toCompressedData(this.id, this.data);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IdAndData idAndData = (IdAndData) o;
return id == idAndData.id &&
data == idAndData.data;
}
@Override
public int hashCode() {
return Objects.hash(id, data);
}
@Override
public String toString() {
return "IdAndData{" +
"id=" + id +
", data=" + data +
'}';
}
}

View File

@ -0,0 +1,245 @@
package net.raphimc.vialegacy.api;
import com.google.common.collect.Lists;
import java.util.List;
public class ItemList1_6 {
public static final List<Item1_6> itemList = Lists.newArrayList();
public static final Item1_6 planks = new Item1_6(5, "wood", 0, true);
public static final Item1_6 sapling = new Item1_6(6, "sapling", 0, true);
public static final Item1_6 wood = new Item1_6(17, "log", 0, true);
public static final Item1_6 leaves = new Item1_6(18, "leaves", 0, true);
public static final Item1_6 sandStone = new Item1_6(24, "sandStone", 0, true);
public static final Item1_6 cloth = new Item1_6(35, "cloth", 0, true);
public static final Item1_6 stoneDoubleSlab = new Item1_6(43, "stoneSlab", 0, true);
public static final Item1_6 stoneSingleSlab = new Item1_6(44, "stoneSlab", 0, true);
public static final Item1_6 silverfish = new Item1_6(97, "monsterStoneEgg", 0, true);
public static final Item1_6 stoneBrick = new Item1_6(98, "stonebricksmooth", 0, true);
public static final Item1_6 woodDoubleSlab = new Item1_6(125, "woodSlab", 0, true);
public static final Item1_6 woodSingleSlab = new Item1_6(126, "woodSlab", 0, true);
public static final Item1_6 cobbleWall = new Item1_6(139, "cobbleWall", 0, true);
public static final Item1_6 anvil = new Item1_6(145, "anvil", 0, true);
public static final Item1_6 blockNetherQuartz = new Item1_6(155, "quartzBlock", 0, true);
public static final Item1_6 stainedClay = new Item1_6(159, "clayHardenedStained", 0, true);
public static final Item1_6 carpet = new Item1_6(171, "woolCarpet", 0, true);
public static final Item1_6 vine = new Item1_6(106, "vine", 0, true);
public static final Item1_6 tallGrass = new Item1_6(31, "tallGrass", 0, true);
public static final Item1_6 snow = new Item1_6(78, "snow", 0, true);
public static final Item1_6 waterlily = new Item1_6(111, "waterlily", 0, true);
public static final Item1_6 pistonBase = new Item1_6(33, "pistonBase", 0, true);
public static final Item1_6 pistonStickyBase = new Item1_6(29, "pistonStickyBase", 0, true);
public static final Item1_6 shovelIron = new Item1_6(256, "shovelIron", 250, false);
public static final Item1_6 pickaxeIron = new Item1_6(257, "pickaxeIron", 250, false);
public static final Item1_6 axeIron = new Item1_6(258, "hatchetIron", 250, false);
public static final Item1_6 flintAndSteel = new Item1_6(259, "flintAndSteel", 64, false);
public static final Item1_6 appleRed = new Item1_6(260, "apple", 0, false);
public static final Item1_6 bow = new Item1_6(261, "bow", 384, false);
public static final Item1_6 arrow = new Item1_6(262, "arrow", 0, false);
public static final Item1_6 coal = new Item1_6(263, "coal", 0, true);
public static final Item1_6 diamond = new Item1_6(264, "diamond", 0, false);
public static final Item1_6 ingotIron = new Item1_6(265, "ingotIron", 0, false);
public static final Item1_6 ingotGold = new Item1_6(266, "ingotGold", 0, false);
public static final Item1_6 swordIron = new Item1_6(267, "swordIron", 250, false);
public static final Item1_6 swordWood = new Item1_6(268, "swordWood", 59, false);
public static final Item1_6 shovelWood = new Item1_6(269, "shovelWood", 59, false);
public static final Item1_6 pickaxeWood = new Item1_6(270, "pickaxeWood", 59, false);
public static final Item1_6 axeWood = new Item1_6(271, "hatchetWood", 59, false);
public static final Item1_6 swordStone = new Item1_6(272, "swordStone", 131, false);
public static final Item1_6 shovelStone = new Item1_6(273, "shovelStone", 131, false);
public static final Item1_6 pickaxeStone = new Item1_6(274, "pickaxeStone", 131, false);
public static final Item1_6 axeStone = new Item1_6(275, "hatchetStone", 131, false);
public static final Item1_6 swordDiamond = new Item1_6(276, "swordDiamond", 1561, false);
public static final Item1_6 shovelDiamond = new Item1_6(277, "shovelDiamond", 1561, false);
public static final Item1_6 pickaxeDiamond = new Item1_6(278, "pickaxeDiamond", 1561, false);
public static final Item1_6 axeDiamond = new Item1_6(279, "hatchetDiamond", 1561, false);
public static final Item1_6 stick = new Item1_6(280, "stick", 0, false);
public static final Item1_6 bowlEmpty = new Item1_6(281, "bowl", 0, false);
public static final Item1_6 bowlSoup = new Item1_6(282, "mushroomStew", 0, false);
public static final Item1_6 swordGold = new Item1_6(283, "swordGold", 32, false);
public static final Item1_6 shovelGold = new Item1_6(284, "shovelGold", 32, false);
public static final Item1_6 pickaxeGold = new Item1_6(285, "pickaxeGold", 32, false);
public static final Item1_6 axeGold = new Item1_6(286, "hatchetGold", 32, false);
public static final Item1_6 silk = new Item1_6(287, "string", 0, false);
public static final Item1_6 feather = new Item1_6(288, "feather", 0, false);
public static final Item1_6 gunpowder = new Item1_6(289, "sulphur", 0, false);
public static final Item1_6 hoeWood = new Item1_6(290, "hoeWood", 59, false);
public static final Item1_6 hoeStone = new Item1_6(291, "hoeStone", 131, false);
public static final Item1_6 hoeIron = new Item1_6(292, "hoeIron", 250, false);
public static final Item1_6 hoeDiamond = new Item1_6(293, "hoeDiamond", 1561, false);
public static final Item1_6 hoeGold = new Item1_6(294, "hoeGold", 32, false);
public static final Item1_6 seeds = new Item1_6(295, "seeds", 0, false);
public static final Item1_6 wheat = new Item1_6(296, "wheat", 0, false);
public static final Item1_6 bread = new Item1_6(297, "bread", 0, false);
public static final Item1_6 helmetLeather = new Item1_6(298, "helmetCloth", 55, false);
public static final Item1_6 plateLeather = new Item1_6(299, "chestplateCloth", 80, false);
public static final Item1_6 legsLeather = new Item1_6(300, "leggingsCloth", 75, false);
public static final Item1_6 bootsLeather = new Item1_6(301, "bootsCloth", 65, false);
public static final Item1_6 helmetChain = new Item1_6(302, "helmetChain", 165, false);
public static final Item1_6 plateChain = new Item1_6(303, "chestplateChain", 240, false);
public static final Item1_6 legsChain = new Item1_6(304, "leggingsChain", 225, false);
public static final Item1_6 bootsChain = new Item1_6(305, "bootsChain", 195, false);
public static final Item1_6 helmetIron = new Item1_6(306, "helmetIron", 165, false);
public static final Item1_6 plateIron = new Item1_6(307, "chestplateIron", 240, false);
public static final Item1_6 legsIron = new Item1_6(308, "leggingsIron", 225, false);
public static final Item1_6 bootsIron = new Item1_6(309, "bootsIron", 195, false);
public static final Item1_6 helmetDiamond = new Item1_6(310, "helmetDiamond", 363, false);
public static final Item1_6 plateDiamond = new Item1_6(311, "chestplateDiamond", 528, false);
public static final Item1_6 legsDiamond = new Item1_6(312, "leggingsDiamond", 495, false);
public static final Item1_6 bootsDiamond = new Item1_6(313, "bootsDiamond", 429, false);
public static final Item1_6 helmetGold = new Item1_6(314, "helmetGold", 77, false);
public static final Item1_6 plateGold = new Item1_6(315, "chestplateGold", 112, false);
public static final Item1_6 legsGold = new Item1_6(316, "leggingsGold", 105, false);
public static final Item1_6 bootsGold = new Item1_6(317, "bootsGold", 91, false);
public static final Item1_6 flint = new Item1_6(318, "flint", 0, false);
public static final Item1_6 porkRaw = new Item1_6(319, "porkchopRaw", 0, false);
public static final Item1_6 porkCooked = new Item1_6(320, "porkchopCooked", 0, false);
public static final Item1_6 painting = new Item1_6(321, "painting", 0, false);
public static final Item1_6 appleGold = new Item1_6(322, "appleGold", 0, true);
public static final Item1_6 sign = new Item1_6(323, "sign", 0, false);
public static final Item1_6 doorWood = new Item1_6(324, "doorWood", 0, false);
public static final Item1_6 bucketEmpty = new Item1_6(325, "bucket", 0, false);
public static final Item1_6 bucketWater = new Item1_6(326, "bucketWater", 0, false);
public static final Item1_6 bucketLava = new Item1_6(327, "bucketLava", 0, false);
public static final Item1_6 minecartEmpty = new Item1_6(328, "minecart", 0, false);
public static final Item1_6 saddle = new Item1_6(329, "saddle", 0, false);
public static final Item1_6 doorIron = new Item1_6(330, "doorIron", 0, false);
public static final Item1_6 redstone = new Item1_6(331, "redstone", 0, false);
public static final Item1_6 snowball = new Item1_6(332, "snowball", 0, false);
public static final Item1_6 boat = new Item1_6(333, "boat", 0, false);
public static final Item1_6 leather = new Item1_6(334, "leather", 0, false);
public static final Item1_6 bucketMilk = new Item1_6(335, "milk", 0, false);
public static final Item1_6 brick = new Item1_6(336, "brick", 0, false);
public static final Item1_6 clay = new Item1_6(337, "clay", 0, false);
public static final Item1_6 reed = new Item1_6(338, "reeds", 0, false);
public static final Item1_6 paper = new Item1_6(339, "paper", 0, false);
public static final Item1_6 book = new Item1_6(340, "book", 0, false);
public static final Item1_6 slimeBall = new Item1_6(341, "slimeball", 0, false);
public static final Item1_6 minecartCrate = new Item1_6(342, "minecartChest", 0, false);
public static final Item1_6 minecartPowered = new Item1_6(343, "minecartFurnace", 0, false);
public static final Item1_6 egg = new Item1_6(344, "egg", 0, false);
public static final Item1_6 compass = new Item1_6(345, "compass", 0, false);
public static final Item1_6 fishingRod = new Item1_6(346, "fishingRod", 64, false);
public static final Item1_6 pocketSundial = new Item1_6(347, "clock", 0, false);
public static final Item1_6 glowstone = new Item1_6(348, "yellowDust", 0, false);
public static final Item1_6 fishRaw = new Item1_6(349, "fishRaw", 0, false);
public static final Item1_6 fishCooked = new Item1_6(350, "fishCooked", 0, false);
public static final Item1_6 dyePowder = new Item1_6(351, "dyePowder", 0, true);
public static final Item1_6 bone = new Item1_6(352, "bone", 0, false);
public static final Item1_6 sugar = new Item1_6(353, "sugar", 0, false);
public static final Item1_6 cake = new Item1_6(354, "cake", 0, false);
public static final Item1_6 bed = new Item1_6(355, "bed", 0, false);
public static final Item1_6 redstoneRepeater = new Item1_6(356, "diode", 0, false);
public static final Item1_6 cookie = new Item1_6(357, "cookie", 0, false);
public static final Item1_6 map = new Item1_6(358, "map", 0, true);
public static final Item1_6 shears = new Item1_6(359, "shears", 238, false);
public static final Item1_6 melon = new Item1_6(360, "melon", 0, false);
public static final Item1_6 pumpkinSeeds = new Item1_6(361, "seeds_pumpkin", 0, false);
public static final Item1_6 melonSeeds = new Item1_6(362, "seeds_melon", 0, false);
public static final Item1_6 beefRaw = new Item1_6(363, "beefRaw", 0, false);
public static final Item1_6 beefCooked = new Item1_6(364, "beefCooked", 0, false);
public static final Item1_6 chickenRaw = new Item1_6(365, "chickenRaw", 0, false);
public static final Item1_6 chickenCooked = new Item1_6(366, "chickenCooked", 0, false);
public static final Item1_6 rottenFlesh = new Item1_6(367, "rottenFlesh", 0, false);
public static final Item1_6 enderPearl = new Item1_6(368, "enderPearl", 0, false);
public static final Item1_6 blazeRod = new Item1_6(369, "blazeRod", 0, false);
public static final Item1_6 ghastTear = new Item1_6(370, "ghastTear", 0, false);
public static final Item1_6 goldNugget = new Item1_6(371, "goldNugget", 0, false);
public static final Item1_6 netherStalkSeeds = new Item1_6(372, "netherStalkSeeds", 0, false);
public static final Item1_6 potion = new Item1_6(373, "potion", 0, true);
public static final Item1_6 glassBottle = new Item1_6(374, "glassBottle", 0, false);
public static final Item1_6 spiderEye = new Item1_6(375, "spiderEye", 0, false);
public static final Item1_6 fermentedSpiderEye = new Item1_6(376, "fermentedSpiderEye", 0, false);
public static final Item1_6 blazePowder = new Item1_6(377, "blazePowder", 0, false);
public static final Item1_6 magmaCream = new Item1_6(378, "magmaCream", 0, false);
public static final Item1_6 brewingStand = new Item1_6(379, "brewingStand", 0, false);
public static final Item1_6 cauldron = new Item1_6(380, "cauldron", 0, false);
public static final Item1_6 eyeOfEnder = new Item1_6(381, "eyeOfEnder", 0, false);
public static final Item1_6 speckledMelon = new Item1_6(382, "speckledMelon", 0, false);
public static final Item1_6 monsterPlacer = new Item1_6(383, "monsterPlacer", 0, true);
public static final Item1_6 expBottle = new Item1_6(384, "expBottle", 0, false);
public static final Item1_6 fireballCharge = new Item1_6(385, "fireball", 0, false);
public static final Item1_6 writableBook = new Item1_6(386, "writingBook", 0, false);
public static final Item1_6 writtenBook = new Item1_6(387, "writtenBook", 0, false);
public static final Item1_6 emerald = new Item1_6(388, "emerald", 0, false);
public static final Item1_6 itemFrame = new Item1_6(389, "frame", 0, false);
public static final Item1_6 flowerPot = new Item1_6(390, "flowerPot", 0, false);
public static final Item1_6 carrot = new Item1_6(391, "carrots", 0, false);
public static final Item1_6 potato = new Item1_6(392, "potato", 0, false);
public static final Item1_6 bakedPotato = new Item1_6(393, "potatoBaked", 0, false);
public static final Item1_6 poisonousPotato = new Item1_6(394, "potatoPoisonous", 0, false);
public static final Item1_6 emptyMap = new Item1_6(395, "emptyMap", 0, false);
public static final Item1_6 goldenCarrot = new Item1_6(396, "carrotGolden", 0, false);
public static final Item1_6 skull = new Item1_6(397, "skull", 0, true);
public static final Item1_6 carrotOnAStick = new Item1_6(398, "carrotOnAStick", 25, false);
public static final Item1_6 netherStar = new Item1_6(399, "netherStar", 0, false);
public static final Item1_6 pumpkinPie = new Item1_6(400, "pumpkinPie", 0, false);
public static final Item1_6 firework = new Item1_6(401, "fireworks", 0, false);
public static final Item1_6 fireworkCharge = new Item1_6(402, "fireworksCharge", 0, false);
public static final Item1_6 enchantedBook = new Item1_6(403, "enchantedBook", 0, false);
public static final Item1_6 comparator = new Item1_6(404, "comparator", 0, false);
public static final Item1_6 netherrackBrick = new Item1_6(405, "netherbrick", 0, false);
public static final Item1_6 netherQuartz = new Item1_6(406, "netherquartz", 0, false);
public static final Item1_6 minecartTnt = new Item1_6(407, "minecartTnt", 0, false);
public static final Item1_6 minecartHopper = new Item1_6(408, "minecartHopper", 0, false);
public static final Item1_6 horseArmorIron = new Item1_6(417, "horsearmormetal", 0, false);
public static final Item1_6 horseArmorGold = new Item1_6(418, "horsearmorgold", 0, false);
public static final Item1_6 horseArmorDiamond = new Item1_6(419, "horsearmordiamond", 0, false);
public static final Item1_6 leash = new Item1_6(420, "leash", 0, false);
public static final Item1_6 nameTag = new Item1_6(421, "nameTag", 0, false);
public static final Item1_6 record13 = new Item1_6(2256, "record", 0, false);
public static final Item1_6 recordCat = new Item1_6(2257, "record", 0, false);
public static final Item1_6 recordBlocks = new Item1_6(2258, "record", 0, false);
public static final Item1_6 recordChirp = new Item1_6(2259, "record", 0, false);
public static final Item1_6 recordFar = new Item1_6(2260, "record", 0, false);
public static final Item1_6 recordMall = new Item1_6(2261, "record", 0, false);
public static final Item1_6 recordMellohi = new Item1_6(2262, "record", 0, false);
public static final Item1_6 recordStal = new Item1_6(2263, "record", 0, false);
public static final Item1_6 recordStrad = new Item1_6(2264, "record", 0, false);
public static final Item1_6 recordWard = new Item1_6(2265, "record", 0, false);
public static final Item1_6 record11 = new Item1_6(2266, "record", 0, false);
public static final Item1_6 recordWait = new Item1_6(2267, "record", 0, false);
public static Item1_6 getByID(final int itemID) {
for (Item1_6 item : itemList) {
if (item.itemID == itemID) {
return item;
}
}
return null;
}
public static Item1_6 getByName(final String name) {
for (Item1_6 item : itemList) {
if (item.name.equalsIgnoreCase(name)) {
return item;
}
}
return null;
}
public static class Item1_6 {
public final int itemID;
public final int maxDamage;
public final boolean hasSubTypes;
public final String name;
public Item1_6(final int itemID, final String name, final int maxDamage, final boolean hasSubTypes) {
this.itemID = itemID;
this.name = name;
this.maxDamage = maxDamage;
this.hasSubTypes = hasSubTypes;
itemList.add(this);
}
public boolean isDamageable() {
return maxDamage > 0 && !hasSubTypes;
}
}
}

View File

@ -0,0 +1,76 @@
package net.raphimc.vialegacy.api;
import com.viaversion.viaversion.api.minecraft.Position;
import java.util.Objects;
public class Location {
private double x;
private double y;
private double z;
public Location(final Position position) {
this(position.x(), position.y(), position.z());
}
public Location(final double x, final double y, final double z) {
this.x = x;
this.y = y;
this.z = z;
}
public void setX(final double x) {
this.x = x;
}
public double getX() {
return this.x;
}
public void setY(final double y) {
this.y = y;
}
public double getY() {
return this.y;
}
public void setZ(final double z) {
this.z = z;
}
public double getZ() {
return this.z;
}
public double distanceTo(final Location p2) {
return Math.sqrt(Math.pow(p2.getX() - this.x, 2) +
Math.pow(p2.getY() - this.y, 2) +
Math.pow(p2.getZ() - this.z, 2)
);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Location location = (Location) o;
return Double.compare(location.x, x) == 0 && Double.compare(location.y, y) == 0 && Double.compare(location.z, z) == 0;
}
@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
@Override
public String toString() {
return "Location{" +
"x=" + x +
", y=" + y +
", z=" + z +
'}';
}
}

View File

@ -0,0 +1,74 @@
package net.raphimc.vialegacy.netty;
import com.google.common.collect.EvictingQueue;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import net.raphimc.vialegacy.ViaLegacy;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettySplitter;
import java.util.List;
public class PreNettyDecoder extends ByteToMessageDecoder {
protected final UserConnection user;
private final EvictingQueue<Integer> lastPackets = EvictingQueue.create(8);
public PreNettyDecoder(final UserConnection user) {
this.user = user;
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
if (!in.isReadable() || in.readableBytes() <= 0) {
return;
}
final PreNettySplitter splitter = this.user.get(PreNettySplitter.class);
if (splitter == null) {
ViaLegacy.getPlatform().getLogger().severe("Received data, but no splitter is set");
return;
}
while (in.readableBytes() > 0) {
in.markReaderIndex();
final int packetId = in.readUnsignedByte();
final PreNettyPacketType packetType = splitter.getPacketType(packetId);
if (packetType == null) {
ViaLegacy.getPlatform().getLogger().severe("Encountered undefined packet: " + packetId + " in " + splitter.getProtocolName());
ViaLegacy.getPlatform().getLogger().severe(ByteBufUtil.hexDump(in.readSlice(in.readableBytes())));
ViaLegacy.getPlatform().getLogger().severe("Last 8 read packet ids: " + this.lastPackets);
ctx.channel().close();
return;
}
this.lastPackets.add(packetId);
try {
final int begin = in.readerIndex();
packetType.getPacketReader().accept(this.user, in);
final int length = in.readerIndex() - begin;
in.readerIndex(begin);
int totalLength = length;
for (int i = 1; i < 5; ++i) {
if ((packetId & -1 << i * 7) == 0) {
totalLength += i;
break;
}
}
final ByteBuf buf = ctx.alloc().buffer();
Type.VAR_INT.writePrimitive(buf, totalLength); // Length
Type.VAR_INT.writePrimitive(buf, packetId); // id
buf.writeBytes(in.readSlice(length)); // content
out.add(buf);
} catch (IndexOutOfBoundsException e) { // Not enough data
in.resetReaderIndex();
return;
}
}
}
}

View File

@ -0,0 +1,24 @@
package net.raphimc.vialegacy.netty;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
public class PreNettyEncoder extends MessageToByteEncoder<ByteBuf> {
protected final UserConnection user;
public PreNettyEncoder(final UserConnection user) {
this.user = user;
}
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
Type.VAR_INT.readPrimitive(in); // length
out.writeByte(Type.VAR_INT.readPrimitive(in) & 255); // id
out.writeBytes(in); // content
}
}

View File

@ -0,0 +1,23 @@
package net.raphimc.vialegacy.platform;
public interface ViaLegacyConfig {
boolean isDynamicOnground();
boolean isIgnoreLong1_8ChannelNames();
boolean isLegacySkullLoading();
boolean isLegacySkinLoading();
boolean isSoundEmulation();
boolean isOldBiomes();
boolean isRemapBasedOnColor();
int getClassicChunkRange();
int getChunksPerTick();
}

View File

@ -0,0 +1,126 @@
package net.raphimc.vialegacy.platform;
import com.google.common.collect.Range;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.ProtocolManager;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_16;
import net.raphimc.vialegacy.ViaLegacy;
import net.raphimc.vialegacy.ViaLegacyConfig;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_16_2toa1_0_15.Protocola1_0_16_2toa1_0_15;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.Protocola1_0_17_1_0_17_4toa1_0_16_2;
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1.Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_2toa1_2_0_1_2_1_1.Protocola1_2_2toa1_2_0_1_2_1_1;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_1_2_3_4toa1_2_2.Protocola1_2_3_1_2_3_4toa1_2_2;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4.Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.Protocol1_0_0_1tob1_8_0_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_1_2tob1_0_1_1.Protocolb1_1_2tob1_0_1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.Protocolb1_2_0_2tob1_1_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.Protocolb1_3_0_1tob1_2_0_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_4_0_1tob1_3_0_1.Protocolb1_4_0_1tob1_3_0_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.Protocolb1_5_0_2tob1_4_0_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.Protocolb1_6_0_6tob1_5_0_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_7_0_3tob1_6_0_6.Protocolb1_7_0_3tob1_6_0_6;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.Protocolb1_8_0_1tob1_7_0_3;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.Protocola1_0_15toc0_30;
import net.raphimc.vialegacy.protocols.classic.protocolc0_0_16a_02to0_0_15a_1.Protocolc0_0_16a_02to0_0_15a_1;
import net.raphimc.vialegacy.protocols.classic.protocolc0_0_18a_02toc0_0_16a_02.Protocolc0_0_18a_02toc0_0_16a_02;
import net.raphimc.vialegacy.protocols.classic.protocolc0_0_19a_06toc0_0_18a_02.Protocolc0_0_19a_06toc0_0_18a_02;
import net.raphimc.vialegacy.protocols.classic.protocolc0_0_20a_27toc0_0_19a_06.Protocolc0_27toc0_0_19a_06;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_0_20a_27.Protocolc0_30toc0_27;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.Protocolc0_30toc0_30cpe;
import net.raphimc.vialegacy.protocols.release.protocol1_1to1_0_0_1.Protocol1_1to1_0_0_1;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.Protocol1_2_1_3to1_1;
import net.raphimc.vialegacy.protocols.release.protocol1_2_4_5to1_2_1_3.Protocol1_2_4_5to1_2_1_3;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.Protocol1_3_1_2to1_2_4_5;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.Protocol1_4_2to1_3_1_2;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.Protocol1_4_4_5to1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.Protocol1_4_6_7to1_4_4_5;
import net.raphimc.vialegacy.protocols.release.protocol1_5_0_1to1_4_6_7.Protocol1_5_0_1to1_4_6_7;
import net.raphimc.vialegacy.protocols.release.protocol1_5_2to1_5_0_1.Protocol1_5_2to1_5_0_1;
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.Protocol1_6_1to1_5_2;
import net.raphimc.vialegacy.protocols.release.protocol1_6_2to1_6_1.Protocol1_6_2to1_6_1;
import net.raphimc.vialegacy.protocols.release.protocol1_6_4to1_6_2.Protocol1_6_4to1_6_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.Protocol1_7_2_5to1_6_4;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.baseprotocols.EmptyBaseProtocol;
import net.raphimc.vialegacy.protocols.release.protocol1_7_6_10to1_7_2_5.Protocol1_7_6_10to1_7_2_5;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.Protocol1_8to1_7_6_10;
import net.raphimc.vialegacy.protocols.snapshot.protocol1_14to3D_Shareware.Protocol1_14to3D_Shareware;
import net.raphimc.vialegacy.protocols.snapshot.protocol1_16_2toCombatTest8c.Protocol1_16_2toCombatTest8c;
import net.raphimc.vialegacy.protocols.snapshot.protocol1_16to20w14infinite.Protocol1_16to20w14infinite;
import net.raphimc.vialegacy.protocols.snapshot.protocol3D_Sharewareto1_14.Protocol3D_Sharewareto1_14;
import net.raphimc.vialegacy.util.VersionEnum;
import java.io.File;
import java.util.logging.Logger;
public interface ViaLegacyPlatform {
default void init(final File dataFolder) {
final ViaLegacyConfig config = new ViaLegacyConfig(new File(dataFolder, "vialegacy.yml"));
config.reloadConfig();
ViaLegacy.init(this, config);
VersionEnum.init();
Via.getManager().getSubPlatforms().add("ViaLegacy-2.0.0");
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
protocolManager.registerProtocol(new Protocol1_8to1_7_6_10(), VersionEnum.r1_8.getProtocol(), VersionEnum.r1_7_6tor1_7_10.getProtocol());
protocolManager.registerProtocol(new Protocol1_7_6_10to1_7_2_5(), VersionEnum.r1_7_6tor1_7_10.getProtocol(), VersionEnum.r1_7_2tor1_7_5.getProtocol());
protocolManager.registerProtocol(new Protocol1_7_2_5to1_6_4(), VersionEnum.r1_7_2tor1_7_5.getProtocol(), VersionEnum.r1_6_4.getProtocol());
protocolManager.registerProtocol(new Protocol1_6_4to1_6_2(), VersionEnum.r1_6_4.getProtocol(), VersionEnum.r1_6_2.getProtocol());
protocolManager.registerProtocol(new Protocol1_6_2to1_6_1(), VersionEnum.r1_6_2.getProtocol(), VersionEnum.r1_6_1.getProtocol());
protocolManager.registerProtocol(new Protocol1_6_1to1_5_2(), VersionEnum.r1_6_1.getProtocol(), VersionEnum.r1_5_2.getProtocol());
protocolManager.registerProtocol(new Protocol1_5_2to1_5_0_1(), VersionEnum.r1_5_2.getProtocol(), VersionEnum.r1_5tor1_5_1.getProtocol());
protocolManager.registerProtocol(new Protocol1_5_0_1to1_4_6_7(), VersionEnum.r1_5tor1_5_1.getProtocol(), VersionEnum.r1_4_6tor1_4_7.getProtocol());
protocolManager.registerProtocol(new Protocol1_4_6_7to1_4_4_5(), VersionEnum.r1_4_6tor1_4_7.getProtocol(), VersionEnum.r1_4_4tor1_4_5.getProtocol());
protocolManager.registerProtocol(new Protocol1_4_4_5to1_4_2(), VersionEnum.r1_4_4tor1_4_5.getProtocol(), VersionEnum.r1_4_2.getProtocol());
protocolManager.registerProtocol(new Protocol1_4_2to1_3_1_2(), VersionEnum.r1_4_2.getProtocol(), VersionEnum.r1_3_1tor1_3_2.getProtocol());
protocolManager.registerProtocol(new Protocol1_3_1_2to1_2_4_5(), VersionEnum.r1_3_1tor1_3_2.getProtocol(), VersionEnum.r1_2_4tor1_2_5.getProtocol());
protocolManager.registerProtocol(new Protocol1_2_4_5to1_2_1_3(), VersionEnum.r1_2_4tor1_2_5.getProtocol(), VersionEnum.r1_2_1tor1_2_3.getProtocol());
protocolManager.registerProtocol(new Protocol1_2_1_3to1_1(), VersionEnum.r1_2_1tor1_2_3.getProtocol(), VersionEnum.r1_1.getProtocol());
protocolManager.registerProtocol(new Protocol1_1to1_0_0_1(), VersionEnum.r1_1.getProtocol(), VersionEnum.r1_0_0tor1_0_1.getProtocol());
protocolManager.registerProtocol(new Protocol1_0_0_1tob1_8_0_1(), VersionEnum.r1_0_0tor1_0_1.getProtocol(), VersionEnum.b1_8tob1_8_1.getProtocol());
protocolManager.registerProtocol(new Protocolb1_8_0_1tob1_7_0_3(), VersionEnum.b1_8tob1_8_1.getProtocol(), VersionEnum.b1_7tob1_7_3.getProtocol());
protocolManager.registerProtocol(new Protocolb1_7_0_3tob1_6_0_6(), VersionEnum.b1_7tob1_7_3.getProtocol(), VersionEnum.b1_6tob1_6_6.getProtocol());
protocolManager.registerProtocol(new Protocolb1_6_0_6tob1_5_0_2(), VersionEnum.b1_6tob1_6_6.getProtocol(), VersionEnum.b1_5tob1_5_2.getProtocol());
protocolManager.registerProtocol(new Protocolb1_5_0_2tob1_4_0_1(), VersionEnum.b1_5tob1_5_2.getProtocol(), VersionEnum.b1_4tob1_4_1.getProtocol());
protocolManager.registerProtocol(new Protocolb1_4_0_1tob1_3_0_1(), VersionEnum.b1_4tob1_4_1.getProtocol(), VersionEnum.b1_3tob1_3_1.getProtocol());
protocolManager.registerProtocol(new Protocolb1_3_0_1tob1_2_0_2(), VersionEnum.b1_3tob1_3_1.getProtocol(), VersionEnum.b1_2_0tob1_2_2.getProtocol());
protocolManager.registerProtocol(new Protocolb1_2_0_2tob1_1_2(), VersionEnum.b1_2_0tob1_2_2.getProtocol(), VersionEnum.b1_1_2.getProtocol());
protocolManager.registerProtocol(new Protocolb1_1_2tob1_0_1_1(), VersionEnum.b1_1_2.getProtocol(), VersionEnum.b1_0tob1_1_1.getProtocol());
protocolManager.registerProtocol(new Protocolb1_0_1_1_1toa1_2_3_5_1_2_6(), VersionEnum.b1_0tob1_1_1.getProtocol(), VersionEnum.a1_2_3_5toa1_2_6.getProtocol());
protocolManager.registerProtocol(new Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4(), VersionEnum.a1_2_3_5toa1_2_6.getProtocol(), VersionEnum.a1_2_3toa1_2_3_4.getProtocol());
protocolManager.registerProtocol(new Protocola1_2_3_1_2_3_4toa1_2_2(), VersionEnum.a1_2_3toa1_2_3_4.getProtocol(), VersionEnum.a1_2_2.getProtocol());
protocolManager.registerProtocol(new Protocola1_2_2toa1_2_0_1_2_1_1(), VersionEnum.a1_2_2.getProtocol(), VersionEnum.a1_2_0toa1_2_1_1.getProtocol());
protocolManager.registerProtocol(new Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1(), VersionEnum.a1_2_0toa1_2_1_1.getProtocol(), VersionEnum.a1_1_0toa1_1_2_1.getProtocol());
protocolManager.registerProtocol(new Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4(), VersionEnum.a1_1_0toa1_1_2_1.getProtocol(), VersionEnum.a1_0_17toa1_0_17_4.getProtocol());
protocolManager.registerProtocol(new Protocola1_0_17_1_0_17_4toa1_0_16_2(), VersionEnum.a1_0_17toa1_0_17_4.getProtocol(), VersionEnum.a1_0_16toa1_0_16_2.getProtocol());
protocolManager.registerProtocol(new Protocola1_0_16_2toa1_0_15(), VersionEnum.a1_0_16toa1_0_16_2.getProtocol(), VersionEnum.a1_0_15.getProtocol());
protocolManager.registerProtocol(new Protocola1_0_15toc0_30(), VersionEnum.a1_0_15.getProtocol(), VersionEnum.c0_28toc0_30.getProtocol());
protocolManager.registerProtocol(new Protocolc0_30toc0_30cpe(), VersionEnum.c0_28toc0_30.getProtocol(), VersionEnum.c0_30cpe.getProtocol());
protocolManager.registerProtocol(new Protocolc0_30toc0_27(), VersionEnum.c0_28toc0_30.getProtocol(), VersionEnum.c0_0_20ac0_27.getProtocol());
protocolManager.registerProtocol(new Protocolc0_27toc0_0_19a_06(), VersionEnum.c0_0_20ac0_27.getProtocol(), VersionEnum.c0_0_19a_06.getProtocol());
protocolManager.registerProtocol(new Protocolc0_0_19a_06toc0_0_18a_02(), VersionEnum.c0_0_19a_06.getProtocol(), VersionEnum.c0_0_18a_02.getProtocol());
protocolManager.registerProtocol(new Protocolc0_0_18a_02toc0_0_16a_02(), VersionEnum.c0_0_18a_02.getProtocol(), VersionEnum.c0_0_16a_02.getProtocol());
protocolManager.registerProtocol(new Protocolc0_0_16a_02to0_0_15a_1(), VersionEnum.c0_0_16a_02.getProtocol(), VersionEnum.c0_0_15a_1.getProtocol());
protocolManager.registerProtocol(new Protocol1_14to3D_Shareware(), VersionEnum.r1_14.getProtocol(), VersionEnum.s3d_shareware.getProtocol());
protocolManager.registerProtocol(new Protocol3D_Sharewareto1_14(), VersionEnum.s3d_shareware.getProtocol(), VersionEnum.r1_14.getProtocol());
protocolManager.registerProtocol(new Protocol1_16to20w14infinite(), VersionEnum.r1_16.getProtocol(), VersionEnum.s20w14infinite.getProtocol());
protocolManager.registerProtocol(new Protocol1_16_2toCombatTest8c(), VersionEnum.r1_16_2.getProtocol(), VersionEnum.sCombatTest8c.getProtocol());
for (VersionEnum version : VersionEnum.LEGACY_VERSIONS) {
Via.getManager().getProtocolManager().registerBaseProtocol(new EmptyBaseProtocol(), Range.singleton(version.getVersion()));
}
protocolManager.registerBaseProtocol(new BaseProtocol1_16(), Range.singleton(VersionEnum.s20w14infinite.getVersion()));
protocolManager.registerBaseProtocol(new BaseProtocol1_16(), Range.singleton(VersionEnum.sCombatTest8c.getVersion()));
}
Logger getLogger();
File getDataFolder();
}

View File

@ -0,0 +1,194 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_16_2toa1_0_15;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ClientboundPacketsa1_0_15 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ClientboundPacketsa1_0_15[] REGISTRY = new ClientboundPacketsa1_0_15[256];
static {
for (ClientboundPacketsa1_0_15 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_0_15 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_0_15(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,40 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_16_2toa1_0_15;
import com.viaversion.viaversion.api.connection.UserConnection;
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.PacketRemapper;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.ClientboundPacketsa1_0_16;
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.ServerboundPacketsa1_0_17;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_0_16_2toa1_0_15 extends AbstractProtocol<ClientboundPacketsa1_0_15, ClientboundPacketsa1_0_16, ServerboundPacketsa1_0_15, ServerboundPacketsa1_0_17> {
public Protocola1_0_16_2toa1_0_15() {
super(ClientboundPacketsa1_0_15.class, ClientboundPacketsa1_0_16.class, ServerboundPacketsa1_0_15.class, ServerboundPacketsa1_0_17.class);
}
@Override
protected void registerPackets() {
this.registerServerbound(State.LOGIN, -1, ServerboundPacketsa1_0_17.HANDSHAKE.getId(), new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
final PacketWrapper handshake = PacketWrapper.create(ClientboundPacketsa1_0_16.HANDSHAKE, wrapper.user());
handshake.write(Typesb1_7_0_3.STRING, "-"); // server hash
handshake.send(Protocola1_0_16_2toa1_0_15.class);
});
}
});
this.cancelServerbound(ServerboundPacketsa1_0_17.HANDSHAKE);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_0_16_2toa1_0_15.class, ClientboundPacketsa1_0_15::getPacket));
}
}

View File

@ -0,0 +1,119 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_16_2toa1_0_15;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ServerboundPacketsa1_0_15 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ServerboundPacketsa1_0_15[] REGISTRY = new ServerboundPacketsa1_0_15[256];
static {
for (ServerboundPacketsa1_0_15 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsa1_0_15 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsa1_0_15(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,198 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ClientboundPacketsa1_0_16 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsa1_0_16[] REGISTRY = new ClientboundPacketsa1_0_16[256];
static {
for (ClientboundPacketsa1_0_16 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_0_16 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_0_16(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,43 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage.TimeLockStorage;
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.ClientboundPacketsa1_0_17;
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.ServerboundPacketsa1_0_17;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_0_17_1_0_17_4toa1_0_16_2 extends AbstractProtocol<ClientboundPacketsa1_0_16, ClientboundPacketsa1_0_17, ServerboundPacketsa1_0_17, ServerboundPacketsa1_0_17> {
public Protocola1_0_17_1_0_17_4toa1_0_16_2() {
super(ClientboundPacketsa1_0_16.class, ClientboundPacketsa1_0_17.class, ServerboundPacketsa1_0_17.class, ServerboundPacketsa1_0_17.class);
}
@Override
protected void registerPackets() {
this.registerServerbound(ServerboundPacketsa1_0_17.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // item id
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
handler(wrapper -> {
if (wrapper.get(Type.SHORT, 0) < 0) {
wrapper.cancel();
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_0_17_1_0_17_4toa1_0_16_2.class, ClientboundPacketsa1_0_16::getPacket));
userConnection.put(new TimeLockStorage(userConnection, 0));
}
}

View File

@ -0,0 +1,23 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class TimeLockStorage extends StoredObject {
private long time;
public TimeLockStorage(UserConnection user, final long time) {
super(user);
this.time = time;
}
public void setTime(final long time) {
this.time = time;
}
public long getTime() {
return this.time;
}
}

View File

@ -0,0 +1,30 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.task;
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 net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.Protocola1_0_17_1_0_17_4toa1_0_16_2;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage.TimeLockStorage;
import net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.ClientboundPacketsa1_0_17;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
public class TimeLockTask implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
final TimeLockStorage timeLockStorage = info.get(TimeLockStorage.class);
final PlayerInfoStorage playerInfoStorage = info.get(PlayerInfoStorage.class);
if (timeLockStorage != null && playerInfoStorage != null && playerInfoStorage.entityId != -1) {
try {
final PacketWrapper updateTime = PacketWrapper.create(ClientboundPacketsa1_0_17.TIME_UPDATE, info);
updateTime.write(Type.LONG, timeLockStorage.getTime() % 24_000L);
updateTime.send(Protocola1_0_17_1_0_17_4toa1_0_16_2.class);
} catch (Throwable ignored) {
}
}
}
}
}

View File

@ -0,0 +1,210 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ClientboundPacketsa1_0_17 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsa1_0_17[] REGISTRY = new ClientboundPacketsa1_0_17[256];
static {
for (ClientboundPacketsa1_0_17 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_0_17 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_0_17(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,26 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1.ClientboundPacketsa1_1_0;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1.ServerboundPacketsa1_1_0;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4 extends AbstractProtocol<ClientboundPacketsa1_0_17, ClientboundPacketsa1_1_0, ServerboundPacketsa1_0_17, ServerboundPacketsa1_1_0> {
public Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4() {
super(ClientboundPacketsa1_0_17.class, ClientboundPacketsa1_1_0.class, ServerboundPacketsa1_0_17.class, ServerboundPacketsa1_1_0.class);
}
@Override
protected void registerPackets() {
this.cancelServerbound(ServerboundPacketsa1_1_0.COMPLEX_ENTITY);
this.cancelServerbound(ServerboundPacketsa1_1_0.PLAYER_INVENTORY);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.class, ClientboundPacketsa1_0_17::getPacket));
}
}

View File

@ -0,0 +1,123 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ServerboundPacketsa1_0_17 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ServerboundPacketsa1_0_17[] REGISTRY = new ServerboundPacketsa1_0_17[256];
static {
for (ServerboundPacketsa1_0_17 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsa1_0_17 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsa1_0_17(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,228 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ClientboundPacketsa1_1_0 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsa1_1_0[] REGISTRY = new ClientboundPacketsa1_1_0[256];
static {
for (ClientboundPacketsa1_1_0 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_1_0 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_1_0(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,49 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_2toa1_2_0_1_2_1_1.ClientboundPacketsa1_2_0;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_2toa1_2_0_1_2_1_1.ServerboundPacketsa1_2_0;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1 extends AbstractProtocol<ClientboundPacketsa1_1_0, ClientboundPacketsa1_2_0, ServerboundPacketsa1_1_0, ServerboundPacketsa1_2_0> {
public Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1() {
super(ClientboundPacketsa1_1_0.class, ClientboundPacketsa1_2_0.class, ServerboundPacketsa1_1_0.class, ServerboundPacketsa1_2_0.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsa1_1_0.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Typesb1_7_0_3.STRING); // username
map(Typesb1_7_0_3.STRING); // password
create(Type.LONG, 0L); // seed
create(Type.BYTE, (byte) 0); // dimension id
}
});
this.registerServerbound(State.LOGIN, ServerboundPacketsa1_1_0.LOGIN.getId(), ServerboundPacketsa1_2_0.LOGIN.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // protocol id
map(Typesb1_7_0_3.STRING); // username
map(Typesb1_7_0_3.STRING); // password
read(Type.LONG); // seed
read(Type.BYTE); // dimension id
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1.class, ClientboundPacketsa1_1_0::getPacket));
}
}

View File

@ -0,0 +1,136 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ServerboundPacketsa1_1_0 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ServerboundPacketsa1_1_0[] REGISTRY = new ServerboundPacketsa1_1_0[256];
static {
for (ServerboundPacketsa1_1_0 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsa1_1_0 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsa1_1_0(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,228 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_2toa1_2_0_1_2_1_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ClientboundPacketsa1_2_0 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) PreNettyTypes.readItemStackb1_2(buf);
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ClientboundPacketsa1_2_0[] REGISTRY = new ClientboundPacketsa1_2_0[256];
static {
for (ClientboundPacketsa1_2_0 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_2_0 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_2_0(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,45 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_2toa1_2_0_1_2_1_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_1_2_3_4toa1_2_2.ClientboundPacketsa1_2_2;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_1_2_3_4toa1_2_2.ServerboundPacketsa1_2_2;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_2_2toa1_2_0_1_2_1_1 extends AbstractProtocol<ClientboundPacketsa1_2_0, ClientboundPacketsa1_2_2, ServerboundPacketsa1_2_0, ServerboundPacketsa1_2_2> {
public Protocola1_2_2toa1_2_0_1_2_1_1() {
super(ClientboundPacketsa1_2_0.class, ClientboundPacketsa1_2_2.class, ServerboundPacketsa1_2_0.class, ServerboundPacketsa1_2_2.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsa1_2_0.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.UNSIGNED_BYTE); // type id
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
handler(wrapper -> {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 91) {
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) 93);
}
});
}
});
this.cancelServerbound(ServerboundPacketsa1_2_2.INTERACT_ENTITY);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_2toa1_2_0_1_2_1_1.class, ClientboundPacketsa1_2_0::getPacket));
}
}

View File

@ -0,0 +1,136 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_2toa1_2_0_1_2_1_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ServerboundPacketsa1_2_0 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) PreNettyTypes.readItemStackb1_2(buf);
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ServerboundPacketsa1_2_0[] REGISTRY = new ServerboundPacketsa1_2_0[256];
static {
for (ServerboundPacketsa1_2_0 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsa1_2_0 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsa1_2_0(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,238 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_1_2_3_4toa1_2_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ClientboundPacketsa1_2_2 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) PreNettyTypes.readItemStackb1_2(buf);
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ClientboundPacketsa1_2_2[] REGISTRY = new ClientboundPacketsa1_2_2[256];
static {
for (ClientboundPacketsa1_2_2 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_2_2 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_2_2(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,50 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_1_2_3_4toa1_2_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4.ClientboundPacketsa1_2_3;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.ServerboundPacketsa1_2_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_2_3_1_2_3_4toa1_2_2 extends AbstractProtocol<ClientboundPacketsa1_2_2, ClientboundPacketsa1_2_3, ServerboundPacketsa1_2_2, ServerboundPacketsa1_2_6> {
public Protocola1_2_3_1_2_3_4toa1_2_2() {
super(ClientboundPacketsa1_2_2.class, ClientboundPacketsa1_2_3.class, ServerboundPacketsa1_2_2.class, ServerboundPacketsa1_2_6.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsa1_2_2.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final PacketWrapper updateHealth = PacketWrapper.create(ClientboundPacketsa1_2_3.UPDATE_HEALTH, wrapper.user());
updateHealth.write(Type.BYTE, (byte) 20); // health
wrapper.send(Protocola1_2_3_1_2_3_4toa1_2_2.class);
updateHealth.send(Protocola1_2_3_1_2_3_4toa1_2_2.class);
wrapper.cancel();
});
}
});
this.registerServerbound(ServerboundPacketsa1_2_6.INTERACT_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // player id
map(Type.INT); // entity id
read(Type.BYTE); // mode
}
});
this.cancelServerbound(ServerboundPacketsa1_2_6.RESPAWN);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_3_1_2_3_4toa1_2_2.class, ClientboundPacketsa1_2_2::getPacket));
}
}

View File

@ -0,0 +1,140 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_1_2_3_4toa1_2_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ServerboundPacketsa1_2_2 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) PreNettyTypes.readItemStackb1_2(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ServerboundPacketsa1_2_2[] REGISTRY = new ServerboundPacketsa1_2_2[256];
static {
for (ServerboundPacketsa1_2_2 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsa1_2_2 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsa1_2_2(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,249 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ClientboundPacketsa1_2_3 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsa1_2_3[] REGISTRY = new ClientboundPacketsa1_2_3[256];
static {
for (ClientboundPacketsa1_2_3 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_2_3 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_2_3(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,35 @@
package net.raphimc.vialegacy.protocols.alpha.protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.ClientboundPacketsa1_2_6;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.ServerboundPacketsa1_2_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4 extends AbstractProtocol<ClientboundPacketsa1_2_3, ClientboundPacketsa1_2_6, ServerboundPacketsa1_2_6, ServerboundPacketsa1_2_6> {
public Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4() {
super(ClientboundPacketsa1_2_3.class, ClientboundPacketsa1_2_6.class, ServerboundPacketsa1_2_6.class, ServerboundPacketsa1_2_6.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsa1_2_3.ENTITY_VELOCITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.SHORT, Type.SHORT, v -> (short) (v / 4.0F)); // velocity x
map(Type.SHORT, Type.SHORT, v -> (short) (v / 4.0F)); // velocity y
map(Type.SHORT, Type.SHORT, v -> (short) (v / 4.0F)); // velocity z
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4.class, ClientboundPacketsa1_2_3::getPacket));
}
}

View File

@ -0,0 +1,261 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ClientboundPacketsa1_2_6 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ADD_TO_INVENTORY(17, (user, buf) -> {
buf.readShort();
buf.readByte();
buf.readShort();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsa1_2_6[] REGISTRY = new ClientboundPacketsa1_2_6[256];
static {
for (ClientboundPacketsa1_2_6 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsa1_2_6 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsa1_2_6(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,517 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
import net.raphimc.vialegacy.ViaLegacy;
import net.raphimc.vialegacy.api.*;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data.AlphaItems;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.AlphaInventoryProvider;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.TrackingAlphaInventoryProvider;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.AlphaInventoryTracker;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.InventoryStorage;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ClientboundPacketsb1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ServerboundPacketsb1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.types.Typesb1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.Protocol1_2_1_3to1_1;
import net.raphimc.vialegacy.protocols.release.protocol1_2_4_5to1_2_1_3.ClientboundPackets1_2_1;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.data.EntityList;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
public class Protocolb1_0_1_1_1toa1_2_3_5_1_2_6 extends AbstractProtocol<ClientboundPacketsa1_2_6, ClientboundPacketsb1_1, ServerboundPacketsa1_2_6, ServerboundPacketsb1_1> {
public Protocolb1_0_1_1_1toa1_2_3_5_1_2_6() {
super(ClientboundPacketsa1_2_6.class, ClientboundPacketsb1_1.class, ServerboundPacketsa1_2_6.class, ServerboundPacketsb1_1.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsa1_2_6.PLAYER_INVENTORY, ClientboundPacketsb1_1.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final InventoryStorage inventoryStorage = wrapper.user().get(InventoryStorage.class);
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
final int type = wrapper.read(Type.INT); // type
Item[] items = wrapper.read(Types1_4_2.NBTLESS_ITEM_ARRAY); // items
final Item[] windowItems = new Item[45];
System.arraycopy(inventoryStorage.mainInventory, 0, windowItems, 36, 9);
System.arraycopy(inventoryStorage.mainInventory, 9, windowItems, 9, 36 - 9);
System.arraycopy(inventoryStorage.craftingInventory, 0, windowItems, 1, 4);
System.arraycopy(inventoryStorage.armorInventory, 0, windowItems, 5, 4);
switch (type) {
case -1: // main
inventoryStorage.mainInventory = items;
if (inventoryTracker != null) inventoryTracker.setMainInventory(copyItems(items));
System.arraycopy(items, 0, windowItems, 36, 9);
System.arraycopy(items, 9, windowItems, 9, 36 - 9);
break;
case -2: // crafting
inventoryStorage.craftingInventory = items;
if (inventoryTracker != null) inventoryTracker.setCraftingInventory(copyItems(items));
System.arraycopy(items, 0, windowItems, 1, 4);
break;
case -3: // armor
inventoryStorage.armorInventory = items;
if (inventoryTracker != null) inventoryTracker.setArmorInventory(copyItems(items));
System.arraycopy(reverseArray(items), 0, windowItems, 5, 4);
}
wrapper.write(Type.BYTE, (byte) 0); // window id
wrapper.write(Types1_4_2.NBTLESS_ITEM_ARRAY, copyItems(windowItems)); // items
});
}
});
this.registerClientbound(ClientboundPacketsa1_2_6.UPDATE_HEALTH, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE, Type.SHORT); // health
}
});
this.registerClientbound(ClientboundPacketsa1_2_6.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.user().get(InventoryStorage.class).resetPlayerInventory();
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
if (inventoryTracker != null) inventoryTracker.onRespawn();
});
}
});
this.registerClientbound(ClientboundPacketsa1_2_6.HELD_ITEM_CHANGE, ClientboundPacketsb1_1.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
create(Type.SHORT, (short) 0); // slot (hand)
map(Type.SHORT); // item id
handler(wrapper -> {
if (wrapper.get(Type.SHORT, 1) == 0) {
wrapper.set(Type.SHORT, 1, (short) -1);
}
});
}
});
this.registerClientbound(ClientboundPacketsa1_2_6.ADD_TO_INVENTORY, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
final Item item = wrapper.read(Types1_3_1.NBTLESS_ITEM); // item
Via.getManager().getProviders().get(AlphaInventoryProvider.class).addToInventory(wrapper.user(), item);
});
}
});
this.registerClientbound(ClientboundPacketsa1_2_6.PRE_CHUNK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // chunkX
map(Type.INT); // chunkZ
map(Type.UNSIGNED_BYTE); // mode
handler(wrapper -> {
wrapper.user().get(InventoryStorage.class).unload(wrapper.get(Type.INT, 0), wrapper.get(Type.INT, 1));
});
}
});
this.registerClientbound(ClientboundPacketsa1_2_6.COMPLEX_ENTITY, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
final InventoryStorage tracker = wrapper.user().get(InventoryStorage.class);
final Position pos = wrapper.read(Types1_7_6.POSITION_SHORT); // position
final CompoundTag tag = wrapper.read(Types1_7_6.COMPRESSED_NBT); // data
if (tag.<IntTag>get("x").asInt() != pos.x() || tag.<IntTag>get("y").asInt() != pos.y() || tag.<IntTag>get("z").asInt() != pos.z()) {
return;
}
final IdAndData block = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
final String blockName = tag.get("id") != null ? tag.<StringTag>get("id").getValue() : "";
if (block.id == BlockList1_6.signPost.blockID || block.id == BlockList1_6.signWall.blockID || blockName.equals("Sign")) {
final PacketWrapper updateSign = PacketWrapper.create(ClientboundPacketsb1_1.UPDATE_SIGN, wrapper.user());
updateSign.write(Types1_7_6.POSITION_SHORT, pos); // position
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text1").getValue()); // line 1
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text2").getValue()); // line 2
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text3").getValue()); // line 3
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text4").getValue()); // line 4
updateSign.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
} else if (block.id == BlockList1_6.mobSpawner.blockID || blockName.equals("MobSpawner")) {
if (wrapper.user().getProtocolInfo().getPipeline().contains(Protocol1_2_1_3to1_1.class)) {
final PacketWrapper spawnerData = PacketWrapper.create(ClientboundPackets1_2_1.BLOCK_ENTITY_DATA, wrapper.user());
spawnerData.write(Types1_7_6.POSITION_SHORT, pos); // position
spawnerData.write(Type.BYTE, (byte) 1); // type
spawnerData.write(Type.INT, EntityList.getEntityId(tag.<StringTag>get("EntityId").getValue())); // entity id
spawnerData.write(Type.INT, 0); // unused
spawnerData.write(Type.INT, 0); // unused
spawnerData.send(Protocol1_2_1_3to1_1.class);
}
} else if (block.id == BlockList1_6.chest.blockID || blockName.equals("Chest")) {
final Item[] chestItems = new Item[3 * 9];
readItemsFromTag(tag, chestItems);
tracker.containers.put(pos, chestItems);
if (pos.equals(tracker.openContainerPos)) sendWindowItems(wrapper.user(), InventoryStorage.CHEST_WID, chestItems);
} else if (block.id == BlockList1_6.furnaceIdle.blockID || block.id == BlockList1_6.furnaceBurning.blockID || blockName.equals("Furnace")) {
final Item[] furnaceItems = new Item[3];
readItemsFromTag(tag, furnaceItems);
tracker.containers.put(pos, furnaceItems);
if (pos.equals(tracker.openContainerPos)) {
sendWindowItems(wrapper.user(), InventoryStorage.FURNACE_WID, furnaceItems);
sendProgressUpdate(wrapper.user(), InventoryStorage.FURNACE_WID, (short) 0, tag.<ShortTag>get("CookTime").asShort()); // cook time
sendProgressUpdate(wrapper.user(), InventoryStorage.FURNACE_WID, (short) 1, tag.<ShortTag>get("BurnTime").asShort()); // furnace burn time
sendProgressUpdate(wrapper.user(), InventoryStorage.FURNACE_WID, (short) 2, getBurningTime(furnaceItems[1])); // item burn time
}
} else {
ViaLegacy.getPlatform().getLogger().warning("Unhandled Complex Entity data: " + block + "@" + pos + ": '" + tag + "'");
}
});
}
});
this.registerServerbound(ServerboundPacketsb1_1.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // status
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
handler(wrapper -> {
final short status = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (status == 4) {
wrapper.cancel();
final Item selectedItem = fixItem(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getHandItem(wrapper.user()));
if (selectedItem == null) {
return;
}
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
if (inventoryTracker != null) inventoryTracker.onHandItemDrop();
selectedItem.setAmount(1);
dropItem(wrapper.user(), selectedItem, false);
}
});
}
});
this.registerServerbound(ServerboundPacketsb1_1.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final InventoryStorage tracker = wrapper.user().get(InventoryStorage.class);
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
final Position pos = wrapper.read(Types1_7_6.POSITION_UBYTE); // position
final short direction = wrapper.read(Type.UNSIGNED_BYTE); // direction
Item item = fixItem(wrapper.read(Typesb1_1.NBTLESS_ITEM)); // item
if (item == null && inventoryTracker != null) {
item = Via.getManager().getProviders().get(AlphaInventoryProvider.class).getHandItem(wrapper.user());
}
wrapper.write(Type.SHORT, item == null ? (short) -1 : (short) item.identifier()); // item id
wrapper.write(Types1_7_6.POSITION_UBYTE, pos);
wrapper.write(Type.UNSIGNED_BYTE, direction);
if (inventoryTracker != null) inventoryTracker.onBlockPlace(pos, direction);
if (direction == 255) return;
final IdAndData block = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
if (block.id != BlockList1_6.furnaceIdle.blockID && block.id != BlockList1_6.furnaceBurning.blockID && block.id != BlockList1_6.chest.blockID && block.id != BlockList1_6.workbench.blockID) {
return;
}
final Item[] containerItems = tracker.containers.get(tracker.openContainerPos = pos);
if (containerItems == null && block.id != BlockList1_6.workbench.blockID) {
tracker.openContainerPos = null;
final PacketWrapper chatMessage = PacketWrapper.create(ClientboundPacketsb1_1.CHAT_MESSAGE, wrapper.user());
chatMessage.write(Typesb1_7_0_3.STRING, "§cMissing Container"); // message
chatMessage.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
return;
}
final PacketWrapper openWindow = PacketWrapper.create(ClientboundPacketsb1_1.OPEN_WINDOW, wrapper.user());
if (block.id == BlockList1_6.chest.blockID) {
openWindow.write(Type.UNSIGNED_BYTE, (short) InventoryStorage.CHEST_WID); // window id
openWindow.write(Type.UNSIGNED_BYTE, (short) 0); // window type
openWindow.write(Typesb1_7_0_3.STRING, "Chest"); // title
openWindow.write(Type.UNSIGNED_BYTE, (short) (3 * 9)); // slots
if (inventoryTracker != null) inventoryTracker.onWindowOpen(0, 3 * 9);
} else if (block.id == BlockList1_6.workbench.blockID) {
openWindow.write(Type.UNSIGNED_BYTE, (short) InventoryStorage.WORKBENCH_WID); // window id
openWindow.write(Type.UNSIGNED_BYTE, (short) 1); // window type
openWindow.write(Typesb1_7_0_3.STRING, "Crafting Table"); // title
openWindow.write(Type.UNSIGNED_BYTE, (short) 9); // slots
if (inventoryTracker != null) inventoryTracker.onWindowOpen(1, 10);
} else { // furnace
openWindow.write(Type.UNSIGNED_BYTE, (short) InventoryStorage.FURNACE_WID); // window id
openWindow.write(Type.UNSIGNED_BYTE, (short) 2); // window type
openWindow.write(Typesb1_7_0_3.STRING, "Furnace"); // title
openWindow.write(Type.UNSIGNED_BYTE, (short) 3); // slots
if (inventoryTracker != null) inventoryTracker.onWindowOpen(2, 3);
}
openWindow.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
if (block.id != BlockList1_6.workbench.blockID) {
sendWindowItems(wrapper.user(), block.id == BlockList1_6.chest.blockID ? InventoryStorage.CHEST_WID : InventoryStorage.FURNACE_WID, containerItems);
}
});
}
});
this.registerServerbound(ServerboundPacketsb1_1.HELD_ITEM_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final InventoryStorage inventoryStorage = wrapper.user().get(InventoryStorage.class);
short slot = wrapper.read(Type.SHORT); // slot
if (slot < 0 || slot > 8) slot = 0;
inventoryStorage.selectedHotbarSlot = slot;
final Item selectedItem = fixItem(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getHandItem(wrapper.user()));
if (Objects.equals(selectedItem, inventoryStorage.handItem)) {
wrapper.cancel();
return;
}
inventoryStorage.handItem = selectedItem;
wrapper.write(Type.INT, 0); // entity id (always 0)
wrapper.write(Type.SHORT, (short) (selectedItem == null ? 0 : selectedItem.identifier())); // item id
});
}
});
this.registerServerbound(ServerboundPacketsb1_1.CLOSE_WINDOW, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
wrapper.user().get(InventoryStorage.class).openContainerPos = null;
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
if (inventoryTracker != null) inventoryTracker.onWindowClose();
});
}
});
this.registerServerbound(ServerboundPacketsb1_1.CLICK_WINDOW, ServerboundPacketsa1_2_6.COMPLEX_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final InventoryStorage tracker = wrapper.user().get(InventoryStorage.class);
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
final byte windowId = wrapper.read(Type.BYTE); // window id
final short slot = wrapper.read(Type.SHORT); // slot
final byte button = wrapper.read(Type.BYTE); // button
final short action = wrapper.read(Type.SHORT); // action
final Item item = fixItem(wrapper.read(Typesb1_1.NBTLESS_ITEM)); // item
if (inventoryTracker != null) inventoryTracker.onWindowClick(windowId, slot, button, action, item);
if ((windowId != InventoryStorage.CHEST_WID && windowId != InventoryStorage.FURNACE_WID) || tracker.openContainerPos == null) {
wrapper.cancel();
return;
}
final Item[] containerItems = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getContainerItems(wrapper.user()));
if (Arrays.equals(tracker.containers.get(tracker.openContainerPos), containerItems)) {
wrapper.cancel();
return;
}
tracker.containers.put(tracker.openContainerPos, containerItems);
final CompoundTag tag = new CompoundTag();
tag.put("id", new StringTag(windowId == InventoryStorage.CHEST_WID ? "Chest" : "Furnace"));
tag.put("x", new IntTag(tracker.openContainerPos.x()));
tag.put("y", new IntTag(tracker.openContainerPos.y()));
tag.put("z", new IntTag(tracker.openContainerPos.z()));
writeItemsToTag(tag, containerItems);
wrapper.write(Type.INT, tracker.openContainerPos.x());
wrapper.write(Type.SHORT, (short) tracker.openContainerPos.y());
wrapper.write(Type.INT, tracker.openContainerPos.z());
wrapper.write(Types1_7_6.COMPRESSED_NBT, tag);
});
}
});
this.registerServerbound(ServerboundPacketsb1_1.UPDATE_SIGN, ServerboundPacketsa1_2_6.COMPLEX_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final Position pos = wrapper.passthrough(Types1_7_6.POSITION_SHORT); // position
final CompoundTag tag = new CompoundTag();
tag.put("id", new StringTag("Sign"));
tag.put("x", new IntTag(pos.x()));
tag.put("y", new IntTag(pos.y()));
tag.put("z", new IntTag(pos.z()));
tag.put("Text1", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 1
tag.put("Text2", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 2
tag.put("Text3", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 3
tag.put("Text4", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 4
wrapper.write(Types1_7_6.COMPRESSED_NBT, tag); // data
});
}
});
this.cancelServerbound(ServerboundPacketsb1_1.WINDOW_CONFIRMATION);
}
private void writeItemsToTag(final CompoundTag tag, final Item[] items) {
final ListTag slotList = new ListTag();
for (int i = 0; i < items.length; i++) {
final Item item = items[i];
if (item == null) continue;
final CompoundTag slotTag = new CompoundTag();
slotTag.put("Slot", new ByteTag((byte) i));
slotTag.put("id", new ShortTag((short) item.identifier()));
slotTag.put("Count", new ByteTag((byte) item.amount()));
slotTag.put("Damage", new ShortTag(item.data()));
slotList.add(slotTag);
}
tag.put("Items", slotList);
}
private void readItemsFromTag(final CompoundTag tag, final Item[] items) {
final ListTag slotList = tag.get("Items");
for (Tag itemTag : slotList) {
final CompoundTag slotTag = (CompoundTag) itemTag;
items[slotTag.<ByteTag>get("Slot").asByte() & 255] = new DataItem(slotTag.<ShortTag>get("id").asShort(), slotTag.<ByteTag>get("Count").asByte(), slotTag.<ShortTag>get("Damage").asShort(), null);
}
}
private void sendWindowItems(final UserConnection user, final byte windowId, final Item[] items) throws Exception {
final PacketWrapper windowItems = PacketWrapper.create(ClientboundPacketsb1_1.WINDOW_ITEMS, user);
windowItems.write(Type.BYTE, windowId); // window id
windowItems.write(Types1_4_2.NBTLESS_ITEM_ARRAY, copyItems(items)); // items
windowItems.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
final AlphaInventoryTracker inventoryTracker = user.get(AlphaInventoryTracker.class);
if (inventoryTracker != null) inventoryTracker.setOpenContainerItems(copyItems(items));
}
private void sendProgressUpdate(final UserConnection user, final short windowId, final short id, final short value) throws Exception {
final PacketWrapper windowProperty = PacketWrapper.create(ClientboundPacketsb1_1.WINDOW_PROPERTY, user);
windowProperty.write(Type.UNSIGNED_BYTE, windowId); // window id
windowProperty.write(Type.SHORT, id); // progress bar id
windowProperty.write(Type.SHORT, value); // progress bar value
windowProperty.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
}
private short getBurningTime(final Item item) {
if (item == null) return 0;
final int id = item.identifier();
if (id == BlockList1_6.bookShelf.blockID || id == BlockList1_6.chest.blockID || id == BlockList1_6.fence.blockID || id == BlockList1_6.jukebox.blockID || id == BlockList1_6.wood.blockID || id == BlockList1_6.planks.blockID || id == BlockList1_6.doorWood.blockID || id == BlockList1_6.signWall.blockID || id == BlockList1_6.signPost.blockID || id == BlockList1_6.workbench.blockID) {
return 300;
} else if (id == ItemList1_6.stick.itemID) {
return 100;
} else if (id == ItemList1_6.coal.itemID) {
return 1600;
} else if (id == ItemList1_6.bucketLava.itemID) {
return 20000;
}
return 0;
}
public static void dropItem(final UserConnection user, final Item item, final boolean flag) throws Exception {
final PlayerInfoStorage playerInfoStorage = user.get(PlayerInfoStorage.class);
final double itemX = playerInfoStorage.posX;
final double itemY = playerInfoStorage.posY + 1.62F - 0.30000001192092896D + 0.12D;
final double itemZ = playerInfoStorage.posZ;
double motionX;
double motionY;
double motionZ;
if (flag) {
final float f2 = ThreadLocalRandom.current().nextFloat() * 0.5F;
final float f1 = (float) (ThreadLocalRandom.current().nextFloat() * Math.PI * 2.0F);
motionX = -Math.sin(f1) * f2;
motionZ = Math.cos(f1) * f2;
motionY = 0.20000000298023224D;
} else {
motionX = -Math.sin((playerInfoStorage.yaw / 180F) * Math.PI) * Math.cos((playerInfoStorage.pitch / 180F) * Math.PI) * 0.3F;
motionZ = Math.cos((playerInfoStorage.yaw / 180F) * Math.PI) * Math.cos((playerInfoStorage.pitch / 180F) * Math.PI) * 0.3F;
motionY = -Math.sin((playerInfoStorage.pitch / 180F) * Math.PI) * 0.3F + 0.1F;
final float f1 = (float) (ThreadLocalRandom.current().nextFloat() * Math.PI * 2.0F);
final float f2 = 0.02F * ThreadLocalRandom.current().nextFloat();
motionX += Math.cos(f1) * (double) f2;
motionY += (ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.1F;
motionZ += Math.sin(f1) * (double) f2;
}
final PacketWrapper spawnItem = PacketWrapper.create(ServerboundPacketsa1_2_6.SPAWN_ITEM, user);
spawnItem.write(Type.INT, 0); // entity id
spawnItem.write(Type.SHORT, (short) item.identifier()); // item id
spawnItem.write(Type.BYTE, (byte) item.amount()); // item count
spawnItem.write(Type.INT, (int) (itemX * 32)); // x
spawnItem.write(Type.INT, (int) (itemY * 32)); // y
spawnItem.write(Type.INT, (int) (itemZ * 32)); // z
spawnItem.write(Type.BYTE, (byte) (motionX * 128)); // velocity x
spawnItem.write(Type.BYTE, (byte) (motionY * 128)); // velocity y
spawnItem.write(Type.BYTE, (byte) (motionZ * 128)); // velocity z
spawnItem.sendToServer(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
}
public static Item[] reverseArray(final Item[] array) {
if (array == null) return null;
final Item[] reversed = new Item[array.length];
for (int i = 0; i < array.length / 2; i++) {
reversed[i] = array[array.length - i - 1];
reversed[array.length - i - 1] = array[i];
}
return reversed;
}
public static Item copyItem(final Item item) {
return item == null ? null : new DataItem(item);
}
public static Item[] copyItems(final Item[] items) {
return Arrays.stream(items).map(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6::copyItem).toArray(Item[]::new);
}
public static Item fixItem(final Item item) {
if (item == null || !AlphaItems.isValid(item.identifier())) return null;
item.setTag(null);
return item;
}
public static Item[] fixItems(final Item[] items) {
for (int i = 0; i < items.length; i++) {
items[i] = fixItem(items[i]);
}
return items;
}
@Override
public void register(ViaProviders providers) {
providers.register(AlphaInventoryProvider.class, new TrackingAlphaInventoryProvider());
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class, ClientboundPacketsa1_2_6::getPacket));
userConnection.put(new InventoryStorage(userConnection));
if (Via.getManager().getProviders().get(AlphaInventoryProvider.class).usesInventoryTracker()) {
userConnection.put(new AlphaInventoryTracker(userConnection));
}
}
}

View File

@ -0,0 +1,143 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ServerboundPacketsa1_2_6 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
PLAYER_INVENTORY(5, (user, buf) -> {
buf.readInt();
int x = buf.readShort();
for (int i = 0; i < x; i++) PreNettyTypes.readItemStackb1_2(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readInt();
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COMPLEX_ENTITY(59, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
int x = buf.readUnsignedShort();
for (int i = 0; i < x; i++) buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ServerboundPacketsa1_2_6[] REGISTRY = new ServerboundPacketsa1_2_6[256];
static {
for (ServerboundPacketsa1_2_6 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsa1_2_6 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsa1_2_6(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,394 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.fastutil.ints.*;
import net.raphimc.vialegacy.api.BlockList1_6;
import net.raphimc.vialegacy.api.IdAndData;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class AlphaItems {
private static final IntList ITEM_IDS = new IntArrayList();
private static final Int2IntMap MAX_STACK_SIZE = new Int2IntOpenHashMap(70, 0.99F);
private static final Int2ObjectMap<Consumer<Item>> INTERACT_ACTION = new Int2ObjectOpenHashMap<>(14, 0.99F);
private static final Int2ObjectMap<BiConsumer<Item, IntObjectPair<IdAndData>>> PLACE_ACTION = new Int2ObjectOpenHashMap<>(15, 0.99F);
static {
ITEM_IDS.add(1);
ITEM_IDS.add(2);
ITEM_IDS.add(3);
ITEM_IDS.add(4);
ITEM_IDS.add(5);
ITEM_IDS.add(6);
ITEM_IDS.add(7);
ITEM_IDS.add(8);
ITEM_IDS.add(9);
ITEM_IDS.add(10);
ITEM_IDS.add(11);
ITEM_IDS.add(12);
ITEM_IDS.add(13);
ITEM_IDS.add(14);
ITEM_IDS.add(15);
ITEM_IDS.add(16);
ITEM_IDS.add(17);
ITEM_IDS.add(18);
ITEM_IDS.add(19);
ITEM_IDS.add(20);
ITEM_IDS.add(35);
ITEM_IDS.add(37);
ITEM_IDS.add(38);
ITEM_IDS.add(39);
ITEM_IDS.add(40);
ITEM_IDS.add(41);
ITEM_IDS.add(42);
ITEM_IDS.add(43);
ITEM_IDS.add(44);
ITEM_IDS.add(45);
ITEM_IDS.add(46);
ITEM_IDS.add(47);
ITEM_IDS.add(48);
ITEM_IDS.add(49);
ITEM_IDS.add(50);
ITEM_IDS.add(51);
ITEM_IDS.add(52);
ITEM_IDS.add(53);
ITEM_IDS.add(54);
ITEM_IDS.add(55);
ITEM_IDS.add(56);
ITEM_IDS.add(57);
ITEM_IDS.add(58);
ITEM_IDS.add(59);
ITEM_IDS.add(60);
ITEM_IDS.add(61);
ITEM_IDS.add(62);
ITEM_IDS.add(63);
ITEM_IDS.add(64);
ITEM_IDS.add(65);
ITEM_IDS.add(66);
ITEM_IDS.add(67);
ITEM_IDS.add(68);
ITEM_IDS.add(69);
ITEM_IDS.add(70);
ITEM_IDS.add(71);
ITEM_IDS.add(72);
ITEM_IDS.add(73);
ITEM_IDS.add(74);
ITEM_IDS.add(75);
ITEM_IDS.add(76);
ITEM_IDS.add(77);
ITEM_IDS.add(78);
ITEM_IDS.add(79);
ITEM_IDS.add(80);
ITEM_IDS.add(81);
ITEM_IDS.add(82);
ITEM_IDS.add(83);
ITEM_IDS.add(84);
ITEM_IDS.add(85);
ITEM_IDS.add(86);
ITEM_IDS.add(87);
ITEM_IDS.add(88);
ITEM_IDS.add(89);
ITEM_IDS.add(90);
ITEM_IDS.add(91);
ITEM_IDS.add(256);
ITEM_IDS.add(257);
ITEM_IDS.add(258);
ITEM_IDS.add(259);
ITEM_IDS.add(260);
ITEM_IDS.add(261);
ITEM_IDS.add(262);
ITEM_IDS.add(263);
ITEM_IDS.add(264);
ITEM_IDS.add(265);
ITEM_IDS.add(266);
ITEM_IDS.add(267);
ITEM_IDS.add(268);
ITEM_IDS.add(269);
ITEM_IDS.add(270);
ITEM_IDS.add(271);
ITEM_IDS.add(272);
ITEM_IDS.add(273);
ITEM_IDS.add(274);
ITEM_IDS.add(275);
ITEM_IDS.add(276);
ITEM_IDS.add(277);
ITEM_IDS.add(278);
ITEM_IDS.add(279);
ITEM_IDS.add(280);
ITEM_IDS.add(281);
ITEM_IDS.add(282);
ITEM_IDS.add(283);
ITEM_IDS.add(284);
ITEM_IDS.add(285);
ITEM_IDS.add(286);
ITEM_IDS.add(287);
ITEM_IDS.add(288);
ITEM_IDS.add(289);
ITEM_IDS.add(290);
ITEM_IDS.add(291);
ITEM_IDS.add(292);
ITEM_IDS.add(293);
ITEM_IDS.add(294);
ITEM_IDS.add(295);
ITEM_IDS.add(296);
ITEM_IDS.add(297);
ITEM_IDS.add(298);
ITEM_IDS.add(299);
ITEM_IDS.add(300);
ITEM_IDS.add(301);
ITEM_IDS.add(302);
ITEM_IDS.add(303);
ITEM_IDS.add(304);
ITEM_IDS.add(305);
ITEM_IDS.add(306);
ITEM_IDS.add(307);
ITEM_IDS.add(308);
ITEM_IDS.add(309);
ITEM_IDS.add(310);
ITEM_IDS.add(311);
ITEM_IDS.add(312);
ITEM_IDS.add(313);
ITEM_IDS.add(314);
ITEM_IDS.add(315);
ITEM_IDS.add(316);
ITEM_IDS.add(317);
ITEM_IDS.add(318);
ITEM_IDS.add(319);
ITEM_IDS.add(320);
ITEM_IDS.add(321);
ITEM_IDS.add(322);
ITEM_IDS.add(323);
ITEM_IDS.add(324);
ITEM_IDS.add(325);
ITEM_IDS.add(326);
ITEM_IDS.add(327);
ITEM_IDS.add(328);
ITEM_IDS.add(329);
ITEM_IDS.add(330);
ITEM_IDS.add(331);
ITEM_IDS.add(332);
ITEM_IDS.add(333);
ITEM_IDS.add(334);
ITEM_IDS.add(335);
ITEM_IDS.add(336);
ITEM_IDS.add(337);
ITEM_IDS.add(338);
ITEM_IDS.add(339);
ITEM_IDS.add(340);
ITEM_IDS.add(341);
ITEM_IDS.add(342);
ITEM_IDS.add(343);
ITEM_IDS.add(344);
ITEM_IDS.add(345);
ITEM_IDS.add(346);
ITEM_IDS.add(347);
ITEM_IDS.add(348);
ITEM_IDS.add(349);
ITEM_IDS.add(350);
ITEM_IDS.add(2256);
ITEM_IDS.add(2257);
MAX_STACK_SIZE.defaultReturnValue(64);
MAX_STACK_SIZE.put(256, 1);
MAX_STACK_SIZE.put(257, 1);
MAX_STACK_SIZE.put(258, 1);
MAX_STACK_SIZE.put(259, 1);
MAX_STACK_SIZE.put(260, 1);
MAX_STACK_SIZE.put(261, 1);
MAX_STACK_SIZE.put(267, 1);
MAX_STACK_SIZE.put(268, 1);
MAX_STACK_SIZE.put(269, 1);
MAX_STACK_SIZE.put(270, 1);
MAX_STACK_SIZE.put(271, 1);
MAX_STACK_SIZE.put(272, 1);
MAX_STACK_SIZE.put(273, 1);
MAX_STACK_SIZE.put(274, 1);
MAX_STACK_SIZE.put(275, 1);
MAX_STACK_SIZE.put(276, 1);
MAX_STACK_SIZE.put(277, 1);
MAX_STACK_SIZE.put(278, 1);
MAX_STACK_SIZE.put(279, 1);
MAX_STACK_SIZE.put(282, 1);
MAX_STACK_SIZE.put(283, 1);
MAX_STACK_SIZE.put(284, 1);
MAX_STACK_SIZE.put(285, 1);
MAX_STACK_SIZE.put(286, 1);
MAX_STACK_SIZE.put(290, 1);
MAX_STACK_SIZE.put(291, 1);
MAX_STACK_SIZE.put(292, 1);
MAX_STACK_SIZE.put(293, 1);
MAX_STACK_SIZE.put(294, 1);
MAX_STACK_SIZE.put(297, 1);
MAX_STACK_SIZE.put(298, 1);
MAX_STACK_SIZE.put(299, 1);
MAX_STACK_SIZE.put(300, 1);
MAX_STACK_SIZE.put(301, 1);
MAX_STACK_SIZE.put(302, 1);
MAX_STACK_SIZE.put(303, 1);
MAX_STACK_SIZE.put(304, 1);
MAX_STACK_SIZE.put(305, 1);
MAX_STACK_SIZE.put(306, 1);
MAX_STACK_SIZE.put(307, 1);
MAX_STACK_SIZE.put(308, 1);
MAX_STACK_SIZE.put(309, 1);
MAX_STACK_SIZE.put(310, 1);
MAX_STACK_SIZE.put(311, 1);
MAX_STACK_SIZE.put(312, 1);
MAX_STACK_SIZE.put(313, 1);
MAX_STACK_SIZE.put(314, 1);
MAX_STACK_SIZE.put(315, 1);
MAX_STACK_SIZE.put(316, 1);
MAX_STACK_SIZE.put(317, 1);
MAX_STACK_SIZE.put(319, 1);
MAX_STACK_SIZE.put(320, 1);
MAX_STACK_SIZE.put(322, 1);
MAX_STACK_SIZE.put(323, 1);
MAX_STACK_SIZE.put(324, 1);
MAX_STACK_SIZE.put(325, 1);
MAX_STACK_SIZE.put(326, 1);
MAX_STACK_SIZE.put(327, 1);
MAX_STACK_SIZE.put(328, 1);
MAX_STACK_SIZE.put(329, 1);
MAX_STACK_SIZE.put(330, 1);
MAX_STACK_SIZE.put(332, 16);
MAX_STACK_SIZE.put(333, 1);
MAX_STACK_SIZE.put(335, 1);
MAX_STACK_SIZE.put(342, 1);
MAX_STACK_SIZE.put(343, 1);
MAX_STACK_SIZE.put(349, 1);
MAX_STACK_SIZE.put(350, 1);
MAX_STACK_SIZE.put(2256, 1);
MAX_STACK_SIZE.put(2257, 1);
INTERACT_ACTION.defaultReturnValue(Item::identifier); // no op
INTERACT_ACTION.put(260, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(297, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(319, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(320, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(322, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(326, i -> i.setIdentifier(325));
INTERACT_ACTION.put(327, i -> i.setIdentifier(325));
INTERACT_ACTION.put(332, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(333, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(335, i -> i.setIdentifier(325));
INTERACT_ACTION.put(346, i -> {
i.setData((short) (i.data() + 1));
if (i.data() > 64) {
i.setAmount(i.amount() - 1);
}
});
INTERACT_ACTION.put(349, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(350, i -> i.setAmount(i.amount() - 1));
INTERACT_ACTION.put(282, i -> {
i.setIdentifier(281);
i.setAmount(1);
i.setData((short) 0);
});
PLACE_ACTION.defaultReturnValue((i, d) -> i.identifier()); // no op
PLACE_ACTION.put(259, (i, d) -> {
i.setData((short) (i.data() + 1));
if (i.data() > 64) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(290, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 32) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(291, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 64) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(292, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 128) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(293, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 256) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(294, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 64) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(295, (i, d) -> {
if (d.keyInt() == 1 && d.value().id == BlockList1_6.tilledField.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(321, (i, d) -> {
if (d.keyInt() != 0 && d.keyInt() != 1) i.setAmount(i.amount() - 1);
});
PLACE_ACTION.put(324, (i, d) -> {
if (d.keyInt() == 1) i.setAmount(i.amount() - 1);
});
PLACE_ACTION.put(328, (i, d) -> {
if (d.value().id == BlockList1_6.rail.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(330, (i, d) -> {
if (d.keyInt() == 1) i.setAmount(i.amount() - 1);
});
PLACE_ACTION.put(342, (i, d) -> {
if (d.value().id == BlockList1_6.rail.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(343, (i, d) -> {
if (d.value().id == BlockList1_6.rail.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(2256, (i, d) -> {
if (d.value().id == BlockList1_6.jukebox.blockID && d.value().data == 0) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(2257, (i, d) -> {
if (d.value().id == BlockList1_6.jukebox.blockID && d.value().data == 0) {
i.setAmount(i.amount() - 1);
}
});
}
public static boolean isValid(final int itemId) {
return ITEM_IDS.contains(itemId);
}
public static int getMaxStackSize(final int itemId) {
return MAX_STACK_SIZE.get(itemId);
}
public static void doInteract(final Item item) {
INTERACT_ACTION.get(item.identifier()).accept(item);
}
public static void doPlace(final Item item, final short direction, final IdAndData placedAgainst) {
PLACE_ACTION.get(item.identifier()).accept(item, new IntObjectImmutablePair<>(direction, placedAgainst));
}
}

View File

@ -0,0 +1,163 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import net.raphimc.vialegacy.api.BlockList1_6;
import net.raphimc.vialegacy.api.ItemList1_6;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.model.CraftingRecipe;
import java.util.*;
public class CraftingManager {
private static final List<CraftingRecipe> recipes = new ArrayList<>();
private static final String[][] tools_pattern = new String[][]{{"XXX", " # ", " # "}, {"X", "#", "#"}, {"XX", "X#", " #"}, {"XX", " #", " #"}};
private static final int[][] tools_ingredients = new int[][]{{BlockList1_6.planks.blockID, BlockList1_6.cobblestone.blockID, ItemList1_6.ingotIron.itemID, ItemList1_6.diamond.itemID, ItemList1_6.ingotGold.itemID}, {ItemList1_6.pickaxeWood.itemID, ItemList1_6.pickaxeStone.itemID, ItemList1_6.pickaxeIron.itemID, ItemList1_6.pickaxeDiamond.itemID, ItemList1_6.pickaxeGold.itemID}, {ItemList1_6.shovelWood.itemID, ItemList1_6.shovelStone.itemID, ItemList1_6.shovelIron.itemID, ItemList1_6.shovelDiamond.itemID, ItemList1_6.shovelGold.itemID}, {ItemList1_6.axeWood.itemID, ItemList1_6.axeStone.itemID, ItemList1_6.axeIron.itemID, ItemList1_6.axeDiamond.itemID, ItemList1_6.axeGold.itemID}, {ItemList1_6.hoeWood.itemID, ItemList1_6.hoeStone.itemID, ItemList1_6.hoeIron.itemID, ItemList1_6.hoeDiamond.itemID, ItemList1_6.hoeGold.itemID}};
private static final String[][] weapons_pattern = new String[][]{{"X", "X", "#"}};
private static final int[][] weapons_ingredients = new int[][]{{BlockList1_6.planks.blockID, BlockList1_6.cobblestone.blockID, ItemList1_6.ingotIron.itemID, ItemList1_6.diamond.itemID, ItemList1_6.ingotGold.itemID}, {ItemList1_6.swordWood.itemID, ItemList1_6.swordStone.itemID, ItemList1_6.swordIron.itemID, ItemList1_6.swordDiamond.itemID, ItemList1_6.swordGold.itemID}};
private static final int[][] ingots_ingredients = new int[][]{{BlockList1_6.blockGold.blockID, ItemList1_6.ingotGold.itemID}, {BlockList1_6.blockIron.blockID, ItemList1_6.ingotIron.itemID}, {BlockList1_6.blockDiamond.blockID, ItemList1_6.diamond.itemID}};
private static final String[][] armor_pattern = new String[][]{{"XXX", "X X"}, {"X X", "XXX", "XXX"}, {"XXX", "X X", "X X"}, {"X X", "X X"}};
private static final int[][] armor_ingredients = new int[][]{{ItemList1_6.leather.itemID, BlockList1_6.fire.blockID, ItemList1_6.ingotIron.itemID, ItemList1_6.diamond.itemID, ItemList1_6.ingotGold.itemID}, {ItemList1_6.helmetLeather.itemID, ItemList1_6.helmetChain.itemID, ItemList1_6.helmetIron.itemID, ItemList1_6.helmetDiamond.itemID, ItemList1_6.helmetGold.itemID}, {ItemList1_6.plateLeather.itemID, ItemList1_6.plateChain.itemID, ItemList1_6.plateIron.itemID, ItemList1_6.plateDiamond.itemID, ItemList1_6.plateGold.itemID}, {ItemList1_6.legsLeather.itemID, ItemList1_6.legsChain.itemID, ItemList1_6.legsIron.itemID, ItemList1_6.legsDiamond.itemID, ItemList1_6.legsGold.itemID}, {ItemList1_6.bootsLeather.itemID, ItemList1_6.bootsChain.itemID, ItemList1_6.bootsIron.itemID, ItemList1_6.bootsDiamond.itemID, ItemList1_6.bootsGold.itemID}};
static {
for (int i = 0; i < tools_ingredients[0].length; ++i) {
for (int i1 = 0; i1 < tools_ingredients.length - 1; ++i1) {
addRecipe(new DataItem(tools_ingredients[i1 + 1][i], (byte) 1, (short) 0, null), tools_pattern[i1], '#', ItemList1_6.stick.itemID, 'X', tools_ingredients[0][i]);
}
}
for (int i = 0; i < weapons_ingredients[0].length; ++i) {
for (int i1 = 0; i1 < weapons_ingredients.length - 1; ++i1) {
addRecipe(new DataItem(weapons_ingredients[i1 + 1][i], (byte) 1, (short) 0, null), weapons_pattern[i1], '#', ItemList1_6.stick.itemID, 'X', weapons_ingredients[0][i]);
}
}
addRecipe(new DataItem(ItemList1_6.bow.itemID, (byte) 1, (short) 0, null), " #X", "# X", " #X", 'X', ItemList1_6.silk.itemID, '#', ItemList1_6.stick.itemID);
addRecipe(new DataItem(ItemList1_6.arrow.itemID, (byte) 4, (short) 0, null), "X", "#", "Y", 'Y', ItemList1_6.feather.itemID, 'X', ItemList1_6.flint.itemID, '#', ItemList1_6.stick.itemID);
for (int[] ingots_ingredient : ingots_ingredients) {
addRecipe(new DataItem(ingots_ingredient[0], (byte) 1, (short) 0, null), "###", "###", "###", '#', ingots_ingredient[1]);
addRecipe(new DataItem(ingots_ingredient[1], (byte) 9, (short) 0, null), "#", '#', ingots_ingredient[0]);
}
addRecipe(new DataItem(ItemList1_6.bowlSoup.itemID, (byte) 1, (short) 0, null), "Y", "X", "#", 'X', BlockList1_6.mushroomBrown.blockID, 'Y', BlockList1_6.mushroomRed.blockID, '#', ItemList1_6.bowlEmpty.itemID);
addRecipe(new DataItem(ItemList1_6.bowlSoup.itemID, (byte) 1, (short) 0, null), "Y", "X", "#", 'X', BlockList1_6.mushroomRed.blockID, 'Y', BlockList1_6.mushroomBrown.blockID, '#', ItemList1_6.bowlEmpty.itemID);
addRecipe(new DataItem(BlockList1_6.chest.blockID, (byte) 1, (short) 0, null), "###", "# #", "###", '#', BlockList1_6.planks.blockID);
addRecipe(new DataItem(BlockList1_6.furnaceIdle.blockID, (byte) 1, (short) 0, null), "###", "# #", "###", '#', BlockList1_6.cobblestone.blockID);
addRecipe(new DataItem(BlockList1_6.workbench.blockID, (byte) 1, (short) 0, null), "##", "##", '#', BlockList1_6.planks.blockID);
for (int i = 0; i < armor_ingredients[0].length; ++i) {
for (int i1 = 0; i1 < armor_ingredients.length - 1; ++i1) {
addRecipe(new DataItem(armor_ingredients[i1 + 1][i], (byte) 1, (short) 0, null), armor_pattern[i1], 'X', armor_ingredients[0][i]);
}
}
addRecipe(new DataItem(ItemList1_6.paper.itemID, (byte) 3, (short) 0, null), "###", '#', ItemList1_6.reed.itemID);
addRecipe(new DataItem(ItemList1_6.book.itemID, (byte) 1, (short) 0, null), "#", "#", "#", '#', ItemList1_6.paper.itemID);
addRecipe(new DataItem(BlockList1_6.fence.blockID, (byte) 2, (short) 0, null), "###", "###", '#', ItemList1_6.stick.itemID);
addRecipe(new DataItem(BlockList1_6.jukebox.blockID, (byte) 1, (short) 0, null), "###", "#X#", "###", '#', BlockList1_6.planks.blockID, 'X', ItemList1_6.diamond.itemID);
addRecipe(new DataItem(BlockList1_6.bookShelf.blockID, (byte) 1, (short) 0, null), "###", "XXX", "###", '#', BlockList1_6.planks.blockID, 'X', ItemList1_6.book.itemID);
addRecipe(new DataItem(BlockList1_6.blockSnow.blockID, (byte) 1, (short) 0, null), "##", "##", '#', ItemList1_6.snowball.itemID);
addRecipe(new DataItem(BlockList1_6.blockClay.blockID, (byte) 1, (short) 0, null), "##", "##", '#', ItemList1_6.clay.itemID);
addRecipe(new DataItem(BlockList1_6.brick.blockID, (byte) 1, (short) 0, null), "##", "##", '#', ItemList1_6.brick.itemID);
addRecipe(new DataItem(BlockList1_6.glowStone.blockID, (byte) 1, (short) 0, null), "###", "###", "###", '#', ItemList1_6.glowstone.itemID);
addRecipe(new DataItem(BlockList1_6.cloth.blockID, (byte) 1, (short) 0, null), "###", "###", "###", '#', ItemList1_6.silk.itemID);
addRecipe(new DataItem(BlockList1_6.tnt.blockID, (byte) 1, (short) 0, null), "X#X", "#X#", "X#X", 'X', ItemList1_6.gunpowder.itemID, '#', BlockList1_6.sand.blockID);
addRecipe(new DataItem(BlockList1_6.stoneSingleSlab.blockID, (byte) 3, (short) 0, null), "###", '#', BlockList1_6.cobblestone.blockID);
addRecipe(new DataItem(BlockList1_6.ladder.blockID, (byte) 1, (short) 0, null), "# #", "###", "# #", '#', ItemList1_6.stick.itemID);
addRecipe(new DataItem(ItemList1_6.doorWood.itemID, (byte) 1, (short) 0, null), "##", "##", "##", '#', BlockList1_6.planks.blockID);
addRecipe(new DataItem(ItemList1_6.doorIron.itemID, (byte) 1, (short) 0, null), "##", "##", "##", '#', ItemList1_6.ingotIron.itemID);
addRecipe(new DataItem(ItemList1_6.sign.itemID, (byte) 1, (short) 0, null), "###", "###", " X ", '#', BlockList1_6.planks.blockID, 'X', ItemList1_6.stick.itemID);
addRecipe(new DataItem(BlockList1_6.planks.blockID, (byte) 4, (short) 0, null), "#", '#', BlockList1_6.wood.blockID);
addRecipe(new DataItem(ItemList1_6.stick.itemID, (byte) 4, (short) 0, null), "#", "#", '#', BlockList1_6.planks.blockID);
addRecipe(new DataItem(BlockList1_6.torchWood.blockID, (byte) 4, (short) 0, null), "X", "#", 'X', ItemList1_6.coal.itemID, '#', ItemList1_6.stick.itemID);
addRecipe(new DataItem(ItemList1_6.bowlEmpty.itemID, (byte) 4, (short) 0, null), "# #", " # ", '#', BlockList1_6.planks.blockID);
addRecipe(new DataItem(BlockList1_6.rail.blockID, (byte) 16, (short) 0, null), "X X", "X#X", "X X", 'X', ItemList1_6.ingotIron.itemID, '#', ItemList1_6.stick.itemID);
addRecipe(new DataItem(ItemList1_6.minecartEmpty.itemID, (byte) 1, (short) 0, null), "# #", "###", '#', ItemList1_6.ingotIron.itemID);
addRecipe(new DataItem(BlockList1_6.pumpkinLantern.blockID, (byte) 1, (short) 0, null), "A", "B", 'A', BlockList1_6.pumpkin.blockID, 'B', BlockList1_6.torchWood.blockID);
addRecipe(new DataItem(ItemList1_6.minecartCrate.itemID, (byte) 1, (short) 0, null), "A", "B", 'A', BlockList1_6.chest.blockID, 'B', ItemList1_6.minecartEmpty.itemID);
addRecipe(new DataItem(ItemList1_6.minecartPowered.itemID, (byte) 1, (short) 0, null), "A", "B", 'A', BlockList1_6.furnaceIdle.blockID, 'B', ItemList1_6.minecartEmpty.itemID);
addRecipe(new DataItem(ItemList1_6.boat.itemID, (byte) 1, (short) 0, null), "# #", "###", '#', BlockList1_6.planks.blockID);
addRecipe(new DataItem(ItemList1_6.bucketEmpty.itemID, (byte) 1, (short) 0, null), "# #", " # ", '#', ItemList1_6.ingotIron.itemID);
addRecipe(new DataItem(ItemList1_6.flintAndSteel.itemID, (byte) 1, (short) 0, null), "A ", " B", 'A', ItemList1_6.ingotIron.itemID, 'B', ItemList1_6.flint.itemID);
addRecipe(new DataItem(ItemList1_6.bread.itemID, (byte) 1, (short) 0, null), "###", '#', ItemList1_6.wheat.itemID);
addRecipe(new DataItem(BlockList1_6.stairsWoodOak.blockID, (byte) 4, (short) 0, null), "# ", "## ", "###", '#', BlockList1_6.planks.blockID);
addRecipe(new DataItem(ItemList1_6.fishingRod.itemID, (byte) 1, (short) 0, null), " #", " #X", "# X", '#', ItemList1_6.stick.itemID, 'X', ItemList1_6.silk.itemID);
addRecipe(new DataItem(BlockList1_6.stairsCobblestone.blockID, (byte) 4, (short) 0, null), "# ", "## ", "###", '#', BlockList1_6.cobblestone.blockID);
addRecipe(new DataItem(ItemList1_6.painting.itemID, (byte) 1, (short) 0, null), "###", "#X#", "###", '#', ItemList1_6.stick.itemID, 'X', BlockList1_6.cloth.blockID);
addRecipe(new DataItem(ItemList1_6.appleGold.itemID, (byte) 1, (short) 0, null), "###", "#X#", "###", '#', BlockList1_6.blockGold.blockID, 'X', ItemList1_6.appleRed.itemID);
addRecipe(new DataItem(BlockList1_6.lever.blockID, (byte) 1, (short) 0, null), "X", "#", '#', BlockList1_6.cobblestone.blockID, 'X', ItemList1_6.stick.itemID);
addRecipe(new DataItem(BlockList1_6.torchRedstoneActive.blockID, (byte) 1, (short) 0, null), "X", "#", '#', ItemList1_6.stick.itemID, 'X', ItemList1_6.redstone.itemID);
addRecipe(new DataItem(ItemList1_6.pocketSundial.itemID, (byte) 1, (short) 0, null), " # ", "#X#", " # ", '#', ItemList1_6.ingotGold.itemID, 'X', ItemList1_6.redstone.itemID);
addRecipe(new DataItem(ItemList1_6.compass.itemID, (byte) 1, (short) 0, null), " # ", "#X#", " # ", '#', ItemList1_6.ingotIron.itemID, 'X', ItemList1_6.redstone.itemID);
addRecipe(new DataItem(BlockList1_6.stoneButton.blockID, (byte) 1, (short) 0, null), "#", "#", '#', BlockList1_6.stone.blockID);
addRecipe(new DataItem(BlockList1_6.pressurePlateStone.blockID, (byte) 1, (short) 0, null), "###", '#', BlockList1_6.stone.blockID);
addRecipe(new DataItem(BlockList1_6.pressurePlatePlanks.blockID, (byte) 1, (short) 0, null), "###", '#', BlockList1_6.planks.blockID);
recipes.sort((o1, o2) -> Integer.compare(o2.getRecipeSize(), o1.getRecipeSize()));
}
private static void addRecipe(final Item resultItem, final Object... objects) {
String var3 = "";
int pos = 0;
int width = 0;
int height = 0;
if (objects[pos] instanceof String[]) {
String[] var11 = (String[]) objects[pos++];
for (String var9 : var11) {
height++;
width = var9.length();
var3 = var3 + var9;
}
} else {
while (objects[pos] instanceof String) {
String var7 = (String) objects[pos++];
height++;
width = var7.length();
var3 = var3 + var7;
}
}
final HashMap<Character, Integer> lookup = new HashMap<>();
while (pos < objects.length) {
lookup.put((char) objects[pos], (int) objects[pos + 1]);
pos += 2;
}
final int[] ingredientMap = new int[width * height];
for (int i = 0; i < ingredientMap.length; i++) {
ingredientMap[i] = lookup.getOrDefault(var3.charAt(i), -1);
}
recipes.add(new CraftingRecipe(width, height, ingredientMap, resultItem));
}
public static Item getResult(final Item[] craftingGrid) {
final int gridSize = (int) Math.sqrt(craftingGrid.length);
final int[] ingredientMap = new int[9];
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
int ingredient = -1;
if (x < gridSize && y < gridSize) {
final Item item = craftingGrid[x + y * gridSize];
if (item != null) {
ingredient = item.identifier();
}
}
ingredientMap[x + y * 3] = ingredient;
}
}
return getResult(ingredientMap);
}
public static Item getResult(final int[] ingredientMap) {
for (CraftingRecipe recipe : recipes) {
if (recipe.matches(ingredientMap)) {
return recipe.createResult();
}
}
return null;
}
}

View File

@ -0,0 +1,65 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.model;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
public class CraftingRecipe {
private final int width;
private final int height;
private final int[] ingredientMap;
private final Item resultItem;
public CraftingRecipe(final int width, final int height, final int[] ingredientMap, final Item resultItem) {
this.width = width;
this.height = height;
this.ingredientMap = ingredientMap;
this.resultItem = resultItem;
}
public boolean matches(final int[] ingredientMap) {
for (int x = 0; x <= 3 - this.width; x++) {
for (int y = 0; y <= 3 - this.height; y++) {
if (this.matches(ingredientMap, x, y, true)) {
return true;
} else if (this.matches(ingredientMap, x, y, false)) {
return true;
}
}
}
return false;
}
private boolean matches(final int[] ingredientMap, final int x, final int y, final boolean b) {
for (int xx = 0; xx < 3; xx++) {
for (int yy = 0; yy < 3; yy++) {
final int rx = xx - x;
final int ry = yy - y;
int var9 = -1;
if (rx >= 0 && ry >= 0 && rx < this.width && ry < this.height) {
if (b) {
var9 = this.ingredientMap[this.width - rx - 1 + ry * this.width];
} else {
var9 = this.ingredientMap[rx + ry * this.width];
}
}
if (ingredientMap[xx + yy * 3] != var9) {
return false;
}
}
}
return true;
}
public Item createResult() {
return new DataItem(this.resultItem);
}
public int getRecipeSize() {
return this.width * this.height;
}
}

View File

@ -0,0 +1,28 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.platform.providers.Provider;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.InventoryStorage;
public abstract class AlphaInventoryProvider implements Provider {
public abstract boolean usesInventoryTracker();
public Item getHandItem(final UserConnection user) {
final InventoryStorage inventoryStorage = user.get(InventoryStorage.class);
final Item[] inventory = this.getMainInventoryItems(user);
return inventory[inventoryStorage.selectedHotbarSlot];
}
public abstract Item[] getMainInventoryItems(final UserConnection user);
public abstract Item[] getCraftingInventoryItems(final UserConnection user);
public abstract Item[] getArmorInventoryItems(final UserConnection user);
public abstract Item[] getContainerItems(final UserConnection user);
public abstract void addToInventory(final UserConnection user, final Item item);
}

View File

@ -0,0 +1,39 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.InventoryStorage;
public class NoOpAlphaInventoryProvider extends AlphaInventoryProvider {
@Override
public boolean usesInventoryTracker() {
return false;
}
@Override
public Item[] getMainInventoryItems(UserConnection user) {
return new Item[36];
}
@Override
public Item[] getCraftingInventoryItems(UserConnection user) {
return new Item[4];
}
@Override
public Item[] getArmorInventoryItems(UserConnection user) {
return new Item[4];
}
@Override
public Item[] getContainerItems(UserConnection user) {
final InventoryStorage inventoryStorage = user.get(InventoryStorage.class);
return inventoryStorage.containers.get(inventoryStorage.openContainerPos);
}
@Override
public void addToInventory(UserConnection user, Item item) {
}
}

View File

@ -0,0 +1,41 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.AlphaInventoryTracker;
import static net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.copyItems;
public class TrackingAlphaInventoryProvider extends AlphaInventoryProvider {
@Override
public boolean usesInventoryTracker() {
return true;
}
@Override
public Item[] getMainInventoryItems(UserConnection user) {
return copyItems(user.get(AlphaInventoryTracker.class).getMainInventory());
}
@Override
public Item[] getCraftingInventoryItems(UserConnection user) {
return copyItems(user.get(AlphaInventoryTracker.class).getCraftingInventory());
}
@Override
public Item[] getArmorInventoryItems(UserConnection user) {
return copyItems(user.get(AlphaInventoryTracker.class).getArmorInventory());
}
@Override
public Item[] getContainerItems(UserConnection user) {
return copyItems(user.get(AlphaInventoryTracker.class).getOpenContainerItems());
}
@Override
public void addToInventory(UserConnection user, Item item) {
user.get(AlphaInventoryTracker.class).addItem(item);
}
}

View File

@ -0,0 +1,443 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.api.*;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data.AlphaItems;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data.CraftingManager;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ClientboundPacketsb1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.types.Typesb1_1;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.Protocolc0_30toc0_30cpe;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
import net.raphimc.vialegacy.util.BlockFaceUtils;
import java.util.Arrays;
import static net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.*;
public class AlphaInventoryTracker extends StoredObject {
private boolean creativeMode;
private Item[] mainInventory = null;
private Item[] craftingInventory = null;
private Item[] armorInventory = null;
private Item[] openContainerItems = null;
private Item cursorItem = null;
private int openWindowType = -1;
final InventoryStorage inventoryStorage;
public AlphaInventoryTracker(UserConnection user) {
super(user);
this.inventoryStorage = user.get(InventoryStorage.class);
this.onRespawn();
}
public void onWindowOpen(final int windowType, final int containerSlots) {
this.openWindowType = windowType;
this.openContainerItems = new Item[containerSlots];
}
public void onWindowClose() throws Exception {
if (this.openWindowType == 1) { // crafting table
for (int i = 1; i <= 9; i++) {
final Item item = this.openContainerItems[i];
if (item == null) continue;
dropItem(this.getUser(), item, false);
this.openContainerItems[i] = null;
}
}
for (int i = 0; i < 4; i++) {
final Item item = this.craftingInventory[i];
if (item == null) continue;
dropItem(this.getUser(), item, false);
this.craftingInventory[i] = null;
}
if (this.cursorItem != null) {
dropItem(this.getUser(), this.cursorItem, false);
this.cursorItem = null;
}
this.openWindowType = -1;
this.updatePlayerInventory();
this.updateCursorItem();
}
public void onWindowClick(final byte windowId, final short slot, final byte button, final short action, final Item item) throws Exception {
final boolean leftClick = button != 1;
if (slot == -999) {
if (this.cursorItem != null) {
if (leftClick) {
dropItem(this.getUser(), this.cursorItem, false);
this.cursorItem = null;
} else {
dropItem(this.getUser(), this.splitStack(this.cursorItem, 1), false);
}
}
} else {
Item[] slots = null;
boolean slotTakesItems = true;
int slotStackLimit = 64;
boolean isCraftingResultSlot = false;
switch (windowId) {
case 0:
slots = new Item[45];
System.arraycopy(this.mainInventory, 0, slots, 36, 9);
System.arraycopy(this.mainInventory, 9, slots, 9, 36 - 9);
System.arraycopy(this.craftingInventory, 0, slots, 1, 4);
System.arraycopy(reverseArray(this.armorInventory), 0, slots, 5, 4);
isCraftingResultSlot = slot == 0; // crafting result slot
slotTakesItems = !isCraftingResultSlot;
slotStackLimit = slot >= 5 && slot <= 8 ? 1 : 64; // armor slots
if (isCraftingResultSlot) {
slots[0] = CraftingManager.getResult(this.craftingInventory);
}
break;
case InventoryStorage.WORKBENCH_WID:
slots = new Item[46];
System.arraycopy(this.openContainerItems, 0, slots, 0, 10);
System.arraycopy(this.mainInventory, 0, slots, 37, 9);
System.arraycopy(this.mainInventory, 9, slots, 10, 36 - 9);
isCraftingResultSlot = slot == 0; // crafting result slot
slotTakesItems = !isCraftingResultSlot;
if (isCraftingResultSlot) {
final Item[] craftingGrid = Arrays.copyOfRange(this.openContainerItems, 1, 10);
slots[0] = CraftingManager.getResult(craftingGrid);
}
break;
case InventoryStorage.FURNACE_WID:
slots = new Item[39];
System.arraycopy(this.openContainerItems, 0, slots, 0, 3);
System.arraycopy(this.mainInventory, 0, slots, 30, 9);
System.arraycopy(this.mainInventory, 9, slots, 3, 36 - 9);
break;
case InventoryStorage.CHEST_WID:
slots = new Item[63];
System.arraycopy(this.openContainerItems, 0, slots, 0, 3 * 9);
System.arraycopy(this.mainInventory, 0, slots, 54, 9);
System.arraycopy(this.mainInventory, 9, slots, 27, 36 - 9);
break;
}
if (slots != null) {
final Item itm = slots[slot];
if (itm == null) { // click empty slot
if (this.cursorItem != null && slotTakesItems) { // with item on cursor
int amount = leftClick ? this.cursorItem.amount() : 1;
if (amount > slotStackLimit) amount = slotStackLimit;
slots[slot] = splitStack(this.cursorItem, amount);
}
} else if (this.cursorItem == null) { // click filled slot with no item on cursor
int amount = leftClick ? itm.amount() : (itm.amount() + 1) / 2;
if (isCraftingResultSlot) amount = itm.amount(); // crafting result slot does not support taking half the stack
this.cursorItem = splitStack(itm, amount);
if (isCraftingResultSlot) this.onCraftingResultPickup(windowId, slots);
} else if (slotTakesItems) { // click filled slot with item on cursor
if (itm.identifier() != this.cursorItem.identifier()) { // items are different
if (this.cursorItem.amount() <= slotStackLimit) {
slots[slot] = this.cursorItem;
this.cursorItem = itm;
}
} else { // items are the same
int amount = leftClick ? this.cursorItem.amount() : 1;
if (amount > slotStackLimit - itm.amount()) amount = slotStackLimit - itm.amount();
if (amount > AlphaItems.getMaxStackSize(this.cursorItem.identifier()) - itm.amount()) {
amount = AlphaItems.getMaxStackSize(this.cursorItem.identifier()) - itm.amount();
}
this.cursorItem.setAmount(this.cursorItem.amount() - amount);
itm.setAmount(itm.amount() + amount);
}
} else if (itm.identifier() == this.cursorItem.identifier() && AlphaItems.getMaxStackSize(this.cursorItem.identifier()) > 1) {
int amount = itm.amount();
if (amount > 0 && amount + this.cursorItem.amount() <= AlphaItems.getMaxStackSize(this.cursorItem.identifier())) {
itm.setAmount(itm.amount() - amount);
this.cursorItem.setAmount(this.cursorItem.amount() + amount);
if (isCraftingResultSlot) this.onCraftingResultPickup(windowId, slots);
}
}
for (int i = 0; i < slots.length; i++) {
final Item slotItem = slots[i];
if (slotItem != null && slotItem.amount() == 0) slots[i] = null;
}
switch (windowId) {
case 0:
System.arraycopy(slots, 36, this.mainInventory, 0, 9);
System.arraycopy(slots, 9, this.mainInventory, 9, 36 - 9);
System.arraycopy(slots, 1, this.craftingInventory, 0, 4);
System.arraycopy(slots, 5, this.armorInventory, 0, 4);
this.armorInventory = reverseArray(this.armorInventory);
break;
case InventoryStorage.WORKBENCH_WID:
System.arraycopy(slots, 0, this.openContainerItems, 0, 10);
System.arraycopy(slots, 37, this.mainInventory, 0, 9);
System.arraycopy(slots, 10, this.mainInventory, 9, 36 - 9);
break;
case InventoryStorage.FURNACE_WID:
System.arraycopy(slots, 0, this.openContainerItems, 0, 3);
System.arraycopy(slots, 30, this.mainInventory, 0, 9);
System.arraycopy(slots, 3, this.mainInventory, 9, 36 - 9);
break;
case InventoryStorage.CHEST_WID:
System.arraycopy(slots, 0, this.openContainerItems, 0, 3 * 9);
System.arraycopy(slots, 54, this.mainInventory, 0, 9);
System.arraycopy(slots, 27, this.mainInventory, 9, 36 - 9);
break;
}
this.updateInventory(windowId, slots);
boolean updateCraftResultSlot = false;
switch (windowId) {
case 0:
updateCraftResultSlot = !this.isEmpty(this.craftingInventory);
if (updateCraftResultSlot) {
slots[0] = CraftingManager.getResult(this.craftingInventory);
}
break;
case InventoryStorage.WORKBENCH_WID:
final Item[] craftingGrid = Arrays.copyOfRange(this.openContainerItems, 1, 10);
updateCraftResultSlot = !this.isEmpty(craftingGrid);
if (updateCraftResultSlot) {
slots[0] = CraftingManager.getResult(craftingGrid);
}
break;
}
if (updateCraftResultSlot) this.updateInventorySlot(windowId, (short) 0, slots[0]);
} else {
this.updatePlayerInventory();
}
}
if (this.cursorItem != null && this.cursorItem.amount() == 0) {
this.cursorItem = null;
}
this.updateCursorItem();
}
public void onBlockPlace(final Position position, final short direction) {
if (this.creativeMode) return;
final Item handItem = this.mainInventory[this.inventoryStorage.selectedHotbarSlot];
if (handItem == null) return;
if (direction == 255) { // interact
AlphaItems.doInteract(handItem);
} else { // place
final IdAndData placedAgainst = this.getUser().get(ChunkTracker.class).getBlockNotNull(position);
final IdAndData targetBlock = this.getUser().get(ChunkTracker.class).getBlockNotNull(position.getRelative(BlockFaceUtils.getFace(direction)));
AlphaItems.doPlace(handItem, direction, placedAgainst);
if (handItem.identifier() < 256 || handItem.identifier() == ItemList1_6.reed.itemID) { // block item
if (targetBlock.id == 0 || targetBlock.id == BlockList1_6.waterStill.blockID || targetBlock.id == BlockList1_6.waterMoving.blockID || targetBlock.id == BlockList1_6.lavaStill.blockID || targetBlock.id == BlockList1_6.lavaMoving.blockID || targetBlock.id == BlockList1_6.fire.blockID || targetBlock.id == BlockList1_6.snow.blockID) {
handItem.setAmount(handItem.amount() - 1);
}
} else if (handItem.identifier() == ItemList1_6.sign.itemID) {
if (direction != 0 && targetBlock.id == 0) handItem.setAmount(handItem.amount() - 1);
} else if (handItem.identifier() == ItemList1_6.redstone.itemID) {
if (targetBlock.id == 0) handItem.setAmount(handItem.amount() - 1);
}
}
if (handItem.amount() == 0) {
this.mainInventory[this.inventoryStorage.selectedHotbarSlot] = null;
}
this.updatePlayerInventorySlot(this.inventoryStorage.selectedHotbarSlot);
}
public void onHandItemDrop() {
final Item handItem = this.mainInventory[this.inventoryStorage.selectedHotbarSlot];
if (handItem == null) return;
handItem.setAmount(handItem.amount() - 1);
if (handItem.amount() == 0) {
this.mainInventory[this.inventoryStorage.selectedHotbarSlot] = null;
}
this.updatePlayerInventorySlot(this.inventoryStorage.selectedHotbarSlot);
}
public void onRespawn() {
this.mainInventory = new Item[37];
this.craftingInventory = new Item[4];
this.armorInventory = new Item[4];
this.openContainerItems = new Item[0];
this.cursorItem = null;
this.openWindowType = -1;
}
public void addItem(final Item item) {
if (item == null) return;
if (item.amount() == 0) return;
if (item.data() == 0) { // item is stackable, try to merge it with stacks of same type
int slot = -1;
for (int i = 0; i < this.mainInventory.length; i++) {
if (this.mainInventory[i] != null && this.mainInventory[i].identifier() == item.identifier() && this.mainInventory[i].amount() < AlphaItems.getMaxStackSize(this.mainInventory[i].identifier())) {
slot = i;
break;
}
}
if (slot != -1) {
int amount = item.amount();
if (amount > AlphaItems.getMaxStackSize(this.mainInventory[slot].identifier()) - this.mainInventory[slot].amount()) {
amount = AlphaItems.getMaxStackSize(this.mainInventory[slot].identifier()) - this.mainInventory[slot].amount();
}
item.setAmount(item.amount() - amount);
this.mainInventory[slot].setAmount(this.mainInventory[slot].amount() + amount);
this.updatePlayerInventorySlot((short) slot);
}
}
if (item.amount() != 0) { // if the item couldn't be fully merged with another stack or is unstackable
int slot = -1;
for (int i = 0; i < this.mainInventory.length; i++) {
if (this.mainInventory[i] == null) {
slot = i;
break;
}
}
if (slot != -1) {
this.mainInventory[slot] = item;
this.updatePlayerInventorySlot((short) slot);
}
}
}
// Add support for cheating items and classic block placement
public void handleCreativeSetSlot(short slot, Item item) throws Exception {
if (!this.getUser().getProtocolInfo().getPipeline().contains(Protocolc0_30toc0_30cpe.class)) item = fixItem(item);
if (slot <= 0) return;
if (slot <= 4) {
slot--; // remove result slot
this.craftingInventory[slot] = item;
} else if (slot <= 8) {
slot -= 5;
slot = (short) (3 - slot); // reverse array
this.armorInventory[slot] = item;
} else if (slot <= 44) {
if (slot >= 36) slot -= 36;
this.mainInventory[slot] = item;
}
}
public void setCreativeMode(final boolean creativeMode) {
this.creativeMode = creativeMode;
}
public void setMainInventory(final Item[] items) {
this.mainInventory = items;
}
public void setCraftingInventory(final Item[] items) {
this.craftingInventory = items;
}
public void setArmorInventory(final Item[] items) {
this.armorInventory = items;
}
public void setOpenContainerItems(final Item[] items) {
this.openContainerItems = items;
}
public Item[] getMainInventory() {
return this.mainInventory;
}
public Item[] getCraftingInventory() {
return this.craftingInventory;
}
public Item[] getArmorInventory() {
return this.armorInventory;
}
public Item[] getOpenContainerItems() {
return this.openContainerItems;
}
public Item getCursorItem() {
return this.cursorItem;
}
private void updatePlayerInventorySlot(final short slot) {
this.updateInventorySlot((byte) 0, slot >= 0 && slot < 9 ? (short) (slot + 36) : slot, this.mainInventory[slot]);
}
private void updateCursorItem() {
this.updateInventorySlot((byte) -1, (short) 0, this.cursorItem);
}
private void updateInventorySlot(final byte windowId, final short slot, final Item item) {
try {
final PacketWrapper setSlot = PacketWrapper.create(ClientboundPacketsb1_1.SET_SLOT, this.getUser());
setSlot.write(Type.BYTE, windowId); // window id
setSlot.write(Type.SHORT, slot); // slot
setSlot.write(Typesb1_1.NBTLESS_ITEM, copyItem(item)); // item
setSlot.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
} catch (Throwable e) {
e.printStackTrace();
}
}
private void updatePlayerInventory() {
final Item[] items = new Item[45];
System.arraycopy(this.mainInventory, 0, items, 36, 9);
System.arraycopy(this.mainInventory, 9, items, 9, 36 - 9);
System.arraycopy(this.craftingInventory, 0, items, 1, 4);
System.arraycopy(reverseArray(this.armorInventory), 0, items, 5, 4);
this.updateInventory((byte) 0, items);
}
private void updateInventory(final byte windowId, final Item[] items) {
try {
final PacketWrapper windowItems = PacketWrapper.create(ClientboundPacketsb1_1.WINDOW_ITEMS, this.getUser());
windowItems.write(Type.BYTE, windowId); // window id
windowItems.write(Types1_4_2.NBTLESS_ITEM_ARRAY, copyItems(items)); // items
windowItems.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
} catch (Throwable e) {
e.printStackTrace();
}
}
private Item splitStack(final Item item, final int size) {
item.setAmount(item.amount() - size);
final Item newItem = new DataItem(item);
newItem.setAmount(size);
return newItem;
}
private void onCraftingResultPickup(final byte windowId, final Item[] slots) {
for (int i = 1; i < 1 + (windowId == 0 ? 4 : 9); i++) {
final Item item = slots[i];
if (item == null) continue;
item.setAmount(item.amount() - 1);
}
}
private boolean isEmpty(final Item[] items) {
for (Item item : items) {
if (item != null && item.amount() != 0) return false;
}
return true;
}
}

View File

@ -0,0 +1,52 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.Item;
import java.util.*;
public class InventoryStorage extends StoredObject {
public static final byte WORKBENCH_WID = 33;
public static final byte FURNACE_WID = 44;
public static final byte CHEST_WID = 55;
public Item handItem = null;
public Item[] mainInventory = null;
public Item[] craftingInventory = null;
public Item[] armorInventory = null;
public final Map<Position, Item[]> containers = new HashMap<>();
public Position openContainerPos = null;
public short selectedHotbarSlot = 0;
public InventoryStorage(UserConnection user) {
super(user);
this.resetPlayerInventory();
}
public void unload(final int chunkX, final int chunkZ) {
final Iterator<Position> it = this.containers.keySet().iterator();
while (it.hasNext()) {
final Position entry = it.next();
final int x = entry.x() >> 4;
final int z = entry.z() >> 4;
if (chunkX == x && chunkZ == z) {
it.remove();
}
}
}
public void resetPlayerInventory() {
// alpha keeps handItem value after respawn
this.mainInventory = new Item[37];
this.craftingInventory = new Item[4];
this.armorInventory = new Item[4];
this.openContainerPos = null;
}
}

View File

@ -0,0 +1,77 @@
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.task;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.ViaLegacy;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.ServerboundPacketsa1_2_6;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.AlphaInventoryProvider;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.InventoryStorage;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ServerboundPacketsb1_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import java.util.Arrays;
import java.util.Objects;
import java.util.logging.Level;
import static net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.*;
public class AlphaInventoryUpdateTask implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
final InventoryStorage inventoryStorage = info.get(InventoryStorage.class);
if (inventoryStorage == null) continue;
try {
final Item[] mainInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getMainInventoryItems(info));
final Item[] craftingInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getCraftingInventoryItems(info));
final Item[] armorInventory = fixItems(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getArmorInventoryItems(info));
final Item handItem = fixItem(Via.getManager().getProviders().get(AlphaInventoryProvider.class).getHandItem(info));
if (!Objects.equals(handItem, inventoryStorage.handItem)) {
final PacketWrapper heldItemChange = PacketWrapper.create(ServerboundPacketsb1_1.HELD_ITEM_CHANGE, info);
heldItemChange.write(Type.SHORT, inventoryStorage.selectedHotbarSlot); // slot
heldItemChange.sendToServer(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class, false);
}
final Item[] mergedMainInventory = copyItems(inventoryStorage.mainInventory);
final Item[] mergedCraftingInventory = copyItems(inventoryStorage.craftingInventory);
final Item[] mergedArmorInventory = copyItems(inventoryStorage.armorInventory);
System.arraycopy(mainInventory, 0, mergedMainInventory, 0, mainInventory.length);
System.arraycopy(craftingInventory, 0, mergedCraftingInventory, 0, craftingInventory.length);
System.arraycopy(armorInventory, 0, mergedArmorInventory, 0, armorInventory.length);
boolean hasChanged = !Arrays.equals(mergedMainInventory, inventoryStorage.mainInventory) || !Arrays.equals(mergedCraftingInventory, inventoryStorage.craftingInventory) || !Arrays.equals(mergedArmorInventory, inventoryStorage.armorInventory);
if (!hasChanged) continue;
inventoryStorage.mainInventory = copyItems(mergedMainInventory);
inventoryStorage.craftingInventory = copyItems(mergedCraftingInventory);
inventoryStorage.armorInventory = copyItems(mergedArmorInventory);
final PacketWrapper mainContent = PacketWrapper.create(ServerboundPacketsa1_2_6.PLAYER_INVENTORY, info);
mainContent.write(Type.INT, -1); // type
mainContent.write(Types1_4_2.NBTLESS_ITEM_ARRAY, mergedMainInventory); // items
final PacketWrapper craftingContent = PacketWrapper.create(ServerboundPacketsa1_2_6.PLAYER_INVENTORY, info);
craftingContent.write(Type.INT, -2); // type
craftingContent.write(Types1_4_2.NBTLESS_ITEM_ARRAY, mergedCraftingInventory); // items
final PacketWrapper armorContent = PacketWrapper.create(ServerboundPacketsa1_2_6.PLAYER_INVENTORY, info);
armorContent.write(Type.INT, -3); // type
armorContent.write(Types1_4_2.NBTLESS_ITEM_ARRAY, mergedArmorInventory); // items
mainContent.sendToServer(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
craftingContent.sendToServer(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
armorContent.sendToServer(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
} catch (Throwable e) {
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error sending inventory update packets", e);
}
}
}
}

View File

@ -0,0 +1,390 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.*;
public enum ClientboundPacketsb1_8 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
buf.readInt();
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readLong();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readString(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readString(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
buf.readShort();
buf.readFloat();
}),
RESPAWN(9, (user, buf) -> {
buf.readByte();
buf.readByte();
buf.readByte();
buf.readShort();
buf.readLong();
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
USE_BED(17, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readByte();
buf.readInt();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
int i = buf.readInt();
if (i > 0) {
buf.readShort();
buf.readShort();
buf.readShort();
}
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
readEntityMetadatab1_5(buf);
}),
SPAWN_PAINTING(25, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_EXPERIENCE_ORB(26, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readShort();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
ENTITY_METADATA(40, (user, buf) -> {
buf.readInt();
readEntityMetadatab1_5(buf);
}),
ENTITY_EFFECT(41, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
REMOVE_ENTITY_EFFECT(42, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SET_EXPERIENCE(43, (user, buf) -> {
buf.readByte();
buf.readByte();
buf.readShort();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
BLOCK_ACTION(54, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
EFFECT(61, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
}),
GAME_EVENT(70, (user, buf) -> {
buf.readByte();
buf.readByte();
}),
SPAWN_GLOBAL_ENTITY(71, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
readString(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
readItemStackb1_2(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
CREATIVE_INVENTORY_ACTION(107, (user, buf) -> {
buf.readShort();
buf.readShort();
buf.readShort();
buf.readShort();
buf.readShort();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readString(buf);
readString(buf);
readString(buf);
readString(buf);
}),
MAP_DATA(131, (user, buf) -> {
buf.readShort();
buf.readShort();
short x = buf.readUnsignedByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
STATISTICS(200, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
PLAYER_INFO(201, (user, buf) -> {
readString(buf);
buf.readByte();
buf.readShort();
}),
DISCONNECT(255, (user, buf) -> {
readString(buf);
});
private static final ClientboundPacketsb1_8[] REGISTRY = new ClientboundPacketsb1_8[256];
static {
for (ClientboundPacketsb1_8 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_8 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_8(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,90 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.storage.PlayerAirTimeStorage;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types.Typesb1_8_0_1;
import net.raphimc.vialegacy.protocols.release.protocol1_1to1_0_0_1.ClientboundPackets1_0;
import net.raphimc.vialegacy.protocols.release.protocol1_1to1_0_0_1.ServerboundPackets1_0;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types.Types1_2_4;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocol1_0_0_1tob1_8_0_1 extends AbstractProtocol<ClientboundPacketsb1_8, ClientboundPackets1_0, ServerboundPacketsb1_8, ServerboundPackets1_0> {
public Protocol1_0_0_1tob1_8_0_1() {
super(ClientboundPacketsb1_8.class, ClientboundPackets1_0.class, ServerboundPacketsb1_8.class, ServerboundPackets1_0.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsb1_8.SET_EXPERIENCE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
float experience = (float) wrapper.read(Type.BYTE);
final byte experienceLevel = wrapper.read(Type.BYTE);
final short experienceTotal = wrapper.read(Type.SHORT);
experience = (experience - 1.0f) / (10 * experienceLevel);
wrapper.write(Type.FLOAT, experience); // experience bar
wrapper.write(Type.SHORT, (short) experienceLevel); // level
wrapper.write(Type.SHORT, experienceTotal); // total experience
});
}
});
this.registerClientbound(ClientboundPacketsb1_8.SET_SLOT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
map(Type.SHORT); // slot
map(Types1_4_2.NBTLESS_ITEM, Types1_2_4.COMPRESSED_NBT_ITEM); // item
}
});
this.registerClientbound(ClientboundPacketsb1_8.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
map(Types1_4_2.NBTLESS_ITEM_ARRAY, Types1_2_4.COMPRESSED_NBT_ITEM_ARRAY); // item
}
});
this.registerServerbound(ServerboundPackets1_0.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
map(Types1_2_4.COMPRESSED_NBT_ITEM, Types1_4_2.NBTLESS_ITEM);
}
});
this.registerServerbound(ServerboundPackets1_0.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
map(Type.SHORT); // slot
map(Type.BYTE); // button
map(Type.SHORT); // action
map(Type.BYTE); // mode
map(Types1_2_4.COMPRESSED_NBT_ITEM, Types1_4_2.NBTLESS_ITEM); // item
}
});
this.registerServerbound(ServerboundPackets1_0.CREATIVE_INVENTORY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // slot
map(Types1_2_4.COMPRESSED_NBT_ITEM, Typesb1_8_0_1.CREATIVE_ITEM); // item
}
});
this.cancelServerbound(ServerboundPackets1_0.CLICK_WINDOW_BUTTON);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocol1_0_0_1tob1_8_0_1.class, ClientboundPacketsb1_8::getPacket));
userConnection.put(new PlayerAirTimeStorage(userConnection));
}
}

View File

@ -0,0 +1,176 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readString;
public enum ServerboundPacketsb1_8 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
buf.readInt();
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readLong();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readString(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readString(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
buf.readByte();
buf.readByte();
buf.readByte();
buf.readShort();
buf.readLong();
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
readItemStackb1_2(buf);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ENTITY_ACTION(19, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
POSITION(27, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readBoolean();
buf.readBoolean();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
CLICK_WINDOW(102, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readBoolean();
readItemStackb1_2(buf);
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
CREATIVE_INVENTORY_ACTION(107, (user, buf) -> {
buf.readShort();
buf.readShort();
buf.readShort();
buf.readShort();
buf.readShort();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readString(buf);
readString(buf);
readString(buf);
readString(buf);
}),
SERVER_PING(254, (user, buf) -> {
}),
DISCONNECT(255, (user, buf) -> {
readString(buf);
});
private static final ServerboundPacketsb1_8[] REGISTRY = new ServerboundPacketsb1_8[256];
static {
for (ServerboundPacketsb1_8 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsb1_8 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsb1_8(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,16 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class PlayerAirTimeStorage extends StoredObject {
public final int MAX_AIR = 300;
public int air = MAX_AIR;
public boolean sentPacket = true;
public PlayerAirTimeStorage(UserConnection user) {
super(user);
}
}

View File

@ -0,0 +1,59 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.task;
import com.google.common.collect.Lists;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.api.BlockList1_6;
import net.raphimc.vialegacy.api.IdAndData;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.Protocol1_0_0_1tob1_8_0_1;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.storage.PlayerAirTimeStorage;
import net.raphimc.vialegacy.protocols.release.protocol1_1to1_0_0_1.ClientboundPackets1_0;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.MetaType1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
public class PlayerAirTimeUpdateTask implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
final PlayerAirTimeStorage playerAirTimeStorage = info.get(PlayerAirTimeStorage.class);
if (playerAirTimeStorage != null) {
final PlayerInfoStorage playerInfoStorage = info.get(PlayerInfoStorage.class);
if (playerInfoStorage == null) continue;
final IdAndData headBlock = info.get(ChunkTracker.class).getBlockNotNull(floor(playerInfoStorage.posX), floor(playerInfoStorage.posY + 1.62F), floor(playerInfoStorage.posZ));
if (headBlock.id == BlockList1_6.waterMoving.blockID || headBlock.id == BlockList1_6.waterStill.blockID) {
playerAirTimeStorage.sentPacket = false;
playerAirTimeStorage.air--;
if (playerAirTimeStorage.air < 0) playerAirTimeStorage.air = 0;
this.sendAirTime(playerInfoStorage, playerAirTimeStorage, info);
} else if (!playerAirTimeStorage.sentPacket) {
playerAirTimeStorage.sentPacket = true;
playerAirTimeStorage.air = playerAirTimeStorage.MAX_AIR;
this.sendAirTime(playerInfoStorage, playerAirTimeStorage, info);
}
}
}
}
private void sendAirTime(final PlayerInfoStorage playerInfoStorage, final PlayerAirTimeStorage playerAirTimeStorage, final UserConnection userConnection) {
try {
final PacketWrapper updateAirTime = PacketWrapper.create(ClientboundPackets1_0.ENTITY_METADATA, userConnection);
updateAirTime.write(Type.INT, playerInfoStorage.entityId); // entity id
updateAirTime.write(Types1_3_1.METADATA_LIST, Lists.newArrayList(new Metadata(1, MetaType1_3_1.Short, Integer.valueOf(playerAirTimeStorage.air).shortValue()))); // metadata
updateAirTime.send(Protocol1_0_0_1tob1_8_0_1.class);
} catch (Throwable e) {
e.printStackTrace();
}
}
private static int floor(double f) {
int i = (int) f;
return f < (double) i ? i - 1 : i;
}
}

View File

@ -0,0 +1,39 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public class NbtLessItemType extends Type<Item> {
public NbtLessItemType() {
super(Item.class);
}
public Item read(ByteBuf buffer) throws Exception {
final short id = buffer.readShort();
if (id < 0) {
return null;
} else {
final Item item = new DataItem();
item.setIdentifier(id);
item.setAmount((byte) buffer.readShort());
item.setData(buffer.readShort());
return item;
}
}
public void write(ByteBuf buffer, Item item) throws Exception {
if (item == null) {
buffer.writeShort(-1);
buffer.writeShort(0);
buffer.writeShort(0);
} else {
buffer.writeShort(item.identifier());
buffer.writeShort(item.amount());
buffer.writeShort(item.data());
}
}
}

View File

@ -0,0 +1,12 @@
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ItemArrayType;
public class Typesb1_8_0_1 {
public static final Type<Item> CREATIVE_ITEM = new NbtLessItemType();
public static final Type<Item[]> CREATIVE_ITEM_ARRAY = new ItemArrayType<>(CREATIVE_ITEM);
}

View File

@ -0,0 +1,13 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_1_2tob1_0_1_1;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ClientboundPacketsb1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ServerboundPacketsb1_1;
public class Protocolb1_1_2tob1_0_1_1 extends AbstractProtocol<ClientboundPacketsb1_1, ClientboundPacketsb1_1, ServerboundPacketsb1_1, ServerboundPacketsb1_1> {
public Protocolb1_1_2tob1_0_1_1() {
super(ClientboundPacketsb1_1.class, ClientboundPacketsb1_1.class, ServerboundPacketsb1_1.class, ServerboundPacketsb1_1.class);
}
}

View File

@ -0,0 +1,282 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.*;
public enum ClientboundPacketsb1_1 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
readUTF(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
readItemStackb1_1(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readUTF(buf);
readUTF(buf);
readUTF(buf);
readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsb1_1[] REGISTRY = new ClientboundPacketsb1_1[256];
static {
for (ClientboundPacketsb1_1 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_1 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_1(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,197 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2;
import com.google.common.collect.Lists;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import net.raphimc.vialegacy.api.IdAndData;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.rewriter.BlockDataRewriter;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.storage.EntityFlagStorage;
import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.types.Typesb1_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.ClientboundPacketsb1_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.ServerboundPacketsb1_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types.MetaTypeb1_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types.Typesb1_2;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Chunk1_1Type;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Types1_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
import java.util.ArrayList;
public class Protocolb1_2_0_2tob1_1_2 extends AbstractProtocol<ClientboundPacketsb1_1, ClientboundPacketsb1_2, ServerboundPacketsb1_1, ServerboundPacketsb1_2> {
private final BlockDataRewriter BLOCK_DATA_REWRITER = new BlockDataRewriter();
public Protocolb1_2_0_2tob1_1_2() {
super(ClientboundPacketsb1_1.class, ClientboundPacketsb1_2.class, ServerboundPacketsb1_1.class, ServerboundPacketsb1_2.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsb1_1.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.SHORT); // slot
map(Type.SHORT); // item id
create(Type.SHORT, (short) 0); // item damage
}
});
this.registerClientbound(ClientboundPacketsb1_1.ENTITY_ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.BYTE); // animation id
handler(wrapper -> {
final int entityId = wrapper.get(Type.INT, 0);
final byte animationId = wrapper.get(Type.BYTE, 0);
if (animationId <= 2) return; // 1 - Swing | 2 - Hurt
wrapper.cancel();
final EntityFlagStorage entityFlagStorage = wrapper.user().get(EntityFlagStorage.class);
final int oldMask = entityFlagStorage.getFlagMask(entityId);
switch (animationId) {
case 100: // start riding
entityFlagStorage.setFlag(entityId, 2, true);
break;
case 101: // stop riding
entityFlagStorage.setFlag(entityId, 2, false);
break;
case 102: // start burning
entityFlagStorage.setFlag(entityId, 0, true);
break;
case 103: // stop burning
entityFlagStorage.setFlag(entityId, 0, false);
break;
case 104: // start sneaking
entityFlagStorage.setFlag(entityId, 1, true);
break;
case 105: // stop sneaking
entityFlagStorage.setFlag(entityId, 1, false);
break;
}
if (oldMask != entityFlagStorage.getFlagMask(entityId)) {
final PacketWrapper metadata = PacketWrapper.create(ClientboundPacketsb1_2.ENTITY_METADATA, wrapper.user());
metadata.write(Type.INT, wrapper.get(Type.INT, 0)); // entity id
metadata.write(Typesb1_2.METADATA_LIST, Lists.newArrayList(new Metadata(0, MetaTypeb1_2.Byte, (byte) entityFlagStorage.getFlagMask(entityId)))); // metadata
metadata.send(Protocolb1_2_0_2tob1_1_2.class);
}
});
}
});
this.registerClientbound(ClientboundPacketsb1_1.SPAWN_ITEM, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
handler(wrapper -> {
final short itemId = wrapper.read(Type.SHORT); // item id
final byte itemCount = wrapper.read(Type.BYTE); // item count
wrapper.write(Types1_3_1.NBTLESS_ITEM, new DataItem(itemId, itemCount, (short) 0, null)); // item
});
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // velocity x
map(Type.BYTE); // velocity y
map(Type.BYTE); // velocity z
}
});
this.registerClientbound(ClientboundPacketsb1_1.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.UNSIGNED_BYTE); // type id
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
create(Typesb1_2.METADATA_LIST, new ArrayList<>()); // metadata
}
});
this.registerClientbound(ClientboundPacketsb1_1.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final ClientWorld clientWorld = new ClientWorld(wrapper.user());
clientWorld.setEnvironment(0);
BLOCK_DATA_REWRITER.remapChunk(wrapper.passthrough(new Chunk1_1Type(clientWorld)));
});
}
});
this.registerClientbound(ClientboundPacketsb1_1.MULTI_BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // chunkX
map(Type.INT); // chunkZ
map(Types1_1.BLOCK_CHANGE_RECORD_ARRAY); // blockChangeRecords
handler(wrapper -> BLOCK_DATA_REWRITER.remapBlockChangeRecords(wrapper.get(Types1_1.BLOCK_CHANGE_RECORD_ARRAY, 0)));
}
});
this.registerClientbound(ClientboundPacketsb1_1.BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // block id
map(Type.UNSIGNED_BYTE); // block data
handler(wrapper -> {
final IdAndData block = new IdAndData(wrapper.get(Type.UNSIGNED_BYTE, 0), wrapper.get(Type.UNSIGNED_BYTE, 1));
BLOCK_DATA_REWRITER.remapBlock(block);
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) block.id);
wrapper.set(Type.UNSIGNED_BYTE, 1, (short) block.data);
});
}
});
this.registerClientbound(ClientboundPacketsb1_1.SET_SLOT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
map(Type.SHORT); // slot
map(Typesb1_1.NBTLESS_ITEM, Types1_4_2.NBTLESS_ITEM); // item
}
});
this.registerServerbound(ServerboundPacketsb1_2.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
map(Types1_4_2.NBTLESS_ITEM, Typesb1_1.NBTLESS_ITEM); // item
}
});
this.registerServerbound(ServerboundPacketsb1_2.ENTITY_ACTION, ServerboundPacketsb1_1.ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.BYTE, Type.UNSIGNED_BYTE, i -> (short) (i + 103)); // action id | start/stop sneaking (1/2) -> 104/105
}
});
this.registerServerbound(ServerboundPacketsb1_2.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
map(Type.SHORT); // slot
map(Type.BYTE); // button
map(Type.SHORT); // action
map(Types1_4_2.NBTLESS_ITEM, Typesb1_1.NBTLESS_ITEM); // item
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_2_0_2tob1_1_2.class, ClientboundPacketsb1_1::getPacket));
userConnection.put(new EntityFlagStorage(userConnection));
}
}

View File

@ -0,0 +1,145 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_1;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ServerboundPacketsb1_1 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
readItemStackb1_1(buf);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
CLICK_WINDOW(102, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
buf.readShort();
readItemStackb1_1(buf);
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readUTF(buf);
readUTF(buf);
readUTF(buf);
readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ServerboundPacketsb1_1[] REGISTRY = new ServerboundPacketsb1_1[256];
static {
for (ServerboundPacketsb1_1 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsb1_1 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsb1_1(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,22 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.rewriter;
import net.raphimc.vialegacy.api.*;
public class BlockDataRewriter extends AbstractBlockRemapper {
public BlockDataRewriter() {
for (int i = 1; i < 16; i++) { // cobblestone
this.registerReplacement(new IdAndData(BlockList1_6.cobblestone.blockID, i), new IdAndData(BlockList1_6.cobblestone.blockID, 0));
}
for (int i = 1; i < 16; i++) { // sand
this.registerReplacement(new IdAndData(BlockList1_6.sand.blockID, i), new IdAndData(BlockList1_6.sand.blockID, 0));
}
for (int i = 1; i < 16; i++) { // gravel
this.registerReplacement(new IdAndData(BlockList1_6.gravel.blockID, i), new IdAndData(BlockList1_6.gravel.blockID, 0));
}
for (int i = 1; i < 16; i++) { // obsidian
this.registerReplacement(new IdAndData(BlockList1_6.obsidian.blockID, i), new IdAndData(BlockList1_6.obsidian.blockID, 0));
}
}
}

View File

@ -0,0 +1,33 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
public class EntityFlagStorage extends StoredObject {
private final Int2IntMap animationFlags = new Int2IntOpenHashMap();
public EntityFlagStorage(UserConnection user) {
super(user);
}
public boolean getFlag(final int entityId, final int index) {
return (this.getFlagMask(entityId) & 1 << index) != 0;
}
public int getFlagMask(final int entityId) {
return this.animationFlags.get(entityId);
}
public void setFlag(final int entityId, final int index, final boolean flag) {
final int mask = this.animationFlags.get(entityId);
if (flag) {
this.animationFlags.put(entityId, mask | 1 << index);
} else {
this.animationFlags.put(entityId, mask & ~(1 << index));
}
}
}

View File

@ -0,0 +1,37 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.types;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public class NbtLessItemType extends Type<Item> {
public NbtLessItemType() {
super(Item.class);
}
public Item read(ByteBuf buffer) throws Exception {
final short id = buffer.readShort();
if (id < 0) {
return null;
}
final Item item = new DataItem();
item.setIdentifier(id);
item.setAmount(buffer.readByte());
item.setData(buffer.readByte());
return item;
}
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.writeByte(item.data());
}
}
}

View File

@ -0,0 +1,10 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.types;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
public class Typesb1_1 {
public static final Type<Item> NBTLESS_ITEM = new NbtLessItemType();
}

View File

@ -0,0 +1,303 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ClientboundPacketsb1_2 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
PreNettyTypes.readEntityMetadatab1_2(buf);
}),
SPAWN_PAINTING(25, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
ENTITY_METADATA(40, (user, buf) -> {
buf.readInt();
PreNettyTypes.readEntityMetadatab1_2(buf);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
BLOCK_ACTION(54, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
PreNettyTypes.readUTF(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
PreNettyTypes.readItemStackb1_2(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) PreNettyTypes.readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ClientboundPacketsb1_2[] REGISTRY = new ClientboundPacketsb1_2[256];
static {
for (ClientboundPacketsb1_2 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_2 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_2(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,130 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.api.IdAndData;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.data.BlockHardnessList;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.storage.BlockDigStorage;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types.Typesb1_2;
import net.raphimc.vialegacy.protocols.beta.protocolb1_4_0_1tob1_3_0_1.ClientboundPacketsb1_3;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.ServerboundPacketsb1_4;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types.MetaTypeb1_4;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types.Typesb1_4;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
import java.util.List;
public class Protocolb1_3_0_1tob1_2_0_2 extends AbstractProtocol<ClientboundPacketsb1_2, ClientboundPacketsb1_3, ServerboundPacketsb1_2, ServerboundPacketsb1_4> {
public Protocolb1_3_0_1tob1_2_0_2() {
super(ClientboundPacketsb1_2.class, ClientboundPacketsb1_3.class, ServerboundPacketsb1_2.class, ServerboundPacketsb1_4.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsb1_2.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.UNSIGNED_BYTE); // type id
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
map(Typesb1_2.METADATA_LIST, Typesb1_4.METADATA_LIST); // metadata
handler(wrapper -> rewriteMetadata(wrapper.get(Typesb1_4.METADATA_LIST, 0)));
}
});
this.registerClientbound(ClientboundPacketsb1_2.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Typesb1_2.METADATA_LIST, Typesb1_4.METADATA_LIST); // metadata
handler(wrapper -> rewriteMetadata(wrapper.get(Typesb1_4.METADATA_LIST, 0)));
}
});
this.registerServerbound(ServerboundPacketsb1_4.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
final short status = wrapper.read(Type.UNSIGNED_BYTE); // status
final Position pos = wrapper.read(Types1_7_6.POSITION_UBYTE); // position
final short facing = wrapper.read(Type.UNSIGNED_BYTE); // direction
if (status != 4) {
wrapper.user().getStoredObjects().remove(BlockDigStorage.class);
}
switch (status) {
case 0:
final IdAndData blockBeingBroken = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
if (BlockHardnessList.canBeBrokenInstantly(blockBeingBroken)) {
sendBlockDigPacket(wrapper.user(), (byte) 0, pos, facing);
sendBlockDigPacket(wrapper.user(), (byte) 3, pos, facing);
sendBlockDigPacket(wrapper.user(), (byte) 1, pos, facing);
sendBlockDigPacket(wrapper.user(), (byte) 2, pos, facing);
return;
}
wrapper.user().put(new BlockDigStorage(wrapper.user(), pos, facing));
sendBlockDigPacket(wrapper.user(), (byte) 0, pos, facing);
sendBlockDigPacket(wrapper.user(), (byte) 1, pos, facing);
break;
case 1:
sendBlockDigPacket(wrapper.user(), (byte) 2, pos, facing);
break;
case 2:
sendBlockDigPacket(wrapper.user(), (byte) 1, pos, facing);
sendBlockDigPacket(wrapper.user(), (byte) 3, pos, facing);
sendBlockDigPacket(wrapper.user(), (byte) 2, pos, facing);
break;
case 4:
sendBlockDigPacket(wrapper.user(), (byte) 4, pos, facing);
break;
}
});
}
});
this.registerServerbound(ServerboundPacketsb1_4.ENTITY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.BYTE); // action id
handler(wrapper -> {
if (wrapper.get(Type.BYTE, 0) > 2) wrapper.cancel();
});
}
});
this.cancelServerbound(ServerboundPacketsb1_4.POSITION);
}
private void rewriteMetadata(final List<Metadata> metadataList) {
for (Metadata metadata : metadataList) {
metadata.setMetaType(MetaTypeb1_4.byId(metadata.metaType().typeId()));
}
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_3_0_1tob1_2_0_2.class, ClientboundPacketsb1_2::getPacket));
}
public static void sendBlockDigPacket(final UserConnection userConnection, final short status, final Position position, final short facing) throws Exception {
final PacketWrapper blockDig = PacketWrapper.create(ServerboundPacketsb1_2.PLAYER_DIGGING, userConnection);
blockDig.write(Type.UNSIGNED_BYTE, status); // status
blockDig.write(Types1_7_6.POSITION_UBYTE, position); // position
blockDig.write(Type.UNSIGNED_BYTE, facing); // direction
blockDig.sendToServer(Protocolb1_3_0_1tob1_2_0_2.class);
}
}

View File

@ -0,0 +1,147 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import net.raphimc.vialegacy.util.PreNettyTypes;
import java.util.function.BiConsumer;
public enum ServerboundPacketsb1_2 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
PreNettyTypes.readUTF(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
PreNettyTypes.readItemStackb1_2(buf);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ENTITY_ACTION(19, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
CLICK_WINDOW(102, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
buf.readShort();
PreNettyTypes.readItemStackb1_2(buf);
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
PreNettyTypes.readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
PreNettyTypes.readUTF(buf);
});
private static final ServerboundPacketsb1_2[] REGISTRY = new ServerboundPacketsb1_2[256];
static {
for (ServerboundPacketsb1_2 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsb1_2 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsb1_2(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,105 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.data;
import net.raphimc.vialegacy.api.IdAndData;
import java.util.HashMap;
import java.util.Map;
public class BlockHardnessList {
private static final Map<Integer, Float> HARDNESS_TABLE = new HashMap<>(82, 0.99F);
static {
HARDNESS_TABLE.put(1, 1.5f);
HARDNESS_TABLE.put(2, 0.6f);
HARDNESS_TABLE.put(3, 0.5f);
HARDNESS_TABLE.put(4, 2.0f);
HARDNESS_TABLE.put(5, 2.0f);
HARDNESS_TABLE.put(6, 0.0f);
HARDNESS_TABLE.put(7, -1.0f);
HARDNESS_TABLE.put(8, 100.0f);
HARDNESS_TABLE.put(9, 100.0f);
HARDNESS_TABLE.put(10, 0.0f);
HARDNESS_TABLE.put(11, 100.0f);
HARDNESS_TABLE.put(12, 0.5f);
HARDNESS_TABLE.put(13, 0.6f);
HARDNESS_TABLE.put(14, 3.0f);
HARDNESS_TABLE.put(15, 3.0f);
HARDNESS_TABLE.put(16, 3.0f);
HARDNESS_TABLE.put(17, 2.0f);
HARDNESS_TABLE.put(18, 0.2f);
HARDNESS_TABLE.put(19, 0.6f);
HARDNESS_TABLE.put(20, 0.3f);
HARDNESS_TABLE.put(21, 3.0f);
HARDNESS_TABLE.put(22, 3.0f);
HARDNESS_TABLE.put(23, 3.5f);
HARDNESS_TABLE.put(24, 0.8f);
HARDNESS_TABLE.put(25, 0.8f);
HARDNESS_TABLE.put(35, 0.8f);
HARDNESS_TABLE.put(37, 0.0f);
HARDNESS_TABLE.put(38, 0.0f);
HARDNESS_TABLE.put(39, 0.0f);
HARDNESS_TABLE.put(40, 0.0f);
HARDNESS_TABLE.put(41, 3.0f);
HARDNESS_TABLE.put(42, 5.0f);
HARDNESS_TABLE.put(43, 2.0f);
HARDNESS_TABLE.put(44, 2.0f);
HARDNESS_TABLE.put(45, 2.0f);
HARDNESS_TABLE.put(46, 0.0f);
HARDNESS_TABLE.put(47, 1.5f);
HARDNESS_TABLE.put(48, 2.0f);
HARDNESS_TABLE.put(49, 10.0f);
HARDNESS_TABLE.put(50, 0.0f);
HARDNESS_TABLE.put(51, 0.0f);
HARDNESS_TABLE.put(52, 5.0f);
HARDNESS_TABLE.put(53, 2.0f);
HARDNESS_TABLE.put(54, 2.5f);
HARDNESS_TABLE.put(55, 0.0f);
HARDNESS_TABLE.put(56, 3.0f);
HARDNESS_TABLE.put(57, 5.0f);
HARDNESS_TABLE.put(58, 2.5f);
HARDNESS_TABLE.put(59, 0.0f);
HARDNESS_TABLE.put(60, 0.6f);
HARDNESS_TABLE.put(61, 3.5f);
HARDNESS_TABLE.put(62, 3.5f);
HARDNESS_TABLE.put(63, 1.0f);
HARDNESS_TABLE.put(64, 3.0f);
HARDNESS_TABLE.put(65, 0.4f);
HARDNESS_TABLE.put(66, 0.7f);
HARDNESS_TABLE.put(67, 2.0f);
HARDNESS_TABLE.put(68, 1.0f);
HARDNESS_TABLE.put(69, 0.5f);
HARDNESS_TABLE.put(70, 0.5f);
HARDNESS_TABLE.put(71, 5.0f);
HARDNESS_TABLE.put(72, 0.5f);
HARDNESS_TABLE.put(73, 3.0f);
HARDNESS_TABLE.put(74, 3.0f);
HARDNESS_TABLE.put(75, 0.0f);
HARDNESS_TABLE.put(76, 0.0f);
HARDNESS_TABLE.put(77, 0.5f);
HARDNESS_TABLE.put(78, 0.1f);
HARDNESS_TABLE.put(79, 0.5f);
HARDNESS_TABLE.put(80, 0.2f);
HARDNESS_TABLE.put(81, 0.4f);
HARDNESS_TABLE.put(82, 0.6f);
HARDNESS_TABLE.put(83, 0.0f);
HARDNESS_TABLE.put(84, 2.0f);
HARDNESS_TABLE.put(85, 2.0f);
HARDNESS_TABLE.put(86, 1.0f);
HARDNESS_TABLE.put(87, 0.4f);
HARDNESS_TABLE.put(88, 0.5f);
HARDNESS_TABLE.put(89, 0.3f);
HARDNESS_TABLE.put(90, -1.0f);
HARDNESS_TABLE.put(91, 1.0f);
HARDNESS_TABLE.put(92, 0.5f);
}
public static boolean canBeBrokenInstantly(final int blockID) {
return HARDNESS_TABLE.get(blockID) == 0;
}
public static boolean canBeBrokenInstantly(final IdAndData block) {
return canBeBrokenInstantly(block.id);
}
}

View File

@ -0,0 +1,34 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.Protocolb1_3_0_1tob1_2_0_2;
public class BlockDigStorage extends StoredObject {
public int tick = 1;
private final Position position;
private final short facing;
public BlockDigStorage(UserConnection user, final Position position, final short facing) {
super(user);
this.position = position;
this.facing = facing;
}
public void tick() {
try {
if (tick >= 5) {
Protocolb1_3_0_1tob1_2_0_2.sendBlockDigPacket(this.getUser(), (byte) 0, position, facing);
tick = 0;
} else {
tick++;
}
Protocolb1_3_0_1tob1_2_0_2.sendBlockDigPacket(this.getUser(), (byte) 1, position, facing);
} catch (Throwable e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,17 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.task;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.storage.BlockDigStorage;
public class BlockDigTickTask implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
final BlockDigStorage blockDigStorage = info.get(BlockDigStorage.class);
if (blockDigStorage != null) blockDigStorage.tick();
}
}
}

View File

@ -0,0 +1,37 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
public enum MetaTypeb1_2 implements MetaType {
Byte(0, Type.BYTE),
Short(1, Type.SHORT),
Int(2, Type.INT),
Float(3, Type.FLOAT),
String(4, Typesb1_7_0_3.STRING),
Slot(5, Types1_3_1.NBTLESS_ITEM);
private final int typeID;
private final Type<?> type;
MetaTypeb1_2(int typeID, Type<?> type) {
this.typeID = typeID;
this.type = type;
}
public static MetaTypeb1_2 byId(int id) {
return values()[id];
}
public int typeId() {
return this.typeID;
}
public Type<?> type() {
return this.type;
}
}

View File

@ -0,0 +1,13 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.types.minecraft.OldMetaType;
public class MetadataType extends OldMetaType {
@Override
protected MetaType getType(int index) {
return MetaTypeb1_2.byId(index);
}
}

View File

@ -0,0 +1,14 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.minecraft.MetaListType;
import java.util.List;
public class Typesb1_2 {
public static final Type<Metadata> METADATA = new MetadataType();
public static final Type<List<Metadata>> METADATA_LIST = new MetaListType(METADATA);
}

View File

@ -0,0 +1,311 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_4_0_1tob1_3_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.*;
public enum ClientboundPacketsb1_3 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
USE_BED(17, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readByte();
buf.readInt();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
readEntityMetadatab1_3(buf);
}),
SPAWN_PAINTING(25, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
ENTITY_METADATA(40, (user, buf) -> {
buf.readInt();
readEntityMetadatab1_3(buf);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
BLOCK_ACTION(54, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
readUTF(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
readItemStackb1_2(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readUTF(buf);
readUTF(buf);
readUTF(buf);
readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsb1_3[] REGISTRY = new ClientboundPacketsb1_3[256];
static {
for (ClientboundPacketsb1_3 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_3 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_3(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,20 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_4_0_1tob1_3_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.ClientboundPacketsb1_4;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.ServerboundPacketsb1_4;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocolb1_4_0_1tob1_3_0_1 extends AbstractProtocol<ClientboundPacketsb1_3, ClientboundPacketsb1_4, ServerboundPacketsb1_4, ServerboundPacketsb1_4> {
public Protocolb1_4_0_1tob1_3_0_1() {
super(ClientboundPacketsb1_3.class, ClientboundPacketsb1_4.class, ServerboundPacketsb1_4.class, ServerboundPacketsb1_4.class);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_4_0_1tob1_3_0_1.class, ClientboundPacketsb1_3::getPacket));
}
}

View File

@ -0,0 +1,314 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.*;
public enum ClientboundPacketsb1_4 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
USE_BED(17, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readByte();
buf.readInt();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
readEntityMetadatab1_3(buf);
}),
SPAWN_PAINTING(25, (user, buf) -> {
buf.readInt();
readUTF(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
ENTITY_METADATA(40, (user, buf) -> {
buf.readInt();
readEntityMetadatab1_3(buf);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
BLOCK_ACTION(54, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
GAME_EVENT(70, (user, buf) -> {
buf.readByte();
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
readUTF(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
readItemStackb1_2(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readUTF(buf);
readUTF(buf);
readUTF(buf);
readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ClientboundPacketsb1_4[] REGISTRY = new ClientboundPacketsb1_4[256];
static {
for (ClientboundPacketsb1_4 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_4 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_4(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,186 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types.Typesb1_4;
import net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.ClientboundPacketsb1_5;
import net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.ServerboundPacketsb1_5;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.MetaType1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Types1_6_4;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
import java.util.List;
public class Protocolb1_5_0_2tob1_4_0_1 extends AbstractProtocol<ClientboundPacketsb1_4, ClientboundPacketsb1_5, ServerboundPacketsb1_4, ServerboundPacketsb1_5> {
public Protocolb1_5_0_2tob1_4_0_1() {
super(ClientboundPacketsb1_4.class, ClientboundPacketsb1_5.class, ServerboundPacketsb1_4.class, ServerboundPacketsb1_5.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(State.LOGIN, ClientboundPacketsb1_4.HANDSHAKE.getId(), ClientboundPacketsb1_5.HANDSHAKE.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // server hash
}
});
this.registerClientbound(State.LOGIN, ClientboundPacketsb1_4.DISCONNECT.getId(), ClientboundPacketsb1_5.DISCONNECT.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // reason
}
});
this.registerClientbound(ClientboundPacketsb1_4.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // username
read(Typesb1_7_0_3.STRING); // password
map(Type.LONG); // seed
map(Type.BYTE); // dimension id
}
});
this.registerClientbound(ClientboundPacketsb1_4.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // message
}
});
this.registerClientbound(ClientboundPacketsb1_4.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // username
handler(wrapper -> {
String name = wrapper.get(Types1_6_4.STRING, 0);
name = name.substring(0, Math.min(name.length(), 16));
wrapper.set(Types1_6_4.STRING, 0, name);
});
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
map(Type.UNSIGNED_SHORT); // item
}
});
this.registerClientbound(ClientboundPacketsb1_4.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.UNSIGNED_BYTE); // type id
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
map(Typesb1_4.METADATA_LIST, Types1_3_1.METADATA_LIST); // metadata
handler(wrapper -> rewriteMetadata(wrapper.get(Types1_3_1.METADATA_LIST, 0)));
}
});
this.registerClientbound(ClientboundPacketsb1_4.SPAWN_PAINTING, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // motive
map(Types1_7_6.POSITION_INT); // position
map(Type.INT); // rotation
}
});
this.registerClientbound(ClientboundPacketsb1_4.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Typesb1_4.METADATA_LIST, Types1_3_1.METADATA_LIST); // metadata
handler(wrapper -> rewriteMetadata(wrapper.get(Types1_3_1.METADATA_LIST, 0)));
}
});
this.registerClientbound(ClientboundPacketsb1_4.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_SHORT); // position
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // line 1
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // line 2
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // line 3
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // line 4
}
});
this.registerClientbound(ClientboundPacketsb1_4.DISCONNECT, new PacketRemapper() {
@Override
public void registerMap() {
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // reason
}
});
this.registerServerbound(State.LOGIN, ServerboundPacketsb1_5.HANDSHAKE.getId(), ServerboundPacketsb1_4.HANDSHAKE.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // username
}
});
this.registerServerbound(State.LOGIN, ServerboundPacketsb1_4.LOGIN.getId(), ServerboundPacketsb1_5.LOGIN.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // protocol id
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // username
create(Typesb1_7_0_3.STRING, "Password"); // password
map(Type.LONG); // seed
map(Type.BYTE); // dimension id
}
});
this.registerServerbound(ServerboundPacketsb1_5.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // message
}
});
this.registerServerbound(ServerboundPacketsb1_5.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
map(Type.SHORT); // slot
map(Type.BYTE); // button
map(Type.SHORT); // action
read(Type.BYTE); // mode
map(Types1_4_2.NBTLESS_ITEM); // item
}
});
this.registerServerbound(ServerboundPacketsb1_5.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_SHORT); // position
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // line 1
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // line 2
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // line 3
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // line 4
}
});
this.registerServerbound(ServerboundPacketsb1_5.DISCONNECT, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_6_4.STRING, Typesb1_7_0_3.STRING); // reason
}
});
}
private void rewriteMetadata(final List<Metadata> metadataList) {
for (Metadata metadata : metadataList) {
metadata.setMetaType(MetaType1_3_1.byId(metadata.metaType().typeId()));
}
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_5_0_2tob1_4_0_1.class, ClientboundPacketsb1_4::getPacket));
}
}

View File

@ -0,0 +1,157 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readUTF;
public enum ServerboundPacketsb1_4 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readUTF(buf);
readUTF(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readUTF(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readUTF(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
readItemStackb1_2(buf);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ENTITY_ACTION(19, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
POSITION(27, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readBoolean();
buf.readBoolean();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
CLICK_WINDOW(102, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
buf.readShort();
readItemStackb1_2(buf);
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readUTF(buf);
readUTF(buf);
readUTF(buf);
readUTF(buf);
}),
DISCONNECT(255, (user, buf) -> {
readUTF(buf);
});
private static final ServerboundPacketsb1_4[] REGISTRY = new ServerboundPacketsb1_4[256];
static {
for (ServerboundPacketsb1_4 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsb1_4 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsb1_4(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,38 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
public enum MetaTypeb1_4 implements MetaType {
Byte(0, Type.BYTE),
Short(1, Type.SHORT),
Int(2, Type.INT),
Float(3, Type.FLOAT),
String(4, Typesb1_7_0_3.STRING),
Slot(5, Types1_3_1.NBTLESS_ITEM),
Position(6, Type.VECTOR);
private final int typeID;
private final Type<?> type;
MetaTypeb1_4(int typeID, Type<?> type) {
this.typeID = typeID;
this.type = type;
}
public static MetaTypeb1_4 byId(int id) {
return values()[id];
}
public int typeId() {
return this.typeID;
}
public Type<?> type() {
return this.type;
}
}

View File

@ -0,0 +1,13 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.types.minecraft.OldMetaType;
public class MetadataType extends OldMetaType {
@Override
protected MetaType getType(int index) {
return MetaTypeb1_4.byId(index);
}
}

View File

@ -0,0 +1,14 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.types;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.minecraft.MetaListType;
import java.util.List;
public class Typesb1_4 {
public static final Type<Metadata> METADATA = new MetadataType();
public static final Type<List<Metadata>> METADATA_LIST = new MetaListType(METADATA);
}

View File

@ -0,0 +1,324 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.*;
public enum ClientboundPacketsb1_5 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readString(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readString(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
USE_BED(17, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readByte();
buf.readInt();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
readEntityMetadatab1_5(buf);
}),
SPAWN_PAINTING(25, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
ENTITY_METADATA(40, (user, buf) -> {
buf.readInt();
readEntityMetadatab1_5(buf);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
BLOCK_ACTION(54, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
GAME_EVENT(70, (user, buf) -> {
buf.readByte();
}),
SPAWN_GLOBAL_ENTITY(71, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
readUTF(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
readItemStackb1_2(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readString(buf);
readString(buf);
readString(buf);
readString(buf);
}),
STATISTICS(200, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
readString(buf);
});
private static final ClientboundPacketsb1_5[] REGISTRY = new ClientboundPacketsb1_5[256];
static {
for (ClientboundPacketsb1_5 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_5 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_5(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,146 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import net.raphimc.vialegacy.api.*;
import net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.storage.WorldTimeStorage;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.ClientboundPacketsb1_7;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.ServerboundPacketsb1_7;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.PlayerInfoStorage;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Types1_6_4;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
public class Protocolb1_6_0_6tob1_5_0_2 extends AbstractProtocol<ClientboundPacketsb1_5, ClientboundPacketsb1_7, ServerboundPacketsb1_5, ServerboundPacketsb1_7> {
public Protocolb1_6_0_6tob1_5_0_2() {
super(ClientboundPacketsb1_5.class, ClientboundPacketsb1_7.class, ServerboundPacketsb1_5.class, ServerboundPacketsb1_7.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsb1_5.TIME_UPDATE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.LONG); // time
handler(wrapper -> wrapper.user().get(WorldTimeStorage.class).time = wrapper.get(Type.LONG, 0));
}
});
this.registerClientbound(ClientboundPacketsb1_5.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
create(Type.BYTE, (byte) 0); // dimension id
}
});
this.registerClientbound(ClientboundPacketsb1_5.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.BYTE); // type id
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
create(Type.INT, 0); // data
}
});
this.registerServerbound(ServerboundPacketsb1_7.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
read(Type.BYTE); // dimension id
}
});
this.registerServerbound(ServerboundPacketsb1_7.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
map(Types1_4_2.NBTLESS_ITEM); // item
handler(wrapper -> {
final PlayerInfoStorage playerInfoStorage = wrapper.user().get(PlayerInfoStorage.class);
Position pos = wrapper.get(Types1_7_6.POSITION_UBYTE, 0);
IdAndData block = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
final Item item = wrapper.get(Types1_4_2.NBTLESS_ITEM, 0);
if (block.id == BlockList1_6.bed.blockID) {
final byte[][] headBlockToFootBlock = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
final boolean isFoot = (block.data & 8) != 0;
if (!isFoot) {
final int bedDirection = block.data & 3;
pos = new Position(pos.x() + headBlockToFootBlock[bedDirection][0], pos.y(), pos.z() + headBlockToFootBlock[bedDirection][1]);
block = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
if (block.id != BlockList1_6.bed.blockID) return;
}
final boolean isOccupied = (block.data & 4) != 0;
if (isOccupied) {
final PacketWrapper chat = PacketWrapper.create(ClientboundPacketsb1_7.CHAT_MESSAGE, wrapper.user());
chat.write(Types1_6_4.STRING, "This bed is occupied");
chat.send(Protocolb1_6_0_6tob1_5_0_2.class);
return;
}
int dayTime = (int) (wrapper.user().get(WorldTimeStorage.class).time % 24000L);
float dayPercent = (dayTime + 1.0F) / 24000F - 0.25F;
if (dayPercent < 0.0F) dayPercent++;
if (dayPercent > 1.0F) dayPercent--;
final float tempDayPercent = dayPercent;
dayPercent = 1.0F - (float) ((Math.cos((double) dayPercent * Math.PI) + 1.0D) / 2D);
dayPercent = tempDayPercent + (dayPercent - tempDayPercent) / 3F;
float skyRotation = (float) (1.0F - (Math.cos(dayPercent * Math.PI * 2.0F) * 2.0F + 0.5F));
if (skyRotation < 0.0F) skyRotation = 0.0F;
if (skyRotation > 1.0F) skyRotation = 1.0F;
final boolean isDayTime = (int) (skyRotation * 11F) < 4;
if (isDayTime) {
final PacketWrapper chat = PacketWrapper.create(ClientboundPacketsb1_7.CHAT_MESSAGE, wrapper.user());
chat.write(Types1_6_4.STRING, "You can only sleep at night");
chat.send(Protocolb1_6_0_6tob1_5_0_2.class);
return;
}
if (Math.abs(playerInfoStorage.posX - (double) pos.x()) > 3D || Math.abs(playerInfoStorage.posY - (double) pos.y()) > 2D || Math.abs(playerInfoStorage.posZ - (double) pos.z()) > 3D) {
return;
}
final PacketWrapper useBed = PacketWrapper.create(ClientboundPacketsb1_7.USE_BED, wrapper.user());
useBed.write(Type.INT, playerInfoStorage.entityId); // entity id
useBed.write(Type.BYTE, (byte) 0); // magic value (always 0)
useBed.write(Types1_7_6.POSITION_BYTE, pos); // position
useBed.send(Protocolb1_6_0_6tob1_5_0_2.class);
} else if (block.id == BlockList1_6.jukebox.blockID) {
if (block.data > 0) {
final PacketWrapper effect = PacketWrapper.create(ClientboundPacketsb1_7.EFFECT, wrapper.user());
effect.write(Type.INT, 1005); // effect id
effect.write(Types1_7_6.POSITION_UBYTE, pos); // position
effect.write(Type.INT, 0); // data
effect.send(Protocolb1_6_0_6tob1_5_0_2.class);
} else if (item != null && (item.identifier() == ItemList1_6.record13.itemID || item.identifier() == ItemList1_6.recordCat.itemID)) {
final PacketWrapper effect = PacketWrapper.create(ClientboundPacketsb1_7.EFFECT, wrapper.user());
effect.write(Type.INT, 1005); // effect id
effect.write(Types1_7_6.POSITION_UBYTE, pos); // position
effect.write(Type.INT, item.identifier()); // data
effect.send(Protocolb1_6_0_6tob1_5_0_2.class);
}
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_6_0_6tob1_5_0_2.class, ClientboundPacketsb1_5::getPacket));
userConnection.put(new WorldTimeStorage(userConnection));
}
}

View File

@ -0,0 +1,157 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readString;
public enum ServerboundPacketsb1_5 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readString(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readString(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
readItemStackb1_2(buf);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ENTITY_ACTION(19, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
POSITION(27, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readBoolean();
buf.readBoolean();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
CLICK_WINDOW(102, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readBoolean();
readItemStackb1_2(buf);
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readString(buf);
readString(buf);
readString(buf);
readString(buf);
}),
DISCONNECT(255, (user, buf) -> {
readString(buf);
});
private static final ServerboundPacketsb1_5[] REGISTRY = new ServerboundPacketsb1_5[256];
static {
for (ServerboundPacketsb1_5 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsb1_5 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsb1_5(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,14 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class WorldTimeStorage extends StoredObject {
public long time;
public WorldTimeStorage(UserConnection user) {
super(user);
}
}

View File

@ -0,0 +1,17 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.task;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.storage.WorldTimeStorage;
public class TimeTrackTask implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
final WorldTimeStorage worldTimeStorage = info.get(WorldTimeStorage.class);
if (worldTimeStorage != null) worldTimeStorage.time++;
}
}
}

View File

@ -0,0 +1,13 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_7_0_3tob1_6_0_6;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.ClientboundPacketsb1_7;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.ServerboundPacketsb1_7;
public class Protocolb1_7_0_3tob1_6_0_6 extends AbstractProtocol<ClientboundPacketsb1_7, ClientboundPacketsb1_7, ServerboundPacketsb1_7, ServerboundPacketsb1_7> {
public Protocolb1_7_0_3tob1_6_0_6() {
super(ClientboundPacketsb1_7.class, ClientboundPacketsb1_7.class, ServerboundPacketsb1_7.class, ServerboundPacketsb1_7.class);
}
}

View File

@ -0,0 +1,344 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.*;
public enum ClientboundPacketsb1_7 implements ClientboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
JOIN_GAME(1, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readString(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readString(buf);
}),
TIME_UPDATE(4, (user, buf) -> {
buf.readLong();
}),
ENTITY_EQUIPMENT(5, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
SPAWN_POSITION(6, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
}),
UPDATE_HEALTH(8, (user, buf) -> {
buf.readShort();
}),
RESPAWN(9, (user, buf) -> {
buf.readByte();
}),
PLAYER_POSITION_ONLY_ONGROUND(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_POSITION_ONLY_LOOK(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
USE_BED(17, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readByte();
buf.readInt();
}),
ENTITY_ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
SPAWN_PLAYER(20, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readShort();
}),
SPAWN_ITEM(21, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
COLLECT_ITEM(22, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
SPAWN_ENTITY(23, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
int i = buf.readInt();
if (i > 0) {
buf.readShort();
buf.readShort();
buf.readShort();
}
}),
SPAWN_MOB(24, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
readEntityMetadatab1_5(buf);
}),
SPAWN_PAINTING(25, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
}),
ENTITY_VELOCITY(28, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readShort();
buf.readShort();
}),
DESTROY_ENTITIES(29, (user, buf) -> {
buf.readInt();
}),
ENTITY_MOVEMENT(30, (user, buf) -> {
buf.readInt();
}),
ENTITY_POSITION(31, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_ROTATION(32, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_POSITION_AND_ROTATION(33, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
buf.readByte();
}),
ENTITY_TELEPORT(34, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readInt();
buf.readInt();
buf.readByte();
buf.readByte();
}),
ENTITY_STATUS(38, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ATTACH_ENTITY(39, (user, buf) -> {
buf.readInt();
buf.readInt();
}),
ENTITY_METADATA(40, (user, buf) -> {
buf.readInt();
readEntityMetadatab1_5(buf);
}),
PRE_CHUNK(50, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
CHUNK_DATA(51, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readByte();
buf.readByte();
buf.readByte();
int x = buf.readInt();
for (int i = 0; i < x; i++) buf.readByte();
}),
MULTI_BLOCK_CHANGE(52, (user, buf) -> {
buf.readInt();
buf.readInt();
short x = buf.readShort();
for (int i = 0; i < x; i++) buf.readShort();
for (int i = 0; i < x; i++) buf.readByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
BLOCK_CHANGE(53, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
BLOCK_ACTION(54, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
buf.readUnsignedByte();
buf.readUnsignedByte();
}),
EXPLOSION(60, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
int x = buf.readInt();
for (int i = 0; i < x; i++) {
buf.readByte();
buf.readByte();
buf.readByte();
}
}),
EFFECT(61, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
}),
GAME_EVENT(70, (user, buf) -> {
buf.readByte();
}),
SPAWN_GLOBAL_ENTITY(71, (user, buf) -> {
buf.readInt();
buf.readByte();
buf.readInt();
buf.readInt();
buf.readInt();
}),
OPEN_WINDOW(100, (user, buf) -> {
buf.readByte();
buf.readByte();
readUTF(buf);
buf.readByte();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
SET_SLOT(103, (user, buf) -> {
buf.readByte();
buf.readShort();
readItemStackb1_2(buf);
}),
WINDOW_ITEMS(104, (user, buf) -> {
buf.readByte();
int x = buf.readShort();
for (int i = 0; i < x; i++) readItemStackb1_2(buf);
}),
WINDOW_PROPERTY(105, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readShort();
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readString(buf);
readString(buf);
readString(buf);
readString(buf);
}),
MAP_DATA(131, (user, buf) -> {
buf.readShort();
buf.readShort();
short x = buf.readUnsignedByte();
for (int i = 0; i < x; i++) buf.readByte();
}),
STATISTICS(200, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
DISCONNECT(255, (user, buf) -> {
readString(buf);
});
private static final ClientboundPacketsb1_7[] REGISTRY = new ClientboundPacketsb1_7[256];
static {
for (ClientboundPacketsb1_7 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ClientboundPacketsb1_7 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ClientboundPacketsb1_7(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,318 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.*;
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.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import net.raphimc.vialegacy.api.BlockList1_6;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.AlphaInventoryTracker;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.ClientboundPacketsb1_8;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.ServerboundPacketsb1_8;
import net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types.Typesb1_8_0_1;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.storage.PlayerHealthTracker;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.storage.PlayerNameTracker;
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.chunks.NibbleArray1_1;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.storage.SeedStorage;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Chunk1_1Type;
import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1;
import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Types1_6_4;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
import net.raphimc.vialegacy.util.PreNettySplitter;
import java.util.concurrent.ThreadLocalRandom;
public class Protocolb1_8_0_1tob1_7_0_3 extends AbstractProtocol<ClientboundPacketsb1_7, ClientboundPacketsb1_8, ServerboundPacketsb1_7, ServerboundPacketsb1_8> {
public Protocolb1_8_0_1tob1_7_0_3() {
super(ClientboundPacketsb1_7.class, ClientboundPacketsb1_8.class, ServerboundPacketsb1_7.class, ServerboundPacketsb1_8.class);
}
@Override
protected void registerPackets() {
this.registerClientbound(ClientboundPacketsb1_7.KEEP_ALIVE, new PacketRemapper() {
@Override
public void registerMap() {
create(Type.INT, ThreadLocalRandom.current().nextInt(Short.MAX_VALUE)); // key
}
});
this.registerClientbound(ClientboundPacketsb1_7.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Types1_6_4.STRING); // username
map(Type.LONG); // seed
create(Type.INT, 0); // game mode
map(Type.BYTE); // dimension id
create(Type.BYTE, (byte) 1); // difficulty
create(Type.BYTE, (byte) -128); // world height
create(Type.BYTE, (byte) 100); // max players
handler(wrapper -> {
final PacketWrapper playerListEntry = PacketWrapper.create(ClientboundPacketsb1_8.PLAYER_INFO, wrapper.user());
playerListEntry.write(Types1_6_4.STRING, wrapper.user().getProtocolInfo().getUsername()); // name
playerListEntry.write(Type.BOOLEAN, true); // online
playerListEntry.write(Type.SHORT, (short) 0); // ping
wrapper.send(Protocolb1_8_0_1tob1_7_0_3.class);
playerListEntry.send(Protocolb1_8_0_1tob1_7_0_3.class);
wrapper.cancel();
});
}
});
this.registerClientbound(ClientboundPacketsb1_7.UPDATE_HEALTH, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // health
create(Type.SHORT, (short) 6); // food
create(Type.FLOAT, 0F); // saturation
handler(wrapper -> wrapper.user().get(PlayerHealthTracker.class).setHealth(wrapper.get(Type.SHORT, 0)));
}
});
this.registerClientbound(ClientboundPacketsb1_7.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // dimension id
create(Type.BYTE, (byte) 1); // difficulty
create(Type.BYTE, (byte) 0); // game mode
create(Type.SHORT, (short) 128); // world height
handler(wrapper -> wrapper.write(Type.LONG, wrapper.user().get(SeedStorage.class).seed)); // seed
}
});
this.registerClientbound(ClientboundPacketsb1_7.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Types1_6_4.STRING); // username
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
map(Type.UNSIGNED_SHORT); // item
handler(wrapper -> {
final int entityId = wrapper.get(Type.INT, 0);
final PlayerNameTracker playerNameTracker = wrapper.user().get(PlayerNameTracker.class);
playerNameTracker.names.put(entityId, wrapper.get(Types1_6_4.STRING, 0));
final PacketWrapper playerListEntry = PacketWrapper.create(ClientboundPacketsb1_8.PLAYER_INFO, wrapper.user());
playerListEntry.write(Types1_6_4.STRING, playerNameTracker.names.get(entityId)); // name
playerListEntry.write(Type.BOOLEAN, true); // online
playerListEntry.write(Type.SHORT, (short) 0); // ping
playerListEntry.send(Protocolb1_8_0_1tob1_7_0_3.class);
});
}
});
this.registerClientbound(ClientboundPacketsb1_7.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.UNSIGNED_BYTE); // type id
map(Type.INT); // x
map(Type.INT); // y
map(Type.INT); // z
map(Type.BYTE); // yaw
map(Type.BYTE); // pitch
map(Types1_3_1.METADATA_LIST); // metadata
handler(wrapper -> {
final short entityType = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (entityType == 49) { // monster
final PacketWrapper spawnMonster = PacketWrapper.create(ClientboundPacketsb1_8.SPAWN_PLAYER, wrapper.user());
spawnMonster.write(Type.INT, wrapper.get(Type.INT, 0)); // entity id
spawnMonster.write(Types1_6_4.STRING, "Monster"); // username
spawnMonster.write(Type.INT, wrapper.get(Type.INT, 1)); // x
spawnMonster.write(Type.INT, wrapper.get(Type.INT, 2)); // y
spawnMonster.write(Type.INT, wrapper.get(Type.INT, 3)); // z
spawnMonster.write(Type.BYTE, wrapper.get(Type.BYTE, 0)); // yaw
spawnMonster.write(Type.BYTE, wrapper.get(Type.BYTE, 1)); // pitch
spawnMonster.write(Type.UNSIGNED_SHORT, 0); // item
final PacketWrapper entityMetadata = PacketWrapper.create(ClientboundPacketsb1_8.ENTITY_METADATA, wrapper.user());
entityMetadata.write(Type.INT, wrapper.get(Type.INT, 0)); // entity id
entityMetadata.write(Types1_3_1.METADATA_LIST, wrapper.get(Types1_3_1.METADATA_LIST, 0)); // metadata
wrapper.cancel();
spawnMonster.send(Protocolb1_8_0_1tob1_7_0_3.class);
entityMetadata.send(Protocolb1_8_0_1tob1_7_0_3.class);
}
});
}
});
this.registerClientbound(ClientboundPacketsb1_7.DESTROY_ENTITIES, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
handler(wrapper -> {
final PlayerNameTracker playerNameTracker = wrapper.user().get(PlayerNameTracker.class);
final String name = playerNameTracker.names.get(wrapper.get(Type.INT, 0));
if (name != null) {
final PacketWrapper playerListEntry = PacketWrapper.create(ClientboundPacketsb1_8.PLAYER_INFO, wrapper.user());
playerListEntry.write(Types1_6_4.STRING, name); // name
playerListEntry.write(Type.BOOLEAN, false); // online
playerListEntry.write(Type.SHORT, (short) 0); // ping
playerListEntry.send(Protocolb1_8_0_1tob1_7_0_3.class);
}
});
}
});
this.registerClientbound(ClientboundPacketsb1_7.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final Chunk chunk = wrapper.passthrough(new Chunk1_1Type(wrapper.user().get(ClientWorld.class)));
boolean hasChest = false;
for (ChunkSection section : chunk.getSections()) {
if (section == null || !section.getLight().hasSkyLight()) continue;
for (int i = 0; i < section.palette(PaletteType.BLOCKS).size(); i++) {
if (section.palette(PaletteType.BLOCKS).idByIndex(i) >> 4 == BlockList1_6.chest.blockID) {
hasChest = true;
break;
}
}
if (!hasChest) continue;
final NibbleArray1_1 sectionSkyLight = new NibbleArray1_1(section.getLight().getSkyLight(), 4);
for (int y = 0; y < 16; y++)
for (int x = 0; x < 16; x++)
for (int z = 0; z < 16; z++)
if (section.palette(PaletteType.BLOCKS).idAt(x, y, z) >> 4 == BlockList1_6.chest.blockID)
sectionSkyLight.set(x, y, z, 15);
}
});
}
});
this.registerClientbound(ClientboundPacketsb1_7.GAME_EVENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // reason
create(Type.BYTE, (byte) 0); // value
}
});
this.registerClientbound(ClientboundPacketsb1_7.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // window id
map(Type.UNSIGNED_BYTE); // window type
map(Typesb1_7_0_3.STRING, Types1_6_4.STRING); // title
map(Type.UNSIGNED_BYTE); // slots
}
});
this.registerServerbound(State.STATUS, -1, ServerboundPacketsb1_8.SERVER_PING.getId(), new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
final PacketWrapper pingResponse = PacketWrapper.create(ClientboundPacketsb1_8.DISCONNECT, wrapper.user());
pingResponse.write(Types1_6_4.STRING, "The server seems to be running!\nWait 5 seconds between each connection§0§1");
pingResponse.send(Protocolb1_8_0_1tob1_7_0_3.class);
});
}
});
this.cancelServerbound(ServerboundPacketsb1_8.SERVER_PING);
this.registerServerbound(State.LOGIN, ServerboundPacketsb1_7.LOGIN.getId(), ServerboundPacketsb1_8.LOGIN.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // protocol id
map(Types1_6_4.STRING); // username
map(Type.LONG); // seed
read(Type.INT); // game mode
map(Type.BYTE); // dimension id
read(Type.BYTE); // difficulty
read(Type.BYTE); // world height
read(Type.BYTE); // max players
}
});
this.registerServerbound(ServerboundPacketsb1_8.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // dimension id
read(Type.BYTE); // difficulty
read(Type.BYTE); // game mode
read(Type.SHORT); // world height
read(Type.LONG); // seed
}
});
this.registerServerbound(ServerboundPacketsb1_8.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // status
handler(wrapper -> {
final short status = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (status == 5) wrapper.cancel(); // Stop using item
});
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
}
});
this.registerServerbound(ServerboundPacketsb1_8.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
map(Types1_4_2.NBTLESS_ITEM); // item
handler(wrapper -> {
final Position pos = wrapper.get(Types1_7_6.POSITION_UBYTE, 0);
if (wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos).id == BlockList1_6.cake.blockID) {
final PacketWrapper updateHealth = PacketWrapper.create(ClientboundPacketsb1_8.UPDATE_HEALTH, wrapper.user());
updateHealth.write(Type.SHORT, wrapper.user().get(PlayerHealthTracker.class).getHealth()); // health
updateHealth.write(Type.SHORT, (short) 6); // food
updateHealth.write(Type.FLOAT, 0F); // saturation
updateHealth.send(Protocolb1_8_0_1tob1_7_0_3.class);
}
});
}
});
this.registerServerbound(ServerboundPacketsb1_8.ENTITY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // entity id
map(Type.BYTE); // action id
handler(wrapper -> {
if (wrapper.get(Type.BYTE, 0) > 3) wrapper.cancel();
});
}
});
this.registerServerbound(ServerboundPacketsb1_8.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // window id
handler(wrapper -> {
if (wrapper.passthrough(Type.SHORT) /*slot*/ == -1) wrapper.cancel();
});
map(Type.BYTE); // button
map(Type.SHORT); // action
map(Type.BYTE); // mode
map(Types1_4_2.NBTLESS_ITEM); // item
}
});
this.registerServerbound(ServerboundPacketsb1_8.CREATIVE_INVENTORY_ACTION, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
// Track the item for later use in classic protocols
final AlphaInventoryTracker inventoryTracker = wrapper.user().get(AlphaInventoryTracker.class);
if (inventoryTracker != null) inventoryTracker.handleCreativeSetSlot(wrapper.read(Type.SHORT), wrapper.read(Typesb1_8_0_1.CREATIVE_ITEM));
});
}
});
this.cancelServerbound(ServerboundPacketsb1_8.KEEP_ALIVE); // beta client only sends this packet every second if in downloading terrain screen
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_8_0_1tob1_7_0_3.class, ClientboundPacketsb1_7::getPacket));
userConnection.put(new PlayerNameTracker(userConnection));
userConnection.put(new PlayerHealthTracker(userConnection));
}
}

View File

@ -0,0 +1,158 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.util.PreNettyPacketType;
import java.util.function.BiConsumer;
import static net.raphimc.vialegacy.util.PreNettyTypes.readItemStackb1_2;
import static net.raphimc.vialegacy.util.PreNettyTypes.readString;
public enum ServerboundPacketsb1_7 implements ServerboundPacketType, PreNettyPacketType {
KEEP_ALIVE(0, (user, buf) -> {
}),
LOGIN(1, (user, buf) -> {
buf.readInt();
readString(buf);
buf.readLong();
buf.readByte();
}),
HANDSHAKE(2, (user, buf) -> {
readString(buf);
}),
CHAT_MESSAGE(3, (user, buf) -> {
readString(buf);
}),
INTERACT_ENTITY(7, (user, buf) -> {
buf.readInt();
buf.readInt();
buf.readByte();
}),
RESPAWN(9, (user, buf) -> {
buf.readByte();
}),
PLAYER_MOVEMENT(10, (user, buf) -> {
buf.readUnsignedByte();
}),
PLAYER_POSITION(11, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readUnsignedByte();
}),
PLAYER_ROTATION(12, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_POSITION_AND_ROTATION(13, (user, buf) -> {
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readDouble();
buf.readFloat();
buf.readFloat();
buf.readUnsignedByte();
}),
PLAYER_DIGGING(14, (user, buf) -> {
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
}),
PLAYER_BLOCK_PLACEMENT(15, (user, buf) -> {
buf.readInt();
buf.readUnsignedByte();
buf.readInt();
buf.readUnsignedByte();
readItemStackb1_2(buf);
}),
HELD_ITEM_CHANGE(16, (user, buf) -> {
buf.readShort();
}),
ANIMATION(18, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
ENTITY_ACTION(19, (user, buf) -> {
buf.readInt();
buf.readByte();
}),
POSITION(27, (user, buf) -> {
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readFloat();
buf.readBoolean();
buf.readBoolean();
}),
CLOSE_WINDOW(101, (user, buf) -> {
buf.readByte();
}),
CLICK_WINDOW(102, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
buf.readShort();
buf.readBoolean();
readItemStackb1_2(buf);
}),
WINDOW_CONFIRMATION(106, (user, buf) -> {
buf.readByte();
buf.readShort();
buf.readByte();
}),
UPDATE_SIGN(130, (user, buf) -> {
buf.readInt();
buf.readShort();
buf.readInt();
readString(buf);
readString(buf);
readString(buf);
readString(buf);
}),
DISCONNECT(255, (user, buf) -> {
readString(buf);
});
private static final ServerboundPacketsb1_7[] REGISTRY = new ServerboundPacketsb1_7[256];
static {
for (ServerboundPacketsb1_7 packet : values()) {
REGISTRY[packet.id] = packet;
}
}
public static ServerboundPacketsb1_7 getPacket(final int id) {
return REGISTRY[id];
}
private final int id;
private final BiConsumer<UserConnection, ByteBuf> packetReader;
ServerboundPacketsb1_7(final int id, final BiConsumer<UserConnection, ByteBuf> packetReader) {
this.id = id;
this.packetReader = packetReader;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getName() {
return name();
}
@Override
public BiConsumer<UserConnection, ByteBuf> getPacketReader() {
return this.packetReader;
}
}

View File

@ -0,0 +1,22 @@
package net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class PlayerHealthTracker extends StoredObject {
private short health = 20;
public PlayerHealthTracker(UserConnection user) {
super(user);
}
public void setHealth(final short health) {
this.health = health;
}
public short getHealth() {
return this.health;
}
}

Some files were not shown because too many files have changed in this diff Show More