[ci skip] Reformat all classes
This commit is contained in:
86 files changed
+6374
-6321
No files matched your search
+1
-1
@@ -1,2 +1,2 @@
|
||||
github: FlorianMichael
|
||||
custom: ['https://florianmichael.de/donate', 'https://creeper123123321.github.io/#donate']
|
||||
custom: [ 'https://florianmichael.de/donate', 'https://creeper123123321.github.io/#donate' ]
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Build
|
||||
on: [pull_request, push, workflow_dispatch]
|
||||
on: [ pull_request, push, workflow_dispatch ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# ViaRewind
|
||||
|
||||
[](https://github.com/ViaVersion/ViaRewind/releases)
|
||||
[](https://github.com/ViaVersion/ViaRewind/actions)
|
||||
[](https://viaversion.com/discord)
|
||||
@@ -6,13 +7,17 @@
|
||||
**ViaVersion addon to allow 1.8.x and 1.7.x clients on newer server versions.** <br>
|
||||
Runs on 1.9-latest servers or 1.8 clients and lower.
|
||||
|
||||
**You can override the included version in [ViaFabric](https://modrinth.com/mod/viafabric) or [ViaProxy](https://github.com/ViaVersion/ViaProxy):**
|
||||
**You can override the included version in [ViaFabric](https://modrinth.com/mod/viafabric)
|
||||
or [ViaProxy](https://github.com/ViaVersion/ViaProxy):**
|
||||
|
||||
- in **ViaFabric**, put ViaRewind into the `mods` folder
|
||||
- in **ViaProxy**, put ViaRewind into the `jars` folder
|
||||
|
||||
Note: when using ViaFabric <= 1.16.5 or J8 ViaProxy builds, you need [J8 ViaRewind](https://ci.viaversion.com/view/ViaRewind/job/ViaRewind-Java8/) builds.
|
||||
Note: when using ViaFabric <= 1.16.5 or J8 ViaProxy builds, you
|
||||
need [J8 ViaRewind](https://ci.viaversion.com/view/ViaRewind/job/ViaRewind-Java8/) builds.
|
||||
|
||||
**Requires [ViaVersion](https://hangar.papermc.io/ViaVersion/ViaVersion) and [ViaBackwards](https://hangar.papermc.io/ViaVersion/ViaBackwards) to be installed..**
|
||||
**Requires [ViaVersion](https://hangar.papermc.io/ViaVersion/ViaVersion)
|
||||
and [ViaBackwards](https://hangar.papermc.io/ViaVersion/ViaBackwards) to be installed..**
|
||||
|
||||
Releases/Dev Builds
|
||||
-
|
||||
|
||||
+8
-3
@@ -2,9 +2,14 @@
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you discover a **security vulnerability**, please **do not** open a public issue. Instead, use one of the following **confidential contact methods**:
|
||||
If you discover a **security vulnerability**, please **do not** open a public issue. Instead, use one of the following *
|
||||
*confidential contact methods**:
|
||||
|
||||
* **Email:** [security@viaversion.com](mailto:security@viaversion.com)
|
||||
* **Discord:** Join our [Discord server](https://discord.gg/viaversion) and visit the [#exploit-report](https://discord.com/channels/316206679014244363/1388847764137316485) channel for further instructions.
|
||||
* **Discord:** Join our [Discord server](https://discord.gg/viaversion) and visit
|
||||
the [#exploit-report](https://discord.com/channels/316206679014244363/1388847764137316485) channel for further
|
||||
instructions.
|
||||
|
||||
If your issue is **not security-related** (e.g., bug reports, feature requests, or usage questions), please use the [GitHub Issues page](https://github.com/ViaVersion/ViaRewind/issues) or contact us via the [Discord server](https://discord.gg/viaversion).
|
||||
If your issue is **not security-related** (e.g., bug reports, feature requests, or usage questions), please use
|
||||
the [GitHub Issues page](https://github.com/ViaVersion/ViaRewind/issues) or contact us via
|
||||
the [Discord server](https://discord.gg/viaversion).
|
||||
@@ -19,13 +19,12 @@ package com.viaversion.viarewind;
|
||||
|
||||
import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BukkitPlugin extends JavaPlugin implements ViaRewindPlatform {
|
||||
|
||||
public BukkitPlugin() {
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
public BukkitPlugin() {
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
name: ViaRewind
|
||||
main: com.viaversion.viarewind.BukkitPlugin
|
||||
authors: [FlorianMichael/EnZaXD, Gerrygames, creeper123123321]
|
||||
authors: [ FlorianMichael/EnZaXD, Gerrygames, creeper123123321 ]
|
||||
version: ${version}
|
||||
description: ${description}
|
||||
website: https://viaversion.com/rewind
|
||||
api-version: 1.13
|
||||
folia-supported: true
|
||||
load: STARTUP
|
||||
depend: [ViaVersion, ViaBackwards]
|
||||
depend: [ ViaVersion, ViaBackwards ]
|
||||
@@ -1,4 +1,4 @@
|
||||
import de.florianmichael.baseproject.*
|
||||
import de.florianmichael.baseproject.latestCommitHash
|
||||
|
||||
plugins {
|
||||
id("net.raphimc.class-token-replacer")
|
||||
|
||||
@@ -23,21 +23,21 @@ import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
|
||||
public class ViaRewind {
|
||||
|
||||
private static ViaRewindPlatform platform;
|
||||
private static ViaRewindConfig config;
|
||||
private static ViaRewindPlatform platform;
|
||||
private static ViaRewindConfig config;
|
||||
|
||||
public static void init(ViaRewindPlatform platform, ViaRewindConfig config) {
|
||||
Preconditions.checkArgument(ViaRewind.platform == null, "ViaRewind is already initialized");
|
||||
public static void init(ViaRewindPlatform platform, ViaRewindConfig config) {
|
||||
Preconditions.checkArgument(ViaRewind.platform == null, "ViaRewind is already initialized");
|
||||
|
||||
ViaRewind.platform = platform;
|
||||
ViaRewind.config = config;
|
||||
}
|
||||
ViaRewind.platform = platform;
|
||||
ViaRewind.config = config;
|
||||
}
|
||||
|
||||
public static ViaRewindPlatform getPlatform() {
|
||||
return ViaRewind.platform;
|
||||
}
|
||||
public static ViaRewindPlatform getPlatform() {
|
||||
return ViaRewind.platform;
|
||||
}
|
||||
|
||||
public static ViaRewindConfig getConfig() {
|
||||
return ViaRewind.config;
|
||||
}
|
||||
public static ViaRewindConfig getConfig() {
|
||||
return ViaRewind.config;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
package com.viaversion.viarewind;
|
||||
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
@@ -29,105 +28,105 @@ import java.util.logging.Logger;
|
||||
|
||||
public class ViaRewindConfig extends Config implements com.viaversion.viarewind.api.ViaRewindConfig {
|
||||
|
||||
private CooldownIndicator cooldownIndicator;
|
||||
private boolean replaceAdventureMode;
|
||||
private boolean replaceParticles;
|
||||
private int maxBookPages;
|
||||
private int maxBookPageSize;
|
||||
private boolean emulateWorldBorder;
|
||||
private boolean alwaysShowOriginalMobName;
|
||||
private String worldBorderParticle;
|
||||
private boolean enableOffhand;
|
||||
private String offhandCommand;
|
||||
private boolean emulateLevitationEffect;
|
||||
private boolean handlePlayerCombatPacket;
|
||||
private CooldownIndicator cooldownIndicator;
|
||||
private boolean replaceAdventureMode;
|
||||
private boolean replaceParticles;
|
||||
private int maxBookPages;
|
||||
private int maxBookPageSize;
|
||||
private boolean emulateWorldBorder;
|
||||
private boolean alwaysShowOriginalMobName;
|
||||
private String worldBorderParticle;
|
||||
private boolean enableOffhand;
|
||||
private String offhandCommand;
|
||||
private boolean emulateLevitationEffect;
|
||||
private boolean handlePlayerCombatPacket;
|
||||
|
||||
public ViaRewindConfig(File configFile, Logger logger) {
|
||||
super(configFile, logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
loadFields();
|
||||
}
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
loadFields();
|
||||
}
|
||||
|
||||
private void loadFields() {
|
||||
cooldownIndicator = CooldownIndicator.valueOf(getString("cooldown-indicator", "TITLE").toUpperCase());
|
||||
replaceAdventureMode = getBoolean("replace-adventure", false);
|
||||
replaceParticles = getBoolean("replace-particles", false);
|
||||
maxBookPages = getInt("max-book-pages", 100);
|
||||
maxBookPageSize = getInt("max-book-page-length", 5000);
|
||||
emulateWorldBorder = getBoolean("emulate-world-border", true);
|
||||
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
||||
worldBorderParticle = getString("world-border-particle", "fireworksSpark");
|
||||
enableOffhand = getBoolean("enable-offhand", true);
|
||||
offhandCommand = getString("offhand-command", "/offhand");
|
||||
emulateLevitationEffect = getBoolean("emulate-levitation-effect", true);
|
||||
handlePlayerCombatPacket = getBoolean("handle-player-combat-packet", true);
|
||||
}
|
||||
private void loadFields() {
|
||||
cooldownIndicator = CooldownIndicator.valueOf(getString("cooldown-indicator", "TITLE").toUpperCase());
|
||||
replaceAdventureMode = getBoolean("replace-adventure", false);
|
||||
replaceParticles = getBoolean("replace-particles", false);
|
||||
maxBookPages = getInt("max-book-pages", 100);
|
||||
maxBookPageSize = getInt("max-book-page-length", 5000);
|
||||
emulateWorldBorder = getBoolean("emulate-world-border", true);
|
||||
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
||||
worldBorderParticle = getString("world-border-particle", "fireworksSpark");
|
||||
enableOffhand = getBoolean("enable-offhand", true);
|
||||
offhandCommand = getString("offhand-command", "/offhand");
|
||||
emulateLevitationEffect = getBoolean("emulate-levitation-effect", true);
|
||||
handlePlayerCombatPacket = getBoolean("handle-player-combat-packet", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public CooldownIndicator getCooldownIndicator() {
|
||||
return cooldownIndicator;
|
||||
return cooldownIndicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceAdventureMode() {
|
||||
return replaceAdventureMode;
|
||||
return replaceAdventureMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceParticles() {
|
||||
return replaceParticles;
|
||||
return replaceParticles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBookPages() {
|
||||
return maxBookPages;
|
||||
return maxBookPages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBookPageSize() {
|
||||
return maxBookPageSize;
|
||||
return maxBookPageSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmulateWorldBorder() {
|
||||
return emulateWorldBorder;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmulateWorldBorder() {
|
||||
return emulateWorldBorder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysShowOriginalMobName() {
|
||||
return alwaysShowOriginalMobName;
|
||||
}
|
||||
@Override
|
||||
public boolean alwaysShowOriginalMobName() {
|
||||
return alwaysShowOriginalMobName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWorldBorderParticle() {
|
||||
return worldBorderParticle;
|
||||
}
|
||||
@Override
|
||||
public String getWorldBorderParticle() {
|
||||
return worldBorderParticle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnableOffhand() {
|
||||
return enableOffhand;
|
||||
}
|
||||
@Override
|
||||
public boolean isEnableOffhand() {
|
||||
return enableOffhand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOffhandCommand() {
|
||||
return offhandCommand;
|
||||
}
|
||||
@Override
|
||||
public String getOffhandCommand() {
|
||||
return offhandCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emulateLevitationEffect() {
|
||||
return emulateLevitationEffect;
|
||||
}
|
||||
@Override
|
||||
public boolean emulateLevitationEffect() {
|
||||
return emulateLevitationEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePlayerCombatPacket() {
|
||||
return handlePlayerCombatPacket;
|
||||
}
|
||||
@Override
|
||||
public boolean handlePlayerCombatPacket() {
|
||||
return handlePlayerCombatPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public URL getDefaultConfigURL() {
|
||||
return getClass().getClassLoader().getResource("assets/viarewind/config.yml");
|
||||
}
|
||||
|
||||
@@ -24,97 +24,97 @@ import com.viaversion.viaversion.api.configuration.Config;
|
||||
*/
|
||||
public interface ViaRewindConfig extends Config {
|
||||
|
||||
enum CooldownIndicator {
|
||||
TITLE, ACTION_BAR, BOSS_BAR, DISABLED
|
||||
}
|
||||
/**
|
||||
* Specifies how 1.8.x clients should see the cooldown indicator
|
||||
* You can choose between TITLE, ACTION_BAR, BOSS_BAR and DISABLED
|
||||
* ONLY DISABLE IF YOU HAVE 1.9 COOLDOWN DISABLED ON YOUR SERVER
|
||||
* 1.8 PLAYERS MAY ASK WHY PVP IS NOT WORKING OTHERWISE
|
||||
*
|
||||
* @return the cooldown indicator
|
||||
*/
|
||||
CooldownIndicator getCooldownIndicator();
|
||||
|
||||
/**
|
||||
* Specifies how 1.8.x clients should see the cooldown indicator
|
||||
* You can choose between TITLE, ACTION_BAR, BOSS_BAR and DISABLED
|
||||
* ONLY DISABLE IF YOU HAVE 1.9 COOLDOWN DISABLED ON YOUR SERVER
|
||||
* 1.8 PLAYERS MAY ASK WHY PVP IS NOT WORKING OTHERWISE
|
||||
*
|
||||
* @return the cooldown indicator
|
||||
*/
|
||||
CooldownIndicator getCooldownIndicator();
|
||||
/**
|
||||
* Replaces Adventure mode with Survival mode for 1.7.x clients
|
||||
* Enable this option if your server is using the 'CanDestroy'
|
||||
* or 'CanPlaceOn' flags on items
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceAdventureMode();
|
||||
|
||||
/**
|
||||
* Replaces Adventure mode with Survival mode for 1.7.x clients
|
||||
* Enable this option if your server is using the 'CanDestroy'
|
||||
* or 'CanPlaceOn' flags on items
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceAdventureMode();
|
||||
/**
|
||||
* Whether 1.9 particles should be replaced by similar ones in
|
||||
* 1.8 and lower
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceParticles();
|
||||
|
||||
/**
|
||||
* Whether 1.9 particles should be replaced by similar ones in
|
||||
* 1.8 and lower
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isReplaceParticles();
|
||||
/**
|
||||
* Max amount of pages for written books before a client gets kicked
|
||||
*
|
||||
* @return the max amount of pages
|
||||
*/
|
||||
int getMaxBookPages();
|
||||
|
||||
/**
|
||||
* Max amount of pages for written books before a client gets kicked
|
||||
*
|
||||
* @return the max amount of pages
|
||||
*/
|
||||
int getMaxBookPages();
|
||||
/**
|
||||
* Max amount of characters in the json (!) string of a book page before a client gets kicked
|
||||
*
|
||||
* @return the max amount of characters
|
||||
*/
|
||||
int getMaxBookPageSize();
|
||||
|
||||
/**
|
||||
* Max amount of characters in the json (!) string of a book page before a client gets kicked
|
||||
*
|
||||
* @return the max amount of characters
|
||||
*/
|
||||
int getMaxBookPageSize();
|
||||
/**
|
||||
* Whether to emulate the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEmulateWorldBorder();
|
||||
|
||||
/**
|
||||
* Whether to emulate the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEmulateWorldBorder();
|
||||
/**
|
||||
* Always shows the original mob's name instead of only when hovering over them with the cursor.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean alwaysShowOriginalMobName();
|
||||
|
||||
/**
|
||||
* Always shows the original mob's name instead of only when hovering over them with the cursor.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean alwaysShowOriginalMobName();
|
||||
/**
|
||||
* The particle to show the world border for the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return the particle name
|
||||
*/
|
||||
String getWorldBorderParticle();
|
||||
|
||||
/**
|
||||
* The particle to show the world border for the 1.8+ world border for 1.7.x clients
|
||||
*
|
||||
* @return the particle name
|
||||
*/
|
||||
String getWorldBorderParticle();
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers can use /offhand to switch items between their main hand and offhand.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEnableOffhand();
|
||||
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers can use /offhand to switch items between their main hand and offhand.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isEnableOffhand();
|
||||
/**
|
||||
* Allows to define the offhand command
|
||||
*
|
||||
* @return the offhand command
|
||||
*/
|
||||
String getOffhandCommand();
|
||||
|
||||
/**
|
||||
* Allows to define the offhand command
|
||||
*
|
||||
* @return the offhand command
|
||||
*/
|
||||
String getOffhandCommand();
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers will also experience the levitation effect by sending velocity packets.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean emulateLevitationEffect();
|
||||
|
||||
/**
|
||||
* If enabled, 1.8 players on 1.9+ servers will also experience the levitation effect by sending velocity packets.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean emulateLevitationEffect();
|
||||
/**
|
||||
* If enabled, 1.8 players will handle the player combat packet added in 1.9 by showing the custom death message above the hotbar.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean handlePlayerCombatPacket();
|
||||
|
||||
/**
|
||||
* If enabled, 1.8 players will handle the player combat packet added in 1.9 by showing the custom death message above the hotbar.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean handlePlayerCombatPacket();
|
||||
enum CooldownIndicator {
|
||||
TITLE, ACTION_BAR, BOSS_BAR, DISABLED
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolManager;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -34,59 +33,59 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public interface ViaRewindPlatform {
|
||||
|
||||
String VERSION = "${version}";
|
||||
String IMPL_VERSION = "${impl_version}";
|
||||
String VERSION = "${version}";
|
||||
String IMPL_VERSION = "${impl_version}";
|
||||
|
||||
/**
|
||||
* Initialize ViaRewind
|
||||
*/
|
||||
default void init(final File configFile) {
|
||||
ViaRewindConfig config = new ViaRewindConfig(configFile, getLogger());
|
||||
config.reload();
|
||||
Via.getManager().getConfigurationProvider().register(config);
|
||||
/**
|
||||
* Initialize ViaRewind
|
||||
*/
|
||||
default void init(final File configFile) {
|
||||
ViaRewindConfig config = new ViaRewindConfig(configFile, getLogger());
|
||||
config.reload();
|
||||
Via.getManager().getConfigurationProvider().register(config);
|
||||
|
||||
ViaRewind.init(this, config);
|
||||
ViaRewind.init(this, config);
|
||||
|
||||
Via.getManager().getSubPlatforms().add(IMPL_VERSION);
|
||||
Via.getManager().getSubPlatforms().add(IMPL_VERSION);
|
||||
|
||||
getLogger().info("Registering protocols...");
|
||||
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
||||
protocolManager.registerProtocol(new Protocol1_7_6_10To1_7_2_5(), ProtocolVersion.v1_7_2, ProtocolVersion.v1_7_6);
|
||||
protocolManager.registerProtocol(new Protocol1_8To1_7_6_10(), ProtocolVersion.v1_7_6, ProtocolVersion.v1_8);
|
||||
getLogger().info("Registering protocols...");
|
||||
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
||||
protocolManager.registerProtocol(new Protocol1_7_6_10To1_7_2_5(), ProtocolVersion.v1_7_2, ProtocolVersion.v1_7_6);
|
||||
protocolManager.registerProtocol(new Protocol1_8To1_7_6_10(), ProtocolVersion.v1_7_6, ProtocolVersion.v1_8);
|
||||
|
||||
protocolManager.registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_8, ProtocolVersion.v1_9);
|
||||
}
|
||||
protocolManager.registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_8, ProtocolVersion.v1_9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform logger
|
||||
*
|
||||
* @return the logger
|
||||
*/
|
||||
Logger getLogger();
|
||||
/**
|
||||
* Get the platform logger
|
||||
*
|
||||
* @return the logger
|
||||
*/
|
||||
Logger getLogger();
|
||||
|
||||
/**
|
||||
* Returns ViaRewind's data folder.
|
||||
*
|
||||
* @return data folder
|
||||
*/
|
||||
File getDataFolder();
|
||||
/**
|
||||
* Returns ViaRewind's data folder.
|
||||
*
|
||||
* @return data folder
|
||||
*/
|
||||
File getDataFolder();
|
||||
|
||||
/**
|
||||
* Returns the platform's compression handler name. Only used in the 1.8 -> 1.7 protocol.
|
||||
*
|
||||
* @return the compression handler name
|
||||
*/
|
||||
default String compressHandlerName() {
|
||||
return "compress";
|
||||
}
|
||||
/**
|
||||
* Returns the platform's compression handler name. Only used in the 1.8 -> 1.7 protocol.
|
||||
*
|
||||
* @return the compression handler name
|
||||
*/
|
||||
default String compressHandlerName() {
|
||||
return "compress";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the platform's decompression handler name. Only used in the 1.8 -> 1.7 protocol.
|
||||
*
|
||||
* @return the decompression handler name
|
||||
*/
|
||||
default String decompressHandlerName() {
|
||||
return "decompress";
|
||||
}
|
||||
/**
|
||||
* Returns the platform's decompression handler name. Only used in the 1.8 -> 1.7 protocol.
|
||||
*
|
||||
* @return the decompression handler name
|
||||
*/
|
||||
default String decompressHandlerName() {
|
||||
return "decompress";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,25 +17,24 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.data;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RewindMappingData extends BackwardsMappingData {
|
||||
|
||||
public RewindMappingData(String unmappedVersion, String mappedVersion) {
|
||||
super(unmappedVersion, mappedVersion);
|
||||
}
|
||||
public RewindMappingData(String unmappedVersion, String mappedVersion) {
|
||||
super(unmappedVersion, mappedVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
@Override
|
||||
protected Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompoundTag readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadNBTFromDir(name);
|
||||
}
|
||||
@Override
|
||||
protected CompoundTag readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadNBTFromDir(name);
|
||||
}
|
||||
}
|
||||
+12
-13
@@ -19,26 +19,25 @@ package com.viaversion.viarewind.api.data;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RewindMappingDataLoader extends BackwardsMappingDataLoader {
|
||||
|
||||
public static final RewindMappingDataLoader INSTANCE = new RewindMappingDataLoader();
|
||||
public static final RewindMappingDataLoader INSTANCE = new RewindMappingDataLoader();
|
||||
|
||||
public RewindMappingDataLoader() {
|
||||
super(RewindMappingDataLoader.class, "assets/viarewind/data/");
|
||||
}
|
||||
public RewindMappingDataLoader() {
|
||||
super(RewindMappingDataLoader.class, "assets/viarewind/data/");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return ViaRewind.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return ViaRewind.getPlatform().getDataFolder();
|
||||
}
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return ViaRewind.getPlatform().getDataFolder();
|
||||
}
|
||||
}
|
||||
+42
-42
@@ -21,57 +21,57 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.NibbleArray;
|
||||
|
||||
public class ExtendedBlockStorage {
|
||||
private final byte[] blockLSBArray = new byte[ChunkSection.SIZE];
|
||||
private final byte[] blockLSBArray = new byte[ChunkSection.SIZE];
|
||||
|
||||
private final NibbleArray blockMetadataArray = new NibbleArray(this.blockLSBArray.length);
|
||||
private final NibbleArray blockLightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
private final NibbleArray blockMetadataArray = new NibbleArray(this.blockLSBArray.length);
|
||||
private final NibbleArray blockLightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
|
||||
private NibbleArray blockMSBArray;
|
||||
private NibbleArray skyLightArray;
|
||||
private NibbleArray blockMSBArray;
|
||||
private NibbleArray skyLightArray;
|
||||
|
||||
public ExtendedBlockStorage(final boolean skylight) {
|
||||
if (skylight) {
|
||||
this.skyLightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
}
|
||||
}
|
||||
public ExtendedBlockStorage(final boolean skylight) {
|
||||
if (skylight) {
|
||||
this.skyLightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockId(final int x, final int y, final int z, final int value) {
|
||||
this.blockLSBArray[ChunkSection.index(x, y, z)] = (byte) (value & 255);
|
||||
if (value > 255) {
|
||||
this.getOrCreateBlockMSBArray().set(x, y, z, (value & 0xF00) >> 8);
|
||||
} else if (this.blockMSBArray != null) {
|
||||
this.blockMSBArray.set(x, y, z, 0);
|
||||
}
|
||||
}
|
||||
public void setBlockId(final int x, final int y, final int z, final int value) {
|
||||
this.blockLSBArray[ChunkSection.index(x, y, z)] = (byte) (value & 255);
|
||||
if (value > 255) {
|
||||
this.getOrCreateBlockMSBArray().set(x, y, z, (value & 0xF00) >> 8);
|
||||
} else if (this.blockMSBArray != null) {
|
||||
this.blockMSBArray.set(x, y, z, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockMetadata(final int x, final int y, final int z, final int value) {
|
||||
this.blockMetadataArray.set(x, y, z, value);
|
||||
}
|
||||
public void setBlockMetadata(final int x, final int y, final int z, final int value) {
|
||||
this.blockMetadataArray.set(x, y, z, value);
|
||||
}
|
||||
|
||||
public boolean hasBlockMSBArray() {
|
||||
return this.blockMSBArray != null;
|
||||
}
|
||||
public boolean hasBlockMSBArray() {
|
||||
return this.blockMSBArray != null;
|
||||
}
|
||||
|
||||
public byte[] getBlockLSBArray() {
|
||||
return this.blockLSBArray;
|
||||
}
|
||||
public byte[] getBlockLSBArray() {
|
||||
return this.blockLSBArray;
|
||||
}
|
||||
|
||||
public NibbleArray getOrCreateBlockMSBArray() {
|
||||
if (this.blockMSBArray == null) {
|
||||
return this.blockMSBArray = new NibbleArray(this.blockLSBArray.length);
|
||||
}
|
||||
return this.blockMSBArray;
|
||||
}
|
||||
public NibbleArray getOrCreateBlockMSBArray() {
|
||||
if (this.blockMSBArray == null) {
|
||||
return this.blockMSBArray = new NibbleArray(this.blockLSBArray.length);
|
||||
}
|
||||
return this.blockMSBArray;
|
||||
}
|
||||
|
||||
public NibbleArray getBlockMetadataArray() {
|
||||
return this.blockMetadataArray;
|
||||
}
|
||||
public NibbleArray getBlockMetadataArray() {
|
||||
return this.blockMetadataArray;
|
||||
}
|
||||
|
||||
public NibbleArray getBlockLightArray() {
|
||||
return this.blockLightArray;
|
||||
}
|
||||
public NibbleArray getBlockLightArray() {
|
||||
return this.blockLightArray;
|
||||
}
|
||||
|
||||
public NibbleArray getSkyLightArray() {
|
||||
return this.skyLightArray;
|
||||
}
|
||||
public NibbleArray getSkyLightArray() {
|
||||
return this.skyLightArray;
|
||||
}
|
||||
}
|
||||
+24
-24
@@ -23,33 +23,33 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
public enum EntityDataTypes1_7_6_10 implements EntityDataType {
|
||||
BYTE(0, Types.BYTE),
|
||||
SHORT(1, Types.SHORT),
|
||||
INT(2, Types.INT),
|
||||
FLOAT(3, Types.FLOAT),
|
||||
STRING(4, Types.STRING),
|
||||
ITEM(5, RewindTypes.COMPRESSED_NBT_ITEM),
|
||||
POSITION(6, Types.VECTOR);
|
||||
BYTE(0, Types.BYTE),
|
||||
SHORT(1, Types.SHORT),
|
||||
INT(2, Types.INT),
|
||||
FLOAT(3, Types.FLOAT),
|
||||
STRING(4, Types.STRING),
|
||||
ITEM(5, RewindTypes.COMPRESSED_NBT_ITEM),
|
||||
POSITION(6, Types.VECTOR);
|
||||
|
||||
private final int typeID;
|
||||
private final Type<?> type;
|
||||
private final int typeID;
|
||||
private final Type<?> type;
|
||||
|
||||
EntityDataTypes1_7_6_10(int typeID, Type<?> type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
EntityDataTypes1_7_6_10(int typeID, Type<?> type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static EntityDataTypes1_7_6_10 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
public static EntityDataTypes1_7_6_10 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return this.typeID;
|
||||
}
|
||||
@Override
|
||||
public int typeId() {
|
||||
return this.typeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<?> type() {
|
||||
return this.type;
|
||||
}
|
||||
@Override
|
||||
public Type<?> type() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,19 @@
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class AABB {
|
||||
Vector3d min;
|
||||
Vector3d max;
|
||||
Vector3d min;
|
||||
Vector3d max;
|
||||
|
||||
public AABB(Vector3d min, Vector3d max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
public AABB(Vector3d min, Vector3d max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Vector3d getMin() {
|
||||
return this.min;
|
||||
}
|
||||
public Vector3d getMin() {
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public Vector3d getMax() {
|
||||
return this.max;
|
||||
}
|
||||
public Vector3d getMax() {
|
||||
return this.max;
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,19 @@
|
||||
package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class Ray3d {
|
||||
Vector3d start;
|
||||
Vector3d dir;
|
||||
Vector3d start;
|
||||
Vector3d dir;
|
||||
|
||||
public Ray3d(Vector3d start, Vector3d dir) {
|
||||
this.start = start;
|
||||
this.dir = dir;
|
||||
}
|
||||
public Ray3d(Vector3d start, Vector3d dir) {
|
||||
this.start = start;
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public Vector3d getStart() {
|
||||
return this.start;
|
||||
}
|
||||
public Vector3d getStart() {
|
||||
return this.start;
|
||||
}
|
||||
|
||||
public Vector3d getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
public Vector3d getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
}
|
||||
@@ -19,40 +19,40 @@ package com.viaversion.viarewind.api.minecraft.math;
|
||||
|
||||
public class RayTracing {
|
||||
|
||||
public static Vector3d trace(Ray3d ray, AABB aabb, double distance) {
|
||||
Vector3d invDir = new Vector3d(1f / ray.dir.x, 1f / ray.dir.y, 1f / ray.dir.z);
|
||||
public static Vector3d trace(Ray3d ray, AABB aabb, double distance) {
|
||||
Vector3d invDir = new Vector3d(1f / ray.dir.x, 1f / ray.dir.y, 1f / ray.dir.z);
|
||||
|
||||
boolean signDirX = invDir.x < 0;
|
||||
boolean signDirY = invDir.y < 0;
|
||||
boolean signDirZ = invDir.z < 0;
|
||||
boolean signDirX = invDir.x < 0;
|
||||
boolean signDirY = invDir.y < 0;
|
||||
boolean signDirZ = invDir.z < 0;
|
||||
|
||||
Vector3d bbox = signDirX ? aabb.max : aabb.min;
|
||||
double tmin = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirX ? aabb.min : aabb.max;
|
||||
double tmax = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirY ? aabb.max : aabb.min;
|
||||
double tymin = (bbox.y - ray.start.y) * invDir.y;
|
||||
bbox = signDirY ? aabb.min : aabb.max;
|
||||
double tymax = (bbox.y - ray.start.y) * invDir.y;
|
||||
Vector3d bbox = signDirX ? aabb.max : aabb.min;
|
||||
double tmin = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirX ? aabb.min : aabb.max;
|
||||
double tmax = (bbox.x - ray.start.x) * invDir.x;
|
||||
bbox = signDirY ? aabb.max : aabb.min;
|
||||
double tymin = (bbox.y - ray.start.y) * invDir.y;
|
||||
bbox = signDirY ? aabb.min : aabb.max;
|
||||
double tymax = (bbox.y - ray.start.y) * invDir.y;
|
||||
|
||||
if (tmin > tymax || tymin > tmax) return null;
|
||||
if (tmin > tymax || tymin > tmax) return null;
|
||||
|
||||
if (tymin > tmin) tmin = tymin;
|
||||
if (tymin > tmin) tmin = tymin;
|
||||
|
||||
if (tymax < tmax) tmax = tymax;
|
||||
if (tymax < tmax) tmax = tymax;
|
||||
|
||||
bbox = signDirZ ? aabb.max : aabb.min;
|
||||
double tzmin = (bbox.z - ray.start.z) * invDir.z;
|
||||
bbox = signDirZ ? aabb.min : aabb.max;
|
||||
double tzmax = (bbox.z - ray.start.z) * invDir.z;
|
||||
bbox = signDirZ ? aabb.max : aabb.min;
|
||||
double tzmin = (bbox.z - ray.start.z) * invDir.z;
|
||||
bbox = signDirZ ? aabb.min : aabb.max;
|
||||
double tzmax = (bbox.z - ray.start.z) * invDir.z;
|
||||
|
||||
if (tmin > tzmax || tzmin > tmax) return null;
|
||||
if (tmin > tzmax || tzmin > tmax) return null;
|
||||
|
||||
if (tzmin > tmin) tmin = tzmin;
|
||||
if (tzmin > tmin) tmin = tzmin;
|
||||
|
||||
if (tzmax < tmax) tmax = tzmax;
|
||||
if (tzmax < tmax) tmax = tzmax;
|
||||
|
||||
return tmin <= distance && tmax > 0 ? ray.start.clone().add(ray.dir.clone().normalize().multiply(tmin)) : null;
|
||||
}
|
||||
return tmin <= distance && tmax > 0 ? ray.start.clone().add(ray.dir.clone().normalize().multiply(tmin)) : null;
|
||||
}
|
||||
|
||||
}
|
||||
+63
-63
@@ -25,79 +25,79 @@ import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
@Deprecated // ?????????
|
||||
public class RelativeMoveUtil {
|
||||
|
||||
public static Vector[] calculateRelativeMoves(UserConnection user, int entityId, int relX, int relY, int relZ) {
|
||||
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
|
||||
public static Vector[] calculateRelativeMoves(UserConnection user, int entityId, int relX, int relY, int relZ) {
|
||||
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Vector offset = tracker.getEntityOffset(entityId);
|
||||
if (offset != null) {
|
||||
relX += offset.blockX();
|
||||
relY += offset.blockY();
|
||||
relZ += offset.blockZ();
|
||||
}
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Vector offset = tracker.getEntityOffset(entityId);
|
||||
if (offset != null) {
|
||||
relX += offset.blockX();
|
||||
relY += offset.blockY();
|
||||
relZ += offset.blockZ();
|
||||
}
|
||||
|
||||
if (relX > Short.MAX_VALUE) {
|
||||
x = relX - Short.MAX_VALUE;
|
||||
relX = Short.MAX_VALUE;
|
||||
} else if (relX < Short.MIN_VALUE) {
|
||||
x = relX - Short.MIN_VALUE;
|
||||
relX = Short.MIN_VALUE;
|
||||
} else {
|
||||
x = 0;
|
||||
}
|
||||
if (relX > Short.MAX_VALUE) {
|
||||
x = relX - Short.MAX_VALUE;
|
||||
relX = Short.MAX_VALUE;
|
||||
} else if (relX < Short.MIN_VALUE) {
|
||||
x = relX - Short.MIN_VALUE;
|
||||
relX = Short.MIN_VALUE;
|
||||
} else {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (relY > Short.MAX_VALUE) {
|
||||
y = relY - Short.MAX_VALUE;
|
||||
relY = Short.MAX_VALUE;
|
||||
} else if (relY < Short.MIN_VALUE) {
|
||||
y = relY - Short.MIN_VALUE;
|
||||
relY = Short.MIN_VALUE;
|
||||
} else {
|
||||
y = 0;
|
||||
}
|
||||
if (relY > Short.MAX_VALUE) {
|
||||
y = relY - Short.MAX_VALUE;
|
||||
relY = Short.MAX_VALUE;
|
||||
} else if (relY < Short.MIN_VALUE) {
|
||||
y = relY - Short.MIN_VALUE;
|
||||
relY = Short.MIN_VALUE;
|
||||
} else {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (relZ > Short.MAX_VALUE) {
|
||||
z = relZ - Short.MAX_VALUE;
|
||||
relZ = Short.MAX_VALUE;
|
||||
} else if (relZ < Short.MIN_VALUE) {
|
||||
z = relZ - Short.MIN_VALUE;
|
||||
relZ = Short.MIN_VALUE;
|
||||
} else {
|
||||
z = 0;
|
||||
}
|
||||
if (relZ > Short.MAX_VALUE) {
|
||||
z = relZ - Short.MAX_VALUE;
|
||||
relZ = Short.MAX_VALUE;
|
||||
} else if (relZ < Short.MIN_VALUE) {
|
||||
z = relZ - Short.MIN_VALUE;
|
||||
relZ = Short.MIN_VALUE;
|
||||
} else {
|
||||
z = 0;
|
||||
}
|
||||
|
||||
int sentRelX, sentRelY, sentRelZ;
|
||||
Vector[] moves;
|
||||
int sentRelX, sentRelY, sentRelZ;
|
||||
Vector[] moves;
|
||||
|
||||
if (relX > Byte.MAX_VALUE * 128 || relX < Byte.MIN_VALUE * 128 || relY > Byte.MAX_VALUE * 128 || relY < Byte.MIN_VALUE * 128 || relZ > Byte.MAX_VALUE * 128 || relZ < Byte.MIN_VALUE * 128) {
|
||||
byte relX1 = (byte) (relX / 256);
|
||||
byte relX2 = (byte) (Math.round((relX - relX1 * 128) / 128f));
|
||||
byte relY1 = (byte) (relY / 256);
|
||||
byte relY2 = (byte) (Math.round((relY - relY1 * 128) / 128f));
|
||||
byte relZ1 = (byte) (relZ / 256);
|
||||
byte relZ2 = (byte) (Math.round((relZ - relZ1 * 128) / 128f));
|
||||
if (relX > Byte.MAX_VALUE * 128 || relX < Byte.MIN_VALUE * 128 || relY > Byte.MAX_VALUE * 128 || relY < Byte.MIN_VALUE * 128 || relZ > Byte.MAX_VALUE * 128 || relZ < Byte.MIN_VALUE * 128) {
|
||||
byte relX1 = (byte) (relX / 256);
|
||||
byte relX2 = (byte) (Math.round((relX - relX1 * 128) / 128f));
|
||||
byte relY1 = (byte) (relY / 256);
|
||||
byte relY2 = (byte) (Math.round((relY - relY1 * 128) / 128f));
|
||||
byte relZ1 = (byte) (relZ / 256);
|
||||
byte relZ2 = (byte) (Math.round((relZ - relZ1 * 128) / 128f));
|
||||
|
||||
sentRelX = relX1 + relX2;
|
||||
sentRelY = relY1 + relY2;
|
||||
sentRelZ = relZ1 + relZ2;
|
||||
sentRelX = relX1 + relX2;
|
||||
sentRelY = relY1 + relY2;
|
||||
sentRelZ = relZ1 + relZ2;
|
||||
|
||||
moves = new Vector[]{new Vector(relX1, relY1, relZ1), new Vector(relX2, relY2, relZ2)};
|
||||
} else {
|
||||
sentRelX = Math.round(relX / 128f);
|
||||
sentRelY = Math.round(relY / 128f);
|
||||
sentRelZ = Math.round(relZ / 128f);
|
||||
moves = new Vector[]{new Vector(relX1, relY1, relZ1), new Vector(relX2, relY2, relZ2)};
|
||||
} else {
|
||||
sentRelX = Math.round(relX / 128f);
|
||||
sentRelY = Math.round(relY / 128f);
|
||||
sentRelZ = Math.round(relZ / 128f);
|
||||
|
||||
moves = new Vector[]{new Vector(sentRelX, sentRelY, sentRelZ)};
|
||||
}
|
||||
moves = new Vector[]{new Vector(sentRelX, sentRelY, sentRelZ)};
|
||||
}
|
||||
|
||||
x = x + relX - sentRelX * 128;
|
||||
y = y + relY - sentRelY * 128;
|
||||
z = z + relZ - sentRelZ * 128;
|
||||
x = x + relX - sentRelX * 128;
|
||||
y = y + relY - sentRelY * 128;
|
||||
z = z + relZ - sentRelZ * 128;
|
||||
|
||||
tracker.setEntityOffset(entityId, new Vector(x, y, z));
|
||||
tracker.setEntityOffset(entityId, new Vector(x, y, z));
|
||||
|
||||
return moves;
|
||||
}
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
@@ -20,109 +20,109 @@ package com.viaversion.viarewind.api.minecraft.math;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Vector3d {
|
||||
double x, y, z;
|
||||
double x, y, z;
|
||||
|
||||
public Vector3d(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public Vector3d(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3d() {
|
||||
}
|
||||
public Vector3d() {
|
||||
}
|
||||
|
||||
public void set(Vector3d vec) {
|
||||
this.x = vec.x;
|
||||
this.y = vec.y;
|
||||
this.z = vec.z;
|
||||
}
|
||||
public void set(Vector3d vec) {
|
||||
this.x = vec.x;
|
||||
this.y = vec.y;
|
||||
this.z = vec.z;
|
||||
}
|
||||
|
||||
public Vector3d set(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
public Vector3d set(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d multiply(double a) {
|
||||
this.x *= a;
|
||||
this.y *= a;
|
||||
this.z *= a;
|
||||
return this;
|
||||
}
|
||||
public Vector3d multiply(double a) {
|
||||
this.x *= a;
|
||||
this.y *= a;
|
||||
this.z *= a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d add(Vector3d vec) {
|
||||
this.x += vec.x;
|
||||
this.y += vec.y;
|
||||
this.z += vec.z;
|
||||
return this;
|
||||
}
|
||||
public Vector3d add(Vector3d vec) {
|
||||
this.x += vec.x;
|
||||
this.y += vec.y;
|
||||
this.z += vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3d substract(Vector3d vec) {
|
||||
this.x -= vec.x;
|
||||
this.y -= vec.y;
|
||||
this.z -= vec.z;
|
||||
return this;
|
||||
}
|
||||
public Vector3d substract(Vector3d vec) {
|
||||
this.x -= vec.x;
|
||||
this.y -= vec.y;
|
||||
this.z -= vec.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
public double lengthSquared() {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
public double lengthSquared() {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
public Vector3d normalize() {
|
||||
double length = length();
|
||||
multiply(1.0 / length);
|
||||
return this;
|
||||
}
|
||||
public Vector3d normalize() {
|
||||
double length = length();
|
||||
multiply(1.0 / length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3d clone() {
|
||||
return new Vector3d(this.x, this.y, this.z);
|
||||
}
|
||||
@Override
|
||||
public Vector3d clone() {
|
||||
return new Vector3d(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Vector3d vector3d = (Vector3d) o;
|
||||
return Double.compare(vector3d.x, x) == 0 && Double.compare(vector3d.y, y) == 0 && Double.compare(vector3d.z, z) == 0;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Vector3d vector3d = (Vector3d) o;
|
||||
return Double.compare(vector3d.x, x) == 0 && Double.compare(vector3d.y, y) == 0 && Double.compare(vector3d.z, z) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector3d{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector3d{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -23,8 +23,8 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
public class ForwardMessageToByteEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
|
||||
out.writeBytes(msg);
|
||||
}
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
|
||||
out.writeBytes(msg);
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -26,17 +26,17 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
public class VRBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType, T extends BackwardsProtocol<C, ?, ?, S>> extends LegacyBlockItemRewriter<C, S, T> {
|
||||
|
||||
protected VRBlockItemRewriter(T protocol, String name) {
|
||||
super(protocol, name);
|
||||
}
|
||||
protected VRBlockItemRewriter(T protocol, String name) {
|
||||
super(protocol, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObject readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadFromDataDir(name);
|
||||
}
|
||||
@Override
|
||||
protected JsonObject readMappingsFile(String name) {
|
||||
return RewindMappingDataLoader.INSTANCE.loadFromDataDir(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nbtTagName() {
|
||||
return "VR|" + protocol.getClass().getSimpleName();
|
||||
}
|
||||
@Override
|
||||
public String nbtTagName() {
|
||||
return "VR|" + protocol.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
@@ -31,36 +31,36 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
|
||||
public abstract class VREntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends LegacyEntityRewriter<C, T> {
|
||||
|
||||
public VREntityRewriter(T protocol) {
|
||||
super(protocol, EntityDataTypes1_8.STRING, EntityDataTypes1_8.BYTE);
|
||||
}
|
||||
public VREntityRewriter(T protocol) {
|
||||
super(protocol, EntityDataTypes1_8.STRING, EntityDataTypes1_8.BYTE);
|
||||
}
|
||||
|
||||
public VREntityRewriter(T protocol, EntityDataType displayType, EntityDataType displayVisibilityType) {
|
||||
super(protocol, displayType, displayVisibilityType);
|
||||
}
|
||||
public VREntityRewriter(T protocol, EntityDataType displayType, EntityDataType displayVisibilityType) {
|
||||
super(protocol, displayType, displayVisibilityType);
|
||||
}
|
||||
|
||||
protected void removeEntities(final UserConnection connection, final int[] entities) {
|
||||
final EntityTrackerBase tracker = tracker(connection);
|
||||
for (int entityId : entities) {
|
||||
tracker.removeEntity(entityId);
|
||||
}
|
||||
}
|
||||
protected void removeEntities(final UserConnection connection, final int[] entities) {
|
||||
final EntityTrackerBase tracker = tracker(connection);
|
||||
for (int entityId : entities) {
|
||||
tracker.removeEntity(entityId);
|
||||
}
|
||||
}
|
||||
|
||||
protected PacketHandler getDimensionHandler() {
|
||||
return wrapper -> {
|
||||
final int dimension = wrapper.get(Types.BYTE, 0);
|
||||
final ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||
clientWorld.setEnvironment(dimension);
|
||||
};
|
||||
}
|
||||
protected PacketHandler getDimensionHandler() {
|
||||
return wrapper -> {
|
||||
final int dimension = wrapper.get(Types.BYTE, 0);
|
||||
final ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||
clientWorld.setEnvironment(dimension);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getDisplayVisibilityDataValue() {
|
||||
return (byte) 1;
|
||||
}
|
||||
@Override
|
||||
protected Object getDisplayVisibilityDataValue() {
|
||||
return (byte) 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean alwaysShowOriginalMobName() {
|
||||
return ViaRewind.getConfig().alwaysShowOriginalMobName();
|
||||
}
|
||||
@Override
|
||||
protected boolean alwaysShowOriginalMobName() {
|
||||
return ViaRewind.getConfig().alwaysShowOriginalMobName();
|
||||
}
|
||||
}
|
||||
@@ -22,23 +22,23 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class IntArrayType extends Type<int[]> {
|
||||
|
||||
public IntArrayType() {
|
||||
super(int[].class);
|
||||
}
|
||||
public IntArrayType() {
|
||||
super(int[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] read(ByteBuf byteBuf) {
|
||||
byte size = byteBuf.readByte();
|
||||
int[] array = new int[size];
|
||||
for (byte i = 0; i < size; i++) {
|
||||
array[i] = byteBuf.readInt();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@Override
|
||||
public int[] read(ByteBuf byteBuf) {
|
||||
byte size = byteBuf.readByte();
|
||||
int[] array = new int[size];
|
||||
for (byte i = 0; i < size; i++) {
|
||||
array[i] = byteBuf.readInt();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, int[] array) {
|
||||
byteBuf.writeByte(array.length);
|
||||
for (int i : array) byteBuf.writeInt(i);
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, int[] array) {
|
||||
byteBuf.writeByte(array.length);
|
||||
for (int i : array) byteBuf.writeInt(i);
|
||||
}
|
||||
}
|
||||
@@ -20,34 +20,33 @@ package com.viaversion.viarewind.api.type;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
public class PositionVarYType<T extends Number> extends Type<BlockPosition> {
|
||||
|
||||
private final Type<T> yType;
|
||||
private final IntFunction<T> toY;
|
||||
private final Type<T> yType;
|
||||
private final IntFunction<T> toY;
|
||||
|
||||
public PositionVarYType(final Type<T> yType, final IntFunction<T> toY) {
|
||||
super(BlockPosition.class);
|
||||
public PositionVarYType(final Type<T> yType, final IntFunction<T> toY) {
|
||||
super(BlockPosition.class);
|
||||
|
||||
this.yType = yType;
|
||||
this.toY = toY;
|
||||
}
|
||||
this.yType = yType;
|
||||
this.toY = toY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosition read(ByteBuf buffer) {
|
||||
final int x = buffer.readInt();
|
||||
final int y = yType.read(buffer).intValue();
|
||||
final int z = buffer.readInt();
|
||||
@Override
|
||||
public BlockPosition read(ByteBuf buffer) {
|
||||
final int x = buffer.readInt();
|
||||
final int y = yType.read(buffer).intValue();
|
||||
final int z = buffer.readInt();
|
||||
|
||||
return new BlockPosition(x, y, z);
|
||||
}
|
||||
return new BlockPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, BlockPosition value) {
|
||||
buffer.writeInt(value.x());
|
||||
yType.write(buffer, this.toY.apply(value.y()));
|
||||
buffer.writeInt(value.z());
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, BlockPosition value) {
|
||||
buffer.writeInt(value.x());
|
||||
yType.write(buffer, this.toY.apply(value.y()));
|
||||
buffer.writeInt(value.z());
|
||||
}
|
||||
}
|
||||
@@ -17,19 +17,18 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type;
|
||||
|
||||
import com.viaversion.viarewind.api.type.item.NBTType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemArrayType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemType;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viarewind.api.type.entitydata.EntityDataListType;
|
||||
import com.viaversion.viarewind.api.type.entitydata.EntityDataType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemArrayType;
|
||||
import com.viaversion.viarewind.api.type.item.ItemType;
|
||||
import com.viaversion.viarewind.api.type.item.NBTType;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.type.types.StringType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -38,16 +37,16 @@ import java.util.List;
|
||||
public class RewindTypes {
|
||||
|
||||
public static final Type<String> SIGN_STRING = new StringType(384);
|
||||
public static final Type<int[]> INT_ARRAY = new IntArrayType(); // Integer array with byte as length indicator
|
||||
public static final Type<int[]> INT_ARRAY = new IntArrayType(); // Integer array with byte as length indicator
|
||||
|
||||
public static final Type<BlockPosition> SHORT_POSITION = new PositionVarYType<>(Types.SHORT, value -> (short) value);
|
||||
public static final Type<BlockPosition> INT_POSITION = new PositionVarYType<>(Types.INT, value -> value);
|
||||
public static final Type<BlockPosition> BYTE_POSITION = new PositionVarYType<>(Types.BYTE, value -> (byte) value);
|
||||
public static final Type<BlockPosition> U_BYTE_POSITION = new PositionVarYType<>(Types.UNSIGNED_BYTE, value -> (short) value);
|
||||
public static final Type<BlockPosition> SHORT_POSITION = new PositionVarYType<>(Types.SHORT, value -> (short) value);
|
||||
public static final Type<BlockPosition> INT_POSITION = new PositionVarYType<>(Types.INT, value -> value);
|
||||
public static final Type<BlockPosition> BYTE_POSITION = new PositionVarYType<>(Types.BYTE, value -> (byte) value);
|
||||
public static final Type<BlockPosition> U_BYTE_POSITION = new PositionVarYType<>(Types.UNSIGNED_BYTE, value -> (short) value);
|
||||
|
||||
public static final Type<CompoundTag> COMPRESSED_NBT = new NBTType();
|
||||
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType();
|
||||
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType();
|
||||
public static final Type<CompoundTag> COMPRESSED_NBT = new NBTType();
|
||||
public static final Type<Item> COMPRESSED_NBT_ITEM = new ItemType();
|
||||
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
public static final Type<EntityData> ENTITY_DATA1_7 = new EntityDataType();
|
||||
public static final Type<List<EntityData>> ENTITY_DATA_LIST1_7 = new EntityDataListType(ENTITY_DATA1_7);
|
||||
|
||||
+59
-60
@@ -22,49 +22,48 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
public class BulkChunkType1_7_6 extends Type<Chunk[]> {
|
||||
|
||||
public static final BulkChunkType1_7_6 TYPE = new BulkChunkType1_7_6();
|
||||
public static final BulkChunkType1_7_6 TYPE = new BulkChunkType1_7_6();
|
||||
|
||||
public BulkChunkType1_7_6() {
|
||||
super(Chunk[].class);
|
||||
}
|
||||
public BulkChunkType1_7_6() {
|
||||
super(Chunk[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk[] read(ByteBuf byteBuf) {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulk1_7_6Type.java
|
||||
}
|
||||
@Override
|
||||
public Chunk[] read(ByteBuf byteBuf) {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulk1_7_6Type.java
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, Chunk[] chunks) {
|
||||
final int chunkCount = chunks.length;
|
||||
final int[] chunkX = new int[chunkCount];
|
||||
final int[] chunkZ = new int[chunkCount];
|
||||
final short[] primaryBitMask = new short[chunkCount];
|
||||
final short[] additionalBitMask = new short[chunkCount];
|
||||
@Override
|
||||
public void write(ByteBuf byteBuf, Chunk[] chunks) {
|
||||
final int chunkCount = chunks.length;
|
||||
final int[] chunkX = new int[chunkCount];
|
||||
final int[] chunkZ = new int[chunkCount];
|
||||
final short[] primaryBitMask = new short[chunkCount];
|
||||
final short[] additionalBitMask = new short[chunkCount];
|
||||
|
||||
final byte[][] dataArrays = new byte[chunkCount][];
|
||||
int dataSize = 0;
|
||||
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
final Chunk chunk = chunks[i];
|
||||
Pair<byte[], Short> chunkData;
|
||||
try {
|
||||
chunkData = ChunkType1_7_6.serialize(chunk);
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
final Chunk chunk = chunks[i];
|
||||
Pair<byte[], Short> chunkData;
|
||||
try {
|
||||
chunkData = ChunkType1_7_6.serialize(chunk);
|
||||
final byte[] data = chunkData.key();
|
||||
dataArrays[i] = data;
|
||||
dataSize += data.length;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to serialize chunk", e);
|
||||
}
|
||||
chunkX[i] = chunk.getX();
|
||||
chunkZ[i] = chunk.getZ();
|
||||
primaryBitMask[i] = (short) chunk.getBitmask();
|
||||
additionalBitMask[i] = chunkData.value();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to serialize chunk", e);
|
||||
}
|
||||
chunkX[i] = chunk.getX();
|
||||
chunkZ[i] = chunk.getZ();
|
||||
primaryBitMask[i] = (short) chunk.getBitmask();
|
||||
additionalBitMask[i] = chunkData.value();
|
||||
}
|
||||
|
||||
final byte[] data = new byte[dataSize];
|
||||
int destPos = 0;
|
||||
@@ -73,39 +72,39 @@ public class BulkChunkType1_7_6 extends Type<Chunk[]> {
|
||||
destPos += array.length;
|
||||
}
|
||||
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
|
||||
byteBuf.writeShort(chunkCount);
|
||||
byteBuf.writeInt(compressedSize);
|
||||
byteBuf.writeShort(chunkCount);
|
||||
byteBuf.writeInt(compressedSize);
|
||||
|
||||
boolean skyLight = false;
|
||||
for (Chunk chunk : chunks) {
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section != null && section.getLight().hasSkyLight()) {
|
||||
skyLight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean skyLight = false;
|
||||
for (Chunk chunk : chunks) {
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section != null && section.getLight().hasSkyLight()) {
|
||||
skyLight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
byteBuf.writeBoolean(skyLight); // hasSkyLight
|
||||
byteBuf.writeBytes(compressedData, 0, compressedSize);
|
||||
byteBuf.writeBoolean(skyLight); // hasSkyLight
|
||||
byteBuf.writeBytes(compressedData, 0, compressedSize);
|
||||
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
byteBuf.writeInt(chunkX[i]);
|
||||
byteBuf.writeInt(chunkZ[i]);
|
||||
byteBuf.writeShort(primaryBitMask[i]);
|
||||
byteBuf.writeShort(additionalBitMask[i]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < chunkCount; i++) {
|
||||
byteBuf.writeInt(chunkX[i]);
|
||||
byteBuf.writeInt(chunkZ[i]);
|
||||
byteBuf.writeShort(primaryBitMask[i]);
|
||||
byteBuf.writeShort(additionalBitMask[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,12 @@
|
||||
package com.viaversion.viarewind.api.type.chunk;
|
||||
|
||||
import com.viaversion.viarewind.api.minecraft.ExtendedBlockStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.*;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
@@ -31,127 +32,90 @@ import static com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight.L
|
||||
|
||||
public class ChunkType1_7_6 extends Type<Chunk> {
|
||||
|
||||
public static final ChunkType1_7_6 TYPE = new ChunkType1_7_6();
|
||||
public static final ChunkType1_7_6 TYPE = new ChunkType1_7_6();
|
||||
|
||||
public ChunkType1_7_6() {
|
||||
super(Chunk.class);
|
||||
}
|
||||
public ChunkType1_7_6() {
|
||||
super(Chunk.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk read(ByteBuf byteBuf) {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Chunk1_7_6Type.java
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf output, Chunk chunk) {
|
||||
Pair<byte[], Short> chunkData;
|
||||
try {
|
||||
chunkData = serialize(chunk);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to serialize chunk", e);
|
||||
}
|
||||
final byte[] data = chunkData.key();
|
||||
final short additionalBitMask = chunkData.value();
|
||||
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
|
||||
output.writeInt(chunk.getX());
|
||||
output.writeInt(chunk.getZ());
|
||||
output.writeBoolean(chunk.isFullChunk());
|
||||
output.writeShort(chunk.getBitmask());
|
||||
output.writeShort(additionalBitMask);
|
||||
output.writeInt(compressedSize);
|
||||
output.writeBytes(compressedData, 0, compressedSize);
|
||||
}
|
||||
|
||||
public static Pair<byte[], Short> serialize(final Chunk chunk) throws IOException {
|
||||
final ExtendedBlockStorage[] storageArrays = new ExtendedBlockStorage[16];
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
final ChunkSection section = chunk.getSections()[i];
|
||||
if (section != null) {
|
||||
final ExtendedBlockStorage storage = storageArrays[i] = new ExtendedBlockStorage(section.getLight().hasSkyLight());
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
final int flatBlock = section.palette(PaletteType.BLOCKS).idAt(x, y, z);
|
||||
storage.setBlockId(x, y, z, flatBlock >> 4);
|
||||
storage.setBlockMetadata(x, y, z, flatBlock & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
storage.getBlockLightArray().setHandle(section.getLight().getBlockLight());
|
||||
if (section.getLight().hasSkyLight()) {
|
||||
storage.getSkyLightArray().setHandle(section.getLight().getSkyLight());
|
||||
}
|
||||
}
|
||||
}
|
||||
public static Pair<byte[], Short> serialize(final Chunk chunk) throws IOException {
|
||||
final ExtendedBlockStorage[] storageArrays = new ExtendedBlockStorage[16];
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
final ChunkSection section = chunk.getSections()[i];
|
||||
if (section != null) {
|
||||
final ExtendedBlockStorage storage = storageArrays[i] = new ExtendedBlockStorage(section.getLight().hasSkyLight());
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
final int flatBlock = section.palette(PaletteType.BLOCKS).idAt(x, y, z);
|
||||
storage.setBlockId(x, y, z, flatBlock >> 4);
|
||||
storage.setBlockMetadata(x, y, z, flatBlock & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
storage.getBlockLightArray().setHandle(section.getLight().getBlockLight());
|
||||
if (section.getLight().hasSkyLight()) {
|
||||
storage.getSkyLightArray().setHandle(section.getLight().getSkyLight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final boolean biomes = chunk.isFullChunk() && chunk.getBiomeData() != null;
|
||||
final int totalSize = calculateSize(storageArrays, chunk.getBitmask(), biomes);
|
||||
|
||||
final byte[] output = new byte[totalSize];
|
||||
final byte[] output = new byte[totalSize];
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
final byte[] blockLSBArray = storageArrays[i].getBlockLSBArray();
|
||||
System.arraycopy(blockLSBArray, 0, output, index, blockLSBArray.length);
|
||||
index += blockLSBArray.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
final byte[] blockMetadataArray = storageArrays[i].getBlockMetadataArray().getHandle();
|
||||
System.arraycopy(blockMetadataArray, 0, output, index, blockMetadataArray.length);
|
||||
index += blockMetadataArray.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0) {
|
||||
final byte[] blockLightArray = storageArrays[i].getBlockLightArray().getHandle();
|
||||
System.arraycopy(blockLightArray, 0, output, index, blockLightArray.length);
|
||||
index += blockLightArray.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0 && storageArrays[i].getSkyLightArray() != null) {
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0 && storageArrays[i].getSkyLightArray() != null) {
|
||||
final byte[] skyLightArray = storageArrays[i].getSkyLightArray().getHandle();
|
||||
System.arraycopy(skyLightArray, 0, output, index, skyLightArray.length);
|
||||
index += skyLightArray.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
short additionalBitMask = 0;
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0 && storageArrays[i].hasBlockMSBArray()) {
|
||||
additionalBitMask |= (short) (1 << i);
|
||||
short additionalBitMask = 0;
|
||||
for (int i = 0; i < storageArrays.length; i++) {
|
||||
if ((chunk.getBitmask() & 1 << i) != 0 && storageArrays[i].hasBlockMSBArray()) {
|
||||
additionalBitMask |= (short) (1 << i);
|
||||
final byte[] blockMSBArray = storageArrays[i].getOrCreateBlockMSBArray().getHandle();
|
||||
System.arraycopy(blockMSBArray, 0, output, index, blockMSBArray.length);
|
||||
index += blockMSBArray.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (biomes) {
|
||||
for (int biome : chunk.getBiomeData()) {
|
||||
output[index++] = (byte) biome;
|
||||
}
|
||||
}
|
||||
if (biomes) {
|
||||
for (int biome : chunk.getBiomeData()) {
|
||||
output[index++] = (byte) biome;
|
||||
}
|
||||
}
|
||||
|
||||
return new Pair<>(output, additionalBitMask);
|
||||
}
|
||||
return new Pair<>(output, additionalBitMask);
|
||||
}
|
||||
|
||||
private static int calculateSize(final ExtendedBlockStorage[] storageArrays, final int bitmask, final boolean biomes) {
|
||||
int totalSize = 0;
|
||||
@@ -176,4 +140,41 @@ public class ChunkType1_7_6 extends Type<Chunk> {
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk read(ByteBuf byteBuf) {
|
||||
throw new UnsupportedOperationException(); // Not needed, see https://github.com/ViaVersion/ViaLegacy/blob/main/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Chunk1_7_6Type.java
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf output, Chunk chunk) {
|
||||
Pair<byte[], Short> chunkData;
|
||||
try {
|
||||
chunkData = serialize(chunk);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to serialize chunk", e);
|
||||
}
|
||||
final byte[] data = chunkData.key();
|
||||
final short additionalBitMask = chunkData.value();
|
||||
|
||||
final Deflater deflater = new Deflater();
|
||||
byte[] compressedData;
|
||||
int compressedSize;
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
compressedData = new byte[data.length];
|
||||
compressedSize = deflater.deflate(compressedData);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
|
||||
output.writeInt(chunk.getX());
|
||||
output.writeInt(chunk.getZ());
|
||||
output.writeBoolean(chunk.isFullChunk());
|
||||
output.writeShort(chunk.getBitmask());
|
||||
output.writeShort(additionalBitMask);
|
||||
output.writeInt(compressedSize);
|
||||
output.writeBytes(compressedData, 0, compressedSize);
|
||||
}
|
||||
|
||||
}
|
||||
+27
-28
@@ -22,41 +22,40 @@ import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.entitydata.EntityDataListTypeTemplate;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityDataListType extends EntityDataListTypeTemplate {
|
||||
|
||||
private final Type<EntityData> type;
|
||||
private final Type<EntityData> type;
|
||||
|
||||
public EntityDataListType(Type<EntityData> type) {
|
||||
this.type = type;
|
||||
}
|
||||
public EntityDataListType(Type<EntityData> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityData> read(ByteBuf buffer) {
|
||||
ArrayList<EntityData> entityData = new ArrayList<>();
|
||||
@Override
|
||||
public List<EntityData> read(ByteBuf buffer) {
|
||||
ArrayList<EntityData> entityData = new ArrayList<>();
|
||||
|
||||
EntityData data;
|
||||
do {
|
||||
data = type.read(buffer);
|
||||
if (data != null) {
|
||||
entityData.add(data);
|
||||
}
|
||||
} while (data != null);
|
||||
EntityData data;
|
||||
do {
|
||||
data = type.read(buffer);
|
||||
if (data != null) {
|
||||
entityData.add(data);
|
||||
}
|
||||
} while (data != null);
|
||||
|
||||
return entityData;
|
||||
}
|
||||
return entityData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, List<EntityData> entityData) {
|
||||
for (EntityData meta : entityData) {
|
||||
type.write(buffer, meta);
|
||||
}
|
||||
if (entityData.isEmpty()) {
|
||||
type.write(buffer, new EntityData(0, EntityDataTypes1_7_6_10.BYTE, (byte) 0));
|
||||
}
|
||||
buffer.writeByte(127);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, List<EntityData> entityData) {
|
||||
for (EntityData meta : entityData) {
|
||||
type.write(buffer, meta);
|
||||
}
|
||||
if (entityData.isEmpty()) {
|
||||
type.write(buffer, new EntityData(0, EntityDataTypes1_7_6_10.BYTE, (byte) 0));
|
||||
}
|
||||
buffer.writeByte(127);
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -23,23 +23,23 @@ import com.viaversion.viaversion.api.type.types.entitydata.EntityDataTypeTemplat
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class EntityDataType extends EntityDataTypeTemplate {
|
||||
@Override
|
||||
public EntityData read(ByteBuf buffer) {
|
||||
byte item = buffer.readByte();
|
||||
if (item == 127) {
|
||||
return null;
|
||||
} else {
|
||||
int typeID = (item & 224) >> 5;
|
||||
EntityDataTypes1_7_6_10 type = EntityDataTypes1_7_6_10.byId(typeID);
|
||||
int id = item & 31;
|
||||
return new EntityData(id, type, type.type().read(buffer));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public EntityData read(ByteBuf buffer) {
|
||||
byte item = buffer.readByte();
|
||||
if (item == 127) {
|
||||
return null;
|
||||
} else {
|
||||
int typeID = (item & 224) >> 5;
|
||||
EntityDataTypes1_7_6_10 type = EntityDataTypes1_7_6_10.byId(typeID);
|
||||
int id = item & 31;
|
||||
return new EntityData(id, type, type.type().read(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, EntityData meta) {
|
||||
int item = (meta.dataType().typeId() << 5 | meta.id() & 31) & 255;
|
||||
buffer.writeByte(item);
|
||||
meta.dataType().type().write(buffer, meta.getValue());
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, EntityData meta) {
|
||||
int item = (meta.dataType().typeId() << 5 | meta.id() & 31) & 255;
|
||||
buffer.writeByte(item);
|
||||
meta.dataType().type().write(buffer, meta.getValue());
|
||||
}
|
||||
}
|
||||
@@ -25,26 +25,26 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ItemArrayType extends Type<Item[]> {
|
||||
|
||||
public ItemArrayType() {
|
||||
super(Item[].class);
|
||||
}
|
||||
public ItemArrayType() {
|
||||
super(Item[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item[] read(ByteBuf buffer) {
|
||||
int amount = Types.SHORT.readPrimitive(buffer);
|
||||
Item[] items = new Item[amount];
|
||||
@Override
|
||||
public Item[] read(ByteBuf buffer) {
|
||||
int amount = Types.SHORT.readPrimitive(buffer);
|
||||
Item[] items = new Item[amount];
|
||||
|
||||
for (int i = 0; i < amount; ++i) {
|
||||
items[i] = RewindTypes.COMPRESSED_NBT_ITEM.read(buffer);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
for (int i = 0; i < amount; ++i) {
|
||||
items[i] = RewindTypes.COMPRESSED_NBT_ITEM.read(buffer);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item[] items) {
|
||||
Types.SHORT.writePrimitive(buffer, (short) items.length);
|
||||
for (Item item : items) {
|
||||
RewindTypes.COMPRESSED_NBT_ITEM.write(buffer, item);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item[] items) {
|
||||
Types.SHORT.writePrimitive(buffer, (short) items.length);
|
||||
for (Item item : items) {
|
||||
RewindTypes.COMPRESSED_NBT_ITEM.write(buffer, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,33 +25,33 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ItemType extends Type<Item> {
|
||||
|
||||
public ItemType() {
|
||||
super(Item.class);
|
||||
}
|
||||
public ItemType() {
|
||||
super(Item.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) {
|
||||
short id = buffer.readShort();
|
||||
if (id < 0) {
|
||||
return null;
|
||||
}
|
||||
Item item = new DataItem();
|
||||
item.setIdentifier(id);
|
||||
item.setAmount(buffer.readByte());
|
||||
item.setData(buffer.readShort());
|
||||
item.setTag(RewindTypes.COMPRESSED_NBT.read(buffer));
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) {
|
||||
short id = buffer.readShort();
|
||||
if (id < 0) {
|
||||
return null;
|
||||
}
|
||||
Item item = new DataItem();
|
||||
item.setIdentifier(id);
|
||||
item.setAmount(buffer.readByte());
|
||||
item.setData(buffer.readShort());
|
||||
item.setTag(RewindTypes.COMPRESSED_NBT.read(buffer));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item item) {
|
||||
if (item == null) {
|
||||
buffer.writeShort(-1);
|
||||
} else {
|
||||
buffer.writeShort(item.identifier());
|
||||
buffer.writeByte(item.amount());
|
||||
buffer.writeShort(item.data());
|
||||
RewindTypes.COMPRESSED_NBT.write(buffer, item.tag());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item item) {
|
||||
if (item == null) {
|
||||
buffer.writeShort(-1);
|
||||
} else {
|
||||
buffer.writeShort(item.identifier());
|
||||
buffer.writeByte(item.amount());
|
||||
buffer.writeShort(item.data());
|
||||
RewindTypes.COMPRESSED_NBT.write(buffer, item.tag());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,57 +17,56 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.api.type.item;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.io.NBTIO;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class NBTType extends Type<CompoundTag> {
|
||||
public NBTType() {
|
||||
super(CompoundTag.class);
|
||||
}
|
||||
public NBTType() {
|
||||
super(CompoundTag.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag read(ByteBuf buffer) {
|
||||
short length = buffer.readShort();
|
||||
if (length <= 0) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public CompoundTag read(ByteBuf buffer) {
|
||||
short length = buffer.readShort();
|
||||
if (length <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteBuf compressed = buffer.readSlice(length);
|
||||
ByteBuf compressed = buffer.readSlice(length);
|
||||
|
||||
try (GZIPInputStream gzipStream = new GZIPInputStream(new ByteBufInputStream(compressed))) {
|
||||
return NBTIO.reader(CompoundTag.class).named().read(gzipStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
try (GZIPInputStream gzipStream = new GZIPInputStream(new ByteBufInputStream(compressed))) {
|
||||
return NBTIO.reader(CompoundTag.class).named().read(gzipStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, CompoundTag nbt) {
|
||||
if (nbt == null) {
|
||||
buffer.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void write(ByteBuf buffer, CompoundTag nbt) {
|
||||
if (nbt == null) {
|
||||
buffer.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuf compressedBuf = buffer.alloc().buffer();
|
||||
try {
|
||||
try (GZIPOutputStream gzipStream = new GZIPOutputStream(new ByteBufOutputStream(compressedBuf))) {
|
||||
NBTIO.writer().named().write(gzipStream, nbt);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ByteBuf compressedBuf = buffer.alloc().buffer();
|
||||
try {
|
||||
try (GZIPOutputStream gzipStream = new GZIPOutputStream(new ByteBufOutputStream(compressedBuf))) {
|
||||
NBTIO.writer().named().write(gzipStream, nbt);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
buffer.writeShort(compressedBuf.readableBytes());
|
||||
buffer.writeBytes(compressedBuf);
|
||||
} finally {
|
||||
compressedBuf.release();
|
||||
}
|
||||
}
|
||||
buffer.writeShort(compressedBuf.readableBytes());
|
||||
buffer.writeBytes(compressedBuf);
|
||||
} finally {
|
||||
compressedBuf.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
+73
-74
@@ -27,90 +27,89 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Protocol1_7_6_10To1_7_2_5 extends AbstractProtocol<ClientboundPackets1_7_2_5, ClientboundPackets1_7_2_5, ServerboundPackets1_7_2_5, ServerboundPackets1_7_2_5> {
|
||||
|
||||
public static final ValueTransformer<String, String> REMOVE_DASHES = new ValueTransformer<>(Types.STRING) {
|
||||
@Override
|
||||
public String transform(PacketWrapper wrapper, String s) {
|
||||
return s.replace("-", "");
|
||||
}
|
||||
};
|
||||
public static final ValueTransformer<String, String> REMOVE_DASHES = new ValueTransformer<>(Types.STRING) {
|
||||
@Override
|
||||
public String transform(PacketWrapper wrapper, String s) {
|
||||
return s.replace("-", "");
|
||||
}
|
||||
};
|
||||
|
||||
public Protocol1_7_6_10To1_7_2_5() {
|
||||
super(ClientboundPackets1_7_2_5.class, ClientboundPackets1_7_2_5.class, ServerboundPackets1_7_2_5.class, ServerboundPackets1_7_2_5.class);
|
||||
}
|
||||
public Protocol1_7_6_10To1_7_2_5() {
|
||||
super(ClientboundPackets1_7_2_5.class, ClientboundPackets1_7_2_5.class, ServerboundPackets1_7_2_5.class, ServerboundPackets1_7_2_5.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING, REMOVE_DASHES); // Uuid
|
||||
map(Types.STRING); // Name
|
||||
}
|
||||
});
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING, REMOVE_DASHES); // Uuid
|
||||
map(Types.STRING); // Name
|
||||
}
|
||||
});
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7_2_5.ADD_PLAYER, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.STRING, REMOVE_DASHES); // Uuid
|
||||
map(Types.STRING); // Name
|
||||
handler(wrapper -> {
|
||||
final int size = wrapper.read(Types.VAR_INT); // Data count
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.read(Types.STRING); // Data name
|
||||
wrapper.read(Types.STRING); // Data value
|
||||
wrapper.read(Types.STRING); // Data signature
|
||||
}
|
||||
});
|
||||
map(Types.INT); // X
|
||||
map(Types.INT); // Y
|
||||
map(Types.INT); // Z
|
||||
map(Types.BYTE); // Yaw
|
||||
map(Types.BYTE); // Pitch
|
||||
map(Types.SHORT); // Item in hand
|
||||
map(RewindTypes.ENTITY_DATA_LIST1_7); // Entity data
|
||||
}
|
||||
});
|
||||
this.registerClientbound(ClientboundPackets1_7_2_5.ADD_PLAYER, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.STRING, REMOVE_DASHES); // Uuid
|
||||
map(Types.STRING); // Name
|
||||
handler(wrapper -> {
|
||||
final int size = wrapper.read(Types.VAR_INT); // Data count
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.read(Types.STRING); // Data name
|
||||
wrapper.read(Types.STRING); // Data value
|
||||
wrapper.read(Types.STRING); // Data signature
|
||||
}
|
||||
});
|
||||
map(Types.INT); // X
|
||||
map(Types.INT); // Y
|
||||
map(Types.INT); // Z
|
||||
map(Types.BYTE); // Yaw
|
||||
map(Types.BYTE); // Pitch
|
||||
map(Types.SHORT); // Item in hand
|
||||
map(RewindTypes.ENTITY_DATA_LIST1_7); // Entity data
|
||||
}
|
||||
});
|
||||
|
||||
this.registerClientbound(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Team name
|
||||
map(Types.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
final byte mode = wrapper.get(Types.BYTE, 0);
|
||||
if (mode == 0 || mode == 2) { // Team is created or information is updated
|
||||
wrapper.passthrough(Types.STRING); // Team display name
|
||||
wrapper.passthrough(Types.STRING); // Team prefix
|
||||
wrapper.passthrough(Types.STRING); // Team suffix
|
||||
wrapper.passthrough(Types.BYTE); // Friendly fire
|
||||
}
|
||||
if (mode == 0 || mode == 3 || mode == 4) { // Team is created, player is added or player is removed
|
||||
List<String> entryList = new ArrayList<>();
|
||||
final int size = wrapper.read(Types.SHORT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
entryList.add(wrapper.read(Types.STRING));
|
||||
}
|
||||
this.registerClientbound(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Team name
|
||||
map(Types.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
final byte mode = wrapper.get(Types.BYTE, 0);
|
||||
if (mode == 0 || mode == 2) { // Team is created or information is updated
|
||||
wrapper.passthrough(Types.STRING); // Team display name
|
||||
wrapper.passthrough(Types.STRING); // Team prefix
|
||||
wrapper.passthrough(Types.STRING); // Team suffix
|
||||
wrapper.passthrough(Types.BYTE); // Friendly fire
|
||||
}
|
||||
if (mode == 0 || mode == 3 || mode == 4) { // Team is created, player is added or player is removed
|
||||
List<String> entryList = new ArrayList<>();
|
||||
final int size = wrapper.read(Types.SHORT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
entryList.add(wrapper.read(Types.STRING));
|
||||
}
|
||||
|
||||
entryList = entryList.stream()
|
||||
.map(it -> it.length() > 16 ? it.substring(0, 16) : it) // trim to 16 characters
|
||||
.distinct() // remove duplicates
|
||||
.collect(Collectors.toList());
|
||||
entryList = entryList.stream()
|
||||
.map(it -> it.length() > 16 ? it.substring(0, 16) : it) // trim to 16 characters
|
||||
.distinct() // remove duplicates
|
||||
.collect(Collectors.toList());
|
||||
|
||||
wrapper.write(Types.SHORT, (short) entryList.size());
|
||||
for (String entry : entryList) {
|
||||
wrapper.write(Types.STRING, entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
wrapper.write(Types.SHORT, (short) entryList.size());
|
||||
for (String entry : entryList) {
|
||||
wrapper.write(Types.STRING, entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+73
-73
@@ -20,79 +20,79 @@ package com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
|
||||
public enum ClientboundPackets1_7_2_5 implements ClientboundPacketType {
|
||||
KEEP_ALIVE, // 0x00
|
||||
LOGIN, // 0x01
|
||||
CHAT, // 0x02
|
||||
SET_TIME, // 0x03
|
||||
SET_EQUIPPED_ITEM, // 0x04
|
||||
SET_DEFAULT_SPAWN_POSITION, // 0x05
|
||||
SET_HEALTH, // 0x06
|
||||
RESPAWN, // 0x07
|
||||
PLAYER_POSITION, // 0x08
|
||||
SET_CARRIED_ITEM, // 0x09
|
||||
PLAYER_SLEEP, // 0x0A
|
||||
ANIMATE, // 0x0B
|
||||
ADD_PLAYER, // 0x0C
|
||||
TAKE_ITEM_ENTITY, // 0x0D
|
||||
ADD_ENTITY, // 0x0E
|
||||
ADD_MOB, // 0x0F
|
||||
ADD_PAINTING, // 0x10
|
||||
ADD_EXPERIENCE_ORB, // 0x11
|
||||
SET_ENTITY_MOTION, // 0x12
|
||||
REMOVE_ENTITIES, // 0x13
|
||||
MOVE_ENTITY, // 0x14
|
||||
MOVE_ENTITY_POS, // 0x15
|
||||
MOVE_ENTITY_ROT, // 0x16
|
||||
MOVE_ENTITY_POS_ROT, // 0x17
|
||||
TELEPORT_ENTITY, // 0x18
|
||||
ROTATE_HEAD, // 0x19
|
||||
ENTITY_EVENT, // 0x1A
|
||||
SET_ENTITY_LINK, // 0x1B
|
||||
SET_ENTITY_DATA, // 0x1C
|
||||
UPDATE_MOB_EFFECT, // 0x1D
|
||||
REMOVE_MOB_EFFECT, // 0x1E
|
||||
SET_EXPERIENCE, // 0x1F
|
||||
UPDATE_ATTRIBUTES, // 0x20
|
||||
LEVEL_CHUNK, // 0x21
|
||||
CHUNK_BLOCKS_UPDATE, // 0x22
|
||||
BLOCK_UPDATE, // 0x23
|
||||
BLOCK_EVENT, // 0x24
|
||||
BLOCK_DESTRUCTION, // 0x25
|
||||
MAP_BULK_CHUNK, // 0x26
|
||||
EXPLODE, // 0x27
|
||||
LEVEL_EVENT, // 0x28
|
||||
CUSTOM_SOUND, // 0x29
|
||||
LEVEL_PARTICLES, // 0x2A
|
||||
GAME_EVENT, // 0x2B
|
||||
ADD_GLOBAL_ENTITY, // 0x2C
|
||||
OPEN_SCREEN, // 0x2D
|
||||
CONTAINER_CLOSE, // 0x2E
|
||||
CONTAINER_SET_SLOT, // 0x2F
|
||||
CONTAINER_SET_CONTENT, // 0x30
|
||||
CONTAINER_SET_DATA, // 0x31
|
||||
CONTAINER_ACK, // 0x32
|
||||
UPDATE_SIGN, // 0x33
|
||||
MAP_ITEM_DATA, // 0x34
|
||||
BLOCK_ENTITY_DATA, // 0x35
|
||||
OPEN_SIGN_EDITOR, // 0x36
|
||||
AWARD_STATS, // 0x37
|
||||
PLAYER_INFO, // 0x38
|
||||
PLAYER_ABILITIES, // 0x39
|
||||
COMMAND_SUGGESTIONS, // 0x3A
|
||||
SET_OBJECTIVE, // 0x3B
|
||||
SET_SCORE, // 0x3C
|
||||
SET_DISPLAY_OBJECTIVE, // 0x3D
|
||||
SET_PLAYER_TEAM, // 0x3E
|
||||
CUSTOM_PAYLOAD, // 0x3F
|
||||
DISCONNECT; // 0x40
|
||||
KEEP_ALIVE, // 0x00
|
||||
LOGIN, // 0x01
|
||||
CHAT, // 0x02
|
||||
SET_TIME, // 0x03
|
||||
SET_EQUIPPED_ITEM, // 0x04
|
||||
SET_DEFAULT_SPAWN_POSITION, // 0x05
|
||||
SET_HEALTH, // 0x06
|
||||
RESPAWN, // 0x07
|
||||
PLAYER_POSITION, // 0x08
|
||||
SET_CARRIED_ITEM, // 0x09
|
||||
PLAYER_SLEEP, // 0x0A
|
||||
ANIMATE, // 0x0B
|
||||
ADD_PLAYER, // 0x0C
|
||||
TAKE_ITEM_ENTITY, // 0x0D
|
||||
ADD_ENTITY, // 0x0E
|
||||
ADD_MOB, // 0x0F
|
||||
ADD_PAINTING, // 0x10
|
||||
ADD_EXPERIENCE_ORB, // 0x11
|
||||
SET_ENTITY_MOTION, // 0x12
|
||||
REMOVE_ENTITIES, // 0x13
|
||||
MOVE_ENTITY, // 0x14
|
||||
MOVE_ENTITY_POS, // 0x15
|
||||
MOVE_ENTITY_ROT, // 0x16
|
||||
MOVE_ENTITY_POS_ROT, // 0x17
|
||||
TELEPORT_ENTITY, // 0x18
|
||||
ROTATE_HEAD, // 0x19
|
||||
ENTITY_EVENT, // 0x1A
|
||||
SET_ENTITY_LINK, // 0x1B
|
||||
SET_ENTITY_DATA, // 0x1C
|
||||
UPDATE_MOB_EFFECT, // 0x1D
|
||||
REMOVE_MOB_EFFECT, // 0x1E
|
||||
SET_EXPERIENCE, // 0x1F
|
||||
UPDATE_ATTRIBUTES, // 0x20
|
||||
LEVEL_CHUNK, // 0x21
|
||||
CHUNK_BLOCKS_UPDATE, // 0x22
|
||||
BLOCK_UPDATE, // 0x23
|
||||
BLOCK_EVENT, // 0x24
|
||||
BLOCK_DESTRUCTION, // 0x25
|
||||
MAP_BULK_CHUNK, // 0x26
|
||||
EXPLODE, // 0x27
|
||||
LEVEL_EVENT, // 0x28
|
||||
CUSTOM_SOUND, // 0x29
|
||||
LEVEL_PARTICLES, // 0x2A
|
||||
GAME_EVENT, // 0x2B
|
||||
ADD_GLOBAL_ENTITY, // 0x2C
|
||||
OPEN_SCREEN, // 0x2D
|
||||
CONTAINER_CLOSE, // 0x2E
|
||||
CONTAINER_SET_SLOT, // 0x2F
|
||||
CONTAINER_SET_CONTENT, // 0x30
|
||||
CONTAINER_SET_DATA, // 0x31
|
||||
CONTAINER_ACK, // 0x32
|
||||
UPDATE_SIGN, // 0x33
|
||||
MAP_ITEM_DATA, // 0x34
|
||||
BLOCK_ENTITY_DATA, // 0x35
|
||||
OPEN_SIGN_EDITOR, // 0x36
|
||||
AWARD_STATS, // 0x37
|
||||
PLAYER_INFO, // 0x38
|
||||
PLAYER_ABILITIES, // 0x39
|
||||
COMMAND_SUGGESTIONS, // 0x3A
|
||||
SET_OBJECTIVE, // 0x3B
|
||||
SET_SCORE, // 0x3C
|
||||
SET_DISPLAY_OBJECTIVE, // 0x3D
|
||||
SET_PLAYER_TEAM, // 0x3E
|
||||
CUSTOM_PAYLOAD, // 0x3F
|
||||
DISCONNECT; // 0x40
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
@Override
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
+32
-32
@@ -20,38 +20,38 @@ package com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
|
||||
public enum ServerboundPackets1_7_2_5 implements ServerboundPacketType {
|
||||
KEEP_ALIVE, // 0x00
|
||||
CHAT, // 0x01
|
||||
INTERACT, // 0x02
|
||||
MOVE_PLAYER_STATUS_ONLY, // 0x03
|
||||
MOVE_PLAYER_POS, // 0x04
|
||||
MOVE_PLAYER_ROT, // 0x05
|
||||
MOVE_PLAYER_POS_ROT, // 0x06
|
||||
PLAYER_ACTION, // 0x07
|
||||
USE_ITEM_ON, // 0x08
|
||||
SET_CARRIED_ITEM, // 0x09
|
||||
SWING, // 0x0A
|
||||
PLAYER_COMMAND, // 0x0B
|
||||
PLAYER_INPUT, // 0x0C
|
||||
CONTAINER_CLOSE, // 0x0D
|
||||
CONTAINER_CLICK, // 0x0E
|
||||
CONTAINER_ACK, // 0x0F
|
||||
SET_CREATIVE_MODE_SLOT, // 0x10
|
||||
CONTAINER_BUTTON_CLICK, // 0x11
|
||||
SIGN_UPDATE, // 0x12
|
||||
PLAYER_ABILITIES, // 0x13
|
||||
COMMAND_SUGGESTION, // 0x14
|
||||
CLIENT_INFORMATION, // 0x15
|
||||
CLIENT_COMMAND, // 0x16
|
||||
CUSTOM_PAYLOAD; // 0x17
|
||||
KEEP_ALIVE, // 0x00
|
||||
CHAT, // 0x01
|
||||
INTERACT, // 0x02
|
||||
MOVE_PLAYER_STATUS_ONLY, // 0x03
|
||||
MOVE_PLAYER_POS, // 0x04
|
||||
MOVE_PLAYER_ROT, // 0x05
|
||||
MOVE_PLAYER_POS_ROT, // 0x06
|
||||
PLAYER_ACTION, // 0x07
|
||||
USE_ITEM_ON, // 0x08
|
||||
SET_CARRIED_ITEM, // 0x09
|
||||
SWING, // 0x0A
|
||||
PLAYER_COMMAND, // 0x0B
|
||||
PLAYER_INPUT, // 0x0C
|
||||
CONTAINER_CLOSE, // 0x0D
|
||||
CONTAINER_CLICK, // 0x0E
|
||||
CONTAINER_ACK, // 0x0F
|
||||
SET_CREATIVE_MODE_SLOT, // 0x10
|
||||
CONTAINER_BUTTON_CLICK, // 0x11
|
||||
SIGN_UPDATE, // 0x12
|
||||
PLAYER_ABILITIES, // 0x13
|
||||
COMMAND_SUGGESTION, // 0x14
|
||||
CLIENT_INFORMATION, // 0x15
|
||||
CLIENT_COMMAND, // 0x16
|
||||
CUSTOM_PAYLOAD; // 0x17
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
@Override
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
+103
-95
@@ -22,11 +22,20 @@ import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.data.RewindMappingData;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet.ClientboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet.ServerboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.EntityPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.*;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.provider.CompressionHandlerProvider;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.provider.compression.TrackingCompressionHandlerProvider;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.*;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.BlockItemPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.EntityPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.PlayerPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.ScoreboardPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter.WorldPacketRewriter1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.CompressionStatusTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.EntityTracker1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.GameProfileStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.InventoryTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.PlayerSessionStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.ScoreboardTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.WorldBorderEmulator;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.task.WorldBorderUpdateTask;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
@@ -42,118 +51,117 @@ import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Protocol1_8To1_7_6_10 extends BackwardsProtocol<ClientboundPackets1_8, ClientboundPackets1_7_2_5, ServerboundPackets1_8, ServerboundPackets1_7_2_5> {
|
||||
|
||||
public static final RewindMappingData MAPPINGS = new RewindMappingData("1.8", "1.7.10");
|
||||
public static final RewindMappingData MAPPINGS = new RewindMappingData("1.8", "1.7.10");
|
||||
|
||||
private final BlockItemPacketRewriter1_8 itemRewriter = new BlockItemPacketRewriter1_8(this);
|
||||
private final EntityPacketRewriter1_8 entityRewriter = new EntityPacketRewriter1_8(this);
|
||||
private final BlockItemPacketRewriter1_8 itemRewriter = new BlockItemPacketRewriter1_8(this);
|
||||
private final EntityPacketRewriter1_8 entityRewriter = new EntityPacketRewriter1_8(this);
|
||||
|
||||
public Protocol1_8To1_7_6_10() {
|
||||
super(ClientboundPackets1_8.class, ClientboundPackets1_7_2_5.class, ServerboundPackets1_8.class, ServerboundPackets1_7_2_5.class);
|
||||
}
|
||||
public Protocol1_8To1_7_6_10() {
|
||||
super(ClientboundPackets1_8.class, ClientboundPackets1_7_2_5.class, ServerboundPackets1_8.class, ServerboundPackets1_7_2_5.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
itemRewriter.register();
|
||||
entityRewriter.register();
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
itemRewriter.register();
|
||||
entityRewriter.register();
|
||||
|
||||
new PlayerPacketRewriter1_8(this).register();
|
||||
new ScoreboardPacketRewriter1_8(this).register();
|
||||
new WorldPacketRewriter1_8(this).register();
|
||||
new PlayerPacketRewriter1_8(this).register();
|
||||
new ScoreboardPacketRewriter1_8(this).register();
|
||||
new WorldPacketRewriter1_8(this).register();
|
||||
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // server hash
|
||||
map(Types.BYTE_ARRAY_PRIMITIVE, Types.SHORT_BYTE_ARRAY); // public key
|
||||
map(Types.BYTE_ARRAY_PRIMITIVE, Types.SHORT_BYTE_ARRAY); // verification token
|
||||
}
|
||||
});
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_COMPRESSION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int threshold = wrapper.read(Types.VAR_INT);
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // server hash
|
||||
map(Types.BYTE_ARRAY_PRIMITIVE, Types.SHORT_BYTE_ARRAY); // public key
|
||||
map(Types.BYTE_ARRAY_PRIMITIVE, Types.SHORT_BYTE_ARRAY); // verification token
|
||||
}
|
||||
});
|
||||
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_COMPRESSION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int threshold = wrapper.read(Types.VAR_INT);
|
||||
|
||||
Via.getManager().getProviders().get(CompressionHandlerProvider.class).onHandleLoginCompressionPacket(wrapper.user(), threshold);
|
||||
wrapper.cancel();
|
||||
});
|
||||
}
|
||||
});
|
||||
this.cancelClientbound(ClientboundPackets1_8.SET_COMPRESSION); // unused
|
||||
this.registerClientbound(ClientboundPackets1_8.KEEP_ALIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT, Types.INT); // id
|
||||
}
|
||||
});
|
||||
Via.getManager().getProviders().get(CompressionHandlerProvider.class).onHandleLoginCompressionPacket(wrapper.user(), threshold);
|
||||
wrapper.cancel();
|
||||
});
|
||||
}
|
||||
});
|
||||
this.cancelClientbound(ClientboundPackets1_8.SET_COMPRESSION); // unused
|
||||
this.registerClientbound(ClientboundPackets1_8.KEEP_ALIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT, Types.INT); // id
|
||||
}
|
||||
});
|
||||
|
||||
this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.SHORT_BYTE_ARRAY, Types.BYTE_ARRAY_PRIMITIVE); // shared secret
|
||||
map(Types.SHORT_BYTE_ARRAY, Types.BYTE_ARRAY_PRIMITIVE); // verification token
|
||||
}
|
||||
});
|
||||
this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.SHORT_BYTE_ARRAY, Types.BYTE_ARRAY_PRIMITIVE); // shared secret
|
||||
map(Types.SHORT_BYTE_ARRAY, Types.BYTE_ARRAY_PRIMITIVE); // verification token
|
||||
}
|
||||
});
|
||||
|
||||
this.registerServerbound(ServerboundPackets1_7_2_5.KEEP_ALIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT, Types.VAR_INT); // id
|
||||
}
|
||||
});
|
||||
}
|
||||
this.registerServerbound(ServerboundPackets1_7_2_5.KEEP_ALIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT, Types.VAR_INT); // id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws CancelException {
|
||||
Via.getManager().getProviders().get(CompressionHandlerProvider.class).onTransformPacket(packetWrapper.user());
|
||||
@Override
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws CancelException {
|
||||
Via.getManager().getProviders().get(CompressionHandlerProvider.class).onTransformPacket(packetWrapper.user());
|
||||
|
||||
super.transform(direction, state, packetWrapper);
|
||||
}
|
||||
super.transform(direction, state, packetWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
connection.addEntityTracker(this.getClass(), new EntityTracker1_8(connection));
|
||||
connection.addClientWorld(this.getClass(), new ClientWorld());
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
connection.addEntityTracker(this.getClass(), new EntityTracker1_8(connection));
|
||||
connection.addClientWorld(this.getClass(), new ClientWorld());
|
||||
|
||||
connection.put(new InventoryTracker(connection));
|
||||
connection.put(new PlayerSessionStorage(connection));
|
||||
connection.put(new GameProfileStorage(connection));
|
||||
connection.put(new ScoreboardTracker(connection));
|
||||
connection.put(new CompressionStatusTracker(connection));
|
||||
connection.put(new WorldBorderEmulator(connection));
|
||||
}
|
||||
connection.put(new InventoryTracker(connection));
|
||||
connection.put(new PlayerSessionStorage(connection));
|
||||
connection.put(new GameProfileStorage(connection));
|
||||
connection.put(new ScoreboardTracker(connection));
|
||||
connection.put(new CompressionStatusTracker(connection));
|
||||
connection.put(new WorldBorderEmulator(connection));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ViaProviders providers) {
|
||||
providers.register(CompressionHandlerProvider.class, new TrackingCompressionHandlerProvider());
|
||||
@Override
|
||||
public void register(ViaProviders providers) {
|
||||
providers.register(CompressionHandlerProvider.class, new TrackingCompressionHandlerProvider());
|
||||
|
||||
if (ViaRewind.getConfig().isEmulateWorldBorder()) {
|
||||
Via.getManager().getScheduler().scheduleRepeating(new WorldBorderUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
if (ViaRewind.getConfig().isEmulateWorldBorder()) {
|
||||
Via.getManager().getScheduler().scheduleRepeating(new WorldBorderUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RewindMappingData getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
@Override
|
||||
public RewindMappingData getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPacketRewriter1_8 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
@Override
|
||||
public BlockItemPacketRewriter1_8 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketRewriter1_8 getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
@Override
|
||||
public EntityPacketRewriter1_8 getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+169
-137
@@ -22,194 +22,226 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.*;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ABSTRACT_AGEABLE;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ABSTRACT_MINECART;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ARMOR_STAND;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ARROW;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.BAT;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.BLAZE;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.BOAT;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.CREEPER;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ENDERMAN;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.END_CRYSTAL;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ENTITY;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.FIREWORK_ROCKET;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.FURNACE_MINECART;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.GHAST;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.GUARDIAN;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.HORSE;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.IRON_GOLEM;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ITEM;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ITEM_FRAME;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.LIVING_ENTITY;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.LIVING_ENTITY_BASE;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.OCELOT;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.PIG;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.PLAYER;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.SHEEP;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.SKELETON;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.SLIME;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.SPIDER;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.TAMABLE_ANIMAL;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.VILLAGER;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.WITCH;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.WITHER;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.WOLF;
|
||||
import static com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8.EntityType.ZOMBIE;
|
||||
|
||||
public enum EntityDataIndex1_7_6_10 {
|
||||
|
||||
ENTITY_FLAGS(ENTITY, 0, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ENTITY_AIR(ENTITY, 1, EntityDataTypes1_7_6_10.SHORT, EntityDataTypes1_8.SHORT),
|
||||
ENTITY_NAME_TAG(ENTITY, -1, null, 2, EntityDataTypes1_8.STRING),
|
||||
ENTITY_NAME_TAG_VISIBILITY(ENTITY, -1, null, 3, EntityDataTypes1_8.BYTE),
|
||||
ENTITY_SILENT(ENTITY, -1, null, 4, EntityDataTypes1_8.BYTE),
|
||||
ENTITY_FLAGS(ENTITY, 0, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ENTITY_AIR(ENTITY, 1, EntityDataTypes1_7_6_10.SHORT, EntityDataTypes1_8.SHORT),
|
||||
ENTITY_NAME_TAG(ENTITY, -1, null, 2, EntityDataTypes1_8.STRING),
|
||||
ENTITY_NAME_TAG_VISIBILITY(ENTITY, -1, null, 3, EntityDataTypes1_8.BYTE),
|
||||
ENTITY_SILENT(ENTITY, -1, null, 4, EntityDataTypes1_8.BYTE),
|
||||
|
||||
LIVING_ENTITY_BASE_HEALTH(LIVING_ENTITY_BASE, 6, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
LIVING_ENTITY_BASE_POTION_EFFECT_COLOR(LIVING_ENTITY_BASE, 7, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
LIVING_ENTITY_BASE_IS_POTION_EFFECT_AMBIENT(LIVING_ENTITY_BASE, 8, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
LIVING_ENTITY_BASE_ARROWS(LIVING_ENTITY_BASE, 9, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
LIVING_ENTITY_BASE_NAME_TAG(LIVING_ENTITY_BASE, 10, EntityDataTypes1_7_6_10.STRING, 2, EntityDataTypes1_8.STRING),
|
||||
LIVING_ENTITY_BASE_NAME_TAG_VISIBILITY(LIVING_ENTITY_BASE, 11, EntityDataTypes1_7_6_10.BYTE, 3, EntityDataTypes1_8.BYTE),
|
||||
LIVING_ENTITY_BASE_HEALTH(LIVING_ENTITY_BASE, 6, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
LIVING_ENTITY_BASE_POTION_EFFECT_COLOR(LIVING_ENTITY_BASE, 7, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
LIVING_ENTITY_BASE_IS_POTION_EFFECT_AMBIENT(LIVING_ENTITY_BASE, 8, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
LIVING_ENTITY_BASE_ARROWS(LIVING_ENTITY_BASE, 9, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
LIVING_ENTITY_BASE_NAME_TAG(LIVING_ENTITY_BASE, 10, EntityDataTypes1_7_6_10.STRING, 2, EntityDataTypes1_8.STRING),
|
||||
LIVING_ENTITY_BASE_NAME_TAG_VISIBILITY(LIVING_ENTITY_BASE, 11, EntityDataTypes1_7_6_10.BYTE, 3, EntityDataTypes1_8.BYTE),
|
||||
|
||||
LIVING_ENTITY_AI(LIVING_ENTITY, -1, null, 15, EntityDataTypes1_8.BYTE),
|
||||
LIVING_ENTITY_AI(LIVING_ENTITY, -1, null, 15, EntityDataTypes1_8.BYTE),
|
||||
|
||||
ABSTRACT_AGEABLE_AGE(ABSTRACT_AGEABLE, 12, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.BYTE),
|
||||
ABSTRACT_AGEABLE_AGE(ABSTRACT_AGEABLE, 12, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.BYTE),
|
||||
|
||||
ARMOR_STAND_FLAGS(ARMOR_STAND, -1, null, 10, EntityDataTypes1_8.BYTE),
|
||||
ARMOR_STAND_HEAD_POSITION(ARMOR_STAND, -1, null, 11, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_BODY_POSITION(ARMOR_STAND, -1, null, 12, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_LEFT_ARM_POSITION(ARMOR_STAND, -1, null, 13, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_RIGHT_ARM_POSITION(ARMOR_STAND, -1, null, 14, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_LEFT_LEG_POSITION(ARMOR_STAND, -1, null, 15, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_RIGHT_LEG_POSITION(ARMOR_STAND, -1, null, 16, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_FLAGS(ARMOR_STAND, -1, null, 10, EntityDataTypes1_8.BYTE),
|
||||
ARMOR_STAND_HEAD_POSITION(ARMOR_STAND, -1, null, 11, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_BODY_POSITION(ARMOR_STAND, -1, null, 12, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_LEFT_ARM_POSITION(ARMOR_STAND, -1, null, 13, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_RIGHT_ARM_POSITION(ARMOR_STAND, -1, null, 14, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_LEFT_LEG_POSITION(ARMOR_STAND, -1, null, 15, EntityDataTypes1_8.ROTATIONS),
|
||||
ARMOR_STAND_RIGHT_LEG_POSITION(ARMOR_STAND, -1, null, 16, EntityDataTypes1_8.ROTATIONS),
|
||||
|
||||
PLAYER_SKIN_FLAGS(PLAYER, 16, EntityDataTypes1_7_6_10.BYTE, 10, EntityDataTypes1_8.BYTE),
|
||||
PLAYER_UNUSED(PLAYER, -1, null, 16, EntityDataTypes1_8.BYTE),
|
||||
PLAYER_ABSORPTION_HEATS(PLAYER, 17, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
PLAYER_SCORE(PLAYER, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
PLAYER_SKIN_FLAGS(PLAYER, 16, EntityDataTypes1_7_6_10.BYTE, 10, EntityDataTypes1_8.BYTE),
|
||||
PLAYER_UNUSED(PLAYER, -1, null, 16, EntityDataTypes1_8.BYTE),
|
||||
PLAYER_ABSORPTION_HEATS(PLAYER, 17, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
PLAYER_SCORE(PLAYER, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
|
||||
HORSE_FLAGS(HORSE, 16, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
HORSE_TYPE(HORSE, 19, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
HORSE_COLOR(HORSE, 20, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
HORSE_OWNER(HORSE, 21, EntityDataTypes1_7_6_10.STRING, EntityDataTypes1_8.STRING),
|
||||
HORSE_ARMOR(HORSE, 22, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
HORSE_FLAGS(HORSE, 16, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
HORSE_TYPE(HORSE, 19, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
HORSE_COLOR(HORSE, 20, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
HORSE_OWNER(HORSE, 21, EntityDataTypes1_7_6_10.STRING, EntityDataTypes1_8.STRING),
|
||||
HORSE_ARMOR(HORSE, 22, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
|
||||
BAT_HANGING(BAT, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
BAT_HANGING(BAT, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
TAMABLE_ANIMAL_FLAGS(TAMABLE_ANIMAL, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
TAMABLE_ANIMAL_OWNER(TAMABLE_ANIMAL, 17, EntityDataTypes1_7_6_10.STRING, EntityDataTypes1_8.STRING),
|
||||
TAMABLE_ANIMAL_FLAGS(TAMABLE_ANIMAL, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
TAMABLE_ANIMAL_OWNER(TAMABLE_ANIMAL, 17, EntityDataTypes1_7_6_10.STRING, EntityDataTypes1_8.STRING),
|
||||
|
||||
OCELOT_TYPE(OCELOT, 18, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
OCELOT_TYPE(OCELOT, 18, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
WOLF_FLAGS(WOLF, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
WOLF_HEALTH(WOLF, 18, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
WOLF_BEGGING(WOLF, 19, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
WOLF_COLLAR_COLOR(WOLF, 20, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
WOLF_FLAGS(WOLF, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
WOLF_HEALTH(WOLF, 18, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
WOLF_BEGGING(WOLF, 19, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
WOLF_COLLAR_COLOR(WOLF, 20, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
PIG_SADDLE(PIG, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
PIG_SADDLE(PIG, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
SHEEP_COLOR_OR_SHEARED(SHEEP, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
SHEEP_COLOR_OR_SHEARED(SHEEP, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
VILLAGER_TYPE(VILLAGER, 16, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
VILLAGER_TYPE(VILLAGER, 16, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
|
||||
ENDERMAN_CARRIED_BLOCK(ENDERMAN, 16, null, EntityDataTypes1_8.SHORT),
|
||||
ENDERMAN_CARRIED_BLOCK_DATA(ENDERMAN, 17, null, EntityDataTypes1_8.BYTE),
|
||||
ENDERMAN_IS_SCREAMING(ENDERMAN, 18, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ENDERMAN_CARRIED_BLOCK(ENDERMAN, 16, null, EntityDataTypes1_8.SHORT),
|
||||
ENDERMAN_CARRIED_BLOCK_DATA(ENDERMAN, 17, null, EntityDataTypes1_8.BYTE),
|
||||
ENDERMAN_IS_SCREAMING(ENDERMAN, 18, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
ZOMBIE_CHILD(ZOMBIE, 12, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ZOMBIE_VILLAGER(ZOMBIE, 13, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ZOMBIE_CONVERTING(ZOMBIE, 14, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ZOMBIE_CHILD(ZOMBIE, 12, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ZOMBIE_VILLAGER(ZOMBIE, 13, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ZOMBIE_CONVERTING(ZOMBIE, 14, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
BLAZE_ON_FIRE(BLAZE, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
BLAZE_ON_FIRE(BLAZE, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
SPIDER_CLIMBING(SPIDER, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
SPIDER_CLIMBING(SPIDER, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
CREEPER_STATE(CREEPER, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
CREEPER_POWERED(CREEPER, 17, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
CREEPER_IGNITED(CREEPER, 18, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
CREEPER_STATE(CREEPER, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
CREEPER_POWERED(CREEPER, 17, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
CREEPER_IGNITED(CREEPER, 18, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
GHAST_STATE(GHAST, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
GHAST_IS_POWERED(GHAST, 17, null, EntityDataTypes1_8.BYTE),
|
||||
GHAST_STATE(GHAST, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
GHAST_IS_POWERED(GHAST, 17, null, EntityDataTypes1_8.BYTE),
|
||||
|
||||
SLIME_SIZE(SLIME, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
SLIME_SIZE(SLIME, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
SKELETON_TYPE(SKELETON, 13, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
SKELETON_TYPE(SKELETON, 13, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
WITCH_AGGRESSIVE(WITCH, 21, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
WITCH_AGGRESSIVE(WITCH, 21, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
IRON_GOLEM_IS_PLAYER_CREATED(IRON_GOLEM, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
IRON_GOLEM_IS_PLAYER_CREATED(IRON_GOLEM, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
WITHER_WATCHED_TARGET_1(WITHER, 17, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_WATCHED_TARGET_2(WITHER, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_WATCHED_TARGET_3(WITHER, 19, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_INVULNERABLE_TIME(WITHER, 20, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_WATCHED_TARGET_1(WITHER, 17, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_WATCHED_TARGET_2(WITHER, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_WATCHED_TARGET_3(WITHER, 19, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
WITHER_INVULNERABLE_TIME(WITHER, 20, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
|
||||
GUARDIAN_FLAGS(GUARDIAN, 16, null, EntityDataTypes1_8.BYTE),
|
||||
GUARDIAN_TARGET(GUARDIAN, 17, null, EntityDataTypes1_8.INT),
|
||||
GUARDIAN_FLAGS(GUARDIAN, 16, null, EntityDataTypes1_8.BYTE),
|
||||
GUARDIAN_TARGET(GUARDIAN, 17, null, EntityDataTypes1_8.INT),
|
||||
|
||||
BOAT_TIME_SINCE_HIT(BOAT, 17, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
BOAT_FORWARD_DIRECTION(BOAT, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
BOAT_DAMAGE_TAKEN(BOAT, 19, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
BOAT_TIME_SINCE_HIT(BOAT, 17, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
BOAT_FORWARD_DIRECTION(BOAT, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
BOAT_DAMAGE_TAKEN(BOAT, 19, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
|
||||
ABSTRACT_MINECART_SHAKING_POWER(ABSTRACT_MINECART, 17, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_SHAKING_DIRECTION(ABSTRACT_MINECART, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_DAMAGE_TAKEN(ABSTRACT_MINECART, 19, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
ABSTRACT_MINECART_BLOCK_INSIDE(ABSTRACT_MINECART, 20, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_BLOCK_Y(ABSTRACT_MINECART, 21, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_SHOW_BLOCK(ABSTRACT_MINECART, 22, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ABSTRACT_MINECART_SHAKING_POWER(ABSTRACT_MINECART, 17, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_SHAKING_DIRECTION(ABSTRACT_MINECART, 18, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_DAMAGE_TAKEN(ABSTRACT_MINECART, 19, EntityDataTypes1_7_6_10.FLOAT, EntityDataTypes1_8.FLOAT),
|
||||
ABSTRACT_MINECART_BLOCK_INSIDE(ABSTRACT_MINECART, 20, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_BLOCK_Y(ABSTRACT_MINECART, 21, EntityDataTypes1_7_6_10.INT, EntityDataTypes1_8.INT),
|
||||
ABSTRACT_MINECART_SHOW_BLOCK(ABSTRACT_MINECART, 22, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
FURNACE_MINECART_IS_POWERED(FURNACE_MINECART, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
FURNACE_MINECART_IS_POWERED(FURNACE_MINECART, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
ITEM_ITEM(ITEM, 10, EntityDataTypes1_7_6_10.ITEM, EntityDataTypes1_8.ITEM),
|
||||
ITEM_ITEM(ITEM, 10, EntityDataTypes1_7_6_10.ITEM, EntityDataTypes1_8.ITEM),
|
||||
|
||||
ARROW_IS_CRITICAL(ARROW, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
ARROW_IS_CRITICAL(ARROW, 16, EntityDataTypes1_7_6_10.BYTE, EntityDataTypes1_8.BYTE),
|
||||
|
||||
FIREWORK_ROCKET_INFO(FIREWORK_ROCKET, 8, EntityDataTypes1_7_6_10.ITEM, EntityDataTypes1_8.ITEM),
|
||||
FIREWORK_ROCKET_INFO(FIREWORK_ROCKET, 8, EntityDataTypes1_7_6_10.ITEM, EntityDataTypes1_8.ITEM),
|
||||
|
||||
ITEM_FRAME_ITEM(ITEM_FRAME, 2, EntityDataTypes1_7_6_10.ITEM, 8, EntityDataTypes1_8.ITEM),
|
||||
ITEM_FRAME_ROTATION(ITEM_FRAME, 3, EntityDataTypes1_7_6_10.BYTE, 9, EntityDataTypes1_8.BYTE),
|
||||
ITEM_FRAME_ITEM(ITEM_FRAME, 2, EntityDataTypes1_7_6_10.ITEM, 8, EntityDataTypes1_8.ITEM),
|
||||
ITEM_FRAME_ROTATION(ITEM_FRAME, 3, EntityDataTypes1_7_6_10.BYTE, 9, EntityDataTypes1_8.BYTE),
|
||||
|
||||
END_CRYSTAL_HEALTH(END_CRYSTAL, 8, EntityDataTypes1_7_6_10.INT, 9, EntityDataTypes1_8.INT);
|
||||
END_CRYSTAL_HEALTH(END_CRYSTAL, 8, EntityDataTypes1_7_6_10.INT, 9, EntityDataTypes1_8.INT);
|
||||
|
||||
private static final HashMap<Pair<EntityTypes1_8.EntityType, Integer>, EntityDataIndex1_7_6_10> ENTITY_DATA_REWRITES = new HashMap<>();
|
||||
private static final HashMap<Pair<EntityTypes1_8.EntityType, Integer>, EntityDataIndex1_7_6_10> ENTITY_DATA_REWRITES = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (EntityDataIndex1_7_6_10 index : EntityDataIndex1_7_6_10.values()) {
|
||||
ENTITY_DATA_REWRITES.put(new Pair<>(index.getClazz(), index.getNewIndex()), index);
|
||||
}
|
||||
}
|
||||
static {
|
||||
for (EntityDataIndex1_7_6_10 index : EntityDataIndex1_7_6_10.values()) {
|
||||
ENTITY_DATA_REWRITES.put(new Pair<>(index.getClazz(), index.getNewIndex()), index);
|
||||
}
|
||||
}
|
||||
|
||||
private final EntityTypes1_8.EntityType clazz;
|
||||
private final int newIndex;
|
||||
private final EntityDataTypes1_8 newType;
|
||||
private final EntityDataTypes1_7_6_10 oldType;
|
||||
private final int index;
|
||||
private final EntityTypes1_8.EntityType clazz;
|
||||
private final int newIndex;
|
||||
private final EntityDataTypes1_8 newType;
|
||||
private final EntityDataTypes1_7_6_10 oldType;
|
||||
private final int index;
|
||||
|
||||
EntityDataIndex1_7_6_10(EntityTypes1_8.EntityType type, int index, EntityDataTypes1_7_6_10 oldType, EntityDataTypes1_8 newType) {
|
||||
this.clazz = type;
|
||||
this.index = index;
|
||||
this.newIndex = index;
|
||||
this.oldType = oldType;
|
||||
this.newType = newType;
|
||||
}
|
||||
EntityDataIndex1_7_6_10(EntityTypes1_8.EntityType type, int index, EntityDataTypes1_7_6_10 oldType, EntityDataTypes1_8 newType) {
|
||||
this.clazz = type;
|
||||
this.index = index;
|
||||
this.newIndex = index;
|
||||
this.oldType = oldType;
|
||||
this.newType = newType;
|
||||
}
|
||||
|
||||
EntityDataIndex1_7_6_10(EntityTypes1_8.EntityType type, int index, EntityDataTypes1_7_6_10 oldType, int newIndex, EntityDataTypes1_8 newType) {
|
||||
this.clazz = type;
|
||||
this.index = index;
|
||||
this.oldType = oldType;
|
||||
this.newIndex = newIndex;
|
||||
this.newType = newType;
|
||||
}
|
||||
EntityDataIndex1_7_6_10(EntityTypes1_8.EntityType type, int index, EntityDataTypes1_7_6_10 oldType, int newIndex, EntityDataTypes1_8 newType) {
|
||||
this.clazz = type;
|
||||
this.index = index;
|
||||
this.oldType = oldType;
|
||||
this.newIndex = newIndex;
|
||||
this.newType = newType;
|
||||
}
|
||||
|
||||
private static Optional<EntityDataIndex1_7_6_10> getIndex(EntityType type, int index) {
|
||||
final Pair<EntityType, Integer> pair = new Pair<>(type, index);
|
||||
return Optional.ofNullable(ENTITY_DATA_REWRITES.get(pair));
|
||||
}
|
||||
private static Optional<EntityDataIndex1_7_6_10> getIndex(EntityType type, int index) {
|
||||
final Pair<EntityType, Integer> pair = new Pair<>(type, index);
|
||||
return Optional.ofNullable(ENTITY_DATA_REWRITES.get(pair));
|
||||
}
|
||||
|
||||
public EntityTypes1_8.EntityType getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
public static EntityDataIndex1_7_6_10 searchIndex(EntityType type, int index) {
|
||||
EntityType currentType = type;
|
||||
do {
|
||||
Optional<EntityDataIndex1_7_6_10> optMeta = getIndex(currentType, index);
|
||||
|
||||
public int getNewIndex() {
|
||||
return newIndex;
|
||||
}
|
||||
if (optMeta.isPresent()) {
|
||||
return optMeta.get();
|
||||
}
|
||||
|
||||
public EntityDataTypes1_8 getNewType() {
|
||||
return newType;
|
||||
}
|
||||
currentType = currentType.getParent();
|
||||
} while (currentType != null);
|
||||
|
||||
public EntityDataTypes1_7_6_10 getOldType() {
|
||||
return oldType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
public EntityTypes1_8.EntityType getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static EntityDataIndex1_7_6_10 searchIndex(EntityType type, int index) {
|
||||
EntityType currentType = type;
|
||||
do {
|
||||
Optional<EntityDataIndex1_7_6_10> optMeta = getIndex(currentType, index);
|
||||
public int getNewIndex() {
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
if (optMeta.isPresent()) {
|
||||
return optMeta.get();
|
||||
}
|
||||
public EntityDataTypes1_8 getNewType() {
|
||||
return newType;
|
||||
}
|
||||
|
||||
currentType = currentType.getParent();
|
||||
} while (currentType != null);
|
||||
public EntityDataTypes1_7_6_10 getOldType() {
|
||||
return oldType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
+68
-67
@@ -20,77 +20,78 @@ package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.data;
|
||||
import java.util.HashMap;
|
||||
|
||||
public enum Particles1_8 {
|
||||
EXPLOSION_NORMAL("explode"),
|
||||
EXPLOSION_LARGE("largeexplode"),
|
||||
EXPLOSION_HUGE("hugeexplosion"),
|
||||
FIREWORKS_SPARK("fireworksSpark"),
|
||||
WATER_BUBBLE("bubble"),
|
||||
WATER_SPLASH("splash"),
|
||||
WATER_WAKE("wake"),
|
||||
SUSPENDED("suspended"),
|
||||
SUSPENDED_DEPTH("depthsuspend"),
|
||||
CRIT("crit"),
|
||||
CRIT_MAGIC("magicCrit"),
|
||||
SMOKE_NORMAL("smoke"),
|
||||
SMOKE_LARGE("largesmoke"),
|
||||
SPELL("spell"),
|
||||
SPELL_INSTANT("instantSpell"),
|
||||
SPELL_MOB("mobSpell"),
|
||||
SPELL_MOB_AMBIENT("mobSpellAmbient"),
|
||||
SPELL_WITCH("witchMagic"),
|
||||
DRIP_WATER("dripWater"),
|
||||
DRIP_LAVA("dripLava"),
|
||||
VILLAGER_ANGRY("angryVillager"),
|
||||
VILLAGER_HAPPY("happyVillager"),
|
||||
TOWN_AURA("townaura"),
|
||||
NOTE("note"),
|
||||
PORTAL("portal"),
|
||||
ENCHANTMENT_TABLE("enchantmenttable"),
|
||||
FLAME("flame"),
|
||||
LAVA("lava"),
|
||||
FOOTSTEP("footstep"),
|
||||
CLOUD("cloud"),
|
||||
REDSTONE("reddust"),
|
||||
SNOWBALL("snowballpoof"),
|
||||
SNOW_SHOVEL("snowshovel"),
|
||||
SLIME("slime"),
|
||||
HEART("heart"),
|
||||
BARRIER("barrier"),
|
||||
ICON_CRACK("iconcrack", 2),
|
||||
BLOCK_CRACK("blockcrack", 1),
|
||||
BLOCK_DUST("blockdust", 1),
|
||||
WATER_DROP("droplet"),
|
||||
ITEM_TAKE("take"),
|
||||
MOB_APPEARANCE("mobappearance");
|
||||
EXPLOSION_NORMAL("explode"),
|
||||
EXPLOSION_LARGE("largeexplode"),
|
||||
EXPLOSION_HUGE("hugeexplosion"),
|
||||
FIREWORKS_SPARK("fireworksSpark"),
|
||||
WATER_BUBBLE("bubble"),
|
||||
WATER_SPLASH("splash"),
|
||||
WATER_WAKE("wake"),
|
||||
SUSPENDED("suspended"),
|
||||
SUSPENDED_DEPTH("depthsuspend"),
|
||||
CRIT("crit"),
|
||||
CRIT_MAGIC("magicCrit"),
|
||||
SMOKE_NORMAL("smoke"),
|
||||
SMOKE_LARGE("largesmoke"),
|
||||
SPELL("spell"),
|
||||
SPELL_INSTANT("instantSpell"),
|
||||
SPELL_MOB("mobSpell"),
|
||||
SPELL_MOB_AMBIENT("mobSpellAmbient"),
|
||||
SPELL_WITCH("witchMagic"),
|
||||
DRIP_WATER("dripWater"),
|
||||
DRIP_LAVA("dripLava"),
|
||||
VILLAGER_ANGRY("angryVillager"),
|
||||
VILLAGER_HAPPY("happyVillager"),
|
||||
TOWN_AURA("townaura"),
|
||||
NOTE("note"),
|
||||
PORTAL("portal"),
|
||||
ENCHANTMENT_TABLE("enchantmenttable"),
|
||||
FLAME("flame"),
|
||||
LAVA("lava"),
|
||||
FOOTSTEP("footstep"),
|
||||
CLOUD("cloud"),
|
||||
REDSTONE("reddust"),
|
||||
SNOWBALL("snowballpoof"),
|
||||
SNOW_SHOVEL("snowshovel"),
|
||||
SLIME("slime"),
|
||||
HEART("heart"),
|
||||
BARRIER("barrier"),
|
||||
ICON_CRACK("iconcrack", 2),
|
||||
BLOCK_CRACK("blockcrack", 1),
|
||||
BLOCK_DUST("blockdust", 1),
|
||||
WATER_DROP("droplet"),
|
||||
ITEM_TAKE("take"),
|
||||
MOB_APPEARANCE("mobappearance");
|
||||
|
||||
public final String name;
|
||||
public final int extra;
|
||||
private static final HashMap<String, Particles1_8> particleMap = new HashMap<>();
|
||||
private static final HashMap<String, Particles1_8> particleMap = new HashMap<>();
|
||||
|
||||
Particles1_8(String name) {
|
||||
this(name, 0);
|
||||
}
|
||||
static {
|
||||
Particles1_8[] particles = values();
|
||||
|
||||
Particles1_8(String name, int extra) {
|
||||
this.name = name;
|
||||
this.extra = extra;
|
||||
}
|
||||
for (Particles1_8 particle : particles) {
|
||||
particleMap.put(particle.name, particle);
|
||||
}
|
||||
}
|
||||
|
||||
public static Particles1_8 find(String part) {
|
||||
return particleMap.get(part);
|
||||
}
|
||||
public final String name;
|
||||
public final int extra;
|
||||
|
||||
public static Particles1_8 find(int id) {
|
||||
if (id < 0) return null;
|
||||
Particles1_8[] values = Particles1_8.values();
|
||||
return id >= values.length ? null : values[id];
|
||||
}
|
||||
Particles1_8(String name) {
|
||||
this(name, 0);
|
||||
}
|
||||
|
||||
static {
|
||||
Particles1_8[] particles = values();
|
||||
Particles1_8(String name, int extra) {
|
||||
this.name = name;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
for (Particles1_8 particle : particles) {
|
||||
particleMap.put(particle.name, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static Particles1_8 find(String part) {
|
||||
return particleMap.get(part);
|
||||
}
|
||||
|
||||
public static Particles1_8 find(int id) {
|
||||
if (id < 0) return null;
|
||||
Particles1_8[] values = Particles1_8.values();
|
||||
return id >= values.length ? null : values[id];
|
||||
}
|
||||
}
|
||||
+12
-10
@@ -24,17 +24,19 @@ import io.netty.channel.ChannelHandler;
|
||||
|
||||
public abstract class CompressionHandlerProvider implements Provider {
|
||||
|
||||
public abstract void onHandleLoginCompressionPacket(UserConnection user, int threshold);
|
||||
public abstract void onTransformPacket(UserConnection user);
|
||||
public abstract void onHandleLoginCompressionPacket(UserConnection user, int threshold);
|
||||
|
||||
public abstract ChannelHandler getEncoder(int threshold);
|
||||
public abstract ChannelHandler getDecoder(int threshold);
|
||||
public abstract void onTransformPacket(UserConnection user);
|
||||
|
||||
public boolean isCompressionEnabled(UserConnection user) {
|
||||
return user.get(CompressionStatusTracker.class).removeCompression;
|
||||
}
|
||||
public abstract ChannelHandler getEncoder(int threshold);
|
||||
|
||||
public void setCompressionEnabled(UserConnection user, boolean enabled) {
|
||||
user.get(CompressionStatusTracker.class).removeCompression = enabled;
|
||||
}
|
||||
public abstract ChannelHandler getDecoder(int threshold);
|
||||
|
||||
public boolean isCompressionEnabled(UserConnection user) {
|
||||
return user.get(CompressionStatusTracker.class).removeCompression;
|
||||
}
|
||||
|
||||
public void setCompressionEnabled(UserConnection user, boolean enabled) {
|
||||
user.get(CompressionStatusTracker.class).removeCompression = enabled;
|
||||
}
|
||||
}
|
||||
+57
-58
@@ -18,7 +18,6 @@
|
||||
package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -26,74 +25,74 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
// TODO I believe this should be a storage?
|
||||
public abstract class TitleRenderProvider implements Provider {
|
||||
protected Map<UUID, Integer> fadeIn = new HashMap<>();
|
||||
protected Map<UUID, Integer> stay = new HashMap<>();
|
||||
protected Map<UUID, Integer> fadeOut = new HashMap<>();
|
||||
protected Map<UUID, String> titles = new HashMap<>();
|
||||
protected Map<UUID, String> subTitles = new HashMap<>();
|
||||
protected Map<UUID, AtomicInteger> times = new HashMap<>();
|
||||
protected Map<UUID, Integer> fadeIn = new HashMap<>();
|
||||
protected Map<UUID, Integer> stay = new HashMap<>();
|
||||
protected Map<UUID, Integer> fadeOut = new HashMap<>();
|
||||
protected Map<UUID, String> titles = new HashMap<>();
|
||||
protected Map<UUID, String> subTitles = new HashMap<>();
|
||||
protected Map<UUID, AtomicInteger> times = new HashMap<>();
|
||||
|
||||
public void setTimings(UUID uuid, int fadeIn, int stay, int fadeOut) {
|
||||
setFadeIn(uuid, fadeIn);
|
||||
setStay(uuid, stay);
|
||||
setFadeOut(uuid, fadeOut);
|
||||
public void setTimings(UUID uuid, int fadeIn, int stay, int fadeOut) {
|
||||
setFadeIn(uuid, fadeIn);
|
||||
setStay(uuid, stay);
|
||||
setFadeOut(uuid, fadeOut);
|
||||
|
||||
AtomicInteger time = getTime(uuid);
|
||||
if (time.get() > 0) time.set(getFadeIn(uuid) + getStay(uuid) + getFadeOut(uuid));
|
||||
}
|
||||
AtomicInteger time = getTime(uuid);
|
||||
if (time.get() > 0) time.set(getFadeIn(uuid) + getStay(uuid) + getFadeOut(uuid));
|
||||
}
|
||||
|
||||
public void reset(UUID uuid) {
|
||||
this.titles.remove(uuid);
|
||||
this.subTitles.remove(uuid);
|
||||
getTime(uuid).set(0);
|
||||
fadeIn.remove(uuid);
|
||||
stay.remove(uuid);
|
||||
fadeOut.remove(uuid);
|
||||
}
|
||||
public void reset(UUID uuid) {
|
||||
this.titles.remove(uuid);
|
||||
this.subTitles.remove(uuid);
|
||||
getTime(uuid).set(0);
|
||||
fadeIn.remove(uuid);
|
||||
stay.remove(uuid);
|
||||
fadeOut.remove(uuid);
|
||||
}
|
||||
|
||||
public void setTitle(UUID uuid, String title) {
|
||||
this.titles.put(uuid, title);
|
||||
getTime(uuid).set(getFadeIn(uuid) + getStay(uuid) + getFadeOut(uuid));
|
||||
}
|
||||
public void setTitle(UUID uuid, String title) {
|
||||
this.titles.put(uuid, title);
|
||||
getTime(uuid).set(getFadeIn(uuid) + getStay(uuid) + getFadeOut(uuid));
|
||||
}
|
||||
|
||||
public void setSubTitle(UUID uuid, String subTitle) {
|
||||
this.subTitles.put(uuid, subTitle);
|
||||
}
|
||||
public void setSubTitle(UUID uuid, String subTitle) {
|
||||
this.subTitles.put(uuid, subTitle);
|
||||
}
|
||||
|
||||
public void clear(UUID uuid) {
|
||||
this.titles.remove(uuid);
|
||||
this.subTitles.remove(uuid);
|
||||
getTime(uuid).set(0);
|
||||
}
|
||||
public void clear(UUID uuid) {
|
||||
this.titles.remove(uuid);
|
||||
this.subTitles.remove(uuid);
|
||||
getTime(uuid).set(0);
|
||||
}
|
||||
|
||||
public AtomicInteger getTime(UUID uuid) {
|
||||
return times.computeIfAbsent(uuid, key -> new AtomicInteger(0));
|
||||
}
|
||||
public AtomicInteger getTime(UUID uuid) {
|
||||
return times.computeIfAbsent(uuid, key -> new AtomicInteger(0));
|
||||
}
|
||||
|
||||
public int getFadeIn(UUID uuid) {
|
||||
return fadeIn.getOrDefault(uuid, 10);
|
||||
}
|
||||
public int getFadeIn(UUID uuid) {
|
||||
return fadeIn.getOrDefault(uuid, 10);
|
||||
}
|
||||
|
||||
public int getStay(UUID uuid) {
|
||||
return stay.getOrDefault(uuid, 70);
|
||||
}
|
||||
public int getStay(UUID uuid) {
|
||||
return stay.getOrDefault(uuid, 70);
|
||||
}
|
||||
|
||||
public int getFadeOut(UUID uuid) {
|
||||
return fadeOut.getOrDefault(uuid, 20);
|
||||
}
|
||||
public int getFadeOut(UUID uuid) {
|
||||
return fadeOut.getOrDefault(uuid, 20);
|
||||
}
|
||||
|
||||
public void setFadeIn(UUID uuid, int fadeIn) {
|
||||
if (fadeIn >= 0) this.fadeIn.put(uuid, fadeIn);
|
||||
else this.fadeIn.remove(uuid);
|
||||
}
|
||||
public void setFadeIn(UUID uuid, int fadeIn) {
|
||||
if (fadeIn >= 0) this.fadeIn.put(uuid, fadeIn);
|
||||
else this.fadeIn.remove(uuid);
|
||||
}
|
||||
|
||||
public void setStay(UUID uuid, int stay) {
|
||||
if (stay >= 0) this.stay.put(uuid, stay);
|
||||
else this.stay.remove(uuid);
|
||||
}
|
||||
public void setStay(UUID uuid, int stay) {
|
||||
if (stay >= 0) this.stay.put(uuid, stay);
|
||||
else this.stay.remove(uuid);
|
||||
}
|
||||
|
||||
public void setFadeOut(UUID uuid, int fadeOut) {
|
||||
if (fadeOut >= 0) this.fadeOut.put(uuid, fadeOut);
|
||||
else this.fadeOut.remove(uuid);
|
||||
}
|
||||
public void setFadeOut(UUID uuid, int fadeOut) {
|
||||
if (fadeOut >= 0) this.fadeOut.put(uuid, fadeOut);
|
||||
else this.fadeOut.remove(uuid);
|
||||
}
|
||||
}
|
||||
+35
-36
@@ -23,50 +23,49 @@ import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
public class CompressionDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
private final Inflater inflater = new Inflater();
|
||||
private final Inflater inflater = new Inflater();
|
||||
|
||||
private final int threshold;
|
||||
private final int threshold;
|
||||
|
||||
public CompressionDecoder(final int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
public CompressionDecoder(final int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (!in.isReadable()) return;
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (!in.isReadable()) return;
|
||||
|
||||
int outLength = Types.VAR_INT.readPrimitive(in);
|
||||
if (outLength == 0) {
|
||||
out.add(in.readBytes(in.readableBytes()));
|
||||
return;
|
||||
}
|
||||
int outLength = Types.VAR_INT.readPrimitive(in);
|
||||
if (outLength == 0) {
|
||||
out.add(in.readBytes(in.readableBytes()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (outLength < this.threshold) {
|
||||
throw new DecoderException("Badly compressed packet - size of " + outLength + " is below server threshold of " + this.threshold);
|
||||
} else if (outLength > 2097152) {
|
||||
throw new DecoderException("Badly compressed packet - size of " + outLength + " is larger than protocol maximum of " + 2097152);
|
||||
}
|
||||
if (outLength < this.threshold) {
|
||||
throw new DecoderException("Badly compressed packet - size of " + outLength + " is below server threshold of " + this.threshold);
|
||||
} else if (outLength > 2097152) {
|
||||
throw new DecoderException("Badly compressed packet - size of " + outLength + " is larger than protocol maximum of " + 2097152);
|
||||
}
|
||||
|
||||
ByteBuf temp = in;
|
||||
if (!in.hasArray()) {
|
||||
temp = ByteBufAllocator.DEFAULT.heapBuffer().writeBytes(in);
|
||||
} else {
|
||||
in.retain();
|
||||
}
|
||||
ByteBuf output = ByteBufAllocator.DEFAULT.heapBuffer(outLength, outLength);
|
||||
try {
|
||||
this.inflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
|
||||
output.writerIndex(output.writerIndex() + this.inflater.inflate(output.array(), output.arrayOffset(), outLength));
|
||||
out.add(output.retain());
|
||||
} finally {
|
||||
output.release();
|
||||
temp.release();
|
||||
this.inflater.reset();
|
||||
}
|
||||
}
|
||||
ByteBuf temp = in;
|
||||
if (!in.hasArray()) {
|
||||
temp = ByteBufAllocator.DEFAULT.heapBuffer().writeBytes(in);
|
||||
} else {
|
||||
in.retain();
|
||||
}
|
||||
ByteBuf output = ByteBufAllocator.DEFAULT.heapBuffer(outLength, outLength);
|
||||
try {
|
||||
this.inflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
|
||||
output.writerIndex(output.writerIndex() + this.inflater.inflate(output.array(), output.arrayOffset(), outLength));
|
||||
out.add(output.retain());
|
||||
} finally {
|
||||
output.release();
|
||||
temp.release();
|
||||
this.inflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-37
@@ -22,49 +22,48 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
public class CompressionEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
private final Deflater deflater = new Deflater();
|
||||
private final Deflater deflater = new Deflater();
|
||||
|
||||
private final int threshold;
|
||||
private final int threshold;
|
||||
|
||||
public CompressionEncoder(final int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
public CompressionEncoder(final int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
|
||||
int frameLength = in.readableBytes();
|
||||
if (frameLength < this.threshold) {
|
||||
out.writeByte(0); // VarInt
|
||||
out.writeBytes(in);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
|
||||
int frameLength = in.readableBytes();
|
||||
if (frameLength < this.threshold) {
|
||||
out.writeByte(0); // VarInt
|
||||
out.writeBytes(in);
|
||||
return;
|
||||
}
|
||||
|
||||
Types.VAR_INT.writePrimitive(out, frameLength);
|
||||
Types.VAR_INT.writePrimitive(out, frameLength);
|
||||
|
||||
ByteBuf temp = in;
|
||||
if (!in.hasArray()) {
|
||||
temp = ByteBufAllocator.DEFAULT.heapBuffer().writeBytes(in);
|
||||
} else {
|
||||
in.retain();
|
||||
}
|
||||
ByteBuf output = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||
try {
|
||||
this.deflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
|
||||
deflater.finish();
|
||||
ByteBuf temp = in;
|
||||
if (!in.hasArray()) {
|
||||
temp = ByteBufAllocator.DEFAULT.heapBuffer().writeBytes(in);
|
||||
} else {
|
||||
in.retain();
|
||||
}
|
||||
ByteBuf output = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||
try {
|
||||
this.deflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
|
||||
deflater.finish();
|
||||
|
||||
while (!deflater.finished()) {
|
||||
output.ensureWritable(4096);
|
||||
output.writerIndex(output.writerIndex() + this.deflater.deflate(output.array(), output.arrayOffset() + output.writerIndex(), output.writableBytes()));
|
||||
}
|
||||
out.writeBytes(output);
|
||||
} finally {
|
||||
output.release();
|
||||
temp.release();
|
||||
this.deflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!deflater.finished()) {
|
||||
output.ensureWritable(4096);
|
||||
output.writerIndex(output.writerIndex() + this.deflater.deflate(output.array(), output.arrayOffset() + output.writerIndex(), output.writableBytes()));
|
||||
}
|
||||
out.writeBytes(output);
|
||||
} finally {
|
||||
output.release();
|
||||
temp.release();
|
||||
this.deflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
-37
@@ -28,47 +28,47 @@ import io.netty.channel.ChannelPipeline;
|
||||
|
||||
public class TrackingCompressionHandlerProvider extends CompressionHandlerProvider {
|
||||
|
||||
@Override
|
||||
public void onHandleLoginCompressionPacket(UserConnection user, int threshold) {
|
||||
final ChannelPipeline pipeline = user.getChannel().pipeline();
|
||||
if (user.isClientSide()) {
|
||||
pipeline.addBefore(Via.getManager().getInjector().getEncoderName(), ViaRewind.getPlatform().compressHandlerName(), getEncoder(threshold));
|
||||
pipeline.addBefore(Via.getManager().getInjector().getDecoderName(), ViaRewind.getPlatform().decompressHandlerName(), getDecoder(threshold));
|
||||
} else {
|
||||
setCompressionEnabled(user, true); // We need to remove compression for 1.7 clients
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onHandleLoginCompressionPacket(UserConnection user, int threshold) {
|
||||
final ChannelPipeline pipeline = user.getChannel().pipeline();
|
||||
if (user.isClientSide()) {
|
||||
pipeline.addBefore(Via.getManager().getInjector().getEncoderName(), ViaRewind.getPlatform().compressHandlerName(), getEncoder(threshold));
|
||||
pipeline.addBefore(Via.getManager().getInjector().getDecoderName(), ViaRewind.getPlatform().decompressHandlerName(), getDecoder(threshold));
|
||||
} else {
|
||||
setCompressionEnabled(user, true); // We need to remove compression for 1.7 clients
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformPacket(UserConnection user) {
|
||||
if (isCompressionEnabled(user)) {
|
||||
final ChannelPipeline pipeline = user.getChannel().pipeline();
|
||||
@Override
|
||||
public void onTransformPacket(UserConnection user) {
|
||||
if (isCompressionEnabled(user)) {
|
||||
final ChannelPipeline pipeline = user.getChannel().pipeline();
|
||||
|
||||
String compressor = null;
|
||||
String decompressor = null;
|
||||
if (pipeline.get(ViaRewind.getPlatform().compressHandlerName()) != null) {
|
||||
compressor = ViaRewind.getPlatform().compressHandlerName();
|
||||
decompressor = ViaRewind.getPlatform().decompressHandlerName();
|
||||
}
|
||||
String compressor = null;
|
||||
String decompressor = null;
|
||||
if (pipeline.get(ViaRewind.getPlatform().compressHandlerName()) != null) {
|
||||
compressor = ViaRewind.getPlatform().compressHandlerName();
|
||||
decompressor = ViaRewind.getPlatform().decompressHandlerName();
|
||||
}
|
||||
|
||||
if (compressor != null) { // We can neutralize the effect of compressor to the client
|
||||
pipeline.replace(decompressor, decompressor, new EmptyChannelHandler());
|
||||
pipeline.replace(compressor, compressor, new ForwardMessageToByteEncoder());
|
||||
} else {
|
||||
throw new IllegalStateException("Couldn't remove compression for 1.7!");
|
||||
}
|
||||
if (compressor != null) { // We can neutralize the effect of compressor to the client
|
||||
pipeline.replace(decompressor, decompressor, new EmptyChannelHandler());
|
||||
pipeline.replace(compressor, compressor, new ForwardMessageToByteEncoder());
|
||||
} else {
|
||||
throw new IllegalStateException("Couldn't remove compression for 1.7!");
|
||||
}
|
||||
|
||||
setCompressionEnabled(user, false);
|
||||
}
|
||||
}
|
||||
setCompressionEnabled(user, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelHandler getEncoder(int threshold) {
|
||||
return new CompressionEncoder(threshold);
|
||||
}
|
||||
@Override
|
||||
public ChannelHandler getEncoder(int threshold) {
|
||||
return new CompressionEncoder(threshold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelHandler getDecoder(int threshold) {
|
||||
return new CompressionDecoder(threshold);
|
||||
}
|
||||
@Override
|
||||
public ChannelHandler getDecoder(int threshold) {
|
||||
return new CompressionDecoder(threshold);
|
||||
}
|
||||
}
|
||||
+239
-238
@@ -17,304 +17,305 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
|
||||
import com.viaversion.viarewind.api.rewriter.VRBlockItemRewriter;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viarewind.protocol.v1_7_6_10to1_7_2_5.packet.ServerboundPackets1_7_2_5;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.Protocol1_8To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.EntityTracker1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.GameProfileStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.InventoryTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.PlayerSessionStorage;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.nbt.tag.*;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BlockItemPacketRewriter1_8 extends VRBlockItemRewriter<ClientboundPackets1_8, ServerboundPackets1_7_2_5, Protocol1_8To1_7_6_10> {
|
||||
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
|
||||
public BlockItemPacketRewriter1_8(Protocol1_8To1_7_6_10 protocol) {
|
||||
super(protocol, "1.8");
|
||||
}
|
||||
public BlockItemPacketRewriter1_8(Protocol1_8To1_7_6_10 protocol) {
|
||||
super(protocol, "1.8");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.OPEN_SCREEN, wrapper -> {
|
||||
final InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.OPEN_SCREEN, wrapper -> {
|
||||
final InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE); // Window id
|
||||
final short windowTypeId = InventoryTracker.getInventoryType(wrapper.read(Types.STRING)); // Window type
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE); // Window id
|
||||
final short windowTypeId = InventoryTracker.getInventoryType(wrapper.read(Types.STRING)); // Window type
|
||||
|
||||
windowTracker.getWindowTypeMap().put(windowId, windowTypeId);
|
||||
wrapper.write(Types.UNSIGNED_BYTE, windowTypeId); // Window type id
|
||||
windowTracker.getWindowTypeMap().put(windowId, windowTypeId);
|
||||
wrapper.write(Types.UNSIGNED_BYTE, windowTypeId); // Window type id
|
||||
|
||||
final JsonElement titleComponent = wrapper.read(Types.COMPONENT); // Title
|
||||
String title = ChatUtil.jsonToLegacy(titleComponent);
|
||||
title = ChatUtil.removeUnusedColor(title, '8');
|
||||
if (title.length() > 32) {
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
wrapper.write(Types.STRING, title); // Window title
|
||||
final JsonElement titleComponent = wrapper.read(Types.COMPONENT); // Title
|
||||
String title = ChatUtil.jsonToLegacy(titleComponent);
|
||||
title = ChatUtil.removeUnusedColor(title, '8');
|
||||
if (title.length() > 32) {
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
wrapper.write(Types.STRING, title); // Window title
|
||||
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Slots
|
||||
wrapper.write(Types.BOOLEAN, true); // Use provided window title
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Slots
|
||||
wrapper.write(Types.BOOLEAN, true); // Use provided window title
|
||||
|
||||
if (windowTypeId == 11) { // Horse
|
||||
wrapper.passthrough(Types.INT); // Entity id
|
||||
}
|
||||
});
|
||||
if (windowTypeId == 11) { // Horse
|
||||
wrapper.passthrough(Types.INT); // Entity id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_CLOSE, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE); // Window id
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_CLOSE, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE); // Window id
|
||||
|
||||
wrapper.user().get(InventoryTracker.class).remove(windowId);
|
||||
});
|
||||
wrapper.user().get(InventoryTracker.class).remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_SET_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Window id
|
||||
map(Types.SHORT); // Slot
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_SET_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Window id
|
||||
map(Types.SHORT); // Slot
|
||||
|
||||
handler(wrapper -> {
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(wrapper.get(Types.BYTE, 0));
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
if (slot == 1) {
|
||||
wrapper.cancel();
|
||||
} else if (slot >= 2) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot - 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
handler(wrapper -> {
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(wrapper.get(Types.BYTE, 0));
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
if (slot == 1) {
|
||||
wrapper.cancel();
|
||||
} else if (slot >= 2) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot - 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
map(Types.ITEM1_8, RewindTypes.COMPRESSED_NBT_ITEM); // item
|
||||
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(RewindTypes.COMPRESSED_NBT_ITEM, 0)));
|
||||
map(Types.ITEM1_8, RewindTypes.COMPRESSED_NBT_ITEM); // item
|
||||
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(RewindTypes.COMPRESSED_NBT_ITEM, 0)));
|
||||
|
||||
handler(wrapper -> {
|
||||
final byte windowId = wrapper.get(Types.BYTE, 0);
|
||||
if (windowId != 0) {
|
||||
return;
|
||||
}
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
if (slot < 5 || slot > 8) {
|
||||
return;
|
||||
}
|
||||
final PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
final Item item = wrapper.get(RewindTypes.COMPRESSED_NBT_ITEM, 0);
|
||||
playerSession.setPlayerEquipment(wrapper.user().getProtocolInfo().getUuid(), item, 8 - slot);
|
||||
handler(wrapper -> {
|
||||
final byte windowId = wrapper.get(Types.BYTE, 0);
|
||||
if (windowId != 0) {
|
||||
return;
|
||||
}
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
if (slot < 5 || slot > 8) {
|
||||
return;
|
||||
}
|
||||
final PlayerSessionStorage playerSession = wrapper.user().get(PlayerSessionStorage.class);
|
||||
final Item item = wrapper.get(RewindTypes.COMPRESSED_NBT_ITEM, 0);
|
||||
playerSession.setPlayerEquipment(wrapper.user().getProtocolInfo().getUuid(), item, 8 - slot);
|
||||
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_7_6_10.class);
|
||||
if (tracker.isSpectator()) { // Spectator mode didn't exist in 1.7.10
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_7_6_10.class);
|
||||
if (tracker.isSpectator()) { // Spectator mode didn't exist in 1.7.10
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_SET_CONTENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // Window id
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_SET_CONTENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // Window id
|
||||
|
||||
// remap enchantment table items
|
||||
handler(wrapper -> {
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(wrapper.get(Types.UNSIGNED_BYTE, 0));
|
||||
// remap enchantment table items
|
||||
handler(wrapper -> {
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(wrapper.get(Types.UNSIGNED_BYTE, 0));
|
||||
|
||||
Item[] items = wrapper.read(Types.ITEM1_8_SHORT_ARRAY);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
Item[] old = items;
|
||||
items = new Item[old.length - 1];
|
||||
items[0] = old[0];
|
||||
System.arraycopy(old, 2, items, 1, old.length - 2);
|
||||
}
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
wrapper.write(RewindTypes.COMPRESSED_NBT_ITEM_ARRAY, items); // Items
|
||||
});
|
||||
Item[] items = wrapper.read(Types.ITEM1_8_SHORT_ARRAY);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
Item[] old = items;
|
||||
items = new Item[old.length - 1];
|
||||
items[0] = old[0];
|
||||
System.arraycopy(old, 2, items, 1, old.length - 2);
|
||||
}
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
wrapper.write(RewindTypes.COMPRESSED_NBT_ITEM_ARRAY, items); // Items
|
||||
});
|
||||
|
||||
handler(wrapper -> {
|
||||
final short windowId = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
if (windowId != 0) {
|
||||
return;
|
||||
}
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_7_6_10.class);
|
||||
final UUID userId = wrapper.user().getProtocolInfo().getUuid();
|
||||
handler(wrapper -> {
|
||||
final short windowId = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
if (windowId != 0) {
|
||||
return;
|
||||
}
|
||||
final EntityTracker1_8 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_7_6_10.class);
|
||||
final UUID userId = wrapper.user().getProtocolInfo().getUuid();
|
||||
|
||||
final Item[] items = wrapper.get(RewindTypes.COMPRESSED_NBT_ITEM_ARRAY, 0);
|
||||
for (int i = 5; i < 9; i++) {
|
||||
wrapper.user().get(PlayerSessionStorage.class).setPlayerEquipment(userId, items[i], 8 - i);
|
||||
if (tracker.isSpectator()) {
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
if (tracker.isSpectator()) {
|
||||
final GameProfileStorage.GameProfile profile = wrapper.user().get(GameProfileStorage.class).get(userId);
|
||||
if (profile != null) {
|
||||
items[5] = profile.getSkull();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
final Item[] items = wrapper.get(RewindTypes.COMPRESSED_NBT_ITEM_ARRAY, 0);
|
||||
for (int i = 5; i < 9; i++) {
|
||||
wrapper.user().get(PlayerSessionStorage.class).setPlayerEquipment(userId, items[i], 8 - i);
|
||||
if (tracker.isSpectator()) {
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
if (tracker.isSpectator()) {
|
||||
final GameProfileStorage.GameProfile profile = wrapper.user().get(GameProfileStorage.class).get(userId);
|
||||
if (profile != null) {
|
||||
items[5] = profile.getSkull();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_SET_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // Window id
|
||||
map(Types.SHORT); // Progress bar id
|
||||
map(Types.SHORT); // Progress bar value
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CONTAINER_SET_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // Window id
|
||||
map(Types.SHORT); // Progress bar id
|
||||
map(Types.SHORT); // Progress bar value
|
||||
|
||||
handler(wrapper -> {
|
||||
final InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
handler(wrapper -> {
|
||||
final InventoryTracker windowTracker = wrapper.user().get(InventoryTracker.class);
|
||||
|
||||
final short windowId = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
final short windowType = windowTracker.get(windowId);
|
||||
final short windowId = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
final short windowType = windowTracker.get(windowId);
|
||||
|
||||
final short progressBarId = wrapper.get(Types.SHORT, 0);
|
||||
short progress = wrapper.get(Types.SHORT, 1);
|
||||
final short progressBarId = wrapper.get(Types.SHORT, 0);
|
||||
short progress = wrapper.get(Types.SHORT, 1);
|
||||
|
||||
if (windowType == 2) { // Furnace
|
||||
// TODO | Proper methods (getOrCreate)=
|
||||
final InventoryTracker.FurnaceData furnace = windowTracker.getFurnaceData().computeIfAbsent(windowId, x -> new InventoryTracker.FurnaceData());
|
||||
if (progressBarId == 0 || progressBarId == 1) {
|
||||
if (progressBarId == 0) {
|
||||
furnace.fuelLeft = progress;
|
||||
} else {
|
||||
furnace.maxFuel = progress;
|
||||
}
|
||||
if (furnace.maxFuel == 0) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
progress = (short) (200 * furnace.fuelLeft / furnace.maxFuel);
|
||||
wrapper.set(Types.SHORT, 0, (short) 1);
|
||||
wrapper.set(Types.SHORT, 1, progress);
|
||||
} else if (progressBarId == 2 || progressBarId == 3) {
|
||||
if (progressBarId == 2) {
|
||||
furnace.progress = progress;
|
||||
} else {
|
||||
furnace.maxProgress = progress;
|
||||
}
|
||||
if (furnace.maxProgress == 0) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
progress = (short) (200 * furnace.progress / furnace.maxProgress);
|
||||
wrapper.set(Types.SHORT, 0, (short) 0);
|
||||
wrapper.set(Types.SHORT, 1, progress);
|
||||
}
|
||||
} else if (windowType == 4 && progressBarId > 2) { // Enchanting Table
|
||||
wrapper.cancel();
|
||||
} else if (windowType == 8) { // Anvil
|
||||
windowTracker.levelCost = progress;
|
||||
windowTracker.anvilId = windowId;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (windowType == 2) { // Furnace
|
||||
// TODO | Proper methods (getOrCreate)=
|
||||
final InventoryTracker.FurnaceData furnace = windowTracker.getFurnaceData().computeIfAbsent(windowId, x -> new InventoryTracker.FurnaceData());
|
||||
if (progressBarId == 0 || progressBarId == 1) {
|
||||
if (progressBarId == 0) {
|
||||
furnace.fuelLeft = progress;
|
||||
} else {
|
||||
furnace.maxFuel = progress;
|
||||
}
|
||||
if (furnace.maxFuel == 0) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
progress = (short) (200 * furnace.fuelLeft / furnace.maxFuel);
|
||||
wrapper.set(Types.SHORT, 0, (short) 1);
|
||||
wrapper.set(Types.SHORT, 1, progress);
|
||||
} else if (progressBarId == 2 || progressBarId == 3) {
|
||||
if (progressBarId == 2) {
|
||||
furnace.progress = progress;
|
||||
} else {
|
||||
furnace.maxProgress = progress;
|
||||
}
|
||||
if (furnace.maxProgress == 0) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
progress = (short) (200 * furnace.progress / furnace.maxProgress);
|
||||
wrapper.set(Types.SHORT, 0, (short) 0);
|
||||
wrapper.set(Types.SHORT, 1, progress);
|
||||
}
|
||||
} else if (windowType == 4 && progressBarId > 2) { // Enchanting Table
|
||||
wrapper.cancel();
|
||||
} else if (windowType == 8) { // Anvil
|
||||
windowTracker.levelCost = progress;
|
||||
windowTracker.anvilId = windowId;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CONTAINER_CLOSE, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Types.BYTE);
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CONTAINER_CLOSE, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Types.BYTE);
|
||||
|
||||
wrapper.user().get(InventoryTracker.class).remove(windowId);
|
||||
});
|
||||
wrapper.user().get(InventoryTracker.class).remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Window id
|
||||
map(Types.SHORT); // Slot
|
||||
handler(wrapper -> {
|
||||
final byte windowId = wrapper.get(Types.BYTE, 0); // Window id
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Window id
|
||||
map(Types.SHORT); // Slot
|
||||
handler(wrapper -> {
|
||||
final byte windowId = wrapper.get(Types.BYTE, 0); // Window id
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(windowId);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
if (slot > 0) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
map(Types.BYTE); // Button
|
||||
map(Types.SHORT); // Action number
|
||||
map(Types.BYTE); // Mode
|
||||
map(RewindTypes.COMPRESSED_NBT_ITEM, Types.ITEM1_8); // Clicked item
|
||||
final short windowType = wrapper.user().get(InventoryTracker.class).get(windowId);
|
||||
if (windowType == 4) { // Enchantment Table
|
||||
if (slot > 0) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
map(Types.BYTE); // Button
|
||||
map(Types.SHORT); // Action number
|
||||
map(Types.BYTE); // Mode
|
||||
map(RewindTypes.COMPRESSED_NBT_ITEM, Types.ITEM1_8); // Clicked item
|
||||
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
|
||||
}
|
||||
});
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.SET_CREATIVE_MODE_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.SHORT); // Slot
|
||||
map(RewindTypes.COMPRESSED_NBT_ITEM, Types.ITEM1_8); // Item
|
||||
protocol.registerServerbound(ServerboundPackets1_7_2_5.SET_CREATIVE_MODE_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.SHORT); // Slot
|
||||
map(RewindTypes.COMPRESSED_NBT_ITEM, Types.ITEM1_8); // Item
|
||||
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName(), false);
|
||||
enchantmentRewriter.registerEnchantment(8, "§7Depth Strider");
|
||||
}
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName(), false);
|
||||
enchantmentRewriter.registerEnchantment(8, "§7Depth Strider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
|
||||
if (item.identifier() == 387) {
|
||||
final ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages == null) return item;
|
||||
if (item.identifier() == 387) {
|
||||
final ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages == null) return item;
|
||||
|
||||
final ListTag<StringTag> oldPages = new ListTag<>(StringTag.class);
|
||||
tag.put(nbtTagName() + "|pages", oldPages);
|
||||
final ListTag<StringTag> oldPages = new ListTag<>(StringTag.class);
|
||||
tag.put(nbtTagName() + "|pages", oldPages);
|
||||
|
||||
for (StringTag page : pages) {
|
||||
final String value = page.getValue();
|
||||
oldPages.add(new StringTag(value));
|
||||
page.setValue(ChatUtil.jsonToLegacy(value));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
for (StringTag page : pages) {
|
||||
final String value = page.getValue();
|
||||
oldPages.add(new StringTag(value));
|
||||
page.setValue(ChatUtil.jsonToLegacy(value));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(connection, item);
|
||||
@Override
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(connection, item);
|
||||
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
|
||||
if (item.identifier() == 387) {
|
||||
final ListTag<StringTag> oldPages = tag.getListTag(nbtTagName() + "|pages", StringTag.class);
|
||||
if (oldPages != null) {
|
||||
tag.remove("pages");
|
||||
tag.put("pages", oldPages);
|
||||
}
|
||||
}
|
||||
if (item.identifier() == 387) {
|
||||
final ListTag<StringTag> oldPages = tag.getListTag(nbtTagName() + "|pages", StringTag.class);
|
||||
if (oldPages != null) {
|
||||
tag.remove("pages");
|
||||
tag.put("pages", oldPages);
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
+655
-656
File diff suppressed because it is too large.
Load diff
+651
-650
File diff suppressed because it is too large.
Load diff
+196
-197
@@ -26,227 +26,226 @@ import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ScoreboardPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10> {
|
||||
|
||||
public ScoreboardPacketRewriter1_8(Protocol1_8To1_7_6_10 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
public ScoreboardPacketRewriter1_8(Protocol1_8To1_7_6_10 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_OBJECTIVE, wrapper -> {
|
||||
String name = wrapper.passthrough(Types.STRING);
|
||||
if (name.length() > 16) {
|
||||
wrapper.set(Types.STRING, 0, name = name.substring(0, 16));
|
||||
}
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_OBJECTIVE, wrapper -> {
|
||||
String name = wrapper.passthrough(Types.STRING);
|
||||
if (name.length() > 16) {
|
||||
wrapper.set(Types.STRING, 0, name = name.substring(0, 16));
|
||||
}
|
||||
|
||||
final byte mode = wrapper.read(Types.BYTE);
|
||||
ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
if (mode == 0) {
|
||||
if (scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
scoreboard.addObjective(name);
|
||||
} else if (mode == 1) {
|
||||
if (!scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
if (scoreboard.getColorIndependentSidebar() != null) {
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent()) {
|
||||
String sidebar = scoreboard.getColorDependentSidebar().get(color.get());
|
||||
if (name.equals(sidebar)) {
|
||||
final PacketWrapper sidebarPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
sidebarPacket.write(Types.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Types.STRING, scoreboard.getColorIndependentSidebar());
|
||||
sidebarPacket.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
scoreboard.removeObjective(name);
|
||||
} else if (mode == 2) {
|
||||
if (!scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
final byte mode = wrapper.read(Types.BYTE);
|
||||
ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
if (mode == 0) {
|
||||
if (scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
scoreboard.addObjective(name);
|
||||
} else if (mode == 1) {
|
||||
if (!scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
if (scoreboard.getColorIndependentSidebar() != null) {
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent()) {
|
||||
String sidebar = scoreboard.getColorDependentSidebar().get(color.get());
|
||||
if (name.equals(sidebar)) {
|
||||
final PacketWrapper sidebarPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
sidebarPacket.write(Types.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Types.STRING, scoreboard.getColorIndependentSidebar());
|
||||
sidebarPacket.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
scoreboard.removeObjective(name);
|
||||
} else if (mode == 2) {
|
||||
if (!scoreboard.objectiveExists(name)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
String displayName = wrapper.passthrough(Types.STRING);
|
||||
if (displayName.length() > 32) {
|
||||
wrapper.set(Types.STRING, 1, displayName.substring(0, 32));
|
||||
}
|
||||
wrapper.read(Types.STRING);
|
||||
} else {
|
||||
wrapper.write(Types.STRING, "");
|
||||
}
|
||||
wrapper.write(Types.BYTE, mode);
|
||||
});
|
||||
if (mode == 0 || mode == 2) {
|
||||
String displayName = wrapper.passthrough(Types.STRING);
|
||||
if (displayName.length() > 32) {
|
||||
wrapper.set(Types.STRING, 1, displayName.substring(0, 32));
|
||||
}
|
||||
wrapper.read(Types.STRING);
|
||||
} else {
|
||||
wrapper.write(Types.STRING, "");
|
||||
}
|
||||
wrapper.write(Types.BYTE, mode);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_SCORE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Name
|
||||
map(Types.VAR_INT, Types.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
byte mode = wrapper.get(Types.BYTE, 0);
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_SCORE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Name
|
||||
map(Types.VAR_INT, Types.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
byte mode = wrapper.get(Types.BYTE, 0);
|
||||
|
||||
if (mode == 1) {
|
||||
name = scoreboard.removeTeamForScore(name);
|
||||
} else {
|
||||
name = scoreboard.sendTeamForScore(name);
|
||||
}
|
||||
if (mode == 1) {
|
||||
name = scoreboard.removeTeamForScore(name);
|
||||
} else {
|
||||
name = scoreboard.sendTeamForScore(name);
|
||||
}
|
||||
|
||||
if (name.length() > 16) {
|
||||
name = ChatColorUtil.stripColor(name);
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
}
|
||||
wrapper.set(Types.STRING, 0, name);
|
||||
if (name.length() > 16) {
|
||||
name = ChatColorUtil.stripColor(name);
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
}
|
||||
wrapper.set(Types.STRING, 0, name);
|
||||
|
||||
String objective = wrapper.read(Types.STRING);
|
||||
if (objective.length() > 16) {
|
||||
objective = objective.substring(0, 16);
|
||||
}
|
||||
String objective = wrapper.read(Types.STRING);
|
||||
if (objective.length() > 16) {
|
||||
objective = objective.substring(0, 16);
|
||||
}
|
||||
|
||||
if (mode != 1) {
|
||||
int score = wrapper.read(Types.VAR_INT);
|
||||
wrapper.write(Types.STRING, objective);
|
||||
wrapper.write(Types.INT, score);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (mode != 1) {
|
||||
int score = wrapper.read(Types.VAR_INT);
|
||||
wrapper.write(Types.STRING, objective);
|
||||
wrapper.write(Types.INT, score);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_DISPLAY_OBJECTIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Position
|
||||
map(Types.STRING); // Score name
|
||||
handler(wrapper -> {
|
||||
byte position = wrapper.get(Types.BYTE, 0);
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
if (position > 2) { // team specific sidebar
|
||||
byte receiverTeamColor = (byte) (position - 3);
|
||||
scoreboard.getColorDependentSidebar().put(receiverTeamColor, name);
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_DISPLAY_OBJECTIVE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Position
|
||||
map(Types.STRING); // Score name
|
||||
handler(wrapper -> {
|
||||
byte position = wrapper.get(Types.BYTE, 0);
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
if (position > 2) { // team specific sidebar
|
||||
byte receiverTeamColor = (byte) (position - 3);
|
||||
scoreboard.getColorDependentSidebar().put(receiverTeamColor, name);
|
||||
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent() && color.get() == receiverTeamColor) {
|
||||
position = 1;
|
||||
} else {
|
||||
position = -1;
|
||||
}
|
||||
} else if (position == 1) { // team independent sidebar
|
||||
scoreboard.setColorIndependentSidebar(name);
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent() && scoreboard.getColorDependentSidebar().containsKey(color.get())) {
|
||||
position = -1;
|
||||
}
|
||||
}
|
||||
if (position == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.set(Types.BYTE, 0, position);
|
||||
});
|
||||
}
|
||||
});
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent() && color.get() == receiverTeamColor) {
|
||||
position = 1;
|
||||
} else {
|
||||
position = -1;
|
||||
}
|
||||
} else if (position == 1) { // team independent sidebar
|
||||
scoreboard.setColorIndependentSidebar(name);
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
Optional<Byte> color = scoreboard.getPlayerTeamColor(username);
|
||||
if (color.isPresent() && scoreboard.getColorDependentSidebar().containsKey(color.get())) {
|
||||
position = -1;
|
||||
}
|
||||
}
|
||||
if (position == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.set(Types.BYTE, 0, position);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_PLAYER_TEAM, wrapper -> {
|
||||
final String team = wrapper.passthrough(Types.STRING);
|
||||
if (team == null) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_PLAYER_TEAM, wrapper -> {
|
||||
final String team = wrapper.passthrough(Types.STRING);
|
||||
if (team == null) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
final ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
final ScoreboardTracker scoreboard = wrapper.user().get(ScoreboardTracker.class);
|
||||
|
||||
final byte mode = wrapper.passthrough(Types.BYTE);
|
||||
if (mode != 0 && !scoreboard.teamExists(team)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
} else if (mode == 0 && scoreboard.teamExists(team)) {
|
||||
scoreboard.removeTeam(team);
|
||||
final byte mode = wrapper.passthrough(Types.BYTE);
|
||||
if (mode != 0 && !scoreboard.teamExists(team)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
} else if (mode == 0 && scoreboard.teamExists(team)) {
|
||||
scoreboard.removeTeam(team);
|
||||
|
||||
final PacketWrapper removeTeam = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, wrapper.user());
|
||||
removeTeam.write(Types.STRING, team);
|
||||
removeTeam.write(Types.BYTE, (byte) 1);
|
||||
removeTeam.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
final PacketWrapper removeTeam = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, wrapper.user());
|
||||
removeTeam.write(Types.STRING, team);
|
||||
removeTeam.write(Types.BYTE, (byte) 1);
|
||||
removeTeam.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
|
||||
if (mode == 0) {
|
||||
scoreboard.addTeam(team);
|
||||
} else if (mode == 1) {
|
||||
scoreboard.removeTeam(team);
|
||||
}
|
||||
if (mode == 0) {
|
||||
scoreboard.addTeam(team);
|
||||
} else if (mode == 1) {
|
||||
scoreboard.removeTeam(team);
|
||||
}
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
wrapper.passthrough(Types.STRING); // Display name
|
||||
wrapper.passthrough(Types.STRING); // Prefix
|
||||
wrapper.passthrough(Types.STRING); // Suffix
|
||||
wrapper.passthrough(Types.BYTE); // Friendly fire
|
||||
wrapper.read(Types.STRING); // Name tag visibility
|
||||
byte color = wrapper.read(Types.BYTE);
|
||||
if (mode == 2 && scoreboard.getTeamColor(team).get() != color) {
|
||||
final String sidebar = scoreboard.getColorDependentSidebar().get(color);
|
||||
if (mode == 0 || mode == 2) {
|
||||
wrapper.passthrough(Types.STRING); // Display name
|
||||
wrapper.passthrough(Types.STRING); // Prefix
|
||||
wrapper.passthrough(Types.STRING); // Suffix
|
||||
wrapper.passthrough(Types.BYTE); // Friendly fire
|
||||
wrapper.read(Types.STRING); // Name tag visibility
|
||||
byte color = wrapper.read(Types.BYTE);
|
||||
if (mode == 2 && scoreboard.getTeamColor(team).get() != color) {
|
||||
final String sidebar = scoreboard.getColorDependentSidebar().get(color);
|
||||
|
||||
final PacketWrapper sidebarPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
sidebarPacket.write(Types.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Types.STRING, sidebar == null ? "" : sidebar);
|
||||
sidebarPacket.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
scoreboard.setTeamColor(team, color);
|
||||
}
|
||||
if (mode == 0 || mode == 3 || mode == 4) {
|
||||
byte color = scoreboard.getTeamColor(team).get();
|
||||
String[] entries = wrapper.read(Types.STRING_ARRAY);
|
||||
List<String> entryList = new ArrayList<>();
|
||||
final PacketWrapper sidebarPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
sidebarPacket.write(Types.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Types.STRING, sidebar == null ? "" : sidebar);
|
||||
sidebarPacket.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
scoreboard.setTeamColor(team, color);
|
||||
}
|
||||
if (mode == 0 || mode == 3 || mode == 4) {
|
||||
byte color = scoreboard.getTeamColor(team).get();
|
||||
String[] entries = wrapper.read(Types.STRING_ARRAY);
|
||||
List<String> entryList = new ArrayList<>();
|
||||
|
||||
for (String entry : entries) {
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
for (String entry : entries) {
|
||||
String username = wrapper.user().getProtocolInfo().getUsername();
|
||||
|
||||
if (mode == 4) {
|
||||
if (!scoreboard.isPlayerInTeam(entry, team)) {
|
||||
continue;
|
||||
}
|
||||
scoreboard.removePlayerFromTeam(entry, team);
|
||||
if (entry.equals(username)) {
|
||||
final PacketWrapper sidebarPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
sidebarPacket.write(Types.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Types.STRING, scoreboard.getColorIndependentSidebar() == null ? "" : scoreboard.getColorIndependentSidebar());
|
||||
sidebarPacket.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
} else {
|
||||
scoreboard.addPlayerToTeam(entry, team);
|
||||
if (entry.equals(username) && scoreboard.getColorDependentSidebar().containsKey(color)) {
|
||||
final PacketWrapper displayObjective = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
displayObjective.write(Types.BYTE, (byte) 1);
|
||||
displayObjective.write(Types.STRING, scoreboard.getColorDependentSidebar().get(color));
|
||||
displayObjective.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
}
|
||||
entryList.add(entry);
|
||||
}
|
||||
if (mode == 4) {
|
||||
if (!scoreboard.isPlayerInTeam(entry, team)) {
|
||||
continue;
|
||||
}
|
||||
scoreboard.removePlayerFromTeam(entry, team);
|
||||
if (entry.equals(username)) {
|
||||
final PacketWrapper sidebarPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
sidebarPacket.write(Types.BYTE, (byte) 1);
|
||||
sidebarPacket.write(Types.STRING, scoreboard.getColorIndependentSidebar() == null ? "" : scoreboard.getColorIndependentSidebar());
|
||||
sidebarPacket.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
} else {
|
||||
scoreboard.addPlayerToTeam(entry, team);
|
||||
if (entry.equals(username) && scoreboard.getColorDependentSidebar().containsKey(color)) {
|
||||
final PacketWrapper displayObjective = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_DISPLAY_OBJECTIVE, wrapper.user());
|
||||
displayObjective.write(Types.BYTE, (byte) 1);
|
||||
displayObjective.write(Types.STRING, scoreboard.getColorDependentSidebar().get(color));
|
||||
displayObjective.scheduleSend(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
}
|
||||
entryList.add(entry);
|
||||
}
|
||||
|
||||
wrapper.write(Types.SHORT, (short) entryList.size());
|
||||
for (String entry : entryList) {
|
||||
wrapper.write(Types.STRING, entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
wrapper.write(Types.SHORT, (short) entryList.size());
|
||||
for (String entry : entryList) {
|
||||
wrapper.write(Types.STRING, entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+221
-221
@@ -17,14 +17,15 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.rewriter;
|
||||
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.Protocol1_8To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.WorldBorderEmulator;
|
||||
import com.viaversion.viarewind.api.type.chunk.ChunkType1_7_6;
|
||||
import com.viaversion.viarewind.api.type.chunk.BulkChunkType1_7_6;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.data.Particles1_8;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viarewind.api.type.chunk.BulkChunkType1_7_6;
|
||||
import com.viaversion.viarewind.api.type.chunk.ChunkType1_7_6;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.Protocol1_8To1_7_6_10;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.data.Particles1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage.WorldBorderEmulator;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@@ -33,261 +34,260 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.FixedByteArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.BulkChunkType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
import com.viaversion.viaversion.util.IdAndData;
|
||||
|
||||
public class WorldPacketRewriter1_8 extends RewriterBase<Protocol1_8To1_7_6_10> {
|
||||
|
||||
public WorldPacketRewriter1_8(Protocol1_8To1_7_6_10 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
public WorldPacketRewriter1_8(Protocol1_8To1_7_6_10 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.LEVEL_CHUNK, wrapper -> {
|
||||
final ClientWorld world = wrapper.user().getClientWorld(Protocol1_8To1_7_6_10.class);
|
||||
final Chunk chunk = wrapper.read(ChunkType1_8.forEnvironment(world.getEnvironment()));
|
||||
protocol.getItemRewriter().handleChunk(chunk);
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_8.LEVEL_CHUNK, wrapper -> {
|
||||
final ClientWorld world = wrapper.user().getClientWorld(Protocol1_8To1_7_6_10.class);
|
||||
final Chunk chunk = wrapper.read(ChunkType1_8.forEnvironment(world.getEnvironment()));
|
||||
protocol.getItemRewriter().handleChunk(chunk);
|
||||
|
||||
wrapper.write(ChunkType1_7_6.TYPE, chunk);
|
||||
});
|
||||
wrapper.write(ChunkType1_7_6.TYPE, chunk);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.U_BYTE_POSITION); // Position
|
||||
handler(wrapper -> {
|
||||
int data = wrapper.read(Types.VAR_INT); // Block data
|
||||
data = protocol.getItemRewriter().handleBlockId(data);
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.U_BYTE_POSITION); // Position
|
||||
handler(wrapper -> {
|
||||
int data = wrapper.read(Types.VAR_INT); // Block data
|
||||
data = protocol.getItemRewriter().handleBlockId(data);
|
||||
|
||||
wrapper.write(Types.VAR_INT, IdAndData.getId(data)); // Block id
|
||||
wrapper.write(Types.UNSIGNED_BYTE, (short) IdAndData.getData(data)); // Block data
|
||||
});
|
||||
}
|
||||
});
|
||||
wrapper.write(Types.VAR_INT, IdAndData.getId(data)); // Block id
|
||||
wrapper.write(Types.UNSIGNED_BYTE, (short) IdAndData.getData(data)); // Block data
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CHUNK_BLOCKS_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Chunk x
|
||||
map(Types.INT); // Chunk z
|
||||
protocol.registerClientbound(ClientboundPackets1_8.CHUNK_BLOCKS_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Chunk x
|
||||
map(Types.INT); // Chunk z
|
||||
|
||||
handler(wrapper -> {
|
||||
final BlockChangeRecord[] records = wrapper.read(Types.BLOCK_CHANGE_ARRAY);
|
||||
handler(wrapper -> {
|
||||
final BlockChangeRecord[] records = wrapper.read(Types.BLOCK_CHANGE_ARRAY);
|
||||
|
||||
wrapper.write(Types.SHORT, (short) records.length); // Record count
|
||||
wrapper.write(Types.INT, records.length * 4); // Data array length (position + block id)
|
||||
wrapper.write(Types.SHORT, (short) records.length); // Record count
|
||||
wrapper.write(Types.INT, records.length * 4); // Data array length (position + block id)
|
||||
|
||||
for (BlockChangeRecord record : records) {
|
||||
wrapper.write(Types.SHORT, (short) (record.getSectionX() << 12 | record.getSectionZ() << 8 | record.getY())); // Position
|
||||
wrapper.write(Types.SHORT, (short) protocol.getItemRewriter().handleBlockId(record.getBlockId())); // Block id
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
for (BlockChangeRecord record : records) {
|
||||
wrapper.write(Types.SHORT, (short) (record.getSectionX() << 12 | record.getSectionZ() << 8 | record.getY())); // Position
|
||||
wrapper.write(Types.SHORT, (short) protocol.getItemRewriter().handleBlockId(record.getBlockId())); // Block id
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // Position
|
||||
map(Types.UNSIGNED_BYTE); // Type
|
||||
map(Types.UNSIGNED_BYTE); // Data
|
||||
map(Types.VAR_INT); // Block id
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // Position
|
||||
map(Types.UNSIGNED_BYTE); // Type
|
||||
map(Types.UNSIGNED_BYTE); // Data
|
||||
map(Types.VAR_INT); // Block id
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_DESTRUCTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.INT_POSITION); // Position
|
||||
map(Types.BYTE); // Progress
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_DESTRUCTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.INT_POSITION); // Position
|
||||
map(Types.BYTE); // Progress
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MAP_BULK_CHUNK, wrapper -> {
|
||||
final Chunk[] chunks = wrapper.read(BulkChunkType1_8.TYPE);
|
||||
for (Chunk chunk : chunks) {
|
||||
protocol.getItemRewriter().handleChunk(chunk);
|
||||
}
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MAP_BULK_CHUNK, wrapper -> {
|
||||
final Chunk[] chunks = wrapper.read(BulkChunkType1_8.TYPE);
|
||||
for (Chunk chunk : chunks) {
|
||||
protocol.getItemRewriter().handleChunk(chunk);
|
||||
}
|
||||
|
||||
wrapper.write(BulkChunkType1_7_6.TYPE, chunks);
|
||||
});
|
||||
wrapper.write(BulkChunkType1_7_6.TYPE, chunks);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.LEVEL_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Effect id
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.BYTE_POSITION); // Position
|
||||
map(Types.INT); // Data
|
||||
map(Types.BOOLEAN); // Disable relative volume
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.LEVEL_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Effect id
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.BYTE_POSITION); // Position
|
||||
map(Types.INT); // Data
|
||||
map(Types.BOOLEAN); // Disable relative volume
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.LEVEL_PARTICLES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int particleId = wrapper.read(Types.INT); // Particle id
|
||||
Particles1_8 particle = Particles1_8.find(particleId);
|
||||
if (particle == null) {
|
||||
particle = Particles1_8.CRIT;
|
||||
}
|
||||
wrapper.write(Types.STRING, particle.name); // Particle name
|
||||
protocol.registerClientbound(ClientboundPackets1_8.LEVEL_PARTICLES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int particleId = wrapper.read(Types.INT); // Particle id
|
||||
Particles1_8 particle = Particles1_8.find(particleId);
|
||||
if (particle == null) {
|
||||
particle = Particles1_8.CRIT;
|
||||
}
|
||||
wrapper.write(Types.STRING, particle.name); // Particle name
|
||||
|
||||
});
|
||||
read(Types.BOOLEAN); // Long distance
|
||||
map(Types.FLOAT); // X
|
||||
map(Types.FLOAT); // Y
|
||||
map(Types.FLOAT); // Z
|
||||
map(Types.FLOAT); // Offset x
|
||||
map(Types.FLOAT); // Offset y
|
||||
map(Types.FLOAT); // Offset z
|
||||
map(Types.FLOAT); // Particle data
|
||||
map(Types.INT); // Particle count
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
Particles1_8 particle = Particles1_8.find(name);
|
||||
});
|
||||
read(Types.BOOLEAN); // Long distance
|
||||
map(Types.FLOAT); // X
|
||||
map(Types.FLOAT); // Y
|
||||
map(Types.FLOAT); // Z
|
||||
map(Types.FLOAT); // Offset x
|
||||
map(Types.FLOAT); // Offset y
|
||||
map(Types.FLOAT); // Offset z
|
||||
map(Types.FLOAT); // Particle data
|
||||
map(Types.INT); // Particle count
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
Particles1_8 particle = Particles1_8.find(name);
|
||||
|
||||
if (particle == Particles1_8.ICON_CRACK || particle == Particles1_8.BLOCK_CRACK || particle == Particles1_8.BLOCK_DUST) {
|
||||
int id = wrapper.read(Types.VAR_INT);
|
||||
int data = particle == Particles1_8.ICON_CRACK ? wrapper.read(Types.VAR_INT) : id / 4096;
|
||||
id %= 4096;
|
||||
if (id >= 256 && id <= 422 || id >= 2256 && id <= 2267) { //item
|
||||
particle = Particles1_8.ICON_CRACK;
|
||||
} else if (id >= 0 && id <= 164 || id >= 170 && id <= 175) {
|
||||
if (particle == Particles1_8.ICON_CRACK)
|
||||
particle = Particles1_8.BLOCK_CRACK;
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
name = particle.name + "_" + id + "_" + data;
|
||||
}
|
||||
if (particle == Particles1_8.ICON_CRACK || particle == Particles1_8.BLOCK_CRACK || particle == Particles1_8.BLOCK_DUST) {
|
||||
int id = wrapper.read(Types.VAR_INT);
|
||||
int data = particle == Particles1_8.ICON_CRACK ? wrapper.read(Types.VAR_INT) : id / 4096;
|
||||
id %= 4096;
|
||||
if (id >= 256 && id <= 422 || id >= 2256 && id <= 2267) { //item
|
||||
particle = Particles1_8.ICON_CRACK;
|
||||
} else if (id >= 0 && id <= 164 || id >= 170 && id <= 175) {
|
||||
if (particle == Particles1_8.ICON_CRACK)
|
||||
particle = Particles1_8.BLOCK_CRACK;
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
name = particle.name + "_" + id + "_" + data;
|
||||
}
|
||||
|
||||
wrapper.set(Types.STRING, 0, name);
|
||||
});
|
||||
}
|
||||
});
|
||||
wrapper.set(Types.STRING, 0, name);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SIGN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // position
|
||||
handler(wrapper -> {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String line = wrapper.read(Types.STRING);
|
||||
line = ChatUtil.jsonToLegacy(line);
|
||||
line = ChatUtil.removeUnusedColor(line, '0');
|
||||
protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SIGN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // position
|
||||
handler(wrapper -> {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String line = wrapper.read(Types.STRING);
|
||||
line = ChatUtil.jsonToLegacy(line);
|
||||
line = ChatUtil.removeUnusedColor(line, '0');
|
||||
|
||||
if (line.length() > 15) {
|
||||
line = ChatColorUtil.stripColor(line);
|
||||
if (line.length() > 15) line = line.substring(0, 15);
|
||||
}
|
||||
wrapper.write(Types.STRING, line);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (line.length() > 15) {
|
||||
line = ChatColorUtil.stripColor(line);
|
||||
if (line.length() > 15) line = line.substring(0, 15);
|
||||
}
|
||||
wrapper.write(Types.STRING, line);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper -> {
|
||||
wrapper.cancel();
|
||||
final int id = wrapper.read(Types.VAR_INT);
|
||||
final byte scale = wrapper.read(Types.BYTE);
|
||||
protocol.registerClientbound(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper -> {
|
||||
wrapper.cancel();
|
||||
final int id = wrapper.read(Types.VAR_INT);
|
||||
final byte scale = wrapper.read(Types.BYTE);
|
||||
|
||||
final int iconCount = wrapper.read(Types.VAR_INT);
|
||||
byte[] icons = new byte[iconCount * 4];
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
final int directionAndType = wrapper.read(Types.BYTE);
|
||||
final int iconCount = wrapper.read(Types.VAR_INT);
|
||||
byte[] icons = new byte[iconCount * 4];
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
final int directionAndType = wrapper.read(Types.BYTE);
|
||||
|
||||
icons[i * 4] = (byte) (directionAndType >> 4 & 0xF);
|
||||
icons[i * 4 + 1] = wrapper.read(Types.BYTE); // x
|
||||
icons[i * 4 + 2] = wrapper.read(Types.BYTE); // z
|
||||
icons[i * 4 + 3] = (byte) (directionAndType & 0xF);
|
||||
}
|
||||
final short columns = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
if (columns > 0) {
|
||||
final short rows = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
final short x = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
final short z = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
icons[i * 4] = (byte) (directionAndType >> 4 & 0xF);
|
||||
icons[i * 4 + 1] = wrapper.read(Types.BYTE); // x
|
||||
icons[i * 4 + 2] = wrapper.read(Types.BYTE); // z
|
||||
icons[i * 4 + 3] = (byte) (directionAndType & 0xF);
|
||||
}
|
||||
final short columns = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
if (columns > 0) {
|
||||
final short rows = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
final short x = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
final short z = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
|
||||
final byte[] data = wrapper.read(Types.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int column = 0; column < columns; column++) {
|
||||
byte[] columnData = new byte[rows + 3];
|
||||
columnData[0] = 0;
|
||||
columnData[1] = (byte) (x + column);
|
||||
columnData[2] = (byte) z;
|
||||
final byte[] data = wrapper.read(Types.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int column = 0; column < columns; column++) {
|
||||
byte[] columnData = new byte[rows + 3];
|
||||
columnData[0] = 0;
|
||||
columnData[1] = (byte) (x + column);
|
||||
columnData[2] = (byte) z;
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
columnData[i + 3] = data[column + i * columns];
|
||||
}
|
||||
for (int i = 0; i < rows; i++) {
|
||||
columnData[i + 3] = data[column + i * columns];
|
||||
}
|
||||
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) columnData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(columnData.length), columnData); // data
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) columnData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(columnData.length), columnData); // data
|
||||
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
}
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
}
|
||||
|
||||
if (iconCount > 0) {
|
||||
final byte[] iconData = new byte[iconCount * 3 + 1];
|
||||
iconData[0] = 1;
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
iconData[i * 3 + 1] = (byte) (icons[i * 4] << 4 | icons[i * 4 + 3] & 0xF);
|
||||
iconData[i * 3 + 2] = icons[i * 4 + 1];
|
||||
iconData[i * 3 + 3] = icons[i * 4 + 2];
|
||||
}
|
||||
if (iconCount > 0) {
|
||||
final byte[] iconData = new byte[iconCount * 3 + 1];
|
||||
iconData[0] = 1;
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
iconData[i * 3 + 1] = (byte) (icons[i * 4] << 4 | icons[i * 4 + 3] & 0xF);
|
||||
iconData[i * 3 + 2] = icons[i * 4 + 1];
|
||||
iconData[i * 3 + 3] = icons[i * 4 + 2];
|
||||
}
|
||||
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) iconData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(iconData.length), iconData); // data
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) iconData.length); // data length
|
||||
mapData.write(new FixedByteArrayType(iconData.length), iconData); // data
|
||||
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
}
|
||||
|
||||
// Update scale
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) 2); // data length
|
||||
mapData.write(new FixedByteArrayType(2), new byte[]{2, scale}); // data
|
||||
// Update scale
|
||||
final PacketWrapper mapData = PacketWrapper.create(ClientboundPackets1_8.MAP_ITEM_DATA, wrapper.user());
|
||||
mapData.write(Types.VAR_INT, id); // map id
|
||||
mapData.write(Types.SHORT, (short) 2); // data length
|
||||
mapData.write(new FixedByteArrayType(2), new byte[]{2, scale}); // data
|
||||
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
});
|
||||
mapData.send(Protocol1_8To1_7_6_10.class);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // position
|
||||
map(Types.UNSIGNED_BYTE); // action
|
||||
map(Types.NAMED_COMPOUND_TAG, RewindTypes.COMPRESSED_NBT); // nbt
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8, RewindTypes.SHORT_POSITION); // position
|
||||
map(Types.UNSIGNED_BYTE); // action
|
||||
map(Types.NAMED_COMPOUND_TAG, RewindTypes.COMPRESSED_NBT); // nbt
|
||||
}
|
||||
});
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.CHANGE_DIFFICULTY);
|
||||
protocol.cancelClientbound(ClientboundPackets1_8.CHANGE_DIFFICULTY);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_BORDER, null, wrapper -> {
|
||||
final WorldBorderEmulator emulator = wrapper.user().get(WorldBorderEmulator.class);
|
||||
wrapper.cancel();
|
||||
protocol.registerClientbound(ClientboundPackets1_8.SET_BORDER, null, wrapper -> {
|
||||
final WorldBorderEmulator emulator = wrapper.user().get(WorldBorderEmulator.class);
|
||||
wrapper.cancel();
|
||||
|
||||
final int action = wrapper.read(Types.VAR_INT);
|
||||
if (action == 0) { // set size
|
||||
emulator.setSize(wrapper.read(Types.DOUBLE)); // radius
|
||||
} else if (action == 1) { // lerp size
|
||||
emulator.lerpSize(wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), wrapper.read(Types.VAR_LONG)); // old radius, new radius, speed
|
||||
} else if (action == 2) { // set center
|
||||
emulator.setCenter(wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE)); // x, z
|
||||
} else if (action == 3) { // initialize
|
||||
emulator.init(
|
||||
wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), // x, z
|
||||
wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), // old radius, new radius
|
||||
wrapper.read(Types.VAR_LONG) // speed
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
final int action = wrapper.read(Types.VAR_INT);
|
||||
if (action == 0) { // set size
|
||||
emulator.setSize(wrapper.read(Types.DOUBLE)); // radius
|
||||
} else if (action == 1) { // lerp size
|
||||
emulator.lerpSize(wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), wrapper.read(Types.VAR_LONG)); // old radius, new radius, speed
|
||||
} else if (action == 2) { // set center
|
||||
emulator.setCenter(wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE)); // x, z
|
||||
} else if (action == 3) { // initialize
|
||||
emulator.init(
|
||||
wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), // x, z
|
||||
wrapper.read(Types.DOUBLE), wrapper.read(Types.DOUBLE), // old radius, new radius
|
||||
wrapper.read(Types.VAR_LONG) // speed
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -24,9 +24,9 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
* @see com.viaversion.viarewind.protocol.v1_8to1_7_6_10.provider.CompressionHandlerProvider
|
||||
*/
|
||||
public class CompressionStatusTracker extends StoredObject {
|
||||
public boolean removeCompression = false;
|
||||
public boolean removeCompression = false;
|
||||
|
||||
public CompressionStatusTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public CompressionStatusTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -36,8 +36,11 @@ import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EntityTracker1_8 extends EntityTrackerBase {
|
||||
|
||||
+97
-94
@@ -17,129 +17,132 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GameProfileStorage extends StoredObject {
|
||||
private final Map<UUID, GameProfile> properties = new HashMap<>();
|
||||
private final Map<UUID, GameProfile> properties = new HashMap<>();
|
||||
|
||||
public GameProfileStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public GameProfileStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public GameProfile put(UUID uuid, String name) {
|
||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||
properties.put(uuid, gameProfile);
|
||||
return gameProfile;
|
||||
}
|
||||
public GameProfile put(UUID uuid, String name) {
|
||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||
properties.put(uuid, gameProfile);
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public GameProfile get(UUID uuid) {
|
||||
return properties.get(uuid);
|
||||
}
|
||||
public GameProfile get(UUID uuid) {
|
||||
return properties.get(uuid);
|
||||
}
|
||||
|
||||
public GameProfile get(String name, boolean ignoreCase) {
|
||||
if (ignoreCase) name = name.toLowerCase();
|
||||
public GameProfile get(String name, boolean ignoreCase) {
|
||||
if (ignoreCase) name = name.toLowerCase();
|
||||
|
||||
for (GameProfile profile : properties.values()) {
|
||||
if (profile.name == null) continue;
|
||||
for (GameProfile profile : properties.values()) {
|
||||
if (profile.name == null) continue;
|
||||
|
||||
String n = ignoreCase ? profile.name.toLowerCase() : profile.name;
|
||||
String n = ignoreCase ? profile.name.toLowerCase() : profile.name;
|
||||
|
||||
if (n.equals(name)) {
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (n.equals(name)) {
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<GameProfile> getAllWithPrefix(String prefix, boolean ignoreCase) {
|
||||
if (ignoreCase) prefix = prefix.toLowerCase();
|
||||
public List<GameProfile> getAllWithPrefix(String prefix, boolean ignoreCase) {
|
||||
if (ignoreCase) prefix = prefix.toLowerCase();
|
||||
|
||||
ArrayList<GameProfile> profiles = new ArrayList<>();
|
||||
ArrayList<GameProfile> profiles = new ArrayList<>();
|
||||
|
||||
for (GameProfile profile : properties.values()) {
|
||||
if (profile.name == null) continue;
|
||||
for (GameProfile profile : properties.values()) {
|
||||
if (profile.name == null) continue;
|
||||
|
||||
String n = ignoreCase ? profile.name.toLowerCase() : profile.name;
|
||||
String n = ignoreCase ? profile.name.toLowerCase() : profile.name;
|
||||
|
||||
if (n.startsWith(prefix)) profiles.add(profile);
|
||||
}
|
||||
if (n.startsWith(prefix)) profiles.add(profile);
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public GameProfile remove(UUID uuid) {
|
||||
return properties.remove(uuid);
|
||||
}
|
||||
public GameProfile remove(UUID uuid) {
|
||||
return properties.remove(uuid);
|
||||
}
|
||||
|
||||
|
||||
public static class GameProfile {
|
||||
public final String name;
|
||||
public final UUID uuid;
|
||||
public String displayName;
|
||||
public int ping;
|
||||
public List<Property> properties = new ArrayList<>();
|
||||
public int gamemode = 0;
|
||||
public static class GameProfile {
|
||||
public final String name;
|
||||
public final UUID uuid;
|
||||
public String displayName;
|
||||
public int ping;
|
||||
public List<Property> properties = new ArrayList<>();
|
||||
public int gamemode = 0;
|
||||
|
||||
public GameProfile(UUID uuid, String name) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
public GameProfile(UUID uuid, String name) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Item getSkull() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
CompoundTag ownerTag = new CompoundTag();
|
||||
tag.put("SkullOwner", ownerTag);
|
||||
ownerTag.put("Id", new StringTag(uuid.toString()));
|
||||
CompoundTag properties = new CompoundTag();
|
||||
ownerTag.put("Properties", properties);
|
||||
ListTag textures = new ListTag(CompoundTag.class);
|
||||
properties.put("textures", textures);
|
||||
for (Property property : this.properties) {
|
||||
if (property.name.equals("textures")) {
|
||||
CompoundTag textureTag = new CompoundTag();
|
||||
textureTag.put("Value", new StringTag(property.value));
|
||||
if (property.signature != null) {
|
||||
textureTag.put("Signature", new StringTag(property.signature));
|
||||
}
|
||||
textures.add(textureTag);
|
||||
}
|
||||
}
|
||||
public Item getSkull() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
CompoundTag ownerTag = new CompoundTag();
|
||||
tag.put("SkullOwner", ownerTag);
|
||||
ownerTag.put("Id", new StringTag(uuid.toString()));
|
||||
CompoundTag properties = new CompoundTag();
|
||||
ownerTag.put("Properties", properties);
|
||||
ListTag textures = new ListTag(CompoundTag.class);
|
||||
properties.put("textures", textures);
|
||||
for (Property property : this.properties) {
|
||||
if (property.name.equals("textures")) {
|
||||
CompoundTag textureTag = new CompoundTag();
|
||||
textureTag.put("Value", new StringTag(property.value));
|
||||
if (property.signature != null) {
|
||||
textureTag.put("Signature", new StringTag(property.signature));
|
||||
}
|
||||
textures.add(textureTag);
|
||||
}
|
||||
}
|
||||
|
||||
return new DataItem(397, (byte) 1, (short) 3, tag);
|
||||
}
|
||||
return new DataItem(397, (byte) 1, (short) 3, tag);
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
String displayName = this.displayName == null ? name : this.displayName;
|
||||
if (displayName.length() > 16) displayName = ChatUtil.removeUnusedColor(displayName, 'f');
|
||||
if (displayName.length() > 16) displayName = ChatColorUtil.stripColor(displayName);
|
||||
if (displayName.length() > 16) displayName = displayName.substring(0, 16);
|
||||
return displayName;
|
||||
}
|
||||
public String getDisplayName() {
|
||||
String displayName = this.displayName == null ? name : this.displayName;
|
||||
if (displayName.length() > 16) displayName = ChatUtil.removeUnusedColor(displayName, 'f');
|
||||
if (displayName.length() > 16) displayName = ChatColorUtil.stripColor(displayName);
|
||||
if (displayName.length() > 16) displayName = displayName.substring(0, 16);
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
public final String name;
|
||||
public final String value;
|
||||
public final String signature;
|
||||
public static class Property {
|
||||
public final String name;
|
||||
public final String value;
|
||||
public final String signature;
|
||||
|
||||
public Property(String name, String value, String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
public Property(String name, String value, String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
-46
@@ -19,66 +19,65 @@ package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InventoryTracker extends StoredObject {
|
||||
public static final Map<String, Integer> WINDOW_TYPE_REGISTRY = new HashMap<>();
|
||||
public static final Map<String, Integer> WINDOW_TYPE_REGISTRY = new HashMap<>();
|
||||
|
||||
static {
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:container", 0);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:chest", 0);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:crafting_table", 1);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:furnace", 2);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:dispenser", 3);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:enchanting_table", 4);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:brewing_stand", 5);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:villager", 6);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:beacon", 7);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:anvil", 8);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:hopper", 9);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:dropper", 10);
|
||||
WINDOW_TYPE_REGISTRY.put("EntityHorse", 11);
|
||||
}
|
||||
static {
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:container", 0);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:chest", 0);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:crafting_table", 1);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:furnace", 2);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:dispenser", 3);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:enchanting_table", 4);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:brewing_stand", 5);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:villager", 6);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:beacon", 7);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:anvil", 8);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:hopper", 9);
|
||||
WINDOW_TYPE_REGISTRY.put("minecraft:dropper", 10);
|
||||
WINDOW_TYPE_REGISTRY.put("EntityHorse", 11);
|
||||
}
|
||||
|
||||
private final HashMap<Short, Short> windowTypeMap = new HashMap<>();
|
||||
private final HashMap<Short, FurnaceData> furnaceData = new HashMap<>();
|
||||
private final HashMap<Short, Short> windowTypeMap = new HashMap<>();
|
||||
private final HashMap<Short, FurnaceData> furnaceData = new HashMap<>();
|
||||
|
||||
public short levelCost = 0;
|
||||
public short anvilId = -1;
|
||||
public short levelCost = 0;
|
||||
public short anvilId = -1;
|
||||
|
||||
public InventoryTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public InventoryTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public short get(short windowId) {
|
||||
return windowTypeMap.getOrDefault(windowId, (short) -1);
|
||||
}
|
||||
public static short getInventoryType(String name) {
|
||||
return WINDOW_TYPE_REGISTRY.getOrDefault(name, -1).shortValue();
|
||||
}
|
||||
|
||||
public void remove(short windowId) {
|
||||
windowTypeMap.remove(windowId);
|
||||
furnaceData.remove(windowId);
|
||||
}
|
||||
public short get(short windowId) {
|
||||
return windowTypeMap.getOrDefault(windowId, (short) -1);
|
||||
}
|
||||
|
||||
public static short getInventoryType(String name) {
|
||||
return WINDOW_TYPE_REGISTRY.getOrDefault(name, -1).shortValue();
|
||||
}
|
||||
public void remove(short windowId) {
|
||||
windowTypeMap.remove(windowId);
|
||||
furnaceData.remove(windowId);
|
||||
}
|
||||
|
||||
public HashMap<Short, Short> getWindowTypeMap() {
|
||||
return windowTypeMap;
|
||||
}
|
||||
public HashMap<Short, Short> getWindowTypeMap() {
|
||||
return windowTypeMap;
|
||||
}
|
||||
|
||||
public HashMap<Short, FurnaceData> getFurnaceData() {
|
||||
return furnaceData;
|
||||
}
|
||||
public HashMap<Short, FurnaceData> getFurnaceData() {
|
||||
return furnaceData;
|
||||
}
|
||||
|
||||
public static class FurnaceData {
|
||||
public static class FurnaceData {
|
||||
|
||||
public short fuelLeft = 0;
|
||||
public short maxFuel = 0;
|
||||
public short progress = 0;
|
||||
public short maxProgress = 200;
|
||||
}
|
||||
public short fuelLeft = 0;
|
||||
public short maxFuel = 0;
|
||||
public short progress = 0;
|
||||
public short maxProgress = 200;
|
||||
}
|
||||
|
||||
}
|
||||
+52
-53
@@ -20,78 +20,77 @@ package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.storage;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerSessionStorage extends StoredObject {
|
||||
|
||||
// Player abilities
|
||||
public boolean sprinting, allowFly, flying, invincible, creative;
|
||||
public float flySpeed, walkSpeed;
|
||||
// Player inventory
|
||||
private final Map<UUID, Item[]> playerEquipment = new HashMap<>();
|
||||
|
||||
// Player position, rotation and data
|
||||
private double posX, posY, posZ;
|
||||
public double receivedPosY;
|
||||
public float yaw, pitch;
|
||||
public boolean onGround;
|
||||
// Player abilities
|
||||
public boolean sprinting, allowFly, flying, invincible, creative;
|
||||
public float flySpeed, walkSpeed;
|
||||
public double receivedPosY;
|
||||
public float yaw, pitch;
|
||||
public boolean onGround;
|
||||
|
||||
// Player inventory
|
||||
private final Map<UUID, Item[]> playerEquipment = new HashMap<>();
|
||||
// Player position, rotation and data
|
||||
private double posX, posY, posZ;
|
||||
|
||||
public PlayerSessionStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public PlayerSessionStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public byte combineAbilities() {
|
||||
byte flags = 0;
|
||||
public byte combineAbilities() {
|
||||
byte flags = 0;
|
||||
|
||||
if (invincible) flags |= 8;
|
||||
if (allowFly) flags |= 4;
|
||||
if (flying) flags |= 2;
|
||||
if (creative) flags |= 1;
|
||||
if (invincible) flags |= 8;
|
||||
if (allowFly) flags |= 4;
|
||||
if (flying) flags |= 2;
|
||||
if (creative) flags |= 1;
|
||||
|
||||
return flags;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
public double getPosX() {
|
||||
return posX;
|
||||
}
|
||||
public double getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public double getPosY() {
|
||||
return posY;
|
||||
}
|
||||
public double getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
public double getPosZ() {
|
||||
return posZ;
|
||||
}
|
||||
public double getPosZ() {
|
||||
return posZ;
|
||||
}
|
||||
|
||||
public void setPos(double x, double y, double z) {
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
}
|
||||
public void setPos(double x, double y, double z) {
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
}
|
||||
|
||||
public Item getPlayerEquipment(final UUID uuid, final int slot) {
|
||||
final Item[] items = playerEquipment.get(uuid);
|
||||
if (items == null || slot < 0 || slot >= items.length) {
|
||||
return null;
|
||||
}
|
||||
public Item getPlayerEquipment(final UUID uuid, final int slot) {
|
||||
final Item[] items = playerEquipment.get(uuid);
|
||||
if (items == null || slot < 0 || slot >= items.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return items[slot];
|
||||
}
|
||||
return items[slot];
|
||||
}
|
||||
|
||||
public void setPlayerEquipment(final UUID uuid, final Item equipment, final int slot) {
|
||||
final Item[] items = playerEquipment.computeIfAbsent(uuid, it -> new Item[5]);
|
||||
if (slot < 0 || slot >= items.length) {
|
||||
return;
|
||||
}
|
||||
public void setPlayerEquipment(final UUID uuid, final Item equipment, final int slot) {
|
||||
final Item[] items = playerEquipment.computeIfAbsent(uuid, it -> new Item[5]);
|
||||
if (slot < 0 || slot >= items.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
items[slot] = equipment;
|
||||
}
|
||||
items[slot] = equipment;
|
||||
}
|
||||
|
||||
public Map<UUID, Item[]> getPlayerEquipment() {
|
||||
return playerEquipment;
|
||||
}
|
||||
public Map<UUID, Item[]> getPlayerEquipment() {
|
||||
return playerEquipment;
|
||||
}
|
||||
}
|
||||
+134
-130
@@ -23,163 +23,167 @@ import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ScoreboardTracker extends StoredObject {
|
||||
private final HashMap<String, List<String>> teams = new HashMap<>();
|
||||
private final HashSet<String> objectives = new HashSet<>();
|
||||
private final HashMap<String, ScoreTeam> scoreTeams = new HashMap<>();
|
||||
private final HashMap<String, Byte> teamColors = new HashMap<>();
|
||||
private final HashSet<String> scoreTeamNames = new HashSet<>();
|
||||
private String colorIndependentSidebar;
|
||||
private final HashMap<Byte, String> colorDependentSidebar = new HashMap<>();
|
||||
private final HashMap<String, List<String>> teams = new HashMap<>();
|
||||
private final HashSet<String> objectives = new HashSet<>();
|
||||
private final HashMap<String, ScoreTeam> scoreTeams = new HashMap<>();
|
||||
private final HashMap<String, Byte> teamColors = new HashMap<>();
|
||||
private final HashSet<String> scoreTeamNames = new HashSet<>();
|
||||
private final HashMap<Byte, String> colorDependentSidebar = new HashMap<>();
|
||||
private String colorIndependentSidebar;
|
||||
|
||||
public ScoreboardTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public ScoreboardTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void addPlayerToTeam(String player, String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>()).add(player);
|
||||
}
|
||||
public void addPlayerToTeam(String player, String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>()).add(player);
|
||||
}
|
||||
|
||||
public void setTeamColor(String team, Byte color) {
|
||||
teamColors.put(team, color);
|
||||
}
|
||||
public void setTeamColor(String team, Byte color) {
|
||||
teamColors.put(team, color);
|
||||
}
|
||||
|
||||
public Optional<Byte> getTeamColor(String team) {
|
||||
return Optional.ofNullable(teamColors.get(team));
|
||||
}
|
||||
public Optional<Byte> getTeamColor(String team) {
|
||||
return Optional.ofNullable(teamColors.get(team));
|
||||
}
|
||||
|
||||
public void addTeam(String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>());
|
||||
}
|
||||
public void addTeam(String team) {
|
||||
teams.computeIfAbsent(team, key -> new ArrayList<>());
|
||||
}
|
||||
|
||||
public void removeTeam(String team) {
|
||||
teams.remove(team);
|
||||
scoreTeams.remove(team);
|
||||
teamColors.remove(team);
|
||||
}
|
||||
public void removeTeam(String team) {
|
||||
teams.remove(team);
|
||||
scoreTeams.remove(team);
|
||||
teamColors.remove(team);
|
||||
}
|
||||
|
||||
public boolean teamExists(String team) {
|
||||
return teams.containsKey(team);
|
||||
}
|
||||
public boolean teamExists(String team) {
|
||||
return teams.containsKey(team);
|
||||
}
|
||||
|
||||
public void removePlayerFromTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
if (teamPlayers != null) teamPlayers.remove(player);
|
||||
}
|
||||
public void removePlayerFromTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
if (teamPlayers != null) teamPlayers.remove(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
return teamPlayers != null && teamPlayers.contains(player);
|
||||
}
|
||||
public boolean isPlayerInTeam(String player, String team) {
|
||||
List<String> teamPlayers = teams.get(team);
|
||||
return teamPlayers != null && teamPlayers.contains(player);
|
||||
}
|
||||
|
||||
public boolean isPlayerInTeam(String player) {
|
||||
for (List<String> teamPlayers : teams.values()) {
|
||||
if (teamPlayers.contains(player)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isPlayerInTeam(String player) {
|
||||
for (List<String> teamPlayers : teams.values()) {
|
||||
if (teamPlayers.contains(player)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Optional<Byte> getPlayerTeamColor(String player) {
|
||||
Optional<String> team = getTeam(player);
|
||||
return team.isPresent() ? getTeamColor(team.get()) : Optional.empty();
|
||||
}
|
||||
public Optional<Byte> getPlayerTeamColor(String player) {
|
||||
Optional<String> team = getTeam(player);
|
||||
return team.isPresent() ? getTeamColor(team.get()) : Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<String> getTeam(String player) {
|
||||
for (Map.Entry<String, List<String>> entry : teams.entrySet())
|
||||
if (entry.getValue().contains(player))
|
||||
return Optional.of(entry.getKey());
|
||||
return Optional.empty();
|
||||
}
|
||||
public Optional<String> getTeam(String player) {
|
||||
for (Map.Entry<String, List<String>> entry : teams.entrySet())
|
||||
if (entry.getValue().contains(player))
|
||||
return Optional.of(entry.getKey());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void addObjective(String name) {
|
||||
objectives.add(name);
|
||||
}
|
||||
public void addObjective(String name) {
|
||||
objectives.add(name);
|
||||
}
|
||||
|
||||
public void removeObjective(String name) {
|
||||
objectives.remove(name);
|
||||
colorDependentSidebar.values().remove(name);
|
||||
if (name.equals(colorIndependentSidebar)) {
|
||||
colorIndependentSidebar = null;
|
||||
}
|
||||
}
|
||||
public void removeObjective(String name) {
|
||||
objectives.remove(name);
|
||||
colorDependentSidebar.values().remove(name);
|
||||
if (name.equals(colorIndependentSidebar)) {
|
||||
colorIndependentSidebar = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean objectiveExists(String name) {
|
||||
return objectives.contains(name);
|
||||
}
|
||||
public boolean objectiveExists(String name) {
|
||||
return objectives.contains(name);
|
||||
}
|
||||
|
||||
public String sendTeamForScore(String score) {
|
||||
if (score.length() <= 16) return score;
|
||||
if (scoreTeams.containsKey(score)) return scoreTeams.get(score).name;
|
||||
int l = 16;
|
||||
int i = Math.min(16, score.length() - 16);
|
||||
String name = score.substring(i, i + l);
|
||||
while (scoreTeamNames.contains(name) || teams.containsKey(name)) {
|
||||
i--;
|
||||
while (score.length() - l - i > 16) {
|
||||
l--;
|
||||
if (l < 1) return score;
|
||||
i = Math.min(16, score.length() - l);
|
||||
}
|
||||
name = score.substring(i, i + l);
|
||||
}
|
||||
String prefix = score.substring(0, i);
|
||||
String suffix = i + l >= score.length() ? "" : score.substring(i + l);
|
||||
public String sendTeamForScore(String score) {
|
||||
if (score.length() <= 16) return score;
|
||||
if (scoreTeams.containsKey(score)) return scoreTeams.get(score).name;
|
||||
int l = 16;
|
||||
int i = Math.min(16, score.length() - 16);
|
||||
String name = score.substring(i, i + l);
|
||||
while (scoreTeamNames.contains(name) || teams.containsKey(name)) {
|
||||
i--;
|
||||
while (score.length() - l - i > 16) {
|
||||
l--;
|
||||
if (l < 1) return score;
|
||||
i = Math.min(16, score.length() - l);
|
||||
}
|
||||
name = score.substring(i, i + l);
|
||||
}
|
||||
String prefix = score.substring(0, i);
|
||||
String suffix = i + l >= score.length() ? "" : score.substring(i + l);
|
||||
|
||||
ScoreTeam scoreTeam = new ScoreTeam(name, prefix, suffix);
|
||||
scoreTeams.put(score, scoreTeam);
|
||||
scoreTeamNames.add(name);
|
||||
ScoreTeam scoreTeam = new ScoreTeam(name, prefix, suffix);
|
||||
scoreTeams.put(score, scoreTeam);
|
||||
scoreTeamNames.add(name);
|
||||
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, getUser());
|
||||
teamPacket.write(Types.STRING, name);
|
||||
teamPacket.write(Types.BYTE, (byte) 0);
|
||||
teamPacket.write(Types.STRING, "ViaRewind");
|
||||
teamPacket.write(Types.STRING, prefix);
|
||||
teamPacket.write(Types.STRING, suffix);
|
||||
teamPacket.write(Types.BYTE, (byte) 0);
|
||||
teamPacket.write(Types.SHORT, (short) 1);
|
||||
teamPacket.write(Types.STRING, name);
|
||||
teamPacket.send(Protocol1_8To1_7_6_10.class);
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, getUser());
|
||||
teamPacket.write(Types.STRING, name);
|
||||
teamPacket.write(Types.BYTE, (byte) 0);
|
||||
teamPacket.write(Types.STRING, "ViaRewind");
|
||||
teamPacket.write(Types.STRING, prefix);
|
||||
teamPacket.write(Types.STRING, suffix);
|
||||
teamPacket.write(Types.BYTE, (byte) 0);
|
||||
teamPacket.write(Types.SHORT, (short) 1);
|
||||
teamPacket.write(Types.STRING, name);
|
||||
teamPacket.send(Protocol1_8To1_7_6_10.class);
|
||||
|
||||
return name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String removeTeamForScore(String score) {
|
||||
ScoreTeam scoreTeam = scoreTeams.remove(score);
|
||||
if (scoreTeam == null) return score;
|
||||
scoreTeamNames.remove(scoreTeam.name);
|
||||
public String removeTeamForScore(String score) {
|
||||
ScoreTeam scoreTeam = scoreTeams.remove(score);
|
||||
if (scoreTeam == null) return score;
|
||||
scoreTeamNames.remove(scoreTeam.name);
|
||||
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, getUser());
|
||||
teamPacket.write(Types.STRING, scoreTeam.name);
|
||||
teamPacket.write(Types.BYTE, (byte) 1);
|
||||
teamPacket.send(Protocol1_8To1_7_6_10.class);
|
||||
PacketWrapper teamPacket = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_PLAYER_TEAM, getUser());
|
||||
teamPacket.write(Types.STRING, scoreTeam.name);
|
||||
teamPacket.write(Types.BYTE, (byte) 1);
|
||||
teamPacket.send(Protocol1_8To1_7_6_10.class);
|
||||
|
||||
return scoreTeam.name;
|
||||
}
|
||||
return scoreTeam.name;
|
||||
}
|
||||
|
||||
public String getColorIndependentSidebar() {
|
||||
return this.colorIndependentSidebar;
|
||||
}
|
||||
public String getColorIndependentSidebar() {
|
||||
return this.colorIndependentSidebar;
|
||||
}
|
||||
|
||||
public HashMap<Byte, String> getColorDependentSidebar() {
|
||||
return this.colorDependentSidebar;
|
||||
}
|
||||
public void setColorIndependentSidebar(String colorIndependentSidebar) {
|
||||
this.colorIndependentSidebar = colorIndependentSidebar;
|
||||
}
|
||||
|
||||
public void setColorIndependentSidebar(String colorIndependentSidebar) {
|
||||
this.colorIndependentSidebar = colorIndependentSidebar;
|
||||
}
|
||||
public HashMap<Byte, String> getColorDependentSidebar() {
|
||||
return this.colorDependentSidebar;
|
||||
}
|
||||
|
||||
private static class ScoreTeam {
|
||||
private final String prefix;
|
||||
private final String suffix;
|
||||
private final String name;
|
||||
private static class ScoreTeam {
|
||||
private final String prefix;
|
||||
private final String suffix;
|
||||
private final String name;
|
||||
|
||||
public ScoreTeam(String name, String prefix, String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
public ScoreTeam(String name, String prefix, String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
-62
@@ -21,87 +21,87 @@ import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public class WorldBorderEmulator extends StoredObject {
|
||||
private double x, z;
|
||||
private double oldDiameter, newDiameter;
|
||||
private double x, z;
|
||||
private double oldDiameter, newDiameter;
|
||||
|
||||
private long lerpTime;
|
||||
private long lerpStartTime;
|
||||
private long lerpTime;
|
||||
private long lerpStartTime;
|
||||
|
||||
private boolean init = false;
|
||||
private boolean init = false;
|
||||
|
||||
public WorldBorderEmulator(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public WorldBorderEmulator(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void init(double x, double z, double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
public void init(double x, double z, double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
|
||||
this.lerpTime = lerpTime;
|
||||
this.lerpTime = lerpTime;
|
||||
|
||||
init = true;
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
||||
public void setCenter(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
public void setCenter(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void lerpSize(double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
this.lerpTime = lerpTime;
|
||||
this.lerpStartTime = System.currentTimeMillis();
|
||||
}
|
||||
public void lerpSize(double oldDiameter, double newDiameter, long lerpTime) {
|
||||
this.oldDiameter = oldDiameter;
|
||||
this.newDiameter = newDiameter;
|
||||
this.lerpTime = lerpTime;
|
||||
this.lerpStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setSize(double size) {
|
||||
this.oldDiameter = size;
|
||||
this.newDiameter = size;
|
||||
public double getSize() {
|
||||
if (lerpTime == 0) {
|
||||
return newDiameter;
|
||||
}
|
||||
|
||||
this.lerpTime = 0;
|
||||
}
|
||||
double percent = ((double) (System.currentTimeMillis() - lerpStartTime) / (double) (lerpTime));
|
||||
|
||||
public double getSize() {
|
||||
if (lerpTime == 0) {
|
||||
return newDiameter;
|
||||
}
|
||||
// Clamp value
|
||||
if (percent > 1.0D) percent = 1.0d;
|
||||
else if (percent < 0.0D) percent = 0.0d;
|
||||
|
||||
double percent = ((double) (System.currentTimeMillis() - lerpStartTime) / (double) (lerpTime));
|
||||
return oldDiameter + (newDiameter - oldDiameter) * percent;
|
||||
}
|
||||
|
||||
// Clamp value
|
||||
if (percent > 1.0D) percent = 1.0d;
|
||||
else if (percent < 0.0D) percent = 0.0d;
|
||||
public void setSize(double size) {
|
||||
this.oldDiameter = size;
|
||||
this.newDiameter = size;
|
||||
|
||||
return oldDiameter + (newDiameter - oldDiameter) * percent;
|
||||
}
|
||||
this.lerpTime = 0;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean isInit() {
|
||||
return init;
|
||||
}
|
||||
public boolean isInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
public enum Side {
|
||||
NORTH(0, -1),
|
||||
EAST(1, 0),
|
||||
SOUTH(0, 1),
|
||||
WEST(-1, 0);
|
||||
public enum Side {
|
||||
NORTH(0, -1),
|
||||
EAST(1, 0),
|
||||
SOUTH(0, 1),
|
||||
WEST(-1, 0);
|
||||
|
||||
public final int modX;
|
||||
public final int modZ;
|
||||
public final int modX;
|
||||
public final int modZ;
|
||||
|
||||
Side(int modX, int modZ) {
|
||||
this.modX = modX;
|
||||
this.modZ = modZ;
|
||||
}
|
||||
}
|
||||
Side(int modX, int modZ) {
|
||||
this.modX = modX;
|
||||
this.modZ = modZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-52
@@ -26,70 +26,69 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldBorderUpdateTask implements Runnable {
|
||||
public static final int VIEW_DISTANCE = 16;
|
||||
public static final int VIEW_DISTANCE = 16;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
final WorldBorderEmulator worldBorderEmulatorTracker = connection.get(WorldBorderEmulator.class);
|
||||
if (!worldBorderEmulatorTracker.isInit()) continue;
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
final WorldBorderEmulator worldBorderEmulatorTracker = connection.get(WorldBorderEmulator.class);
|
||||
if (!worldBorderEmulatorTracker.isInit()) continue;
|
||||
|
||||
final PlayerSessionStorage playerSession = connection.get(PlayerSessionStorage.class);
|
||||
final PlayerSessionStorage playerSession = connection.get(PlayerSessionStorage.class);
|
||||
|
||||
double radius = worldBorderEmulatorTracker.getSize() / 2.0;
|
||||
double radius = worldBorderEmulatorTracker.getSize() / 2.0;
|
||||
|
||||
for (WorldBorderEmulator.Side side : WorldBorderEmulator.Side.values()) {
|
||||
double d;
|
||||
double pos;
|
||||
double center;
|
||||
if (side.modX != 0) {
|
||||
pos = playerSession.getPosZ();
|
||||
center = worldBorderEmulatorTracker.getZ();
|
||||
d = Math.abs(worldBorderEmulatorTracker.getX() + radius * side.modX - playerSession.getPosX());
|
||||
} else {
|
||||
center = worldBorderEmulatorTracker.getX();
|
||||
pos = playerSession.getPosX();
|
||||
d = Math.abs(worldBorderEmulatorTracker.getZ() + radius * side.modZ - playerSession.getPosZ());
|
||||
}
|
||||
if (d >= VIEW_DISTANCE) continue;
|
||||
for (WorldBorderEmulator.Side side : WorldBorderEmulator.Side.values()) {
|
||||
double d;
|
||||
double pos;
|
||||
double center;
|
||||
if (side.modX != 0) {
|
||||
pos = playerSession.getPosZ();
|
||||
center = worldBorderEmulatorTracker.getZ();
|
||||
d = Math.abs(worldBorderEmulatorTracker.getX() + radius * side.modX - playerSession.getPosX());
|
||||
} else {
|
||||
center = worldBorderEmulatorTracker.getX();
|
||||
pos = playerSession.getPosX();
|
||||
d = Math.abs(worldBorderEmulatorTracker.getZ() + radius * side.modZ - playerSession.getPosZ());
|
||||
}
|
||||
if (d >= VIEW_DISTANCE) continue;
|
||||
|
||||
double r = Math.sqrt(VIEW_DISTANCE * VIEW_DISTANCE - d * d);
|
||||
double r = Math.sqrt(VIEW_DISTANCE * VIEW_DISTANCE - d * d);
|
||||
|
||||
double minH = Math.ceil(pos - r);
|
||||
double maxH = Math.floor(pos + r);
|
||||
double minV = Math.ceil(playerSession.getPosY() - r);
|
||||
double maxV = Math.floor(playerSession.getPosY() + r);
|
||||
double minH = Math.ceil(pos - r);
|
||||
double maxH = Math.floor(pos + r);
|
||||
double minV = Math.ceil(playerSession.getPosY() - r);
|
||||
double maxV = Math.floor(playerSession.getPosY() + r);
|
||||
|
||||
if (minH < center - radius) minH = Math.ceil(center - radius);
|
||||
if (maxH > center + radius) maxH = Math.floor(center + radius);
|
||||
if (minV < 0.0) minV = 0.0;
|
||||
if (minH < center - radius) minH = Math.ceil(center - radius);
|
||||
if (maxH > center + radius) maxH = Math.floor(center + radius);
|
||||
if (minV < 0.0) minV = 0.0;
|
||||
|
||||
double centerH = (minH + maxH) / 2.0;
|
||||
double centerV = (minV + maxV) / 2.0;
|
||||
double centerH = (minH + maxH) / 2.0;
|
||||
double centerV = (minV + maxV) / 2.0;
|
||||
|
||||
double particleOffset = 2.5;
|
||||
double particleOffset = 2.5;
|
||||
|
||||
final PacketWrapper spawnParticle = PacketWrapper.create(ClientboundPackets1_8.LEVEL_PARTICLES, connection);
|
||||
spawnParticle.write(Types.STRING, ViaRewind.getConfig().getWorldBorderParticle()); // particle name
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX != 0 ? worldBorderEmulatorTracker.getX() + (radius * side.modX) : centerH)); // x
|
||||
spawnParticle.write(Types.FLOAT, (float) centerV); // y
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX == 0 ? worldBorderEmulatorTracker.getZ() + (radius * side.modZ) : centerH)); // z
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX != 0 ? 0f : (maxH - minH) / particleOffset)); // offset x
|
||||
spawnParticle.write(Types.FLOAT, (float) ((maxV - minV) / particleOffset)); // offset y
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX == 0 ? 0f : (maxH - minH) / particleOffset)); // offset z
|
||||
spawnParticle.write(Types.FLOAT, 0F); // particle data
|
||||
spawnParticle.write(Types.INT, (int) Math.floor((maxH - minH) * (maxV - minV) * 0.5));
|
||||
final PacketWrapper spawnParticle = PacketWrapper.create(ClientboundPackets1_8.LEVEL_PARTICLES, connection);
|
||||
spawnParticle.write(Types.STRING, ViaRewind.getConfig().getWorldBorderParticle()); // particle name
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX != 0 ? worldBorderEmulatorTracker.getX() + (radius * side.modX) : centerH)); // x
|
||||
spawnParticle.write(Types.FLOAT, (float) centerV); // y
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX == 0 ? worldBorderEmulatorTracker.getZ() + (radius * side.modZ) : centerH)); // z
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX != 0 ? 0f : (maxH - minH) / particleOffset)); // offset x
|
||||
spawnParticle.write(Types.FLOAT, (float) ((maxV - minV) / particleOffset)); // offset y
|
||||
spawnParticle.write(Types.FLOAT, (float) (side.modX == 0 ? 0f : (maxH - minH) / particleOffset)); // offset z
|
||||
spawnParticle.write(Types.FLOAT, 0F); // particle data
|
||||
spawnParticle.write(Types.INT, (int) Math.floor((maxH - minH) * (maxV - minV) * 0.5));
|
||||
|
||||
try {
|
||||
spawnParticle.send(Protocol1_8To1_7_6_10.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send world border particle", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
spawnParticle.send(Protocol1_8To1_7_6_10.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send world border particle", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
-61
@@ -19,93 +19,100 @@ package com.viaversion.viarewind.protocol.v1_9to1_8;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.data.RewindMappingData1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.rewriter.BlockItemPacketRewriter1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.rewriter.EntityPacketRewriter1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.rewriter.*;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.*;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.rewriter.PlayerPacketRewriter1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.rewriter.WorldPacketRewriter1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.BlockPlaceDestroyTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.BossBarStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.CooldownStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.EntityTracker1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.LevitationStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.PlayerPositionTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.WindowTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.task.CooldownIndicatorTask;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.task.LevitationUpdateTask;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_9;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Protocol1_9To1_8 extends BackwardsProtocol<ClientboundPackets1_9, ClientboundPackets1_8, ServerboundPackets1_9, ServerboundPackets1_8> {
|
||||
|
||||
public static final ValueTransformer<Double, Integer> DOUBLE_TO_INT_TIMES_32 = new ValueTransformer<>(Types.INT) {
|
||||
@Override
|
||||
public Integer transform(PacketWrapper wrapper, Double inputValue) {
|
||||
return (int) (inputValue * 32.0D);
|
||||
}
|
||||
};
|
||||
public static final ValueTransformer<Float, Byte> DEGREES_TO_ANGLE = new ValueTransformer<>(Types.BYTE) {
|
||||
@Override
|
||||
public Byte transform(PacketWrapper packetWrapper, Float degrees) {
|
||||
return (byte) ((degrees / 360F) * 256);
|
||||
}
|
||||
};
|
||||
public static final ValueTransformer<Double, Integer> DOUBLE_TO_INT_TIMES_32 = new ValueTransformer<>(Types.INT) {
|
||||
@Override
|
||||
public Integer transform(PacketWrapper wrapper, Double inputValue) {
|
||||
return (int) (inputValue * 32.0D);
|
||||
}
|
||||
};
|
||||
public static final ValueTransformer<Float, Byte> DEGREES_TO_ANGLE = new ValueTransformer<>(Types.BYTE) {
|
||||
@Override
|
||||
public Byte transform(PacketWrapper packetWrapper, Float degrees) {
|
||||
return (byte) ((degrees / 360F) * 256);
|
||||
}
|
||||
};
|
||||
|
||||
public static final RewindMappingData1_8 MAPPINGS = new RewindMappingData1_8();
|
||||
public static final RewindMappingData1_8 MAPPINGS = new RewindMappingData1_8();
|
||||
|
||||
private final BlockItemPacketRewriter1_9 itemRewriter = new BlockItemPacketRewriter1_9(this);
|
||||
private final EntityPacketRewriter1_9 entityRewriter = new EntityPacketRewriter1_9(this);
|
||||
private final BlockItemPacketRewriter1_9 itemRewriter = new BlockItemPacketRewriter1_9(this);
|
||||
private final EntityPacketRewriter1_9 entityRewriter = new EntityPacketRewriter1_9(this);
|
||||
|
||||
public Protocol1_9To1_8() {
|
||||
super(ClientboundPackets1_9.class, ClientboundPackets1_8.class, ServerboundPackets1_9.class, ServerboundPackets1_8.class);
|
||||
}
|
||||
public Protocol1_9To1_8() {
|
||||
super(ClientboundPackets1_9.class, ClientboundPackets1_8.class, ServerboundPackets1_9.class, ServerboundPackets1_8.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
entityRewriter.register();
|
||||
itemRewriter.register();
|
||||
new PlayerPacketRewriter1_9(this).register();
|
||||
new WorldPacketRewriter1_9(this).register();
|
||||
}
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
entityRewriter.register();
|
||||
itemRewriter.register();
|
||||
new PlayerPacketRewriter1_9(this).register();
|
||||
new WorldPacketRewriter1_9(this).register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
connection.addEntityTracker(this.getClass(), new EntityTracker1_9(connection));
|
||||
connection.addClientWorld(this.getClass(), new ClientWorld());
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
connection.addEntityTracker(this.getClass(), new EntityTracker1_9(connection));
|
||||
connection.addClientWorld(this.getClass(), new ClientWorld());
|
||||
|
||||
connection.put(new WindowTracker(connection));
|
||||
connection.put(new LevitationStorage());
|
||||
connection.put(new PlayerPositionTracker());
|
||||
connection.put(new CooldownStorage());
|
||||
connection.put(new BlockPlaceDestroyTracker());
|
||||
connection.put(new BossBarStorage(connection));
|
||||
}
|
||||
connection.put(new WindowTracker(connection));
|
||||
connection.put(new LevitationStorage());
|
||||
connection.put(new PlayerPositionTracker());
|
||||
connection.put(new CooldownStorage());
|
||||
connection.put(new BlockPlaceDestroyTracker());
|
||||
connection.put(new BossBarStorage(connection));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ViaProviders providers) {
|
||||
Via.getManager().getScheduler().scheduleRepeating(new LevitationUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
Via.getManager().getScheduler().scheduleRepeating(new CooldownIndicatorTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
@Override
|
||||
public void register(ViaProviders providers) {
|
||||
Via.getManager().getScheduler().scheduleRepeating(new LevitationUpdateTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
Via.getManager().getScheduler().scheduleRepeating(new CooldownIndicatorTask(), 0L, 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RewindMappingData1_8 getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
@Override
|
||||
public RewindMappingData1_8 getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPacketRewriter1_9 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
@Override
|
||||
public BlockItemPacketRewriter1_9 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketRewriter1_9 getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
@Override
|
||||
public EntityPacketRewriter1_9 getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -25,26 +25,26 @@ import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
public class ActionBarVisualization implements CooldownVisualization {
|
||||
private final UserConnection user;
|
||||
private final UserConnection user;
|
||||
|
||||
public ActionBarVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
public ActionBarVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
sendActionBar(CooldownVisualization.buildProgressText("■", progress));
|
||||
}
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
sendActionBar(CooldownVisualization.buildProgressText("■", progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
sendActionBar("§r");
|
||||
}
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
sendActionBar("§r");
|
||||
}
|
||||
|
||||
private void sendActionBar(final String bar) {
|
||||
PacketWrapper actionBarPacket = PacketWrapper.create(ClientboundPackets1_8.CHAT, user);
|
||||
actionBarPacket.write(Types.COMPONENT, new JsonPrimitive(bar));
|
||||
actionBarPacket.write(Types.BYTE, (byte) 2); // Position - above hotbar
|
||||
actionBarPacket.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
private void sendActionBar(final String bar) {
|
||||
PacketWrapper actionBarPacket = PacketWrapper.create(ClientboundPackets1_8.CHAT, user);
|
||||
actionBarPacket.write(Types.COMPONENT, new JsonPrimitive(bar));
|
||||
actionBarPacket.write(Types.BYTE, (byte) 2); // Position - above hotbar
|
||||
actionBarPacket.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
}
|
||||
+35
-36
@@ -23,46 +23,45 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BossBarVisualization implements CooldownVisualization {
|
||||
private final UserConnection user;
|
||||
private UUID bossUUID;
|
||||
private final UserConnection user;
|
||||
private UUID bossUUID;
|
||||
|
||||
public BossBarVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
public BossBarVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
final PacketWrapper setBossbar = PacketWrapper.create(ClientboundPackets1_9.BOSS_EVENT, user);
|
||||
if (bossUUID == null) {
|
||||
bossUUID = UUID.randomUUID();
|
||||
setBossbar.write(Types.UUID, bossUUID);
|
||||
setBossbar.write(Types.VAR_INT, 0); // Action - add
|
||||
setBossbar.write(Types.COMPONENT, new JsonPrimitive(" ")); // Title
|
||||
setBossbar.write(Types.FLOAT, (float) progress); // Health
|
||||
setBossbar.write(Types.VAR_INT, 0); // Color
|
||||
setBossbar.write(Types.VAR_INT, 0); // Division
|
||||
setBossbar.write(Types.UNSIGNED_BYTE, (short) 0); // Flags
|
||||
} else {
|
||||
setBossbar.write(Types.UUID, bossUUID);
|
||||
setBossbar.write(Types.VAR_INT, 2); // Action - update health
|
||||
setBossbar.write(Types.FLOAT, (float) progress); // Health
|
||||
}
|
||||
setBossbar.send(Protocol1_9To1_8.class, false);
|
||||
}
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
final PacketWrapper setBossbar = PacketWrapper.create(ClientboundPackets1_9.BOSS_EVENT, user);
|
||||
if (bossUUID == null) {
|
||||
bossUUID = UUID.randomUUID();
|
||||
setBossbar.write(Types.UUID, bossUUID);
|
||||
setBossbar.write(Types.VAR_INT, 0); // Action - add
|
||||
setBossbar.write(Types.COMPONENT, new JsonPrimitive(" ")); // Title
|
||||
setBossbar.write(Types.FLOAT, (float) progress); // Health
|
||||
setBossbar.write(Types.VAR_INT, 0); // Color
|
||||
setBossbar.write(Types.VAR_INT, 0); // Division
|
||||
setBossbar.write(Types.UNSIGNED_BYTE, (short) 0); // Flags
|
||||
} else {
|
||||
setBossbar.write(Types.UUID, bossUUID);
|
||||
setBossbar.write(Types.VAR_INT, 2); // Action - update health
|
||||
setBossbar.write(Types.FLOAT, (float) progress); // Health
|
||||
}
|
||||
setBossbar.send(Protocol1_9To1_8.class, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
if (bossUUID == null) {
|
||||
return;
|
||||
}
|
||||
final PacketWrapper removeBossbar = PacketWrapper.create(ClientboundPackets1_9.BOSS_EVENT, user);
|
||||
removeBossbar.write(Types.UUID, bossUUID);
|
||||
removeBossbar.write(Types.VAR_INT, 1); // Action - remove
|
||||
removeBossbar.send(Protocol1_9To1_8.class, false);
|
||||
bossUUID = null;
|
||||
}
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
if (bossUUID == null) {
|
||||
return;
|
||||
}
|
||||
final PacketWrapper removeBossbar = PacketWrapper.create(ClientboundPackets1_9.BOSS_EVENT, user);
|
||||
removeBossbar.write(Types.UUID, bossUUID);
|
||||
removeBossbar.write(Types.VAR_INT, 1); // Action - remove
|
||||
removeBossbar.send(Protocol1_9To1_8.class, false);
|
||||
bossUUID = null;
|
||||
}
|
||||
}
|
||||
+32
-33
@@ -22,44 +22,43 @@ import com.viaversion.viarewind.api.ViaRewindConfig.CooldownIndicator;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public interface CooldownVisualization {
|
||||
void show(double progress) throws Exception;
|
||||
int MAX_PROGRESS_TEXT_LENGTH = 10;
|
||||
|
||||
void hide() throws Exception;
|
||||
static String buildProgressText(String symbol, double cooldown) {
|
||||
int green = (int) Math.floor(((double) MAX_PROGRESS_TEXT_LENGTH) * cooldown);
|
||||
int grey = MAX_PROGRESS_TEXT_LENGTH - green;
|
||||
StringBuilder builder = new StringBuilder("§8");
|
||||
while (green-- > 0) builder.append(symbol);
|
||||
builder.append("§7");
|
||||
while (grey-- > 0) builder.append(symbol);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
void show(double progress) throws Exception;
|
||||
|
||||
int MAX_PROGRESS_TEXT_LENGTH = 10;
|
||||
void hide() throws Exception;
|
||||
|
||||
static String buildProgressText(String symbol, double cooldown) {
|
||||
int green = (int) Math.floor(((double) MAX_PROGRESS_TEXT_LENGTH) * cooldown);
|
||||
int grey = MAX_PROGRESS_TEXT_LENGTH - green;
|
||||
StringBuilder builder = new StringBuilder("§8");
|
||||
while (green-- > 0) builder.append(symbol);
|
||||
builder.append("§7");
|
||||
while (grey-- > 0) builder.append(symbol);
|
||||
return builder.toString();
|
||||
}
|
||||
interface Factory {
|
||||
Factory DISABLED = user -> new DisabledCooldownVisualization();
|
||||
|
||||
interface Factory {
|
||||
CooldownVisualization create(UserConnection user);
|
||||
static Factory fromConfiguration() {
|
||||
try {
|
||||
return fromIndicator(ViaRewind.getConfig().getCooldownIndicator());
|
||||
} catch (IllegalArgumentException e) {
|
||||
ViaRewind.getPlatform().getLogger().warning("Invalid cooldown-indicator setting");
|
||||
return DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
static Factory fromConfiguration() {
|
||||
try {
|
||||
return fromIndicator(ViaRewind.getConfig().getCooldownIndicator());
|
||||
} catch (IllegalArgumentException e) {
|
||||
ViaRewind.getPlatform().getLogger().warning("Invalid cooldown-indicator setting");
|
||||
return DISABLED;
|
||||
}
|
||||
}
|
||||
static Factory fromIndicator(CooldownIndicator indicator) {
|
||||
return switch (indicator) {
|
||||
case TITLE -> TitleCooldownVisualization::new;
|
||||
case BOSS_BAR -> BossBarVisualization::new;
|
||||
case ACTION_BAR -> ActionBarVisualization::new;
|
||||
case DISABLED -> DISABLED;
|
||||
};
|
||||
}
|
||||
|
||||
static Factory fromIndicator(CooldownIndicator indicator) {
|
||||
return switch (indicator) {
|
||||
case TITLE -> TitleCooldownVisualization::new;
|
||||
case BOSS_BAR -> BossBarVisualization::new;
|
||||
case ACTION_BAR -> ActionBarVisualization::new;
|
||||
case DISABLED -> DISABLED;
|
||||
};
|
||||
}
|
||||
|
||||
Factory DISABLED = user -> new DisabledCooldownVisualization();
|
||||
}
|
||||
CooldownVisualization create(UserConnection user);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -19,12 +19,12 @@ package com.viaversion.viarewind.protocol.v1_9to1_8.cooldown;
|
||||
|
||||
public class DisabledCooldownVisualization implements CooldownVisualization {
|
||||
|
||||
@Override
|
||||
public void show(double progress) {
|
||||
}
|
||||
@Override
|
||||
public void show(double progress) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
}
|
||||
@Override
|
||||
public void hide() {
|
||||
}
|
||||
|
||||
}
|
||||
+30
-30
@@ -23,45 +23,45 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TitleCooldownVisualization implements CooldownVisualization {
|
||||
|
||||
private static final int ACTION_SET_TITLE = 0;
|
||||
private static final int ACTION_SET_SUBTITLE = 1;
|
||||
private static final int ACTION_SET_TIMES_AND_DISPLAY = 2;
|
||||
private static final int ACTION_HIDE = 3;
|
||||
private static final int ACTION_SET_TITLE = 0;
|
||||
private static final int ACTION_SET_SUBTITLE = 1;
|
||||
private static final int ACTION_SET_TIMES_AND_DISPLAY = 2;
|
||||
private static final int ACTION_HIDE = 3;
|
||||
|
||||
private final UserConnection user;
|
||||
private final UserConnection user;
|
||||
|
||||
public TitleCooldownVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
public TitleCooldownVisualization(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
final String text = CooldownVisualization.buildProgressText("˙", progress);
|
||||
@Override
|
||||
public void show(double progress) throws Exception {
|
||||
final String text = CooldownVisualization.buildProgressText("˙", progress);
|
||||
|
||||
sendTitlePacket(ACTION_SET_TITLE, wrapper -> wrapper.write(Types.COMPONENT, new JsonPrimitive("")));
|
||||
sendTitlePacket(ACTION_SET_SUBTITLE, wrapper -> wrapper.write(Types.COMPONENT, new JsonPrimitive(text)));
|
||||
sendTitlePacket(ACTION_SET_TIMES_AND_DISPLAY, wrapper -> {
|
||||
wrapper.write(Types.INT, 0);
|
||||
wrapper.write(Types.INT, 2);
|
||||
wrapper.write(Types.INT, 5);
|
||||
});
|
||||
}
|
||||
sendTitlePacket(ACTION_SET_TITLE, wrapper -> wrapper.write(Types.COMPONENT, new JsonPrimitive("")));
|
||||
sendTitlePacket(ACTION_SET_SUBTITLE, wrapper -> wrapper.write(Types.COMPONENT, new JsonPrimitive(text)));
|
||||
sendTitlePacket(ACTION_SET_TIMES_AND_DISPLAY, wrapper -> {
|
||||
wrapper.write(Types.INT, 0);
|
||||
wrapper.write(Types.INT, 2);
|
||||
wrapper.write(Types.INT, 5);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
sendTitlePacket(ACTION_HIDE, wrapper -> {});
|
||||
}
|
||||
@Override
|
||||
public void hide() throws Exception {
|
||||
sendTitlePacket(ACTION_HIDE, wrapper -> {
|
||||
});
|
||||
}
|
||||
|
||||
private void sendTitlePacket(int action, Consumer<PacketWrapper> writer) {
|
||||
final PacketWrapper title = PacketWrapper.create(ClientboundPackets1_8.SET_TITLES, user);
|
||||
title.write(Types.VAR_INT, action);
|
||||
writer.accept(title);
|
||||
title.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
private void sendTitlePacket(int action, Consumer<PacketWrapper> writer) {
|
||||
final PacketWrapper title = PacketWrapper.create(ClientboundPackets1_8.SET_TITLES, user);
|
||||
title.write(Types.VAR_INT, action);
|
||||
writer.accept(title);
|
||||
title.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
|
||||
}
|
||||
+42
-42
@@ -21,49 +21,49 @@ import java.util.HashMap;
|
||||
|
||||
public class EffectIdMappings1_8 {
|
||||
|
||||
private static final HashMap<Integer, Integer> effects = new HashMap<>();
|
||||
private static final HashMap<Integer, Integer> effects = new HashMap<>();
|
||||
|
||||
static {
|
||||
effects.put(1003, 1002);
|
||||
effects.put(1005, 1003);
|
||||
effects.put(1006, 1003);
|
||||
effects.put(1007, 1003);
|
||||
effects.put(1008, 1003);
|
||||
effects.put(1009, 1004);
|
||||
effects.put(1010, 1005);
|
||||
effects.put(1011, 1006);
|
||||
effects.put(1012, 1006);
|
||||
effects.put(1013, 1006);
|
||||
effects.put(1014, 1006);
|
||||
effects.put(1015, 1007);
|
||||
effects.put(1016, 1008);
|
||||
effects.put(1017, 1008);
|
||||
effects.put(1018, 1009);
|
||||
effects.put(1019, 1010);
|
||||
effects.put(1020, 1011);
|
||||
effects.put(1021, 1012);
|
||||
effects.put(1022, 1012);
|
||||
effects.put(1023, 1013);
|
||||
effects.put(1024, 1014);
|
||||
effects.put(1025, 1015);
|
||||
effects.put(1026, 1016);
|
||||
effects.put(1027, 1017);
|
||||
effects.put(1028, 1018);
|
||||
effects.put(1029, 1020);
|
||||
effects.put(1030, 1021);
|
||||
effects.put(1031, 1022);
|
||||
effects.put(1032, -1);
|
||||
effects.put(1033, -1);
|
||||
effects.put(1034, -1);
|
||||
effects.put(1035, -1);
|
||||
effects.put(1036, 1003);
|
||||
effects.put(1037, 1006);
|
||||
static {
|
||||
effects.put(1003, 1002);
|
||||
effects.put(1005, 1003);
|
||||
effects.put(1006, 1003);
|
||||
effects.put(1007, 1003);
|
||||
effects.put(1008, 1003);
|
||||
effects.put(1009, 1004);
|
||||
effects.put(1010, 1005);
|
||||
effects.put(1011, 1006);
|
||||
effects.put(1012, 1006);
|
||||
effects.put(1013, 1006);
|
||||
effects.put(1014, 1006);
|
||||
effects.put(1015, 1007);
|
||||
effects.put(1016, 1008);
|
||||
effects.put(1017, 1008);
|
||||
effects.put(1018, 1009);
|
||||
effects.put(1019, 1010);
|
||||
effects.put(1020, 1011);
|
||||
effects.put(1021, 1012);
|
||||
effects.put(1022, 1012);
|
||||
effects.put(1023, 1013);
|
||||
effects.put(1024, 1014);
|
||||
effects.put(1025, 1015);
|
||||
effects.put(1026, 1016);
|
||||
effects.put(1027, 1017);
|
||||
effects.put(1028, 1018);
|
||||
effects.put(1029, 1020);
|
||||
effects.put(1030, 1021);
|
||||
effects.put(1031, 1022);
|
||||
effects.put(1032, -1);
|
||||
effects.put(1033, -1);
|
||||
effects.put(1034, -1);
|
||||
effects.put(1035, -1);
|
||||
effects.put(1036, 1003);
|
||||
effects.put(1037, 1006);
|
||||
|
||||
effects.put(3000, -1);
|
||||
effects.put(3001, -1);
|
||||
}
|
||||
effects.put(3000, -1);
|
||||
effects.put(3001, -1);
|
||||
}
|
||||
|
||||
public static int getOldId(int id) {
|
||||
return effects.getOrDefault(id, id);
|
||||
}
|
||||
public static int getOldId(int id) {
|
||||
return effects.getOrDefault(id, id);
|
||||
}
|
||||
}
|
||||
+21
-22
@@ -21,35 +21,34 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.data.EntityDataIndex1_9;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityDataIndex1_8 {
|
||||
|
||||
private static final HashMap<Pair<EntityTypes1_9.EntityType, Integer>, EntityDataIndex1_9> ENTITY_DATA_REWRITES = new HashMap<>();
|
||||
private static final HashMap<Pair<EntityTypes1_9.EntityType, Integer>, EntityDataIndex1_9> ENTITY_DATA_REWRITES = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (EntityDataIndex1_9 index : EntityDataIndex1_9.values()) {
|
||||
ENTITY_DATA_REWRITES.put(new Pair<>(index.getClazz(), index.getNewIndex()), index);
|
||||
}
|
||||
}
|
||||
static {
|
||||
for (EntityDataIndex1_9 index : EntityDataIndex1_9.values()) {
|
||||
ENTITY_DATA_REWRITES.put(new Pair<>(index.getClazz(), index.getNewIndex()), index);
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<EntityDataIndex1_9> getIndex(final EntityType type, final int index) {
|
||||
final Pair<EntityType, Integer> pair = new Pair<>(type, index);
|
||||
return Optional.ofNullable(ENTITY_DATA_REWRITES.get(pair));
|
||||
}
|
||||
private static Optional<EntityDataIndex1_9> getIndex(final EntityType type, final int index) {
|
||||
final Pair<EntityType, Integer> pair = new Pair<>(type, index);
|
||||
return Optional.ofNullable(ENTITY_DATA_REWRITES.get(pair));
|
||||
}
|
||||
|
||||
public static EntityDataIndex1_9 searchIndex(final EntityType type, final int index) {
|
||||
EntityType currentType = type;
|
||||
do {
|
||||
final Optional<EntityDataIndex1_9> optMeta = getIndex(currentType, index);
|
||||
if (optMeta.isPresent()) {
|
||||
return optMeta.get();
|
||||
}
|
||||
currentType = currentType.getParent();
|
||||
} while (currentType != null);
|
||||
return null;
|
||||
}
|
||||
public static EntityDataIndex1_9 searchIndex(final EntityType type, final int index) {
|
||||
EntityType currentType = type;
|
||||
do {
|
||||
final Optional<EntityDataIndex1_9> optMeta = getIndex(currentType, index);
|
||||
if (optMeta.isPresent()) {
|
||||
return optMeta.get();
|
||||
}
|
||||
currentType = currentType.getParent();
|
||||
} while (currentType != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+52
-53
@@ -18,63 +18,62 @@
|
||||
package com.viaversion.viarewind.protocol.v1_9to1_8.data;
|
||||
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.data.PotionIdMappings1_9;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionIdMappings1_8 {
|
||||
public static final Map<String, String> POTION_NAME_INDEX = new HashMap<>();
|
||||
public static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
||||
public static final Map<String, String> POTION_NAME_INDEX = new HashMap<>();
|
||||
public static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
||||
|
||||
static {
|
||||
POTION_NAME_TO_ID.putAll(PotionIdMappings1_9.POTION_NAME_TO_ID);
|
||||
POTION_NAME_TO_ID.put("luck", 8203); // Map new potion to similar one (luck->leaping)
|
||||
static {
|
||||
POTION_NAME_TO_ID.putAll(PotionIdMappings1_9.POTION_NAME_TO_ID);
|
||||
POTION_NAME_TO_ID.put("luck", 8203); // Map new potion to similar one (luck->leaping)
|
||||
|
||||
POTION_NAME_INDEX.put("water", "§rWater Bottle");
|
||||
POTION_NAME_INDEX.put("mundane", "§rMundane Potion");
|
||||
POTION_NAME_INDEX.put("thick", "§rThick Potion");
|
||||
POTION_NAME_INDEX.put("awkward", "§rAwkward Potion");
|
||||
POTION_NAME_INDEX.put("water_splash", "§rSplash Water Bottle");
|
||||
POTION_NAME_INDEX.put("mundane_splash", "§rMundane Splash Potion");
|
||||
POTION_NAME_INDEX.put("thick_splash", "§rThick Splash Potion");
|
||||
POTION_NAME_INDEX.put("awkward_splash", "§rAwkward Splash Potion");
|
||||
POTION_NAME_INDEX.put("water_lingering", "§rLingering Water Bottle");
|
||||
POTION_NAME_INDEX.put("mundane_lingering", "§rMundane Lingering Potion");
|
||||
POTION_NAME_INDEX.put("thick_lingering", "§rThick Lingering Potion");
|
||||
POTION_NAME_INDEX.put("awkward_lingering", "§rAwkward Lingering Potion");
|
||||
POTION_NAME_INDEX.put("night_vision_lingering", "§rLingering Potion of Night Vision");
|
||||
POTION_NAME_INDEX.put("long_night_vision_lingering", "§rLingering Potion of Night Vision");
|
||||
POTION_NAME_INDEX.put("invisibility_lingering", "§rLingering Potion of Invisibility");
|
||||
POTION_NAME_INDEX.put("long_invisibility_lingering", "§rLingering Potion of Invisibility");
|
||||
POTION_NAME_INDEX.put("leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("long_leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("strong_leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("fire_resistance_lingering", "§rLingering Potion of Fire Resistance");
|
||||
POTION_NAME_INDEX.put("long_fire_resistance_lingering", "§rLingering Potion of Fire Resistance");
|
||||
POTION_NAME_INDEX.put("swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("long_swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("strong_swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("slowness_lingering", "§rLingering Potion of Slowness");
|
||||
POTION_NAME_INDEX.put("long_slowness_lingering", "§rLingering Potion of Slowness");
|
||||
POTION_NAME_INDEX.put("water_breathing_lingering", "§rLingering Potion of Water Breathing");
|
||||
POTION_NAME_INDEX.put("long_water_breathing_lingering", "§rLingering Potion of Water Breathing");
|
||||
POTION_NAME_INDEX.put("healing_lingering", "§rLingering Potion of Healing");
|
||||
POTION_NAME_INDEX.put("strong_healing_lingering", "§rLingering Potion of Healing");
|
||||
POTION_NAME_INDEX.put("harming_lingering", "§rLingering Potion of Harming");
|
||||
POTION_NAME_INDEX.put("strong_harming_lingering", "§rLingering Potion of Harming");
|
||||
POTION_NAME_INDEX.put("poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("long_poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("strong_poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("long_regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("strong_regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("long_strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("strong_strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("weakness_lingering", "§rLingering Potion of Weakness");
|
||||
POTION_NAME_INDEX.put("long_weakness_lingering", "§rLingering Potion of Weakness");
|
||||
POTION_NAME_INDEX.put("luck_lingering", "§rLingering Potion of Luck");
|
||||
POTION_NAME_INDEX.put("luck", "§rPotion of Luck");
|
||||
POTION_NAME_INDEX.put("luck_splash", "§rSplash Potion of Luck");
|
||||
}
|
||||
POTION_NAME_INDEX.put("water", "§rWater Bottle");
|
||||
POTION_NAME_INDEX.put("mundane", "§rMundane Potion");
|
||||
POTION_NAME_INDEX.put("thick", "§rThick Potion");
|
||||
POTION_NAME_INDEX.put("awkward", "§rAwkward Potion");
|
||||
POTION_NAME_INDEX.put("water_splash", "§rSplash Water Bottle");
|
||||
POTION_NAME_INDEX.put("mundane_splash", "§rMundane Splash Potion");
|
||||
POTION_NAME_INDEX.put("thick_splash", "§rThick Splash Potion");
|
||||
POTION_NAME_INDEX.put("awkward_splash", "§rAwkward Splash Potion");
|
||||
POTION_NAME_INDEX.put("water_lingering", "§rLingering Water Bottle");
|
||||
POTION_NAME_INDEX.put("mundane_lingering", "§rMundane Lingering Potion");
|
||||
POTION_NAME_INDEX.put("thick_lingering", "§rThick Lingering Potion");
|
||||
POTION_NAME_INDEX.put("awkward_lingering", "§rAwkward Lingering Potion");
|
||||
POTION_NAME_INDEX.put("night_vision_lingering", "§rLingering Potion of Night Vision");
|
||||
POTION_NAME_INDEX.put("long_night_vision_lingering", "§rLingering Potion of Night Vision");
|
||||
POTION_NAME_INDEX.put("invisibility_lingering", "§rLingering Potion of Invisibility");
|
||||
POTION_NAME_INDEX.put("long_invisibility_lingering", "§rLingering Potion of Invisibility");
|
||||
POTION_NAME_INDEX.put("leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("long_leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("strong_leaping_lingering", "§rLingering Potion of Leaping");
|
||||
POTION_NAME_INDEX.put("fire_resistance_lingering", "§rLingering Potion of Fire Resistance");
|
||||
POTION_NAME_INDEX.put("long_fire_resistance_lingering", "§rLingering Potion of Fire Resistance");
|
||||
POTION_NAME_INDEX.put("swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("long_swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("strong_swiftness_lingering", "§rLingering Potion of Swiftness");
|
||||
POTION_NAME_INDEX.put("slowness_lingering", "§rLingering Potion of Slowness");
|
||||
POTION_NAME_INDEX.put("long_slowness_lingering", "§rLingering Potion of Slowness");
|
||||
POTION_NAME_INDEX.put("water_breathing_lingering", "§rLingering Potion of Water Breathing");
|
||||
POTION_NAME_INDEX.put("long_water_breathing_lingering", "§rLingering Potion of Water Breathing");
|
||||
POTION_NAME_INDEX.put("healing_lingering", "§rLingering Potion of Healing");
|
||||
POTION_NAME_INDEX.put("strong_healing_lingering", "§rLingering Potion of Healing");
|
||||
POTION_NAME_INDEX.put("harming_lingering", "§rLingering Potion of Harming");
|
||||
POTION_NAME_INDEX.put("strong_harming_lingering", "§rLingering Potion of Harming");
|
||||
POTION_NAME_INDEX.put("poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("long_poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("strong_poison_lingering", "§rLingering Potion of Poisen");
|
||||
POTION_NAME_INDEX.put("regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("long_regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("strong_regeneration_lingering", "§rLingering Potion of Regeneration");
|
||||
POTION_NAME_INDEX.put("strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("long_strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("strong_strength_lingering", "§rLingering Potion of Strength");
|
||||
POTION_NAME_INDEX.put("weakness_lingering", "§rLingering Potion of Weakness");
|
||||
POTION_NAME_INDEX.put("long_weakness_lingering", "§rLingering Potion of Weakness");
|
||||
POTION_NAME_INDEX.put("luck_lingering", "§rLingering Potion of Luck");
|
||||
POTION_NAME_INDEX.put("luck", "§rPotion of Luck");
|
||||
POTION_NAME_INDEX.put("luck_splash", "§rSplash Potion of Luck");
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -17,32 +17,32 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_9to1_8.data;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viarewind.api.data.RewindMappingDataLoader;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.ObjectArrayList;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.ObjectList;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
|
||||
public final class RewindMappingData1_8 extends com.viaversion.viarewind.api.data.RewindMappingData {
|
||||
|
||||
private final ObjectList<String> sounds = new ObjectArrayList<>();
|
||||
private final ObjectList<String> sounds = new ObjectArrayList<>();
|
||||
|
||||
public RewindMappingData1_8() {
|
||||
super("1.9.4", "1.8");
|
||||
}
|
||||
public RewindMappingData1_8() {
|
||||
super("1.9.4", "1.8");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadExtras(CompoundTag data) {
|
||||
super.loadExtras(data);
|
||||
@Override
|
||||
protected void loadExtras(CompoundTag data) {
|
||||
super.loadExtras(data);
|
||||
|
||||
final JsonArray sounds = RewindMappingDataLoader.INSTANCE.loadData("sounds-1.9.json").getAsJsonArray("sounds");
|
||||
for (final JsonElement sound : sounds) {
|
||||
this.sounds.add(sound.getAsString());
|
||||
}
|
||||
}
|
||||
final JsonArray sounds = RewindMappingDataLoader.INSTANCE.loadData("sounds-1.9.json").getAsJsonArray("sounds");
|
||||
for (final JsonElement sound : sounds) {
|
||||
this.sounds.add(sound.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public String soundName(final int soundId) {
|
||||
return sounds.get(soundId);
|
||||
}
|
||||
public String soundName(final int soundId) {
|
||||
return sounds.get(soundId);
|
||||
}
|
||||
}
|
||||
+182
-181
@@ -28,224 +28,225 @@ import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WitherBossBar implements BossBar {
|
||||
|
||||
private static int highestId = Integer.MAX_VALUE - 10000;
|
||||
private static int highestId = Integer.MAX_VALUE - 10000;
|
||||
|
||||
private final UUID uuid;
|
||||
private String title;
|
||||
private float health;
|
||||
private boolean visible = false;
|
||||
private final UUID uuid;
|
||||
private final UserConnection connection;
|
||||
private final int entityId = highestId++;
|
||||
private String title;
|
||||
private float health;
|
||||
private boolean visible = false;
|
||||
private double locX, locY, locZ;
|
||||
|
||||
private final UserConnection connection;
|
||||
public WitherBossBar(UserConnection connection, UUID uuid, String title, float health) {
|
||||
this.connection = connection;
|
||||
this.uuid = uuid;
|
||||
this.title = title;
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
private final int entityId = highestId++;
|
||||
private double locX, locY, locZ;
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public WitherBossBar(UserConnection connection, UUID uuid, String title, float health) {
|
||||
this.connection = connection;
|
||||
this.uuid = uuid;
|
||||
this.title = title;
|
||||
this.health = health;
|
||||
}
|
||||
@Override
|
||||
public BossBar setTitle(String title) {
|
||||
this.title = title;
|
||||
if (this.visible) {
|
||||
updateEntityData();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setTitle(String title) {
|
||||
this.title = title;
|
||||
if (this.visible) {
|
||||
updateEntityData();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public BossBar setHealth(float health) {
|
||||
this.health = health;
|
||||
if (this.health <= 0) {
|
||||
this.health = 0.0001f;
|
||||
}
|
||||
if (this.visible) {
|
||||
updateEntityData();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
@Override
|
||||
public BossColor getColor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setHealth(float health) {
|
||||
this.health = health;
|
||||
if (this.health <= 0) {
|
||||
this.health = 0.0001f;
|
||||
}
|
||||
if (this.visible) {
|
||||
updateEntityData();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public BossBar setColor(BossColor bossColor) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support color");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossColor getColor() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public BossStyle getStyle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setColor(BossColor bossColor) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support color");
|
||||
}
|
||||
@Override
|
||||
public BossBar setStyle(BossStyle bossStyle) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support styles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossStyle getStyle() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public BossBar addPlayer(UUID uuid) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setStyle(BossStyle bossStyle) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support styles");
|
||||
}
|
||||
@Override
|
||||
public BossBar addConnection(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addPlayer(UUID uuid) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
@Override
|
||||
public BossBar removePlayer(UUID uuid) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addConnection(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
@Override
|
||||
public BossBar removeConnection(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removePlayer(UUID uuid) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
@Override
|
||||
public BossBar addFlag(BossFlag bossFlag) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support flags");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removeConnection(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
@Override
|
||||
public BossBar removeFlag(BossFlag bossFlag) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support flags");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar addFlag(BossFlag bossFlag) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support flags");
|
||||
}
|
||||
@Override
|
||||
public boolean hasFlag(BossFlag bossFlag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar removeFlag(BossFlag bossFlag) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support flags");
|
||||
}
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return Collections.singleton(connection.getProtocolInfo().getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFlag(BossFlag bossFlag) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return Collections.singleton(connection.getProtocolInfo().getUuid());
|
||||
}
|
||||
@Override
|
||||
public BossBar show() {
|
||||
if (!this.visible) {
|
||||
addWither();
|
||||
this.visible = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UserConnection> getConnections() {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " is only for one UserConnection!");
|
||||
}
|
||||
@Override
|
||||
public BossBar hide() {
|
||||
if (this.visible) {
|
||||
removeWither();
|
||||
this.visible = false;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar show() {
|
||||
if (!this.visible) {
|
||||
addWither();
|
||||
this.visible = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar hide() {
|
||||
if (this.visible) {
|
||||
removeWither();
|
||||
this.visible = false;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
public void setLocation(double x, double y, double z) {
|
||||
locX = x;
|
||||
locY = y;
|
||||
locZ = z;
|
||||
updateLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return this.uuid;
|
||||
}
|
||||
private void addWither() {
|
||||
final PacketWrapper addMob = PacketWrapper.create(ClientboundPackets1_7_2_5.ADD_MOB, this.connection);
|
||||
addMob.write(Types.VAR_INT, entityId);
|
||||
addMob.write(Types.UNSIGNED_BYTE, (short) 64);
|
||||
addMob.write(Types.INT, (int) (locX * 32D));
|
||||
addMob.write(Types.INT, (int) (locY * 32D));
|
||||
addMob.write(Types.INT, (int) (locZ * 32D));
|
||||
addMob.write(Types.BYTE, (byte) 0);
|
||||
addMob.write(Types.BYTE, (byte) 0);
|
||||
addMob.write(Types.BYTE, (byte) 0);
|
||||
addMob.write(Types.SHORT, (short) 0);
|
||||
addMob.write(Types.SHORT, (short) 0);
|
||||
addMob.write(Types.SHORT, (short) 0);
|
||||
|
||||
public void setLocation(double x, double y, double z) {
|
||||
locX = x;
|
||||
locY = y;
|
||||
locZ = z;
|
||||
updateLocation();
|
||||
}
|
||||
final List<EntityData> entityData = new ArrayList<>();
|
||||
entityData.add(new EntityData(0, EntityDataTypes1_8.BYTE, (byte) 0x20));
|
||||
entityData.add(new EntityData(2, EntityDataTypes1_8.STRING, title));
|
||||
entityData.add(new EntityData(3, EntityDataTypes1_8.BYTE, (byte) 1));
|
||||
entityData.add(new EntityData(6, EntityDataTypes1_8.FLOAT, health * 300f));
|
||||
|
||||
private void addWither() {
|
||||
final PacketWrapper addMob = PacketWrapper.create(ClientboundPackets1_7_2_5.ADD_MOB, this.connection);
|
||||
addMob.write(Types.VAR_INT, entityId);
|
||||
addMob.write(Types.UNSIGNED_BYTE, (short) 64);
|
||||
addMob.write(Types.INT, (int) (locX * 32D));
|
||||
addMob.write(Types.INT, (int) (locY * 32D));
|
||||
addMob.write(Types.INT, (int) (locZ * 32D));
|
||||
addMob.write(Types.BYTE, (byte) 0);
|
||||
addMob.write(Types.BYTE, (byte) 0);
|
||||
addMob.write(Types.BYTE, (byte) 0);
|
||||
addMob.write(Types.SHORT, (short) 0);
|
||||
addMob.write(Types.SHORT, (short) 0);
|
||||
addMob.write(Types.SHORT, (short) 0);
|
||||
addMob.write(Types.ENTITY_DATA_LIST1_8, entityData);
|
||||
addMob.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
|
||||
final List<EntityData> entityData = new ArrayList<>();
|
||||
entityData.add(new EntityData(0, EntityDataTypes1_8.BYTE, (byte) 0x20));
|
||||
entityData.add(new EntityData(2, EntityDataTypes1_8.STRING, title));
|
||||
entityData.add(new EntityData(3, EntityDataTypes1_8.BYTE, (byte) 1));
|
||||
entityData.add(new EntityData(6, EntityDataTypes1_8.FLOAT, health * 300f));
|
||||
private void updateLocation() {
|
||||
final PacketWrapper teleportEntity = PacketWrapper.create(ClientboundPackets1_7_2_5.TELEPORT_ENTITY, this.connection);
|
||||
teleportEntity.write(Types.VAR_INT, entityId);
|
||||
teleportEntity.write(Types.INT, (int) (locX * 32D));
|
||||
teleportEntity.write(Types.INT, (int) (locY * 32D));
|
||||
teleportEntity.write(Types.INT, (int) (locZ * 32D));
|
||||
teleportEntity.write(Types.BYTE, (byte) 0);
|
||||
teleportEntity.write(Types.BYTE, (byte) 0);
|
||||
teleportEntity.write(Types.BOOLEAN, false);
|
||||
teleportEntity.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
|
||||
addMob.write(Types.ENTITY_DATA_LIST1_8, entityData);
|
||||
addMob.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
private void updateEntityData() {
|
||||
final PacketWrapper setEntityData = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_ENTITY_DATA, this.connection);
|
||||
setEntityData.write(Types.VAR_INT, entityId);
|
||||
|
||||
private void updateLocation() {
|
||||
final PacketWrapper teleportEntity = PacketWrapper.create(ClientboundPackets1_7_2_5.TELEPORT_ENTITY, this.connection);
|
||||
teleportEntity.write(Types.VAR_INT, entityId);
|
||||
teleportEntity.write(Types.INT, (int) (locX * 32D));
|
||||
teleportEntity.write(Types.INT, (int) (locY * 32D));
|
||||
teleportEntity.write(Types.INT, (int) (locZ * 32D));
|
||||
teleportEntity.write(Types.BYTE, (byte) 0);
|
||||
teleportEntity.write(Types.BYTE, (byte) 0);
|
||||
teleportEntity.write(Types.BOOLEAN, false);
|
||||
teleportEntity.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
final List<EntityData> entityData = new ArrayList<>();
|
||||
entityData.add(new EntityData(2, EntityDataTypes1_8.STRING, title));
|
||||
entityData.add(new EntityData(6, EntityDataTypes1_8.FLOAT, health * 300f));
|
||||
|
||||
private void updateEntityData() {
|
||||
final PacketWrapper setEntityData = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_ENTITY_DATA, this.connection);
|
||||
setEntityData.write(Types.VAR_INT, entityId);
|
||||
setEntityData.write(Types.ENTITY_DATA_LIST1_8, entityData);
|
||||
setEntityData.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
|
||||
final List<EntityData> entityData = new ArrayList<>();
|
||||
entityData.add(new EntityData(2, EntityDataTypes1_8.STRING, title));
|
||||
entityData.add(new EntityData(6, EntityDataTypes1_8.FLOAT, health * 300f));
|
||||
private void removeWither() {
|
||||
final PacketWrapper removeEntity = PacketWrapper.create(ClientboundPackets1_7_2_5.REMOVE_ENTITIES, this.connection);
|
||||
removeEntity.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{entityId});
|
||||
removeEntity.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
|
||||
setEntityData.write(Types.ENTITY_DATA_LIST1_8, entityData);
|
||||
setEntityData.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
public void setPlayerLocation(double posX, double posY, double posZ, float yaw, float pitch) {
|
||||
double yawR = Math.toRadians(yaw);
|
||||
double pitchR = Math.toRadians(pitch);
|
||||
|
||||
private void removeWither() {
|
||||
final PacketWrapper removeEntity = PacketWrapper.create(ClientboundPackets1_7_2_5.REMOVE_ENTITIES, this.connection);
|
||||
removeEntity.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{entityId});
|
||||
removeEntity.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
posX -= Math.cos(pitchR) * Math.sin(yawR) * 48;
|
||||
posY -= Math.sin(pitchR) * 48;
|
||||
posZ += Math.cos(pitchR) * Math.cos(yawR) * 48;
|
||||
|
||||
public void setPlayerLocation(double posX, double posY, double posZ, float yaw, float pitch) {
|
||||
double yawR = Math.toRadians(yaw);
|
||||
double pitchR = Math.toRadians(pitch);
|
||||
|
||||
posX -= Math.cos(pitchR) * Math.sin(yawR) * 48;
|
||||
posY -= Math.sin(pitchR) * 48;
|
||||
posZ += Math.cos(pitchR) * Math.cos(yawR) * 48;
|
||||
|
||||
setLocation(posX, posY, posZ);
|
||||
}
|
||||
setLocation(posX, posY, posZ);
|
||||
}
|
||||
|
||||
}
|
||||
+262
-259
@@ -17,6 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_9to1_8.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
|
||||
import com.viaversion.viarewind.api.rewriter.VRBlockItemRewriter;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
@@ -26,315 +31,313 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.nbt.tag.*;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.data.EntityIds1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.data.PotionIdMappings1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockItemPacketRewriter1_9 extends VRBlockItemRewriter<ClientboundPackets1_9, ServerboundPackets1_8, Protocol1_9To1_8> {
|
||||
|
||||
public final Set<String> VALID_ATTRIBUTES = new HashSet<>();
|
||||
public final Set<String> VALID_ATTRIBUTES = new HashSet<>();
|
||||
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
|
||||
public BlockItemPacketRewriter1_9(Protocol1_9To1_8 protocol) {
|
||||
super(protocol, "1.9");
|
||||
public BlockItemPacketRewriter1_9(Protocol1_9To1_8 protocol) {
|
||||
super(protocol, "1.9");
|
||||
|
||||
VALID_ATTRIBUTES.add("generic.maxHealth");
|
||||
VALID_ATTRIBUTES.add("generic.followRange");
|
||||
VALID_ATTRIBUTES.add("generic.knockbackResistance");
|
||||
VALID_ATTRIBUTES.add("generic.movementSpeed");
|
||||
VALID_ATTRIBUTES.add("generic.attackDamage");
|
||||
VALID_ATTRIBUTES.add("horse.jumpStrength");
|
||||
VALID_ATTRIBUTES.add("zombie.spawnReinforcements");
|
||||
}
|
||||
VALID_ATTRIBUTES.add("generic.maxHealth");
|
||||
VALID_ATTRIBUTES.add("generic.followRange");
|
||||
VALID_ATTRIBUTES.add("generic.knockbackResistance");
|
||||
VALID_ATTRIBUTES.add("generic.movementSpeed");
|
||||
VALID_ATTRIBUTES.add("generic.attackDamage");
|
||||
VALID_ATTRIBUTES.add("horse.jumpStrength");
|
||||
VALID_ATTRIBUTES.add("zombie.spawnReinforcements");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerBlockChange(ClientboundPackets1_9.BLOCK_UPDATE);
|
||||
registerMultiBlockChange(ClientboundPackets1_9.CHUNK_BLOCKS_UPDATE);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_8.SET_CREATIVE_MODE_SLOT);
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerBlockChange(ClientboundPackets1_9.BLOCK_UPDATE);
|
||||
registerMultiBlockChange(ClientboundPackets1_9.CHUNK_BLOCKS_UPDATE);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_8.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_CLOSE, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_CLOSE, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
|
||||
final WindowTracker tracker = wrapper.user().get(WindowTracker.class);
|
||||
final WindowTracker tracker = wrapper.user().get(WindowTracker.class);
|
||||
|
||||
final String windowType = tracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:enchanting_table")) {
|
||||
tracker.clearEnchantmentProperties();
|
||||
}
|
||||
tracker.remove(windowId);
|
||||
});
|
||||
final String windowType = tracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:enchanting_table")) {
|
||||
tracker.clearEnchantmentProperties();
|
||||
}
|
||||
tracker.remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.OPEN_SCREEN, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
final String windowType = wrapper.passthrough(Types.STRING);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.OPEN_SCREEN, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
final String windowType = wrapper.passthrough(Types.STRING);
|
||||
|
||||
wrapper.user().get(WindowTracker.class).put(windowId, windowType);
|
||||
});
|
||||
wrapper.user().get(WindowTracker.class).put(windowId, windowType);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_SET_CONTENT, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_SET_CONTENT, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
|
||||
Item[] items = wrapper.read(Types.ITEM1_8_SHORT_ARRAY);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
Item[] items = wrapper.read(Types.ITEM1_8_SHORT_ARRAY);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
|
||||
if (windowId == 0 && items.length == 46) {
|
||||
Item[] old = items;
|
||||
items = new Item[45];
|
||||
System.arraycopy(old, 0, items, 0, 45);
|
||||
} else {
|
||||
final String type = wrapper.user().get(WindowTracker.class).get(windowId);
|
||||
if (type != null && type.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
System.arraycopy(items, 0, wrapper.user().get(WindowTracker.class).getBrewingItems(windowId), 0, 4);
|
||||
WindowTracker.updateBrewingStand(wrapper.user(), items[4], windowId);
|
||||
Item[] old = items;
|
||||
items = new Item[old.length - 1];
|
||||
System.arraycopy(old, 0, items, 0, 4);
|
||||
System.arraycopy(old, 5, items, 4, old.length - 5);
|
||||
}
|
||||
}
|
||||
if (windowId == 0 && items.length == 46) {
|
||||
Item[] old = items;
|
||||
items = new Item[45];
|
||||
System.arraycopy(old, 0, items, 0, 45);
|
||||
} else {
|
||||
final String type = wrapper.user().get(WindowTracker.class).get(windowId);
|
||||
if (type != null && type.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
System.arraycopy(items, 0, wrapper.user().get(WindowTracker.class).getBrewingItems(windowId), 0, 4);
|
||||
WindowTracker.updateBrewingStand(wrapper.user(), items[4], windowId);
|
||||
Item[] old = items;
|
||||
items = new Item[old.length - 1];
|
||||
System.arraycopy(old, 0, items, 0, 4);
|
||||
System.arraycopy(old, 5, items, 4, old.length - 5);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.write(Types.ITEM1_8_SHORT_ARRAY, items);
|
||||
});
|
||||
wrapper.write(Types.ITEM1_8_SHORT_ARRAY, items);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_SET_SLOT, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Types.BYTE);
|
||||
final short slot = wrapper.passthrough(Types.SHORT);
|
||||
final Item item = wrapper.passthrough(Types.ITEM1_8);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_SET_SLOT, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Types.BYTE);
|
||||
final short slot = wrapper.passthrough(Types.SHORT);
|
||||
final Item item = wrapper.passthrough(Types.ITEM1_8);
|
||||
|
||||
handleItemToClient(wrapper.user(), item);
|
||||
if (windowId == 0 && slot == 45) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
final WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
|
||||
final String windowType = windowTracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
if (slot > 4) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot - 1));
|
||||
} else if (slot == 4) {
|
||||
wrapper.cancel();
|
||||
WindowTracker.updateBrewingStand(wrapper.user(), wrapper.get(Types.ITEM1_8, 0), windowId);
|
||||
} else {
|
||||
windowTracker.getBrewingItems(windowId)[slot] = wrapper.get(Types.ITEM1_8, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
handleItemToClient(wrapper.user(), item);
|
||||
if (windowId == 0 && slot == 45) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
final WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
|
||||
final String windowType = windowTracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
if (slot > 4) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot - 1));
|
||||
} else if (slot == 4) {
|
||||
wrapper.cancel();
|
||||
WindowTracker.updateBrewingStand(wrapper.user(), wrapper.get(Types.ITEM1_8, 0), windowId);
|
||||
} else {
|
||||
windowTracker.getBrewingItems(windowId)[slot] = wrapper.get(Types.ITEM1_8, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CONTAINER_CLOSE, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Types.BYTE);
|
||||
wrapper.user().get(WindowTracker.class).remove(windowId);
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CONTAINER_CLOSE, wrapper -> {
|
||||
final byte windowId = wrapper.passthrough(Types.BYTE);
|
||||
wrapper.user().get(WindowTracker.class).remove(windowId);
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Window id
|
||||
map(Types.SHORT); // Slot
|
||||
map(Types.BYTE); // Button
|
||||
map(Types.SHORT); // Action number
|
||||
map(Types.BYTE, Types.VAR_INT); // Mode
|
||||
map(Types.ITEM1_8); // Clicked item
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
|
||||
handler(wrapper -> {
|
||||
final byte windowId = wrapper.get(Types.BYTE, 0);
|
||||
final String windowType = wrapper.user().get(WindowTracker.class).get(windowId);
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BYTE); // Window id
|
||||
map(Types.SHORT); // Slot
|
||||
map(Types.BYTE); // Button
|
||||
map(Types.SHORT); // Action number
|
||||
map(Types.BYTE, Types.VAR_INT); // Mode
|
||||
map(Types.ITEM1_8); // Clicked item
|
||||
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
|
||||
handler(wrapper -> {
|
||||
final byte windowId = wrapper.get(Types.BYTE, 0);
|
||||
final String windowType = wrapper.user().get(WindowTracker.class).get(windowId);
|
||||
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
if (slot > 3) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:brewing_stand")) {
|
||||
final short slot = wrapper.get(Types.SHORT, 0);
|
||||
if (slot > 3) {
|
||||
wrapper.set(Types.SHORT, 0, (short) (slot + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_SET_DATA, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
short key = wrapper.read(Types.SHORT);
|
||||
short value = wrapper.read(Types.SHORT);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CONTAINER_SET_DATA, wrapper -> {
|
||||
final short windowId = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
short key = wrapper.read(Types.SHORT);
|
||||
short value = wrapper.read(Types.SHORT);
|
||||
|
||||
final WindowTracker tracker = wrapper.user().get(WindowTracker.class);
|
||||
final String windowType = tracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:enchanting_table")) {
|
||||
if (key >= 4 && key <= 6) { // Store enchantment ids
|
||||
tracker.putEnchantmentProperty(key, value);
|
||||
wrapper.cancel();
|
||||
} else if (key >= 7 && key <= 9) { // Mix levels with tracked ids
|
||||
key -= 3;
|
||||
final short property = tracker.getEnchantmentValue(key);
|
||||
value = (short) (property | (value << 8));
|
||||
}
|
||||
}
|
||||
wrapper.write(Types.SHORT, key);
|
||||
wrapper.write(Types.SHORT, value);
|
||||
});
|
||||
}
|
||||
final WindowTracker tracker = wrapper.user().get(WindowTracker.class);
|
||||
final String windowType = tracker.get(windowId);
|
||||
if (windowType != null && windowType.equalsIgnoreCase("minecraft:enchanting_table")) {
|
||||
if (key >= 4 && key <= 6) { // Store enchantment ids
|
||||
tracker.putEnchantmentProperty(key, value);
|
||||
wrapper.cancel();
|
||||
} else if (key >= 7 && key <= 9) { // Mix levels with tracked ids
|
||||
key -= 3;
|
||||
final short property = tracker.getEnchantmentValue(key);
|
||||
value = (short) (property | (value << 8));
|
||||
}
|
||||
}
|
||||
wrapper.write(Types.SHORT, key);
|
||||
wrapper.write(Types.SHORT, value);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(9, "§7Frost Walker");
|
||||
enchantmentRewriter.registerEnchantment(70, "§7Mending");
|
||||
}
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(9, "§7Frost Walker");
|
||||
enchantmentRewriter.registerEnchantment(70, "§7Mending");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
CompoundTag tag = item.tag();
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
|
||||
CompoundTag displayTag = tag == null ? null : tag.getCompoundTag("display");
|
||||
if (item.data() != 0) {
|
||||
final ByteTag unbreakableTag = tag == null ? null : tag.getByteTag("Unbreakable");
|
||||
if (unbreakableTag != null && unbreakableTag.asByte() != 0) {
|
||||
tag.put(nbtTagName() + "|Unbreakable", new ByteTag(unbreakableTag.asByte()));
|
||||
tag.remove("Unbreakable");
|
||||
CompoundTag displayTag = tag == null ? null : tag.getCompoundTag("display");
|
||||
if (item.data() != 0) {
|
||||
final ByteTag unbreakableTag = tag == null ? null : tag.getByteTag("Unbreakable");
|
||||
if (unbreakableTag != null && unbreakableTag.asByte() != 0) {
|
||||
tag.put(nbtTagName() + "|Unbreakable", new ByteTag(unbreakableTag.asByte()));
|
||||
tag.remove("Unbreakable");
|
||||
|
||||
if (displayTag == null) { // Remove the display tag again if it was only added to emulate unbreakable
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag(true));
|
||||
}
|
||||
if (displayTag == null) { // Remove the display tag again if it was only added to emulate unbreakable
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag(true));
|
||||
}
|
||||
|
||||
ListTag<StringTag> loreTag = displayTag.getListTag("Lore", StringTag.class);
|
||||
if (loreTag == null) {
|
||||
displayTag.put("Lore", loreTag = new ListTag<>(StringTag.class));
|
||||
}
|
||||
loreTag.add(new StringTag("§9Unbreakable"));
|
||||
}
|
||||
}
|
||||
ListTag<StringTag> loreTag = displayTag.getListTag("Lore", StringTag.class);
|
||||
if (loreTag == null) {
|
||||
displayTag.put("Lore", loreTag = new ListTag<>(StringTag.class));
|
||||
}
|
||||
loreTag.add(new StringTag("§9Unbreakable"));
|
||||
}
|
||||
}
|
||||
|
||||
if (item.identifier() == 383 && item.data() == 0) { // Spawn eggs
|
||||
int data = 0;
|
||||
final CompoundTag entityTag = tag == null ? null : tag.getCompoundTag("EntityTag");
|
||||
if (entityTag != null) {
|
||||
final StringTag idTag = entityTag.getStringTag("id");
|
||||
if (idTag != null) {
|
||||
final String id = idTag.getValue();
|
||||
if (EntityIds1_8.ENTITY_NAME_TO_ID.containsKey(id)) {
|
||||
data = EntityIds1_8.ENTITY_NAME_TO_ID.get(id);
|
||||
} else if (displayTag == null) {
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag(true));
|
||||
displayTag.put("Name", new StringTag("§rSpawn " + id));
|
||||
}
|
||||
}
|
||||
}
|
||||
item.setData((short) data);
|
||||
}
|
||||
if (item.identifier() == 383 && item.data() == 0) { // Spawn eggs
|
||||
int data = 0;
|
||||
final CompoundTag entityTag = tag == null ? null : tag.getCompoundTag("EntityTag");
|
||||
if (entityTag != null) {
|
||||
final StringTag idTag = entityTag.getStringTag("id");
|
||||
if (idTag != null) {
|
||||
final String id = idTag.getValue();
|
||||
if (EntityIds1_8.ENTITY_NAME_TO_ID.containsKey(id)) {
|
||||
data = EntityIds1_8.ENTITY_NAME_TO_ID.get(id);
|
||||
} else if (displayTag == null) {
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag(true));
|
||||
displayTag.put("Name", new StringTag("§rSpawn " + id));
|
||||
}
|
||||
}
|
||||
}
|
||||
item.setData((short) data);
|
||||
}
|
||||
|
||||
// Potion, splash potion, lingering potion
|
||||
final boolean potion = item.identifier() == 373;
|
||||
final boolean splashPotion = item.identifier() == 438;
|
||||
final boolean lingeringPotion = item.identifier() == 441;
|
||||
// Potion, splash potion, lingering potion
|
||||
final boolean potion = item.identifier() == 373;
|
||||
final boolean splashPotion = item.identifier() == 438;
|
||||
final boolean lingeringPotion = item.identifier() == 441;
|
||||
|
||||
if (potion || splashPotion || lingeringPotion) {
|
||||
int data = 0;
|
||||
final StringTag potionTag = tag == null ? null : tag.getStringTag("Potion");
|
||||
if (potionTag != null) {
|
||||
String potionName = Key.stripMinecraftNamespace(potionTag.getValue());
|
||||
if (PotionIdMappings1_8.POTION_NAME_TO_ID.containsKey(potionName)) {
|
||||
data = PotionIdMappings1_8.POTION_NAME_TO_ID.get(potionName);
|
||||
}
|
||||
if (splashPotion) {
|
||||
potionName += "_splash";
|
||||
} else if (lingeringPotion) {
|
||||
potionName += "_lingering";
|
||||
}
|
||||
// Don't override custom name
|
||||
if ((displayTag == null || !displayTag.contains("Name")) && PotionIdMappings1_8.POTION_NAME_INDEX.containsKey(potionName)) {
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag(true));
|
||||
displayTag.put("Name", new StringTag(PotionIdMappings1_8.POTION_NAME_INDEX.get(potionName)));
|
||||
}
|
||||
}
|
||||
if (splashPotion || lingeringPotion) { // Convert splash and lingering potions to normal potions
|
||||
item.setIdentifier(373);
|
||||
data += 8192;
|
||||
}
|
||||
if (potion || splashPotion || lingeringPotion) {
|
||||
int data = 0;
|
||||
final StringTag potionTag = tag == null ? null : tag.getStringTag("Potion");
|
||||
if (potionTag != null) {
|
||||
String potionName = Key.stripMinecraftNamespace(potionTag.getValue());
|
||||
if (PotionIdMappings1_8.POTION_NAME_TO_ID.containsKey(potionName)) {
|
||||
data = PotionIdMappings1_8.POTION_NAME_TO_ID.get(potionName);
|
||||
}
|
||||
if (splashPotion) {
|
||||
potionName += "_splash";
|
||||
} else if (lingeringPotion) {
|
||||
potionName += "_lingering";
|
||||
}
|
||||
// Don't override custom name
|
||||
if ((displayTag == null || !displayTag.contains("Name")) && PotionIdMappings1_8.POTION_NAME_INDEX.containsKey(potionName)) {
|
||||
tag.put("display", displayTag = new CompoundTag());
|
||||
tag.put(nbtTagName() + "|noDisplay", new ByteTag(true));
|
||||
displayTag.put("Name", new StringTag(PotionIdMappings1_8.POTION_NAME_INDEX.get(potionName)));
|
||||
}
|
||||
}
|
||||
if (splashPotion || lingeringPotion) { // Convert splash and lingering potions to normal potions
|
||||
item.setIdentifier(373);
|
||||
data += 8192;
|
||||
}
|
||||
|
||||
item.setData((short) data);
|
||||
}
|
||||
item.setData((short) data);
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> attributeModifiers = tag == null ? null : tag.getListTag("AttributeModifiers", CompoundTag.class);
|
||||
if (attributeModifiers != null) {
|
||||
tag.put(nbtTagName() + "|AttributeModifiers", attributeModifiers.copy());
|
||||
attributeModifiers.getValue().removeIf(entries -> {
|
||||
final StringTag nameTag = entries.getStringTag("AttributeName");
|
||||
return nameTag != null && !VALID_ATTRIBUTES.contains(nameTag.getValue());
|
||||
});
|
||||
}
|
||||
final ListTag<CompoundTag> attributeModifiers = tag == null ? null : tag.getListTag("AttributeModifiers", CompoundTag.class);
|
||||
if (attributeModifiers != null) {
|
||||
tag.put(nbtTagName() + "|AttributeModifiers", attributeModifiers.copy());
|
||||
attributeModifiers.getValue().removeIf(entries -> {
|
||||
final StringTag nameTag = entries.getStringTag("AttributeName");
|
||||
return nameTag != null && !VALID_ATTRIBUTES.contains(nameTag.getValue());
|
||||
});
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(connection, item);
|
||||
@Override
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
CompoundTag tag = item.tag();
|
||||
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
|
||||
if (item.identifier() == 383 && item.data() != 0) { // Spawn eggs
|
||||
if ((tag == null || !tag.contains("EntityTag")) && EntityIds1_8.ENTITY_ID_TO_NAME.containsKey((int) item.data())) {
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
}
|
||||
final CompoundTag entityTag = new CompoundTag();
|
||||
entityTag.put("id", new StringTag(EntityIds1_8.ENTITY_ID_TO_NAME.get((int) item.data())));
|
||||
tag.put("EntityTag", entityTag);
|
||||
}
|
||||
item.setData((short) 0);
|
||||
}
|
||||
if (item.identifier() == 383 && item.data() != 0) { // Spawn eggs
|
||||
if ((tag == null || !tag.contains("EntityTag")) && EntityIds1_8.ENTITY_ID_TO_NAME.containsKey((int) item.data())) {
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
}
|
||||
final CompoundTag entityTag = new CompoundTag();
|
||||
entityTag.put("id", new StringTag(EntityIds1_8.ENTITY_ID_TO_NAME.get((int) item.data())));
|
||||
tag.put("EntityTag", entityTag);
|
||||
}
|
||||
item.setData((short) 0);
|
||||
}
|
||||
|
||||
if (item.identifier() == 373 && (tag == null || !tag.contains("Potion"))) { // Potions
|
||||
if (item.identifier() == 373 && (tag == null || !tag.contains("Potion"))) { // Potions
|
||||
if (item.data() >= 16384) {
|
||||
item.setIdentifier(438);
|
||||
item.setData((short) (item.data() - 8192));
|
||||
}
|
||||
item.setIdentifier(438);
|
||||
item.setData((short) (item.data() - 8192));
|
||||
}
|
||||
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
if (tag == null) {
|
||||
item.setTag(tag = new CompoundTag());
|
||||
|
||||
final String name = item.data() == 8192 ? "water" : PotionIdMappings1_9.potionNameFromDamage(item.data());
|
||||
tag.put("Potion", new StringTag("minecraft:" + name));
|
||||
}
|
||||
item.setData((short) 0);
|
||||
}
|
||||
final String name = item.data() == 8192 ? "water" : PotionIdMappings1_9.potionNameFromDamage(item.data());
|
||||
tag.put("Potion", new StringTag("minecraft:" + name));
|
||||
}
|
||||
item.setData((short) 0);
|
||||
}
|
||||
|
||||
if (tag == null) {
|
||||
return item;
|
||||
}
|
||||
final Tag noDisplayTag = tag.remove(nbtTagName() + "|noDisplay");
|
||||
if (noDisplayTag != null) {
|
||||
tag.remove("display");
|
||||
if (tag.isEmpty()) {
|
||||
item.setTag(null);
|
||||
}
|
||||
}
|
||||
final Tag unbreakableTag = tag.remove(nbtTagName() + "|Unbreakable");
|
||||
if (unbreakableTag != null) {
|
||||
tag.put("Unbreakable", unbreakableTag);
|
||||
}
|
||||
final Tag attributeModifiersTag = tag.remove(nbtTagName() + "|AttributeModifiers");
|
||||
if (attributeModifiersTag != null) {
|
||||
tag.put("AttributeModifiers", attributeModifiersTag);
|
||||
}
|
||||
if (tag == null) {
|
||||
return item;
|
||||
}
|
||||
final Tag noDisplayTag = tag.remove(nbtTagName() + "|noDisplay");
|
||||
if (noDisplayTag != null) {
|
||||
tag.remove("display");
|
||||
if (tag.isEmpty()) {
|
||||
item.setTag(null);
|
||||
}
|
||||
}
|
||||
final Tag unbreakableTag = tag.remove(nbtTagName() + "|Unbreakable");
|
||||
if (unbreakableTag != null) {
|
||||
tag.put("Unbreakable", unbreakableTag);
|
||||
}
|
||||
final Tag attributeModifiersTag = tag.remove(nbtTagName() + "|AttributeModifiers");
|
||||
if (attributeModifiersTag != null) {
|
||||
tag.put("AttributeModifiers", attributeModifiersTag);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
+516
-517
File diff suppressed because it is too large.
Load diff
+423
-420
@@ -17,512 +17,515 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_9to1_8.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.api.type.RewindTypes;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.*;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.BlockPlaceDestroyTracker;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.BossBarStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.CooldownStorage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.EntityTracker1_9;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.storage.PlayerPositionTracker;
|
||||
import com.viaversion.viarewind.utils.ChatUtil;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.libs.gson.JsonParser;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_9;
|
||||
import com.viaversion.viaversion.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerPacketRewriter1_9 extends RewriterBase<Protocol1_9To1_8> {
|
||||
|
||||
public PlayerPacketRewriter1_9(Protocol1_9To1_8 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
public PlayerPacketRewriter1_9(Protocol1_9To1_8 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BOSS_EVENT, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
final BossBarStorage bossbar = wrapper.user().get(BossBarStorage.class);
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BOSS_EVENT, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
final BossBarStorage bossbar = wrapper.user().get(BossBarStorage.class);
|
||||
|
||||
final UUID uuid = wrapper.read(Types.UUID);
|
||||
final int action = wrapper.read(Types.VAR_INT);
|
||||
if (action == 0 /* add */) {
|
||||
final JsonElement title = wrapper.read(Types.COMPONENT);
|
||||
final float health = wrapper.read(Types.FLOAT);
|
||||
wrapper.read(Types.VAR_INT); // Color
|
||||
wrapper.read(Types.VAR_INT); // Division
|
||||
wrapper.read(Types.UNSIGNED_BYTE); // Flags
|
||||
final UUID uuid = wrapper.read(Types.UUID);
|
||||
final int action = wrapper.read(Types.VAR_INT);
|
||||
if (action == 0 /* add */) {
|
||||
final JsonElement title = wrapper.read(Types.COMPONENT);
|
||||
final float health = wrapper.read(Types.FLOAT);
|
||||
wrapper.read(Types.VAR_INT); // Color
|
||||
wrapper.read(Types.VAR_INT); // Division
|
||||
wrapper.read(Types.UNSIGNED_BYTE); // Flags
|
||||
|
||||
bossbar.add(uuid, ChatUtil.jsonToLegacy(title), health);
|
||||
} else if (action == 1 /* remove */) {
|
||||
bossbar.remove(uuid);
|
||||
} else if (action == 2 /* update health */) {
|
||||
final float health = wrapper.read(Types.FLOAT);
|
||||
bossbar.updateHealth(uuid, health);
|
||||
} else if (action == 3 /* update title */) {
|
||||
final JsonElement title = wrapper.read(Types.COMPONENT);
|
||||
bossbar.updateTitle(uuid, ChatUtil.jsonToLegacy(title));
|
||||
}
|
||||
});
|
||||
bossbar.add(uuid, ChatUtil.jsonToLegacy(title), health);
|
||||
} else if (action == 1 /* remove */) {
|
||||
bossbar.remove(uuid);
|
||||
} else if (action == 2 /* update health */) {
|
||||
final float health = wrapper.read(Types.FLOAT);
|
||||
bossbar.updateHealth(uuid, health);
|
||||
} else if (action == 3 /* update title */) {
|
||||
final JsonElement title = wrapper.read(Types.COMPONENT);
|
||||
bossbar.updateTitle(uuid, ChatUtil.jsonToLegacy(title));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SET_PLAYER_TEAM, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Team name
|
||||
map(Types.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
final byte mode = wrapper.get(Types.BYTE, 0);
|
||||
if (mode == 0 /* create team */ || mode == 2 /* update team info */) {
|
||||
wrapper.passthrough(Types.STRING); // Display name
|
||||
wrapper.passthrough(Types.STRING); // Prefix
|
||||
wrapper.passthrough(Types.STRING); // Suffix
|
||||
wrapper.passthrough(Types.BYTE); // Friendly fire
|
||||
wrapper.passthrough(Types.STRING); // Name tag visibility
|
||||
wrapper.read(Types.STRING); // Collision rule
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SET_PLAYER_TEAM, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Team name
|
||||
map(Types.BYTE); // Mode
|
||||
handler(wrapper -> {
|
||||
final byte mode = wrapper.get(Types.BYTE, 0);
|
||||
if (mode == 0 /* create team */ || mode == 2 /* update team info */) {
|
||||
wrapper.passthrough(Types.STRING); // Display name
|
||||
wrapper.passthrough(Types.STRING); // Prefix
|
||||
wrapper.passthrough(Types.STRING); // Suffix
|
||||
wrapper.passthrough(Types.BYTE); // Friendly fire
|
||||
wrapper.passthrough(Types.STRING); // Name tag visibility
|
||||
wrapper.read(Types.STRING); // Collision rule
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_9.COOLDOWN);
|
||||
protocol.cancelClientbound(ClientboundPackets1_9.COOLDOWN);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Types.STRING, 0);
|
||||
if (channel.equals("MC|BOpen")) {
|
||||
wrapper.read(Types.VAR_INT);
|
||||
} else if (channel.equals("MC|TrList")) {
|
||||
protocol.getItemRewriter().handleTradeList(wrapper);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Types.STRING, 0);
|
||||
if (channel.equals("MC|BOpen")) {
|
||||
wrapper.read(Types.VAR_INT);
|
||||
} else if (channel.equals("MC|TrList")) {
|
||||
protocol.getItemRewriter().handleTradeList(wrapper);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.DOUBLE); // X
|
||||
map(Types.DOUBLE); // Feet y
|
||||
map(Types.DOUBLE); // Z
|
||||
map(Types.FLOAT); // Yaw
|
||||
map(Types.FLOAT); // Pitch
|
||||
map(Types.BYTE); // Relative arguments
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.DOUBLE); // X
|
||||
map(Types.DOUBLE); // Feet y
|
||||
map(Types.DOUBLE); // Z
|
||||
map(Types.FLOAT); // Yaw
|
||||
map(Types.FLOAT); // Pitch
|
||||
map(Types.BYTE); // Relative arguments
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker pos = wrapper.user().get(PlayerPositionTracker.class);
|
||||
|
||||
pos.setConfirmId(wrapper.read(Types.VAR_INT));
|
||||
pos.setConfirmId(wrapper.read(Types.VAR_INT));
|
||||
|
||||
byte flags = wrapper.get(Types.BYTE, 0);
|
||||
double x = wrapper.get(Types.DOUBLE, 0);
|
||||
double y = wrapper.get(Types.DOUBLE, 1);
|
||||
double z = wrapper.get(Types.DOUBLE, 2);
|
||||
float yaw = wrapper.get(Types.FLOAT, 0);
|
||||
float pitch = wrapper.get(Types.FLOAT, 1);
|
||||
byte flags = wrapper.get(Types.BYTE, 0);
|
||||
double x = wrapper.get(Types.DOUBLE, 0);
|
||||
double y = wrapper.get(Types.DOUBLE, 1);
|
||||
double z = wrapper.get(Types.DOUBLE, 2);
|
||||
float yaw = wrapper.get(Types.FLOAT, 0);
|
||||
float pitch = wrapper.get(Types.FLOAT, 1);
|
||||
|
||||
wrapper.set(Types.BYTE, 0, (byte) 0);
|
||||
wrapper.set(Types.BYTE, 0, (byte) 0);
|
||||
|
||||
if (flags != 0) {
|
||||
if ((flags & 0x01) != 0) {
|
||||
x += pos.getPosX();
|
||||
wrapper.set(Types.DOUBLE, 0, x);
|
||||
}
|
||||
if ((flags & 0x02) != 0) {
|
||||
y += pos.getPosY();
|
||||
wrapper.set(Types.DOUBLE, 1, y);
|
||||
}
|
||||
if ((flags & 0x04) != 0) {
|
||||
z += pos.getPosZ();
|
||||
wrapper.set(Types.DOUBLE, 2, z);
|
||||
}
|
||||
if ((flags & 0x08) != 0) {
|
||||
yaw += pos.getYaw();
|
||||
wrapper.set(Types.FLOAT, 0, yaw);
|
||||
}
|
||||
if ((flags & 0x10) != 0) {
|
||||
pitch += pos.getPitch();
|
||||
wrapper.set(Types.FLOAT, 1, pitch);
|
||||
}
|
||||
}
|
||||
if (flags != 0) {
|
||||
if ((flags & 0x01) != 0) {
|
||||
x += pos.getPosX();
|
||||
wrapper.set(Types.DOUBLE, 0, x);
|
||||
}
|
||||
if ((flags & 0x02) != 0) {
|
||||
y += pos.getPosY();
|
||||
wrapper.set(Types.DOUBLE, 1, y);
|
||||
}
|
||||
if ((flags & 0x04) != 0) {
|
||||
z += pos.getPosZ();
|
||||
wrapper.set(Types.DOUBLE, 2, z);
|
||||
}
|
||||
if ((flags & 0x08) != 0) {
|
||||
yaw += pos.getYaw();
|
||||
wrapper.set(Types.FLOAT, 0, yaw);
|
||||
}
|
||||
if ((flags & 0x10) != 0) {
|
||||
pitch += pos.getPitch();
|
||||
wrapper.set(Types.FLOAT, 1, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
pos.setPos(x, y, z);
|
||||
pos.setYaw(yaw);
|
||||
pos.setPitch(pitch);
|
||||
});
|
||||
}
|
||||
});
|
||||
pos.setPos(x, y, z);
|
||||
pos.setYaw(yaw);
|
||||
pos.setPitch(pitch);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.RESPAWN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Dimension
|
||||
handler(wrapper -> {
|
||||
final ClientWorld world = wrapper.user().getClientWorld(Protocol1_9To1_8.class);
|
||||
final int dimension = wrapper.get(Types.INT, 0);
|
||||
protocol.registerClientbound(ClientboundPackets1_9.RESPAWN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Dimension
|
||||
handler(wrapper -> {
|
||||
final ClientWorld world = wrapper.user().getClientWorld(Protocol1_9To1_8.class);
|
||||
final int dimension = wrapper.get(Types.INT, 0);
|
||||
|
||||
if (world.setEnvironment(dimension)) {
|
||||
if (world.setEnvironment(dimension)) {
|
||||
final EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
tracker.clearEntities();
|
||||
wrapper.user().get(BossBarStorage.class).reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
wrapper.user().get(BossBarStorage.class).reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Packet implementation doesn't do anything until 1.9
|
||||
protocol.registerClientbound(ClientboundPackets1_9.PLAYER_COMBAT, wrapper -> {
|
||||
if (!ViaRewind.getConfig().handlePlayerCombatPacket()) {
|
||||
return;
|
||||
}
|
||||
// Packet implementation doesn't do anything until 1.9
|
||||
protocol.registerClientbound(ClientboundPackets1_9.PLAYER_COMBAT, wrapper -> {
|
||||
if (!ViaRewind.getConfig().handlePlayerCombatPacket()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int action = wrapper.passthrough(Types.VAR_INT);
|
||||
if (action != 2) {
|
||||
return;
|
||||
}
|
||||
final int action = wrapper.passthrough(Types.VAR_INT);
|
||||
if (action != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
final int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||
wrapper.passthrough(Types.INT); // Killer id
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
final int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||
wrapper.passthrough(Types.INT); // Killer id
|
||||
|
||||
if (entityId != tracker.clientEntityId()) {
|
||||
return;
|
||||
}
|
||||
if (entityId != tracker.clientEntityId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final JsonElement message = wrapper.passthrough(Types.COMPONENT);
|
||||
final JsonElement message = wrapper.passthrough(Types.COMPONENT);
|
||||
|
||||
final PacketWrapper killPlayer = wrapper.create(ClientboundPackets1_8.SET_HEALTH);
|
||||
killPlayer.write(Types.FLOAT, 0F); // Health
|
||||
killPlayer.write(Types.VAR_INT, 0); // Food
|
||||
killPlayer.write(Types.FLOAT, 0F); // Food Saturation
|
||||
killPlayer.scheduleSend(Protocol1_9To1_8.class);
|
||||
final PacketWrapper killPlayer = wrapper.create(ClientboundPackets1_8.SET_HEALTH);
|
||||
killPlayer.write(Types.FLOAT, 0F); // Health
|
||||
killPlayer.write(Types.VAR_INT, 0); // Food
|
||||
killPlayer.write(Types.FLOAT, 0F); // Food Saturation
|
||||
killPlayer.scheduleSend(Protocol1_9To1_8.class);
|
||||
|
||||
final PacketWrapper chatMessage = wrapper.create(ClientboundPackets1_8.CHAT);
|
||||
chatMessage.write(Types.COMPONENT, message);
|
||||
chatMessage.write(Types.BYTE, (byte) 2); // Position - above hotbar
|
||||
chatMessage.scheduleSend(Protocol1_9To1_8.class);
|
||||
});
|
||||
final PacketWrapper chatMessage = wrapper.create(ClientboundPackets1_8.CHAT);
|
||||
chatMessage.write(Types.COMPONENT, message);
|
||||
chatMessage.write(Types.BYTE, (byte) 2); // Position - above hotbar
|
||||
chatMessage.scheduleSend(Protocol1_9To1_8.class);
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CHAT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Message
|
||||
handler(wrapper -> {
|
||||
if (!ViaRewind.getConfig().isEnableOffhand()) {
|
||||
return;
|
||||
}
|
||||
final String message = wrapper.get(Types.STRING, 0);
|
||||
if (message.toLowerCase().trim().startsWith(ViaRewind.getConfig().getOffhandCommand())) {
|
||||
wrapper.cancel();
|
||||
final PacketWrapper swapItems = PacketWrapper.create(ServerboundPackets1_9.PLAYER_ACTION, wrapper.user());
|
||||
swapItems.write(Types.VAR_INT, 6);
|
||||
swapItems.write(Types.BLOCK_POSITION1_8, new BlockPosition(0, 0, 0));
|
||||
swapItems.write(Types.UNSIGNED_BYTE, (short) 255);
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CHAT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Message
|
||||
handler(wrapper -> {
|
||||
if (!ViaRewind.getConfig().isEnableOffhand()) {
|
||||
return;
|
||||
}
|
||||
final String message = wrapper.get(Types.STRING, 0);
|
||||
if (message.toLowerCase().trim().startsWith(ViaRewind.getConfig().getOffhandCommand())) {
|
||||
wrapper.cancel();
|
||||
final PacketWrapper swapItems = PacketWrapper.create(ServerboundPackets1_9.PLAYER_ACTION, wrapper.user());
|
||||
swapItems.write(Types.VAR_INT, 6);
|
||||
swapItems.write(Types.BLOCK_POSITION1_8, new BlockPosition(0, 0, 0));
|
||||
swapItems.write(Types.UNSIGNED_BYTE, (short) 255);
|
||||
|
||||
swapItems.sendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
swapItems.sendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.INTERACT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Target
|
||||
map(Types.VAR_INT); // Type
|
||||
handler(wrapper -> {
|
||||
final int type = wrapper.get(Types.VAR_INT, 1);
|
||||
if (type == 2 /* attack */) {
|
||||
wrapper.passthrough(Types.FLOAT); // Target x
|
||||
wrapper.passthrough(Types.FLOAT); // Target y
|
||||
wrapper.passthrough(Types.FLOAT); // Target z
|
||||
}
|
||||
if (type == 2 /* attack */ || type == 0 /* interact */) {
|
||||
wrapper.write(Types.VAR_INT, 0); // Hand
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_8.INTERACT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Target
|
||||
map(Types.VAR_INT); // Type
|
||||
handler(wrapper -> {
|
||||
final int type = wrapper.get(Types.VAR_INT, 1);
|
||||
if (type == 2 /* attack */) {
|
||||
wrapper.passthrough(Types.FLOAT); // Target x
|
||||
wrapper.passthrough(Types.FLOAT); // Target y
|
||||
wrapper.passthrough(Types.FLOAT); // Target z
|
||||
}
|
||||
if (type == 2 /* attack */ || type == 0 /* interact */) {
|
||||
wrapper.write(Types.VAR_INT, 0); // Hand
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_STATUS_ONLY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(PlayerPositionTracker.class).sendAnimations();
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_STATUS_ONLY, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(PlayerPositionTracker.class).sendAnimations();
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
if (tracker.isInsideVehicle(tracker.clientEntityId())) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
if (tracker.isInsideVehicle(tracker.clientEntityId())) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_POS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.DOUBLE); // X
|
||||
map(Types.DOUBLE); // Feet y
|
||||
map(Types.DOUBLE); // Z
|
||||
map(Types.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker storage = wrapper.user().get(PlayerPositionTracker.class);
|
||||
storage.sendAnimations();
|
||||
if (storage.getConfirmId() != -1) {
|
||||
return;
|
||||
}
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_POS, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.DOUBLE); // X
|
||||
map(Types.DOUBLE); // Feet y
|
||||
map(Types.DOUBLE); // Z
|
||||
map(Types.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker storage = wrapper.user().get(PlayerPositionTracker.class);
|
||||
storage.sendAnimations();
|
||||
if (storage.getConfirmId() != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
storage.setPos(wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2));
|
||||
storage.setOnGround(wrapper.get(Types.BOOLEAN, 0));
|
||||
});
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).updateLocation());
|
||||
}
|
||||
});
|
||||
storage.setPos(wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2));
|
||||
storage.setOnGround(wrapper.get(Types.BOOLEAN, 0));
|
||||
});
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).updateLocation());
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_ROT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.FLOAT); // Yaw
|
||||
map(Types.FLOAT); // Pitch
|
||||
map(Types.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker storage = wrapper.user().get(PlayerPositionTracker.class);
|
||||
storage.sendAnimations();
|
||||
if (storage.getConfirmId() != -1) {
|
||||
return;
|
||||
}
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_ROT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.FLOAT); // Yaw
|
||||
map(Types.FLOAT); // Pitch
|
||||
map(Types.BOOLEAN); // On ground
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker storage = wrapper.user().get(PlayerPositionTracker.class);
|
||||
storage.sendAnimations();
|
||||
if (storage.getConfirmId() != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
storage.setYaw(wrapper.get(Types.FLOAT, 0));
|
||||
storage.setPitch(wrapper.get(Types.FLOAT, 1));
|
||||
storage.setOnGround(wrapper.get(Types.BOOLEAN, 0));
|
||||
});
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).updateLocation());
|
||||
}
|
||||
});
|
||||
storage.setYaw(wrapper.get(Types.FLOAT, 0));
|
||||
storage.setPitch(wrapper.get(Types.FLOAT, 1));
|
||||
storage.setOnGround(wrapper.get(Types.BOOLEAN, 0));
|
||||
});
|
||||
handler(wrapper -> wrapper.user().get(BossBarStorage.class).updateLocation());
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_POS_ROT, wrapper -> {
|
||||
final double x = wrapper.passthrough(Types.DOUBLE);
|
||||
final double y = wrapper.passthrough(Types.DOUBLE);
|
||||
final double z = wrapper.passthrough(Types.DOUBLE);
|
||||
final float yaw = wrapper.passthrough(Types.FLOAT);
|
||||
final float pitch = wrapper.passthrough(Types.FLOAT);
|
||||
final boolean onGround = wrapper.passthrough(Types.BOOLEAN);
|
||||
protocol.registerServerbound(ServerboundPackets1_8.MOVE_PLAYER_POS_ROT, wrapper -> {
|
||||
final double x = wrapper.passthrough(Types.DOUBLE);
|
||||
final double y = wrapper.passthrough(Types.DOUBLE);
|
||||
final double z = wrapper.passthrough(Types.DOUBLE);
|
||||
final float yaw = wrapper.passthrough(Types.FLOAT);
|
||||
final float pitch = wrapper.passthrough(Types.FLOAT);
|
||||
final boolean onGround = wrapper.passthrough(Types.BOOLEAN);
|
||||
|
||||
final PlayerPositionTracker storage = wrapper.user().get(PlayerPositionTracker.class);
|
||||
storage.sendAnimations();
|
||||
if (storage.getConfirmId() != -1) {
|
||||
if (storage.getPosX() == x && storage.getPosY() == y && storage.getPosZ() == z && storage.getYaw() == yaw && storage.getPitch() == pitch) {
|
||||
final PacketWrapper confirmTeleport = PacketWrapper.create(ServerboundPackets1_9.ACCEPT_TELEPORTATION, wrapper.user());
|
||||
confirmTeleport.write(Types.VAR_INT, storage.getConfirmId());
|
||||
confirmTeleport.sendToServer(Protocol1_9To1_8.class);
|
||||
final PlayerPositionTracker storage = wrapper.user().get(PlayerPositionTracker.class);
|
||||
storage.sendAnimations();
|
||||
if (storage.getConfirmId() != -1) {
|
||||
if (storage.getPosX() == x && storage.getPosY() == y && storage.getPosZ() == z && storage.getYaw() == yaw && storage.getPitch() == pitch) {
|
||||
final PacketWrapper confirmTeleport = PacketWrapper.create(ServerboundPackets1_9.ACCEPT_TELEPORTATION, wrapper.user());
|
||||
confirmTeleport.write(Types.VAR_INT, storage.getConfirmId());
|
||||
confirmTeleport.sendToServer(Protocol1_9To1_8.class);
|
||||
|
||||
storage.setConfirmId(-1);
|
||||
}
|
||||
} else {
|
||||
storage.setPos(x, y, z);
|
||||
storage.setYaw(yaw);
|
||||
storage.setPitch(pitch);
|
||||
storage.setOnGround(onGround);
|
||||
wrapper.user().get(BossBarStorage.class).updateLocation();
|
||||
}
|
||||
});
|
||||
storage.setConfirmId(-1);
|
||||
}
|
||||
} else {
|
||||
storage.setPos(x, y, z);
|
||||
storage.setYaw(yaw);
|
||||
storage.setPitch(pitch);
|
||||
storage.setOnGround(onGround);
|
||||
wrapper.user().get(BossBarStorage.class).updateLocation();
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_ACTION, wrapper -> {
|
||||
final int status = wrapper.passthrough(Types.VAR_INT);
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_ACTION, wrapper -> {
|
||||
final int status = wrapper.passthrough(Types.VAR_INT);
|
||||
|
||||
final BlockPlaceDestroyTracker tracker = wrapper.user().get(BlockPlaceDestroyTracker.class);
|
||||
if (status == 0 || status == 1 || status == 2) { // Start, cancel or finish
|
||||
tracker.setMining();
|
||||
}
|
||||
final BlockPlaceDestroyTracker tracker = wrapper.user().get(BlockPlaceDestroyTracker.class);
|
||||
if (status == 0 || status == 1 || status == 2) { // Start, cancel or finish
|
||||
tracker.setMining();
|
||||
}
|
||||
|
||||
final CooldownStorage cooldown = wrapper.user().get(CooldownStorage.class);
|
||||
if (status == 1) { // Cancel
|
||||
tracker.setLastMining(0);
|
||||
cooldown.hit();
|
||||
} else if (status == 2) { // Finish
|
||||
tracker.setLastMining(System.currentTimeMillis() + 100);
|
||||
cooldown.setLastHit(0);
|
||||
}
|
||||
});
|
||||
final CooldownStorage cooldown = wrapper.user().get(CooldownStorage.class);
|
||||
if (status == 1) { // Cancel
|
||||
tracker.setLastMining(0);
|
||||
cooldown.hit();
|
||||
} else if (status == 2) { // Finish
|
||||
tracker.setLastMining(System.currentTimeMillis() + 100);
|
||||
cooldown.setLastHit(0);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.USE_ITEM_ON, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.BYTE, Types.VAR_INT); // Face
|
||||
read(Types.ITEM1_8); // Current item
|
||||
create(Types.VAR_INT, 0); // Hand - main
|
||||
map(Types.BYTE, Types.UNSIGNED_BYTE); // Cursor position x
|
||||
map(Types.BYTE, Types.UNSIGNED_BYTE); // Cursor position y
|
||||
map(Types.BYTE, Types.UNSIGNED_BYTE); // Cursor position z
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Types.VAR_INT, 0) == -1) {
|
||||
wrapper.cancel();
|
||||
final PacketWrapper useItem = PacketWrapper.create(ServerboundPackets1_9.USE_ITEM, wrapper.user());
|
||||
useItem.write(Types.VAR_INT, 0);
|
||||
useItem.sendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_8.USE_ITEM_ON, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.BYTE, Types.VAR_INT); // Face
|
||||
read(Types.ITEM1_8); // Current item
|
||||
create(Types.VAR_INT, 0); // Hand - main
|
||||
map(Types.BYTE, Types.UNSIGNED_BYTE); // Cursor position x
|
||||
map(Types.BYTE, Types.UNSIGNED_BYTE); // Cursor position y
|
||||
map(Types.BYTE, Types.UNSIGNED_BYTE); // Cursor position z
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Types.VAR_INT, 0) == -1) {
|
||||
wrapper.cancel();
|
||||
final PacketWrapper useItem = PacketWrapper.create(ServerboundPackets1_9.USE_ITEM, wrapper.user());
|
||||
useItem.write(Types.VAR_INT, 0);
|
||||
useItem.sendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.SET_CARRIED_ITEM, wrapper -> wrapper.user().get(CooldownStorage.class).hit());
|
||||
protocol.registerServerbound(ServerboundPackets1_8.SET_CARRIED_ITEM, wrapper -> wrapper.user().get(CooldownStorage.class).hit());
|
||||
|
||||
// Queue swing packet to be sent after on ground idle packets
|
||||
protocol.registerServerbound(ServerboundPackets1_8.SWING, wrapper -> {
|
||||
wrapper.cancel();
|
||||
// Queue swing packet to be sent after on ground idle packets
|
||||
protocol.registerServerbound(ServerboundPackets1_8.SWING, wrapper -> {
|
||||
wrapper.cancel();
|
||||
|
||||
final PacketWrapper swing = PacketWrapper.create(ServerboundPackets1_9.SWING, wrapper.user());
|
||||
swing.write(Types.VAR_INT, 0); // Main Hand
|
||||
wrapper.user().get(PlayerPositionTracker.class).queueAnimation(swing);
|
||||
final PacketWrapper swing = PacketWrapper.create(ServerboundPackets1_9.SWING, wrapper.user());
|
||||
swing.write(Types.VAR_INT, 0); // Main Hand
|
||||
wrapper.user().get(PlayerPositionTracker.class).queueAnimation(swing);
|
||||
|
||||
wrapper.user().get(BlockPlaceDestroyTracker.class).updateMining();
|
||||
wrapper.user().get(CooldownStorage.class).hit();
|
||||
});
|
||||
wrapper.user().get(BlockPlaceDestroyTracker.class).updateMining();
|
||||
wrapper.user().get(CooldownStorage.class).hit();
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_COMMAND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.VAR_INT); // Action id
|
||||
map(Types.VAR_INT); // Action parameter
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker tracker = wrapper.user().get(PlayerPositionTracker.class);
|
||||
final int action = wrapper.get(Types.VAR_INT, 1);
|
||||
if (action == 6) { // Jump with horse
|
||||
wrapper.set(Types.VAR_INT, 1, 7);
|
||||
} else if (action == 0 && !tracker.isOnGround()) { // Start sneaking
|
||||
final PacketWrapper elytra = PacketWrapper.create(ServerboundPackets1_9.PLAYER_COMMAND, wrapper.user());
|
||||
elytra.write(Types.VAR_INT, wrapper.get(Types.VAR_INT, 0));
|
||||
elytra.write(Types.VAR_INT, 8);
|
||||
elytra.write(Types.VAR_INT, 0);
|
||||
elytra.scheduleSendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_COMMAND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.VAR_INT); // Action id
|
||||
map(Types.VAR_INT); // Action parameter
|
||||
handler(wrapper -> {
|
||||
final PlayerPositionTracker tracker = wrapper.user().get(PlayerPositionTracker.class);
|
||||
final int action = wrapper.get(Types.VAR_INT, 1);
|
||||
if (action == 6) { // Jump with horse
|
||||
wrapper.set(Types.VAR_INT, 1, 7);
|
||||
} else if (action == 0 && !tracker.isOnGround()) { // Start sneaking
|
||||
final PacketWrapper elytra = PacketWrapper.create(ServerboundPackets1_9.PLAYER_COMMAND, wrapper.user());
|
||||
elytra.write(Types.VAR_INT, wrapper.get(Types.VAR_INT, 0));
|
||||
elytra.write(Types.VAR_INT, 8);
|
||||
elytra.write(Types.VAR_INT, 0);
|
||||
elytra.scheduleSendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_INPUT, wrapper -> {
|
||||
final float sideways = wrapper.passthrough(Types.FLOAT);
|
||||
final float forward = wrapper.passthrough(Types.FLOAT);
|
||||
protocol.registerServerbound(ServerboundPackets1_8.PLAYER_INPUT, wrapper -> {
|
||||
final float sideways = wrapper.passthrough(Types.FLOAT);
|
||||
final float forward = wrapper.passthrough(Types.FLOAT);
|
||||
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
final Integer vehicle = tracker.getVehicle(tracker.clientEntityId());
|
||||
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
final Integer vehicle = tracker.getVehicle(tracker.clientEntityId());
|
||||
|
||||
if (vehicle != null && tracker.entityType(vehicle) == EntityTypes1_9.EntityType.BOAT) {
|
||||
final PacketWrapper paddleBoat = PacketWrapper.create(ServerboundPackets1_9.PADDLE_BOAT, wrapper.user());
|
||||
paddleBoat.write(Types.BOOLEAN, forward != 0.0f || sideways < 0.0f);
|
||||
paddleBoat.write(Types.BOOLEAN, forward != 0.0f || sideways > 0.0f);
|
||||
paddleBoat.scheduleSendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
if (vehicle != null && tracker.entityType(vehicle) == EntityTypes1_9.EntityType.BOAT) {
|
||||
final PacketWrapper paddleBoat = PacketWrapper.create(ServerboundPackets1_9.PADDLE_BOAT, wrapper.user());
|
||||
paddleBoat.write(Types.BOOLEAN, forward != 0.0f || sideways < 0.0f);
|
||||
paddleBoat.write(Types.BOOLEAN, forward != 0.0f || sideways > 0.0f);
|
||||
paddleBoat.scheduleSendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.SIGN_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
handler(wrapper -> {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
protocol.registerServerbound(ServerboundPackets1_8.SIGN_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
handler(wrapper -> {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final JsonElement json = JsonParser.parseString(wrapper.read(RewindTypes.SIGN_STRING));
|
||||
if (!json.isJsonPrimitive()) {
|
||||
throw new IllegalStateException("Invalid sign text: " + StringUtil.forLogging(json));
|
||||
}
|
||||
|
||||
wrapper.write(Types.STRING, ChatUtil.jsonToLegacy(json));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
wrapper.write(Types.STRING, ChatUtil.jsonToLegacy(json));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.COMMAND_SUGGESTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Message
|
||||
create(Types.BOOLEAN, false); // Has position
|
||||
map(Types.OPTIONAL_POSITION1_8); // Looked at block (position)
|
||||
}
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_8.COMMAND_SUGGESTION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Message
|
||||
create(Types.BOOLEAN, false); // Has position
|
||||
map(Types.OPTIONAL_POSITION1_8); // Looked at block (position)
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CLIENT_INFORMATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Locale
|
||||
map(Types.BYTE); // View distance
|
||||
map(Types.BYTE, Types.VAR_INT); // Chat mode
|
||||
map(Types.BOOLEAN); // Chat colors
|
||||
map(Types.UNSIGNED_BYTE); // Displayed skin parts
|
||||
create(Types.VAR_INT, 1); // Main hand
|
||||
handler(wrapper -> {
|
||||
final short flags = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CLIENT_INFORMATION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Locale
|
||||
map(Types.BYTE); // View distance
|
||||
map(Types.BYTE, Types.VAR_INT); // Chat mode
|
||||
map(Types.BOOLEAN); // Chat colors
|
||||
map(Types.UNSIGNED_BYTE); // Displayed skin parts
|
||||
create(Types.VAR_INT, 1); // Main hand
|
||||
handler(wrapper -> {
|
||||
final short flags = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
|
||||
final PacketWrapper updateSkin = PacketWrapper.create(ClientboundPackets1_8.SET_ENTITY_DATA, wrapper.user());
|
||||
updateSkin.write(Types.VAR_INT, wrapper.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId());
|
||||
final PacketWrapper updateSkin = PacketWrapper.create(ClientboundPackets1_8.SET_ENTITY_DATA, wrapper.user());
|
||||
updateSkin.write(Types.VAR_INT, wrapper.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId());
|
||||
|
||||
final List<EntityData> entityData = new ArrayList<>();
|
||||
entityData.add(new EntityData(10, EntityDataTypes1_8.BYTE, (byte) flags));
|
||||
final List<EntityData> entityData = new ArrayList<>();
|
||||
entityData.add(new EntityData(10, EntityDataTypes1_8.BYTE, (byte) flags));
|
||||
|
||||
updateSkin.write(Types.ENTITY_DATA_LIST1_8, entityData);
|
||||
updateSkin.scheduleSend(Protocol1_9To1_8.class);
|
||||
});
|
||||
}
|
||||
});
|
||||
updateSkin.write(Types.ENTITY_DATA_LIST1_8, entityData);
|
||||
updateSkin.scheduleSend(Protocol1_9To1_8.class);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Types.STRING, 0);
|
||||
if (channel.equals("MC|BEdit") || channel.equals("MC|BSign")) {
|
||||
final Item book = wrapper.passthrough(Types.ITEM1_8);
|
||||
book.setIdentifier(386);
|
||||
final CompoundTag tag = book.tag();
|
||||
if (tag == null) {
|
||||
return;
|
||||
}
|
||||
final ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages == null) {
|
||||
return;
|
||||
}
|
||||
if (pages.size() > ViaRewind.getConfig().getMaxBookPages()) {
|
||||
wrapper.user().disconnect("Too many book pages");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < pages.size(); i++) {
|
||||
final StringTag pageTag = pages.get(i);
|
||||
final String value = pageTag.getValue();
|
||||
protocol.registerServerbound(ServerboundPackets1_8.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Types.STRING, 0);
|
||||
if (channel.equals("MC|BEdit") || channel.equals("MC|BSign")) {
|
||||
final Item book = wrapper.passthrough(Types.ITEM1_8);
|
||||
book.setIdentifier(386);
|
||||
final CompoundTag tag = book.tag();
|
||||
if (tag == null) {
|
||||
return;
|
||||
}
|
||||
final ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages == null) {
|
||||
return;
|
||||
}
|
||||
if (pages.size() > ViaRewind.getConfig().getMaxBookPages()) {
|
||||
wrapper.user().disconnect("Too many book pages");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < pages.size(); i++) {
|
||||
final StringTag pageTag = pages.get(i);
|
||||
final String value = pageTag.getValue();
|
||||
|
||||
if (value.length() > ViaRewind.getConfig().getMaxBookPageSize()) {
|
||||
wrapper.user().disconnect("Book page too large");
|
||||
return;
|
||||
}
|
||||
if (value.length() > ViaRewind.getConfig().getMaxBookPageSize()) {
|
||||
wrapper.user().disconnect("Book page too large");
|
||||
return;
|
||||
}
|
||||
|
||||
pageTag.setValue(ChatUtil.jsonToLegacy(value));
|
||||
}
|
||||
} else if (channel.equals("MC|AdvCdm")) {
|
||||
wrapper.set(Types.STRING, 0, "MC|AdvCmd");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
pageTag.setValue(ChatUtil.jsonToLegacy(value));
|
||||
}
|
||||
} else if (channel.equals("MC|AdvCdm")) {
|
||||
wrapper.set(Types.STRING, 0, "MC|AdvCmd");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+207
-208
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package com.viaversion.viarewind.protocol.v1_9to1_8.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viarewind.ViaRewind;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
@@ -37,235 +39,232 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WorldPacketRewriter1_9 extends RewriterBase<Protocol1_9To1_8> {
|
||||
|
||||
public WorldPacketRewriter1_9(Protocol1_9To1_8 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
public WorldPacketRewriter1_9(Protocol1_9To1_8 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.UNSIGNED_BYTE); // Action
|
||||
map(Types.NAMED_COMPOUND_TAG); // Tag
|
||||
handler(wrapper -> {
|
||||
final CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.UNSIGNED_BYTE); // Action
|
||||
map(Types.NAMED_COMPOUND_TAG); // Tag
|
||||
handler(wrapper -> {
|
||||
final CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
|
||||
|
||||
if (tag.remove("SpawnData") instanceof CompoundTag spawnData) {
|
||||
final Tag id = spawnData.remove("id");
|
||||
if (id instanceof StringTag) {
|
||||
tag.put("EntityId", id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (tag.remove("SpawnData") instanceof CompoundTag spawnData) {
|
||||
final Tag id = spawnData.remove("id");
|
||||
if (id instanceof StringTag) {
|
||||
tag.put("EntityId", id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BLOCK_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.UNSIGNED_BYTE); // Byte 1 (depending on block type)
|
||||
map(Types.UNSIGNED_BYTE); // Byte 2 (depending on block type)
|
||||
map(Types.VAR_INT); // Block
|
||||
handler(wrapper -> {
|
||||
final int block = wrapper.get(Types.VAR_INT, 0);
|
||||
if (block >= 219 && block <= 234) {
|
||||
wrapper.set(Types.VAR_INT, 0, 130);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.BLOCK_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.UNSIGNED_BYTE); // Byte 1 (depending on block type)
|
||||
map(Types.UNSIGNED_BYTE); // Byte 2 (depending on block type)
|
||||
map(Types.VAR_INT); // Block
|
||||
handler(wrapper -> {
|
||||
final int block = wrapper.get(Types.VAR_INT, 0);
|
||||
if (block >= 219 && block <= 234) {
|
||||
wrapper.set(Types.VAR_INT, 0, 130);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CUSTOM_SOUND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Sound name
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
name = protocol.getMappingData().getMappedNamedSound(name);
|
||||
if (name == null) {
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.set(Types.STRING, 0, name);
|
||||
}
|
||||
});
|
||||
read(Types.VAR_INT); // Sound category
|
||||
map(Types.INT); // Effect position x
|
||||
map(Types.INT); // Effect position y
|
||||
map(Types.INT); // Effect position z
|
||||
map(Types.FLOAT); // Volume
|
||||
map(Types.UNSIGNED_BYTE); // Pitch
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.CUSTOM_SOUND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // Sound name
|
||||
handler(wrapper -> {
|
||||
String name = wrapper.get(Types.STRING, 0);
|
||||
name = protocol.getMappingData().getMappedNamedSound(name);
|
||||
if (name == null) {
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.set(Types.STRING, 0, name);
|
||||
}
|
||||
});
|
||||
read(Types.VAR_INT); // Sound category
|
||||
map(Types.INT); // Effect position x
|
||||
map(Types.INT); // Effect position y
|
||||
map(Types.INT); // Effect position z
|
||||
map(Types.FLOAT); // Volume
|
||||
map(Types.UNSIGNED_BYTE); // Pitch
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.FORGET_LEVEL_CHUNK, ClientboundPackets1_8.LEVEL_CHUNK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final Environment environment = wrapper.user().getClientWorld(Protocol1_9To1_8.class).getEnvironment();
|
||||
protocol.registerClientbound(ClientboundPackets1_9.FORGET_LEVEL_CHUNK, ClientboundPackets1_8.LEVEL_CHUNK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final Environment environment = wrapper.user().getClientWorld(Protocol1_9To1_8.class).getEnvironment();
|
||||
|
||||
final int chunkX = wrapper.read(Types.INT);
|
||||
final int chunkZ = wrapper.read(Types.INT);
|
||||
final int chunkX = wrapper.read(Types.INT);
|
||||
final int chunkZ = wrapper.read(Types.INT);
|
||||
|
||||
wrapper.write(ChunkType1_8.forEnvironment(environment), new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>()));
|
||||
});
|
||||
}
|
||||
});
|
||||
wrapper.write(ChunkType1_8.forEnvironment(environment), new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>()));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.LEVEL_CHUNK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final Environment environment = wrapper.user().getClientWorld(Protocol1_9To1_8.class).getEnvironment();
|
||||
protocol.registerClientbound(ClientboundPackets1_9.LEVEL_CHUNK, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final Environment environment = wrapper.user().getClientWorld(Protocol1_9To1_8.class).getEnvironment();
|
||||
|
||||
Chunk chunk = wrapper.read(ChunkType1_9_1.forEnvironment(environment));
|
||||
Chunk chunk = wrapper.read(ChunkType1_9_1.forEnvironment(environment));
|
||||
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) continue;
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int block = palette.idByIndex(i);
|
||||
int replacedBlock = protocol.getItemRewriter().handleBlockId(block);
|
||||
palette.setIdByIndex(i, replacedBlock);
|
||||
}
|
||||
}
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) continue;
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int block = palette.idByIndex(i);
|
||||
int replacedBlock = protocol.getItemRewriter().handleBlockId(block);
|
||||
palette.setIdByIndex(i, replacedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.isFullChunk() && chunk.getBitmask() == 0) { // This would be an unload packet for 1.8 clients. Just set one air section
|
||||
boolean skylight = environment == Environment.NORMAL;
|
||||
ChunkSection[] sections = new ChunkSection[16];
|
||||
ChunkSection section = new ChunkSectionImpl(true);
|
||||
sections[0] = section;
|
||||
section.palette(PaletteType.BLOCKS).addId(0);
|
||||
if (skylight) section.getLight().setSkyLight(new byte[2048]);
|
||||
chunk = new BaseChunk(chunk.getX(), chunk.getZ(), true, false, 1, sections, chunk.getBiomeData(), chunk.getBlockEntities());
|
||||
}
|
||||
if (chunk.isFullChunk() && chunk.getBitmask() == 0) { // This would be an unload packet for 1.8 clients. Just set one air section
|
||||
boolean skylight = environment == Environment.NORMAL;
|
||||
ChunkSection[] sections = new ChunkSection[16];
|
||||
ChunkSection section = new ChunkSectionImpl(true);
|
||||
sections[0] = section;
|
||||
section.palette(PaletteType.BLOCKS).addId(0);
|
||||
if (skylight) section.getLight().setSkyLight(new byte[2048]);
|
||||
chunk = new BaseChunk(chunk.getX(), chunk.getZ(), true, false, 1, sections, chunk.getBiomeData(), chunk.getBlockEntities());
|
||||
}
|
||||
|
||||
wrapper.write(ChunkType1_8.forEnvironment(environment), chunk);
|
||||
wrapper.write(ChunkType1_8.forEnvironment(environment), chunk);
|
||||
|
||||
chunk.getBlockEntities().forEach(nbt -> {
|
||||
if (!nbt.contains("x") || !nbt.contains("y") || !nbt.contains("z") || !nbt.contains("id")) {
|
||||
return;
|
||||
}
|
||||
BlockPosition position = new BlockPosition((int) nbt.get("x").getValue(), (int) nbt.get("y").getValue(), (int) nbt.get("z").getValue());
|
||||
String id = (String) nbt.get("id").getValue();
|
||||
chunk.getBlockEntities().forEach(nbt -> {
|
||||
if (!nbt.contains("x") || !nbt.contains("y") || !nbt.contains("z") || !nbt.contains("id")) {
|
||||
return;
|
||||
}
|
||||
BlockPosition position = new BlockPosition((int) nbt.get("x").getValue(), (int) nbt.get("y").getValue(), (int) nbt.get("z").getValue());
|
||||
String id = (String) nbt.get("id").getValue();
|
||||
|
||||
short action;
|
||||
switch (id) {
|
||||
case "minecraft:mob_spawner":
|
||||
action = 1;
|
||||
break;
|
||||
case "minecraft:command_block":
|
||||
action = 2;
|
||||
break;
|
||||
case "minecraft:beacon":
|
||||
action = 3;
|
||||
break;
|
||||
case "minecraft:skull":
|
||||
action = 4;
|
||||
break;
|
||||
case "minecraft:flower_pot":
|
||||
action = 5;
|
||||
break;
|
||||
case "minecraft:banner":
|
||||
action = 6;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
short action;
|
||||
switch (id) {
|
||||
case "minecraft:mob_spawner":
|
||||
action = 1;
|
||||
break;
|
||||
case "minecraft:command_block":
|
||||
action = 2;
|
||||
break;
|
||||
case "minecraft:beacon":
|
||||
action = 3;
|
||||
break;
|
||||
case "minecraft:skull":
|
||||
action = 4;
|
||||
break;
|
||||
case "minecraft:flower_pot":
|
||||
action = 5;
|
||||
break;
|
||||
case "minecraft:banner":
|
||||
action = 6;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
final PacketWrapper blockEntityData = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, wrapper.user());
|
||||
blockEntityData.write(Types.BLOCK_POSITION1_8, position);
|
||||
blockEntityData.write(Types.UNSIGNED_BYTE, action);
|
||||
blockEntityData.write(Types.NAMED_COMPOUND_TAG, nbt);
|
||||
blockEntityData.scheduleSend(Protocol1_9To1_8.class, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
final PacketWrapper blockEntityData = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, wrapper.user());
|
||||
blockEntityData.write(Types.BLOCK_POSITION1_8, position);
|
||||
blockEntityData.write(Types.UNSIGNED_BYTE, action);
|
||||
blockEntityData.write(Types.NAMED_COMPOUND_TAG, nbt);
|
||||
blockEntityData.scheduleSend(Protocol1_9To1_8.class, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.LEVEL_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Effect id
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.INT); // data
|
||||
map(Types.BOOLEAN); // disable relative volume
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Types.INT, 0);
|
||||
id = EffectIdMappings1_8.getOldId(id);
|
||||
if (id == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.set(Types.INT, 0, id);
|
||||
if (id == 2001) {
|
||||
int replacedBlock = protocol.getItemRewriter().handleBlockId(wrapper.get(Types.INT, 1));
|
||||
wrapper.set(Types.INT, 1, replacedBlock);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.LEVEL_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Effect id
|
||||
map(Types.BLOCK_POSITION1_8); // Position
|
||||
map(Types.INT); // data
|
||||
map(Types.BOOLEAN); // disable relative volume
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Types.INT, 0);
|
||||
id = EffectIdMappings1_8.getOldId(id);
|
||||
if (id == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.set(Types.INT, 0, id);
|
||||
if (id == 2001) {
|
||||
int replacedBlock = protocol.getItemRewriter().handleBlockId(wrapper.get(Types.INT, 1));
|
||||
wrapper.set(Types.INT, 1, replacedBlock);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.LEVEL_PARTICLES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Particle id
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Types.INT, 0);
|
||||
if (id > 41 && !ViaRewind.getConfig().isReplaceParticles()) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
if (id == 42) { // Dragon Breath
|
||||
wrapper.set(Types.INT, 0, 24); // Portal
|
||||
} else if (id == 43) { // End Rod
|
||||
wrapper.set(Types.INT, 0, 3); // Firework Spark
|
||||
} else if (id == 44) { // Damage Indicator
|
||||
wrapper.set(Types.INT, 0, 34); // Heart
|
||||
} else if (id == 45) { // Sweep Attack
|
||||
wrapper.set(Types.INT, 0, 1); // Large Explosion
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.LEVEL_PARTICLES, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Particle id
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Types.INT, 0);
|
||||
if (id > 41 && !ViaRewind.getConfig().isReplaceParticles()) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
if (id == 42) { // Dragon Breath
|
||||
wrapper.set(Types.INT, 0, 24); // Portal
|
||||
} else if (id == 43) { // End Rod
|
||||
wrapper.set(Types.INT, 0, 3); // Firework Spark
|
||||
} else if (id == 44) { // Damage Indicator
|
||||
wrapper.set(Types.INT, 0, 34); // Heart
|
||||
} else if (id == 45) { // Sweep Attack
|
||||
wrapper.set(Types.INT, 0, 1); // Large Explosion
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.MAP_ITEM_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Item damage
|
||||
map(Types.BYTE); // Scale
|
||||
read(Types.BOOLEAN); // Tracking position
|
||||
}
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_9.MAP_ITEM_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Item damage
|
||||
map(Types.BYTE); // Scale
|
||||
read(Types.BOOLEAN); // Tracking position
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SOUND, ClientboundPackets1_8.CUSTOM_SOUND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int soundId = wrapper.read(Types.VAR_INT);
|
||||
final String soundName = protocol.getMappingData().soundName(soundId);
|
||||
if (soundName == null) {
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.write(Types.STRING, protocol.getMappingData().getMappedNamedSound(soundName));
|
||||
}
|
||||
});
|
||||
read(Types.VAR_INT); // Sound category
|
||||
map(Types.INT); // Effect position x
|
||||
map(Types.INT); // Effect position y
|
||||
map(Types.INT); // Effect position z
|
||||
map(Types.FLOAT); // Volume
|
||||
map(Types.UNSIGNED_BYTE); // Pitch
|
||||
}
|
||||
});
|
||||
}
|
||||
protocol.registerClientbound(ClientboundPackets1_9.SOUND, ClientboundPackets1_8.CUSTOM_SOUND, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final int soundId = wrapper.read(Types.VAR_INT);
|
||||
final String soundName = protocol.getMappingData().soundName(soundId);
|
||||
if (soundName == null) {
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
wrapper.write(Types.STRING, protocol.getMappingData().getMappedNamedSound(soundName));
|
||||
}
|
||||
});
|
||||
read(Types.VAR_INT); // Sound category
|
||||
map(Types.INT); // Effect position x
|
||||
map(Types.INT); // Effect position y
|
||||
map(Types.INT); // Effect position z
|
||||
map(Types.FLOAT); // Volume
|
||||
map(Types.UNSIGNED_BYTE); // Pitch
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -20,24 +20,24 @@ package com.viaversion.viarewind.protocol.v1_9to1_8.storage;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class BlockPlaceDestroyTracker implements StorableObject {
|
||||
private long lastMining;
|
||||
private long lastMining;
|
||||
|
||||
public boolean isMining() {
|
||||
long time = System.currentTimeMillis() - lastMining;
|
||||
return time < 75;
|
||||
}
|
||||
public boolean isMining() {
|
||||
long time = System.currentTimeMillis() - lastMining;
|
||||
return time < 75;
|
||||
}
|
||||
|
||||
public void setMining() {
|
||||
lastMining = System.currentTimeMillis();
|
||||
}
|
||||
public void setMining() {
|
||||
lastMining = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void updateMining() {
|
||||
if (this.isMining()) {
|
||||
lastMining = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
public void updateMining() {
|
||||
if (this.isMining()) {
|
||||
lastMining = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLastMining(long lastMining) {
|
||||
this.lastMining = lastMining;
|
||||
}
|
||||
public void setLastMining(long lastMining) {
|
||||
this.lastMining = lastMining;
|
||||
}
|
||||
}
|
||||
+46
-47
@@ -20,65 +20,64 @@ package com.viaversion.viarewind.protocol.v1_9to1_8.storage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.data.WitherBossBar;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BossBarStorage extends StoredObject {
|
||||
|
||||
private final Map<UUID, WitherBossBar> bossBars = new HashMap<>();
|
||||
private final Map<UUID, WitherBossBar> bossBars = new HashMap<>();
|
||||
|
||||
public BossBarStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public BossBarStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
updateLocation();
|
||||
changeWorld();
|
||||
}
|
||||
public void reset() {
|
||||
updateLocation();
|
||||
changeWorld();
|
||||
}
|
||||
|
||||
public void add(UUID uuid, String title, float health) {
|
||||
WitherBossBar bossBar = new WitherBossBar(this.getUser(), uuid, title, health);
|
||||
PlayerPositionTracker playerPositionTracker = this.getUser().get(PlayerPositionTracker.class);
|
||||
bossBar.setPlayerLocation(playerPositionTracker.getPosX(), playerPositionTracker.getPosY(), playerPositionTracker.getPosZ(), playerPositionTracker.getYaw(), playerPositionTracker.getPitch());
|
||||
bossBar.show();
|
||||
bossBars.put(uuid, bossBar);
|
||||
}
|
||||
public void add(UUID uuid, String title, float health) {
|
||||
WitherBossBar bossBar = new WitherBossBar(this.getUser(), uuid, title, health);
|
||||
PlayerPositionTracker playerPositionTracker = this.getUser().get(PlayerPositionTracker.class);
|
||||
bossBar.setPlayerLocation(playerPositionTracker.getPosX(), playerPositionTracker.getPosY(), playerPositionTracker.getPosZ(), playerPositionTracker.getYaw(), playerPositionTracker.getPitch());
|
||||
bossBar.show();
|
||||
bossBars.put(uuid, bossBar);
|
||||
}
|
||||
|
||||
public void remove(UUID uuid) {
|
||||
WitherBossBar bossBar = bossBars.remove(uuid);
|
||||
if (bossBar == null) return;
|
||||
bossBar.hide();
|
||||
}
|
||||
public void remove(UUID uuid) {
|
||||
WitherBossBar bossBar = bossBars.remove(uuid);
|
||||
if (bossBar == null) return;
|
||||
bossBar.hide();
|
||||
}
|
||||
|
||||
public void updateLocation() {
|
||||
PlayerPositionTracker playerPositionTracker = this.getUser().get(PlayerPositionTracker.class);
|
||||
bossBars.values().forEach(bossBar -> {
|
||||
try {
|
||||
bossBar.setPlayerLocation(playerPositionTracker.getPosX(), playerPositionTracker.getPosY(), playerPositionTracker.getPosZ(), playerPositionTracker.getYaw(), playerPositionTracker.getPitch());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
public void updateLocation() {
|
||||
PlayerPositionTracker playerPositionTracker = this.getUser().get(PlayerPositionTracker.class);
|
||||
bossBars.values().forEach(bossBar -> {
|
||||
try {
|
||||
bossBar.setPlayerLocation(playerPositionTracker.getPosX(), playerPositionTracker.getPosY(), playerPositionTracker.getPosZ(), playerPositionTracker.getYaw(), playerPositionTracker.getPitch());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void changeWorld() {
|
||||
bossBars.values().forEach(bossBar -> {
|
||||
bossBar.hide();
|
||||
bossBar.show();
|
||||
});
|
||||
}
|
||||
public void changeWorld() {
|
||||
bossBars.values().forEach(bossBar -> {
|
||||
bossBar.hide();
|
||||
bossBar.show();
|
||||
});
|
||||
}
|
||||
|
||||
public void updateHealth(UUID uuid, float health) {
|
||||
WitherBossBar bossBar = bossBars.get(uuid);
|
||||
if (bossBar == null) return;
|
||||
bossBar.setHealth(health);
|
||||
}
|
||||
public void updateHealth(UUID uuid, float health) {
|
||||
WitherBossBar bossBar = bossBars.get(uuid);
|
||||
if (bossBar == null) return;
|
||||
bossBar.setHealth(health);
|
||||
}
|
||||
|
||||
public void updateTitle(UUID uuid, String title) {
|
||||
WitherBossBar bossBar = bossBars.get(uuid);
|
||||
if (bossBar == null) return;
|
||||
bossBar.setTitle(title);
|
||||
}
|
||||
public void updateTitle(UUID uuid, String title) {
|
||||
WitherBossBar bossBar = bossBars.get(uuid);
|
||||
if (bossBar == null) return;
|
||||
bossBar.setTitle(title);
|
||||
}
|
||||
}
|
||||
+80
-81
@@ -22,101 +22,100 @@ import com.viaversion.viarewind.protocol.v1_9to1_8.cooldown.CooldownVisualizatio
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CooldownStorage implements StorableObject {
|
||||
|
||||
private CooldownVisualization.Factory visualizationFactory = CooldownVisualization.Factory.fromConfiguration();
|
||||
private CooldownVisualization current;
|
||||
private CooldownVisualization.Factory visualizationFactory = CooldownVisualization.Factory.fromConfiguration();
|
||||
private CooldownVisualization current;
|
||||
|
||||
private double attackSpeed = 4.0;
|
||||
private long lastHit = 0;
|
||||
private double attackSpeed = 4.0;
|
||||
private long lastHit = 0;
|
||||
|
||||
public void tick(final UserConnection connection) {
|
||||
if (!hasCooldown()) {
|
||||
endCurrentVisualization();
|
||||
return;
|
||||
}
|
||||
BlockPlaceDestroyTracker tracker = connection.get(BlockPlaceDestroyTracker.class);
|
||||
if (tracker.isMining()) {
|
||||
lastHit = 0;
|
||||
endCurrentVisualization();
|
||||
return;
|
||||
}
|
||||
if (current == null) {
|
||||
current = visualizationFactory.create(connection);
|
||||
}
|
||||
try {
|
||||
current.show(getCooldown());
|
||||
} catch (Exception exception) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Unable to show cooldown visualization", exception);
|
||||
}
|
||||
}
|
||||
public void tick(final UserConnection connection) {
|
||||
if (!hasCooldown()) {
|
||||
endCurrentVisualization();
|
||||
return;
|
||||
}
|
||||
BlockPlaceDestroyTracker tracker = connection.get(BlockPlaceDestroyTracker.class);
|
||||
if (tracker.isMining()) {
|
||||
lastHit = 0;
|
||||
endCurrentVisualization();
|
||||
return;
|
||||
}
|
||||
if (current == null) {
|
||||
current = visualizationFactory.create(connection);
|
||||
}
|
||||
try {
|
||||
current.show(getCooldown());
|
||||
} catch (Exception exception) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Unable to show cooldown visualization", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private void endCurrentVisualization() {
|
||||
if (current != null) {
|
||||
try {
|
||||
current.hide();
|
||||
} catch (Exception exception) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Unable to hide cooldown visualization", exception);
|
||||
}
|
||||
current = null;
|
||||
}
|
||||
}
|
||||
private void endCurrentVisualization() {
|
||||
if (current != null) {
|
||||
try {
|
||||
current.hide();
|
||||
} catch (Exception exception) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Unable to hide cooldown visualization", exception);
|
||||
}
|
||||
current = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCooldown() {
|
||||
long time = System.currentTimeMillis() - lastHit;
|
||||
double cooldown = restrain(((double) time) * attackSpeed / 1000d, 1.5);
|
||||
return cooldown > 0.1 && cooldown < 1.1;
|
||||
}
|
||||
public boolean hasCooldown() {
|
||||
long time = System.currentTimeMillis() - lastHit;
|
||||
double cooldown = restrain(((double) time) * attackSpeed / 1000d, 1.5);
|
||||
return cooldown > 0.1 && cooldown < 1.1;
|
||||
}
|
||||
|
||||
public double getCooldown() {
|
||||
long time = System.currentTimeMillis() - lastHit;
|
||||
return restrain(((double) time) * attackSpeed / 1000d, 1);
|
||||
}
|
||||
public double getCooldown() {
|
||||
long time = System.currentTimeMillis() - lastHit;
|
||||
return restrain(((double) time) * attackSpeed / 1000d, 1);
|
||||
}
|
||||
|
||||
private double restrain(double x, double b) {
|
||||
if (x < 0) return 0;
|
||||
return Math.min(x, b);
|
||||
}
|
||||
private double restrain(double x, double b) {
|
||||
if (x < 0) return 0;
|
||||
return Math.min(x, b);
|
||||
}
|
||||
|
||||
public void setAttackSpeed(double base, List<Pair<Byte, Double>> modifiers) {
|
||||
attackSpeed = base;
|
||||
for (int j = 0; j < modifiers.size(); j++) {
|
||||
if (modifiers.get(j).key() == 0) {
|
||||
attackSpeed += modifiers.get(j).value();
|
||||
modifiers.remove(j--);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < modifiers.size(); j++) {
|
||||
if (modifiers.get(j).key() == 1) {
|
||||
attackSpeed += base * modifiers.get(j).value();
|
||||
modifiers.remove(j--);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < modifiers.size(); j++) {
|
||||
if (modifiers.get(j).key() == 2) {
|
||||
attackSpeed *= (1.0 + modifiers.get(j).value());
|
||||
modifiers.remove(j--);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setAttackSpeed(double base, List<Pair<Byte, Double>> modifiers) {
|
||||
attackSpeed = base;
|
||||
for (int j = 0; j < modifiers.size(); j++) {
|
||||
if (modifiers.get(j).key() == 0) {
|
||||
attackSpeed += modifiers.get(j).value();
|
||||
modifiers.remove(j--);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < modifiers.size(); j++) {
|
||||
if (modifiers.get(j).key() == 1) {
|
||||
attackSpeed += base * modifiers.get(j).value();
|
||||
modifiers.remove(j--);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < modifiers.size(); j++) {
|
||||
if (modifiers.get(j).key() == 2) {
|
||||
attackSpeed *= (1.0 + modifiers.get(j).value());
|
||||
modifiers.remove(j--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hit() {
|
||||
lastHit = System.currentTimeMillis();
|
||||
}
|
||||
public void hit() {
|
||||
lastHit = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setLastHit(long lastHit) {
|
||||
this.lastHit = lastHit;
|
||||
}
|
||||
public void setLastHit(long lastHit) {
|
||||
this.lastHit = lastHit;
|
||||
}
|
||||
|
||||
public CooldownVisualization.Factory getVisualizationFactory() {
|
||||
return visualizationFactory;
|
||||
}
|
||||
public CooldownVisualization.Factory getVisualizationFactory() {
|
||||
return visualizationFactory;
|
||||
}
|
||||
|
||||
public void setVisualizationFactory(CooldownVisualization.Factory visualizationFactory) {
|
||||
this.visualizationFactory = visualizationFactory;
|
||||
}
|
||||
public void setVisualizationFactory(CooldownVisualization.Factory visualizationFactory) {
|
||||
this.visualizationFactory = visualizationFactory;
|
||||
}
|
||||
}
|
||||
+51
-47
@@ -21,67 +21,71 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.*;
|
||||
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntArrayList;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EntityTracker1_9 extends EntityTrackerBase {
|
||||
|
||||
private final Int2ObjectMap<IntList> vehicles = new Int2ObjectOpenHashMap<>();
|
||||
private final Int2ObjectMap<Vector> offsets = new Int2ObjectOpenHashMap<>();
|
||||
private final Int2IntMap status = new Int2IntOpenHashMap();
|
||||
private final Int2ObjectMap<IntList> vehicles = new Int2ObjectOpenHashMap<>();
|
||||
private final Int2ObjectMap<Vector> offsets = new Int2ObjectOpenHashMap<>();
|
||||
private final Int2IntMap status = new Int2IntOpenHashMap();
|
||||
|
||||
public EntityTracker1_9(UserConnection connection) {
|
||||
super(connection, EntityTypes1_9.EntityType.PLAYER);
|
||||
}
|
||||
public EntityTracker1_9(UserConnection connection) {
|
||||
super(connection, EntityTypes1_9.EntityType.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int id) {
|
||||
vehicles.remove(id);
|
||||
offsets.remove(id);
|
||||
status.remove(id);
|
||||
@Override
|
||||
public void removeEntity(int id) {
|
||||
vehicles.remove(id);
|
||||
offsets.remove(id);
|
||||
status.remove(id);
|
||||
|
||||
vehicles.forEach((vehicle, passengers) -> passengers.rem(id));
|
||||
vehicles.int2ObjectEntrySet().removeIf(entry -> entry.getValue().isEmpty());
|
||||
super.removeEntity(id);
|
||||
}
|
||||
vehicles.forEach((vehicle, passengers) -> passengers.rem(id));
|
||||
vehicles.int2ObjectEntrySet().removeIf(entry -> entry.getValue().isEmpty());
|
||||
super.removeEntity(id);
|
||||
}
|
||||
|
||||
public void resetEntityOffset(final int id) {
|
||||
offsets.remove(id);
|
||||
}
|
||||
public void resetEntityOffset(final int id) {
|
||||
offsets.remove(id);
|
||||
}
|
||||
|
||||
public Vector getEntityOffset(final int id) {
|
||||
return offsets.get(id);
|
||||
}
|
||||
public Vector getEntityOffset(final int id) {
|
||||
return offsets.get(id);
|
||||
}
|
||||
|
||||
public void setEntityOffset(final int id, Vector offset) {
|
||||
offsets.put(id, offset);
|
||||
}
|
||||
public void setEntityOffset(final int id, Vector offset) {
|
||||
offsets.put(id, offset);
|
||||
}
|
||||
|
||||
public IntList getPassengers(final int id) {
|
||||
return vehicles.getOrDefault(id, new IntArrayList());
|
||||
}
|
||||
public IntList getPassengers(final int id) {
|
||||
return vehicles.getOrDefault(id, new IntArrayList());
|
||||
}
|
||||
|
||||
public void setPassengers(final int id, final IntList passengers) {
|
||||
vehicles.put(id, passengers);
|
||||
}
|
||||
public void setPassengers(final int id, final IntList passengers) {
|
||||
vehicles.put(id, passengers);
|
||||
}
|
||||
|
||||
public boolean isInsideVehicle(final int id) {
|
||||
for (List<Integer> vehicle : vehicles.values()) {
|
||||
if (vehicle.contains(id)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isInsideVehicle(final int id) {
|
||||
for (List<Integer> vehicle : vehicles.values()) {
|
||||
if (vehicle.contains(id)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Integer getVehicle(final int passenger) {
|
||||
for (Map.Entry<Integer, IntList> vehicle : vehicles.int2ObjectEntrySet()) {
|
||||
if (vehicle.getValue().contains(passenger)) return vehicle.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Integer getVehicle(final int passenger) {
|
||||
for (Map.Entry<Integer, IntList> vehicle : vehicles.int2ObjectEntrySet()) {
|
||||
if (vehicle.getValue().contains(passenger)) return vehicle.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Int2IntMap getStatus() {
|
||||
return status;
|
||||
}
|
||||
public Int2IntMap getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -21,22 +21,22 @@ import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class LevitationStorage implements StorableObject {
|
||||
|
||||
private boolean active;
|
||||
private int amplifier;
|
||||
private boolean active;
|
||||
private int amplifier;
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public int getAmplifier() {
|
||||
return amplifier;
|
||||
}
|
||||
public int getAmplifier() {
|
||||
return amplifier;
|
||||
}
|
||||
|
||||
public void setAmplifier(int amplifier) {
|
||||
this.amplifier = amplifier;
|
||||
}
|
||||
public void setAmplifier(int amplifier) {
|
||||
this.amplifier = amplifier;
|
||||
}
|
||||
}
|
||||
+52
-53
@@ -20,77 +20,76 @@ package com.viaversion.viarewind.protocol.v1_9to1_8.storage;
|
||||
import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class PlayerPositionTracker implements StorableObject {
|
||||
|
||||
private final Queue<PacketWrapper> animations = new ConcurrentLinkedQueue<>();
|
||||
private double posX, posY, posZ;
|
||||
private float yaw, pitch;
|
||||
private boolean onGround;
|
||||
private int confirmId = -1;
|
||||
private final Queue<PacketWrapper> animations = new ConcurrentLinkedQueue<>();
|
||||
private double posX, posY, posZ;
|
||||
private float yaw, pitch;
|
||||
private boolean onGround;
|
||||
private int confirmId = -1;
|
||||
|
||||
public void setPos(double x, double y, double z) {
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.posZ = z;
|
||||
}
|
||||
public void setPos(double x, double y, double z) {
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.posZ = z;
|
||||
}
|
||||
|
||||
public void sendAnimations() {
|
||||
PacketWrapper wrapper;
|
||||
while ((wrapper = animations.poll()) != null) {
|
||||
wrapper.sendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
}
|
||||
public void sendAnimations() {
|
||||
PacketWrapper wrapper;
|
||||
while ((wrapper = animations.poll()) != null) {
|
||||
wrapper.sendToServer(Protocol1_9To1_8.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void queueAnimation(final PacketWrapper wrapper) {
|
||||
animations.add(wrapper);
|
||||
}
|
||||
public void queueAnimation(final PacketWrapper wrapper) {
|
||||
animations.add(wrapper);
|
||||
}
|
||||
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw % 360f;
|
||||
}
|
||||
public double getPosX() {
|
||||
return this.posX;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch % 360f;
|
||||
}
|
||||
public double getPosY() {
|
||||
return this.posY;
|
||||
}
|
||||
|
||||
public double getPosX() {
|
||||
return this.posX;
|
||||
}
|
||||
public double getPosZ() {
|
||||
return this.posZ;
|
||||
}
|
||||
|
||||
public double getPosY() {
|
||||
return this.posY;
|
||||
}
|
||||
public float getYaw() {
|
||||
return this.yaw;
|
||||
}
|
||||
|
||||
public double getPosZ() {
|
||||
return this.posZ;
|
||||
}
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw % 360f;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.yaw;
|
||||
}
|
||||
public float getPitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch % 360f;
|
||||
}
|
||||
|
||||
public boolean isOnGround() {
|
||||
return this.onGround;
|
||||
}
|
||||
public boolean isOnGround() {
|
||||
return this.onGround;
|
||||
}
|
||||
|
||||
public int getConfirmId() {
|
||||
return this.confirmId;
|
||||
}
|
||||
public void setOnGround(boolean onGround) {
|
||||
this.onGround = onGround;
|
||||
}
|
||||
|
||||
public void setOnGround(boolean onGround) {
|
||||
this.onGround = onGround;
|
||||
}
|
||||
public int getConfirmId() {
|
||||
return this.confirmId;
|
||||
}
|
||||
|
||||
public void setConfirmId(int confirmId) {
|
||||
this.confirmId = confirmId;
|
||||
}
|
||||
public void setConfirmId(int confirmId) {
|
||||
this.confirmId = confirmId;
|
||||
}
|
||||
|
||||
}
|
||||
+61
-62
@@ -30,83 +30,82 @@ import com.viaversion.viaversion.libs.mcstructs.text.components.StringComponent;
|
||||
import com.viaversion.viaversion.libs.mcstructs.text.components.TranslationComponent;
|
||||
import com.viaversion.viaversion.libs.mcstructs.text.serializer.TextComponentSerializer;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WindowTracker extends StoredObject {
|
||||
private final HashMap<Short, String> types = new HashMap<>();
|
||||
private final HashMap<Short, Item[]> brewingItems = new HashMap<>();
|
||||
private final Map<Short, Short> enchantmentProperties = new HashMap<>();
|
||||
private final HashMap<Short, String> types = new HashMap<>();
|
||||
private final HashMap<Short, Item[]> brewingItems = new HashMap<>();
|
||||
private final Map<Short, Short> enchantmentProperties = new HashMap<>();
|
||||
|
||||
public WindowTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public WindowTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public String get(short windowId) {
|
||||
return types.get(windowId);
|
||||
}
|
||||
public static void updateBrewingStand(UserConnection user, Item blazePowder, short windowId) {
|
||||
if (blazePowder != null && blazePowder.identifier() != 377) {
|
||||
return;
|
||||
}
|
||||
int amount = blazePowder == null ? 0 : blazePowder.amount();
|
||||
|
||||
public void put(short windowId, String type) {
|
||||
types.put(windowId, type);
|
||||
}
|
||||
PacketWrapper openWindow = PacketWrapper.create(ClientboundPackets1_8.OPEN_SCREEN, user);
|
||||
openWindow.write(Types.UNSIGNED_BYTE, windowId);
|
||||
openWindow.write(Types.STRING, "minecraft:brewing_stand");
|
||||
|
||||
public void remove(short windowId) {
|
||||
types.remove(windowId);
|
||||
brewingItems.remove(windowId);
|
||||
}
|
||||
TextComponent title = new StringComponent().
|
||||
append(new TranslationComponent("container.brewing")).
|
||||
append(new StringComponent(": " + TextFormatting.DARK_GRAY)).
|
||||
append(new StringComponent(amount + " " + TextFormatting.DARK_RED)).
|
||||
append(new TranslationComponent("item.blazePowder.name", TextFormatting.DARK_RED));
|
||||
|
||||
public Item[] getBrewingItems(short windowId) {
|
||||
return brewingItems.computeIfAbsent(windowId, key -> new Item[]{
|
||||
new DataItem(),
|
||||
new DataItem(),
|
||||
new DataItem(),
|
||||
new DataItem()
|
||||
});
|
||||
}
|
||||
openWindow.write(Types.COMPONENT, TextComponentSerializer.V1_8.serializeJson(title));
|
||||
openWindow.write(Types.UNSIGNED_BYTE, (short) 420);
|
||||
openWindow.scheduleSend(Protocol1_9To1_8.class);
|
||||
|
||||
public short getEnchantmentValue(final short key) {
|
||||
if (!enchantmentProperties.containsKey(key)) {
|
||||
return 0;
|
||||
}
|
||||
return enchantmentProperties.remove(key);
|
||||
}
|
||||
Item[] items = user.get(WindowTracker.class).getBrewingItems(windowId);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
PacketWrapper setSlot = PacketWrapper.create(ClientboundPackets1_8.CONTAINER_SET_SLOT, user);
|
||||
setSlot.write(Types.BYTE, (byte) windowId);
|
||||
setSlot.write(Types.SHORT, (short) i);
|
||||
setSlot.write(Types.ITEM1_8, items[i]);
|
||||
setSlot.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void putEnchantmentProperty(short key, short value) {
|
||||
enchantmentProperties.put(key, value);
|
||||
}
|
||||
public String get(short windowId) {
|
||||
return types.get(windowId);
|
||||
}
|
||||
|
||||
public void clearEnchantmentProperties() {
|
||||
enchantmentProperties.clear();
|
||||
}
|
||||
public void put(short windowId, String type) {
|
||||
types.put(windowId, type);
|
||||
}
|
||||
|
||||
public static void updateBrewingStand(UserConnection user, Item blazePowder, short windowId) {
|
||||
if (blazePowder != null && blazePowder.identifier() != 377) {
|
||||
return;
|
||||
}
|
||||
int amount = blazePowder == null ? 0 : blazePowder.amount();
|
||||
public void remove(short windowId) {
|
||||
types.remove(windowId);
|
||||
brewingItems.remove(windowId);
|
||||
}
|
||||
|
||||
PacketWrapper openWindow = PacketWrapper.create(ClientboundPackets1_8.OPEN_SCREEN, user);
|
||||
openWindow.write(Types.UNSIGNED_BYTE, windowId);
|
||||
openWindow.write(Types.STRING, "minecraft:brewing_stand");
|
||||
public Item[] getBrewingItems(short windowId) {
|
||||
return brewingItems.computeIfAbsent(windowId, key -> new Item[]{
|
||||
new DataItem(),
|
||||
new DataItem(),
|
||||
new DataItem(),
|
||||
new DataItem()
|
||||
});
|
||||
}
|
||||
|
||||
TextComponent title = new StringComponent().
|
||||
append(new TranslationComponent("container.brewing")).
|
||||
append(new StringComponent(": " + TextFormatting.DARK_GRAY)).
|
||||
append(new StringComponent(amount + " " + TextFormatting.DARK_RED)).
|
||||
append(new TranslationComponent("item.blazePowder.name", TextFormatting.DARK_RED));
|
||||
public short getEnchantmentValue(final short key) {
|
||||
if (!enchantmentProperties.containsKey(key)) {
|
||||
return 0;
|
||||
}
|
||||
return enchantmentProperties.remove(key);
|
||||
}
|
||||
|
||||
openWindow.write(Types.COMPONENT, TextComponentSerializer.V1_8.serializeJson(title));
|
||||
openWindow.write(Types.UNSIGNED_BYTE, (short) 420);
|
||||
openWindow.scheduleSend(Protocol1_9To1_8.class);
|
||||
public void putEnchantmentProperty(short key, short value) {
|
||||
enchantmentProperties.put(key, value);
|
||||
}
|
||||
|
||||
Item[] items = user.get(WindowTracker.class).getBrewingItems(windowId);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
PacketWrapper setSlot = PacketWrapper.create(ClientboundPackets1_8.CONTAINER_SET_SLOT, user);
|
||||
setSlot.write(Types.BYTE, (byte) windowId);
|
||||
setSlot.write(Types.SHORT, (short) i);
|
||||
setSlot.write(Types.ITEM1_8, items[i]);
|
||||
setSlot.scheduleSend(Protocol1_9To1_8.class);
|
||||
}
|
||||
}
|
||||
public void clearEnchantmentProperties() {
|
||||
enchantmentProperties.clear();
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -23,10 +23,10 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public class CooldownIndicatorTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
connection.get(CooldownStorage.class).tick(connection);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
connection.get(CooldownStorage.class).tick(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-23
@@ -25,32 +25,31 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class LevitationUpdateTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!ViaRewind.getConfig().emulateLevitationEffect()) {
|
||||
return;
|
||||
}
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
final LevitationStorage levitation = connection.get(LevitationStorage.class);
|
||||
if (!levitation.isActive()) {
|
||||
continue;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
if (!ViaRewind.getConfig().emulateLevitationEffect()) {
|
||||
return;
|
||||
}
|
||||
for (UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
final LevitationStorage levitation = connection.get(LevitationStorage.class);
|
||||
if (!levitation.isActive()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final PacketWrapper velocityPacket = PacketWrapper.create(ClientboundPackets1_8.SET_ENTITY_MOTION, connection);
|
||||
velocityPacket.write(Types.VAR_INT, connection.getEntityTracker(Protocol1_9To1_8.class).clientEntityId());
|
||||
velocityPacket.write(Types.SHORT, (short) 0);
|
||||
velocityPacket.write(Types.SHORT, (short) ((levitation.getAmplifier() + 1) * 360));
|
||||
velocityPacket.write(Types.SHORT, (short) 0);
|
||||
try {
|
||||
velocityPacket.scheduleSend(Protocol1_9To1_8.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send levitation packet", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
final PacketWrapper velocityPacket = PacketWrapper.create(ClientboundPackets1_8.SET_ENTITY_MOTION, connection);
|
||||
velocityPacket.write(Types.VAR_INT, connection.getEntityTracker(Protocol1_9To1_8.class).clientEntityId());
|
||||
velocityPacket.write(Types.SHORT, (short) 0);
|
||||
velocityPacket.write(Types.SHORT, (short) ((levitation.getAmplifier() + 1) * 360));
|
||||
velocityPacket.write(Types.SHORT, (short) 0);
|
||||
try {
|
||||
velocityPacket.scheduleSend(Protocol1_9To1_8.class);
|
||||
} catch (Exception e) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.SEVERE, "Failed to send levitation packet", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,75 +26,74 @@ import com.viaversion.viaversion.libs.gson.JsonParser;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Deprecated
|
||||
public class ChatUtil {
|
||||
private static final Pattern UNUSED_COLOR_PATTERN = Pattern.compile("(?>(?>§[0-fk-or])*(§r|\\Z))|(?>(?>§[0-f])*(§[0-f]))");
|
||||
private static final JsonNBTComponentRewriter<ClientboundPacketType> LEGACY_REWRITER = new JsonNBTComponentRewriter<>(null, JsonNBTComponentRewriter.ReadType.JSON) {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject object, String translate) {
|
||||
String text = Protocol1_12_2To1_13.MAPPINGS.getMojangTranslation().get(translate);
|
||||
if (text != null) {
|
||||
object.addProperty("translate", text);
|
||||
}
|
||||
}
|
||||
};
|
||||
private static final Pattern UNUSED_COLOR_PATTERN = Pattern.compile("(?>(?>§[0-fk-or])*(§r|\\Z))|(?>(?>§[0-f])*(§[0-f]))");
|
||||
private static final JsonNBTComponentRewriter<ClientboundPacketType> LEGACY_REWRITER = new JsonNBTComponentRewriter<>(null, JsonNBTComponentRewriter.ReadType.JSON) {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject object, String translate) {
|
||||
String text = Protocol1_12_2To1_13.MAPPINGS.getMojangTranslation().get(translate);
|
||||
if (text != null) {
|
||||
object.addProperty("translate", text);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static String jsonToLegacy(String json) {
|
||||
if (json == null || json.equals("null") || json.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return jsonToLegacy(JsonParser.parseString(json));
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Could not convert component to legacy text: " + json, e);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public static String jsonToLegacy(String json) {
|
||||
if (json == null || json.equals("null") || json.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return jsonToLegacy(JsonParser.parseString(json));
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Could not convert component to legacy text: " + json, e);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String jsonToLegacy(JsonElement component) {
|
||||
if (component.isJsonNull() || component.isJsonArray() && component.getAsJsonArray().isEmpty() || component.isJsonObject() && component.getAsJsonObject().isEmpty()) {
|
||||
return "";
|
||||
} else if (component.isJsonPrimitive()) {
|
||||
return component.getAsString();
|
||||
} else {
|
||||
try {
|
||||
LEGACY_REWRITER.processText(null, component);
|
||||
String legacy = ComponentUtil.jsonToLegacy(component);
|
||||
public static String jsonToLegacy(JsonElement component) {
|
||||
if (component.isJsonNull() || component.isJsonArray() && component.getAsJsonArray().isEmpty() || component.isJsonObject() && component.getAsJsonObject().isEmpty()) {
|
||||
return "";
|
||||
} else if (component.isJsonPrimitive()) {
|
||||
return component.getAsString();
|
||||
} else {
|
||||
try {
|
||||
LEGACY_REWRITER.processText(null, component);
|
||||
String legacy = ComponentUtil.jsonToLegacy(component);
|
||||
int attempts = 0;
|
||||
while (legacy.startsWith("§f") && attempts++ < 10) {
|
||||
legacy = legacy.substring(2);
|
||||
}
|
||||
return legacy;
|
||||
} catch (Exception ex) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Could not convert component to legacy text: " + component, ex);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return legacy;
|
||||
} catch (Exception ex) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaRewind.getPlatform().getLogger().log(Level.WARNING, "Could not convert component to legacy text: " + component, ex);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String removeUnusedColor(String legacy, char last) {
|
||||
if (legacy == null) return null;
|
||||
legacy = UNUSED_COLOR_PATTERN.matcher(legacy).replaceAll("$1$2");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < legacy.length(); i++) {
|
||||
char current = legacy.charAt(i);
|
||||
if (current != '§' || i == legacy.length() - 1) {
|
||||
builder.append(current);
|
||||
continue;
|
||||
}
|
||||
current = legacy.charAt(++i);
|
||||
if (current == last) continue;
|
||||
builder.append('§').append(current);
|
||||
last = current;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
public static String removeUnusedColor(String legacy, char last) {
|
||||
if (legacy == null) return null;
|
||||
legacy = UNUSED_COLOR_PATTERN.matcher(legacy).replaceAll("$1$2");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < legacy.length(); i++) {
|
||||
char current = legacy.charAt(i);
|
||||
if (current != '§' || i == legacy.length() - 1) {
|
||||
builder.append(current);
|
||||
continue;
|
||||
}
|
||||
current = legacy.charAt(++i);
|
||||
if (current == last) continue;
|
||||
builder.append('§').append(current);
|
||||
last = current;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -19,31 +19,30 @@ package com.viaversion.viarewind;
|
||||
|
||||
import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
import com.viaversion.viarewind.fabric.util.LoggerWrapper;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.logging.Logger;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
public class ViaFabricAddon implements ViaRewindPlatform, Runnable {
|
||||
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaRewind"));
|
||||
private File configDir;
|
||||
private File configDir;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Path configDirPath = FabricLoader.getInstance().getConfigDir().resolve("ViaRewind");
|
||||
this.configDir = configDirPath.toFile();
|
||||
this.init(new File(getDataFolder(), "config.yml"));
|
||||
final Path configDirPath = FabricLoader.getInstance().getConfigDir().resolve("ViaRewind");
|
||||
this.configDir = configDirPath.toFile();
|
||||
this.init(new File(getDataFolder(), "config.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return this.configDir;
|
||||
}
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return this.configDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,12 @@ public class LoggerWrapper extends Logger {
|
||||
this.base = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void log(LogRecord record) {
|
||||
this.log(record.getLevel(), record.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
if (level == Level.FINE) {
|
||||
this.base.debug(msg);
|
||||
@@ -51,7 +51,7 @@ public class LoggerWrapper extends Logger {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void log(Level level, String msg, Object param1) {
|
||||
if (level == Level.FINE) {
|
||||
this.base.debug(msg, param1);
|
||||
@@ -67,12 +67,12 @@ public class LoggerWrapper extends Logger {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void log(Level level, String msg, Object[] params) {
|
||||
log(level, MessageFormat.format(msg, params));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void log(Level level, String msg, Throwable params) {
|
||||
if (level == Level.FINE) {
|
||||
this.base.debug(msg, params);
|
||||
@@ -87,4 +87,4 @@ public class LoggerWrapper extends Logger {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,9 @@
|
||||
"custom": {
|
||||
"modmenu:api": true,
|
||||
"modmenu": {
|
||||
"badges": [ "library" ],
|
||||
"badges": [
|
||||
"library"
|
||||
],
|
||||
"parent": "viafabric"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,59 +24,58 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.velocity.util.LoggerWrapper;
|
||||
import com.viaversion.viarewind.api.ViaRewindPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Plugin(id = "viarewind",
|
||||
name = "ViaRewind",
|
||||
version = ViaRewindPlatform.VERSION,
|
||||
authors = { "FlorianMichael/EnZaXD", "Gerrygames", "creeper123123321"},
|
||||
description = "ViaVersion addon to allow 1.8.x and 1.7.x clients on newer server versions.",
|
||||
dependencies = {
|
||||
@Dependency(id = "viaversion"),
|
||||
@Dependency(id = "viabackwards")
|
||||
},
|
||||
url = "https://viaversion.com/rewind"
|
||||
name = "ViaRewind",
|
||||
version = ViaRewindPlatform.VERSION,
|
||||
authors = {"FlorianMichael/EnZaXD", "Gerrygames", "creeper123123321"},
|
||||
description = "ViaVersion addon to allow 1.8.x and 1.7.x clients on newer server versions.",
|
||||
dependencies = {
|
||||
@Dependency(id = "viaversion"),
|
||||
@Dependency(id = "viabackwards")
|
||||
},
|
||||
url = "https://viaversion.com/rewind"
|
||||
)
|
||||
public class VelocityPlugin implements ViaRewindPlatform {
|
||||
private Logger logger;
|
||||
private Logger logger;
|
||||
|
||||
@Inject
|
||||
private org.slf4j.Logger loggerSlf4j;
|
||||
@Inject
|
||||
private org.slf4j.Logger loggerSlf4j;
|
||||
|
||||
@Inject
|
||||
@DataDirectory
|
||||
private Path configPath;
|
||||
@Inject
|
||||
@DataDirectory
|
||||
private Path configPath;
|
||||
|
||||
@Subscribe(order = PostOrder.LATE)
|
||||
public void onProxyStart(ProxyInitializeEvent e) {
|
||||
this.logger = new LoggerWrapper(loggerSlf4j);
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
@Subscribe(order = PostOrder.LATE)
|
||||
public void onProxyStart(ProxyInitializeEvent e) {
|
||||
this.logger = new LoggerWrapper(loggerSlf4j);
|
||||
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return configPath.toFile();
|
||||
}
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return configPath.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String compressHandlerName() {
|
||||
return "compression-encoder";
|
||||
}
|
||||
@Override
|
||||
public String compressHandlerName() {
|
||||
return "compression-encoder";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decompressHandlerName() {
|
||||
return "compression-decoder";
|
||||
}
|
||||
@Override
|
||||
public String decompressHandlerName() {
|
||||
return "compression-decoder";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user