mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2026-11-04 08:52:10 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fb3aa8c7a | ||
|
|
f175a903a3 | ||
|
|
7c80e37e3a | ||
|
|
ff61e1d897 | ||
|
|
d49272a41f | ||
|
|
bea6df1174 | ||
|
|
4ca84f6001 | ||
|
|
61c079af19 | ||
|
|
e0b9deb128 | ||
|
|
1d89bc7f95 | ||
|
|
28c18c33fa | ||
|
|
d08cb1b743 | ||
|
|
fb18f69a0b | ||
|
|
56e1d32aa0 | ||
|
|
d4aa5a2fb3 | ||
|
|
b54a87f465 | ||
|
|
5acfa9faf7 | ||
|
|
638f4cd19a | ||
|
|
baf12dd516 | ||
|
|
4b6b26fbba | ||
|
|
5c5784795d | ||
|
|
1f8e7515b1 | ||
|
|
3778698018 | ||
|
|
40dd2be139 | ||
|
|
edbe2c92ce | ||
|
|
b9ae1ef43e | ||
|
|
4631fd1977 | ||
|
|
3d25686745 | ||
|
|
18b5b2626a | ||
|
|
219ad4737a | ||
|
|
b9368ae80a | ||
|
|
03c80ccff8 | ||
|
|
f6aed5578f | ||
|
|
646de0b1af | ||
|
|
4e33a40ede | ||
|
|
21b0ac7a43 | ||
|
|
15d3944700 | ||
|
|
acd9a6f57c | ||
|
|
d5fe4e22b4 | ||
|
|
9f0c38915a | ||
|
|
bc7f081b3a | ||
|
|
46b6627f9f | ||
|
|
51cc1843ad | ||
|
|
98d1d2cb49 | ||
|
|
556560a0f3 | ||
|
|
be2534c6e6 | ||
|
|
d40d1bd232 | ||
|
|
6143f78ccf | ||
|
|
52cdebc3d3 | ||
|
|
cdccae95e0 | ||
|
|
b0c45e3ed3 | ||
|
|
3ba518650c | ||
|
|
5a303996a1 | ||
|
|
695534e8a8 | ||
|
|
16ba011243 | ||
|
|
0ea7271157 | ||
|
|
dc2b2f1407 | ||
|
|
85baefc69b | ||
|
|
41e0fdc20f | ||
|
|
5c328fba33 | ||
|
|
91b11878fb | ||
|
|
0ea5e07d63 | ||
|
|
152e4e77a8 | ||
|
|
cf20c6397d | ||
|
|
981672e2cf | ||
|
|
d10b600e72 | ||
|
|
de9cec36c7 | ||
|
|
6eb561607c | ||
|
|
db3e1f605a | ||
|
|
31583fc2d3 | ||
|
|
6096ce4eea | ||
|
|
873da12233 | ||
|
|
78191ea366 | ||
|
|
f8d7c5c193 | ||
|
|
bc9c979e7d | ||
|
|
d686a9ddf0 | ||
|
|
9dd610605f | ||
|
|
219e163ac2 | ||
|
|
925e7b4664 | ||
|
|
5a9f040af8 | ||
|
|
992ad7f35a | ||
|
|
bb93ac011c | ||
|
|
4070ea9f02 | ||
|
|
499efa1608 | ||
|
|
0196d9c83e |
No files matched your search
@@ -11,13 +11,13 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v5
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
@@ -12,13 +12,13 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v5
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Update Gradle Wrapper
|
||||
|
||||
+19
-98
@@ -1,115 +1,36 @@
|
||||
### Java files ###
|
||||
*.class
|
||||
# Gradle
|
||||
|
||||
# Package Files
|
||||
#*.jar
|
||||
*.war
|
||||
*.ear
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
.kotlin/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
# Eclipse
|
||||
|
||||
*.launch
|
||||
|
||||
# Idea
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
|
||||
# Ignore project files
|
||||
*.iml
|
||||
|
||||
# Ignore IDEA directory
|
||||
.idea/*
|
||||
.idea/
|
||||
!.idea/copyright/*
|
||||
!.idea/scopes/*
|
||||
|
||||
# Include the project's dictionary
|
||||
!.idea/dictionaries/
|
||||
!.idea/dictionaries/*
|
||||
|
||||
# File-based project format:
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
### Plugin-specific files: ###
|
||||
# IntelliJ
|
||||
/out/
|
||||
# VSCode
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
*.pydevproject
|
||||
.metadata
|
||||
.gradle
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# Eclipse Core
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
# macOS
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
|
||||
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
.nb-gradle/
|
||||
|
||||
### MacOS ###
|
||||
.DS_Store
|
||||
|
||||
### Run Folder (ViaProxy) ###
|
||||
common/run/
|
||||
# Misc
|
||||
|
||||
run/
|
||||
@@ -8,7 +8,7 @@
|
||||
it works on any platform you can think of.**
|
||||
|
||||
The base ViaVersion jar runs on Paper and Velocity. We also have projects integrating ViaVersion to run
|
||||
on Fabric, Forge, Bungee, Sponge, or as a standalone proxy to join from basically any client version on
|
||||
on Fabric, Forge, Sponge, or as a standalone proxy to join from basically any client version on
|
||||
any server version from the past decade. **See [HERE](https://viaversion.com) for an overview of the different Via\* projects.**
|
||||
|
||||
Note that ViaVersion will be able to **run best on either Paper servers or through [ViaFabricPlus](https://github.com/ViaVersion/ViaFabricPlus?tab=readme-ov-file#viafabricplus)** due to having
|
||||
@@ -16,7 +16,7 @@ direct access to client/server state and more extensive API.
|
||||
|
||||
Supported Versions:
|
||||
|
||||

|
||||

|
||||
|
||||
**User Docs:** https://docs.viaversion.com
|
||||
|
||||
@@ -87,12 +87,10 @@ of the `build/libs` directory.
|
||||
|
||||
You need JDK 17 or newer to build ViaVersion.
|
||||
|
||||
|
||||
Mapping Files
|
||||
--------------
|
||||
Mapping files are generated and managed in our [Mappings repository](https://github.com/ViaVersion/Mappings). The generated mapping output is stored [here](./common/src/main/resources/assets/viaversion).
|
||||
|
||||
|
||||
Resources
|
||||
--------
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public interface ViaAPI<T> {
|
||||
boolean isInjected(UUID uuid);
|
||||
|
||||
/**
|
||||
* Returns whether Via injected into this player connection. Note that this method may not work on
|
||||
* Returns the injected UserConnection if present. Note that this method may not work on
|
||||
* clientside implementations and is generally not recommended to be used. Use {@link ConnectionManager} instead.
|
||||
*
|
||||
* @param uuid uuid of the player
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.configuration;
|
||||
|
||||
public record RateLimitConfig(boolean enabled, int maxRate, String maxRateKickMessage, int warningRate, int maxWarnings,
|
||||
long trackingPeriodNanos, String warningKickMessage, String ratePlaceholder) {
|
||||
}
|
||||
@@ -147,6 +147,7 @@ public interface ViaVersionConfig extends Config {
|
||||
*
|
||||
* @return The number of packets a client can send per second.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
int getMaxPPS();
|
||||
|
||||
/**
|
||||
@@ -154,6 +155,7 @@ public interface ViaVersionConfig extends Config {
|
||||
*
|
||||
* @return Kick message, with colour codes using '&amp;'
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
String getMaxPPSKickMessage();
|
||||
|
||||
/**
|
||||
@@ -161,6 +163,7 @@ public interface ViaVersionConfig extends Config {
|
||||
*
|
||||
* @return Time in seconds that should be tracked for warnings
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
int getTrackingPeriod();
|
||||
|
||||
/**
|
||||
@@ -168,6 +171,7 @@ public interface ViaVersionConfig extends Config {
|
||||
*
|
||||
* @return The number of packets per second to count as a warning.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
int getWarningPPS();
|
||||
|
||||
/**
|
||||
@@ -175,6 +179,7 @@ public interface ViaVersionConfig extends Config {
|
||||
*
|
||||
* @return The number of packets a client can send per second.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
int getMaxWarnings();
|
||||
|
||||
/**
|
||||
@@ -182,8 +187,13 @@ public interface ViaVersionConfig extends Config {
|
||||
*
|
||||
* @return Kick message, with colour codes using '&amp;'
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
String getMaxWarningsKickMessage();
|
||||
|
||||
RateLimitConfig getPacketTrackerConfig();
|
||||
|
||||
RateLimitConfig getPacketSizeTrackerConfig();
|
||||
|
||||
/**
|
||||
* Send supported versions in the status response packet
|
||||
*
|
||||
@@ -263,6 +273,8 @@ public interface ViaVersionConfig extends Config {
|
||||
*/
|
||||
String getBlockedDisconnectMsg();
|
||||
|
||||
boolean logBlockedJoins();
|
||||
|
||||
/**
|
||||
* Get the message sent to players being kicked on reload.
|
||||
* Players are kicked to stop the server crashing
|
||||
|
||||
@@ -194,9 +194,15 @@ public interface UserConnection {
|
||||
/**
|
||||
* Monitors serverbound packets and returns whether a packet can/should be processed.
|
||||
*
|
||||
* @param bytes the number of bytes in the packet
|
||||
* @return false if this packet should be cancelled
|
||||
*/
|
||||
boolean checkServerboundPacket();
|
||||
boolean checkServerboundPacket(int bytes);
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
default boolean checkServerboundPacket() {
|
||||
return checkServerboundPacket(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors clientbound packets and returns whether a packet can/should be processed.
|
||||
@@ -209,6 +215,11 @@ public interface UserConnection {
|
||||
* @see #checkClientboundPacket()
|
||||
* @see #checkServerboundPacket()
|
||||
*/
|
||||
default boolean checkIncomingPacket(final int bytes) {
|
||||
return isClientSide() ? checkClientboundPacket() : checkServerboundPacket(bytes);
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
default boolean checkIncomingPacket() {
|
||||
return isClientSide() ? checkClientboundPacket() : checkServerboundPacket();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.data;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.TagData;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -140,12 +141,14 @@ public interface MappingData {
|
||||
|
||||
@Nullable Mappings getBlockMappings();
|
||||
|
||||
@Nullable Mappings getBlockEntityMappings();
|
||||
@Nullable FullMappings getFullBlockMappings();
|
||||
|
||||
@Nullable Mappings getBlockStateMappings();
|
||||
|
||||
@Nullable Mappings getSoundMappings();
|
||||
|
||||
@Nullable FullMappings getFullSoundMappings();
|
||||
|
||||
@Nullable Mappings getStatisticsMappings();
|
||||
|
||||
@Nullable Mappings getMenuMappings();
|
||||
@@ -154,6 +157,8 @@ public interface MappingData {
|
||||
|
||||
@Nullable Mappings getPaintingMappings();
|
||||
|
||||
@Nullable FullMappings getBlockEntityMappings();
|
||||
|
||||
@Nullable FullMappings getAttributeMappings();
|
||||
|
||||
@Nullable FullMappings getEntityMappings();
|
||||
@@ -163,4 +168,26 @@ public interface MappingData {
|
||||
@Nullable FullMappings getRecipeSerializerMappings();
|
||||
|
||||
@Nullable FullMappings getDataComponentSerializerMappings();
|
||||
|
||||
default @Nullable FullMappings getFullMappings(final MappingType mappingType) {
|
||||
return switch (mappingType) {
|
||||
case ITEM -> getFullItemMappings();
|
||||
case SOUND -> getFullSoundMappings();
|
||||
case ENTITY -> getEntityMappings();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of block (not block state) ids that had their base type or properties changed.
|
||||
*
|
||||
* @return set of changed block ids, or null if not tracked/none are present
|
||||
*/
|
||||
@Nullable IntSet changedBlocks();
|
||||
|
||||
/**
|
||||
* Type of mappings. Currently only relevant for ops writing of generic holder classes and expanded when needed.
|
||||
*/
|
||||
enum MappingType {
|
||||
ITEM, SOUND, ENTITY
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.TagData;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
@@ -44,17 +46,21 @@ public class MappingDataBase implements MappingData {
|
||||
protected FullMappings recipeSerializerMappings;
|
||||
protected FullMappings itemDataSerializerMappings;
|
||||
protected FullMappings attributeMappings;
|
||||
protected FullMappings blockEntityMappings;
|
||||
protected ParticleMappings particleMappings;
|
||||
protected BiMappings itemMappings;
|
||||
protected BiMappings blockMappings;
|
||||
protected Mappings blockStateMappings;
|
||||
protected Mappings blockEntityMappings;
|
||||
protected Mappings soundMappings;
|
||||
protected Mappings statisticsMappings;
|
||||
protected Mappings enchantmentMappings;
|
||||
protected Mappings paintingMappings;
|
||||
protected Mappings menuMappings;
|
||||
protected Map<RegistryType, List<TagData>> tags;
|
||||
/**
|
||||
* Set of block ids that have had type or property changes.
|
||||
*/
|
||||
protected IntSet changedBlocks;
|
||||
|
||||
public MappingDataBase(final String unmappedVersion, final String mappedVersion) {
|
||||
this.unmappedVersion = unmappedVersion;
|
||||
@@ -68,10 +74,7 @@ public class MappingDataBase implements MappingData {
|
||||
}
|
||||
|
||||
final CompoundTag data = readMappingsFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
||||
blockMappings = loadBiMappings(data, "blocks");
|
||||
blockStateMappings = loadMappings(data, "blockstates");
|
||||
blockEntityMappings = loadMappings(data, "blockentities");
|
||||
soundMappings = loadMappings(data, "sounds");
|
||||
statisticsMappings = loadMappings(data, "statistics");
|
||||
menuMappings = loadMappings(data, "menus");
|
||||
enchantmentMappings = loadMappings(data, "enchantments");
|
||||
@@ -80,12 +83,16 @@ public class MappingDataBase implements MappingData {
|
||||
final CompoundTag unmappedIdentifierData = readUnmappedIdentifiersFile("identifiers-" + unmappedVersion + ".nbt");
|
||||
final CompoundTag mappedIdentifierData = readMappedIdentifiersFile("identifiers-" + mappedVersion + ".nbt");
|
||||
if (unmappedIdentifierData != null && mappedIdentifierData != null) {
|
||||
itemMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "items");
|
||||
itemMappings = loadFullOrBiMappings(data, unmappedIdentifierData, mappedIdentifierData, "items");
|
||||
blockMappings = loadFullOrBiMappings(data, unmappedIdentifierData, mappedIdentifierData, "blocks");
|
||||
soundMappings = loadFullOrBiMappings(data, unmappedIdentifierData, mappedIdentifierData, "sounds");
|
||||
|
||||
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
|
||||
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
|
||||
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
|
||||
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
|
||||
attributeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "attributes");
|
||||
blockEntityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "blockentities");
|
||||
|
||||
final List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles");
|
||||
final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles");
|
||||
@@ -99,6 +106,8 @@ public class MappingDataBase implements MappingData {
|
||||
} else {
|
||||
// Might not have identifiers in older versions
|
||||
itemMappings = loadBiMappings(data, "items");
|
||||
blockMappings = loadBiMappings(data, "blocks");
|
||||
soundMappings = loadMappings(data, "sounds");
|
||||
}
|
||||
|
||||
final CompoundTag tagsTag = data.getCompoundTag("tags");
|
||||
@@ -109,6 +118,11 @@ public class MappingDataBase implements MappingData {
|
||||
loadTags(RegistryType.ENTITY, tagsTag);
|
||||
}
|
||||
|
||||
final IntArrayTag changedBlocks = data.getIntArrayTag("changed_blocks");
|
||||
if (changedBlocks != null) {
|
||||
this.changedBlocks = new IntOpenHashSet(changedBlocks.getValue());
|
||||
}
|
||||
|
||||
loadExtras(data);
|
||||
}
|
||||
|
||||
@@ -132,6 +146,11 @@ public class MappingDataBase implements MappingData {
|
||||
return MappingDataLoader.INSTANCE.loadMappings(data, key);
|
||||
}
|
||||
|
||||
protected @Nullable BiMappings loadFullOrBiMappings(final CompoundTag data, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) {
|
||||
final FullMappings mappings = loadFullMappings(data, unmappedIdentifiersTag, mappedIdentifiersTag, key);
|
||||
return mappings != null ? mappings : loadBiMappings(data, key);
|
||||
}
|
||||
|
||||
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) {
|
||||
if (!unmappedIdentifiersTag.contains(key) || !mappedIdentifiersTag.contains(key)) {
|
||||
return null;
|
||||
@@ -224,8 +243,8 @@ public class MappingDataBase implements MappingData {
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getFullItemMappings() {
|
||||
if (itemMappings instanceof FullMappings) {
|
||||
return (FullMappings) itemMappings;
|
||||
if (itemMappings instanceof FullMappings fullItemMappings) {
|
||||
return fullItemMappings;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -241,7 +260,15 @@ public class MappingDataBase implements MappingData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getBlockEntityMappings() {
|
||||
public @Nullable FullMappings getFullBlockMappings() {
|
||||
if (blockMappings instanceof FullMappings fullBlockMappings) {
|
||||
return fullBlockMappings;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getBlockEntityMappings() {
|
||||
return blockEntityMappings;
|
||||
}
|
||||
|
||||
@@ -255,6 +282,14 @@ public class MappingDataBase implements MappingData {
|
||||
return soundMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getFullSoundMappings() {
|
||||
if (soundMappings instanceof FullMappings fullSoundMappings) {
|
||||
return fullSoundMappings;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getStatisticsMappings() {
|
||||
return statisticsMappings;
|
||||
@@ -300,6 +335,11 @@ public class MappingDataBase implements MappingData {
|
||||
return recipeSerializerMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable IntSet changedBlocks() {
|
||||
return changedBlocks;
|
||||
}
|
||||
|
||||
protected Logger getLogger() {
|
||||
return Via.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public class MappingDataLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int mappedSize = tag.getIntTag("mappedSize").asInt();
|
||||
final int mappedSize = tag.getInt("mappedSize", -1);
|
||||
final byte strategy = tag.getByteTag("id").asByte();
|
||||
final V mappings;
|
||||
if (strategy == DIRECT_ID) {
|
||||
|
||||
@@ -82,6 +82,11 @@ public interface EntityTracker {
|
||||
*/
|
||||
void clearEntities();
|
||||
|
||||
/**
|
||||
* Clears all stored data, including entity types, entity data and client entity id.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Returns the stored entity data if an entity with the id is tracked, else null.
|
||||
* If no data has been initialized yet, it will be done and returned by this method.
|
||||
@@ -180,6 +185,20 @@ public interface EntityTracker {
|
||||
*/
|
||||
void setCurrentWorld(String currentWorld);
|
||||
|
||||
/**
|
||||
* Returns the id of the current dimension, or -1 if unset (i.e. before 1.20.5).
|
||||
*
|
||||
* @return id of the current dimension, or -1 if unset
|
||||
*/
|
||||
int currentDimensionId();
|
||||
|
||||
/**
|
||||
* Sets the id of the current dimension.
|
||||
*
|
||||
* @param currentDimensionId id of the current dimension
|
||||
*/
|
||||
void setCurrentDimensionId(int currentDimensionId);
|
||||
|
||||
int biomesSent();
|
||||
|
||||
void setBiomesSent(int biomesSent);
|
||||
|
||||
@@ -29,7 +29,11 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public record GameProfile(@Nullable String name, @Nullable UUID id, Property[] properties) {
|
||||
public record GameProfile(@Nullable String name, @Nullable UUID id, Property[] properties, boolean dynamic) {
|
||||
|
||||
public GameProfile(@Nullable final String name, @Nullable final UUID id, final Property[] properties) {
|
||||
this(name, id, properties, true);
|
||||
}
|
||||
|
||||
public GameProfile(@Nullable final String name, @Nullable final UUID id) {
|
||||
this(name, id, new Property[0]);
|
||||
|
||||
@@ -22,7 +22,11 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Set of ids that either holds a string tag key or an array of ids.
|
||||
@@ -32,7 +36,7 @@ public interface HolderSet {
|
||||
/**
|
||||
* Creates a new holder set for the given tag.
|
||||
*
|
||||
* @param tagKey the tag key
|
||||
* @param tagKey the tag key, not including '#'
|
||||
* @return a new holder set
|
||||
*/
|
||||
static HolderSet of(final String tagKey) {
|
||||
@@ -49,10 +53,29 @@ public interface HolderSet {
|
||||
return new HolderSetImpl.Ids(ids);
|
||||
}
|
||||
|
||||
static HolderSet fromTag(final Tag tag, final Function<String, Integer> mappingFunction) {
|
||||
if (tag instanceof StringTag stringTag) {
|
||||
if (stringTag.getValue().startsWith("#")) {
|
||||
return HolderSet.of(stringTag.getValue().substring(1));
|
||||
}
|
||||
|
||||
final int id = mappingFunction.apply(stringTag.getValue());
|
||||
return HolderSet.of(new int[]{id});
|
||||
} else if (tag instanceof ListTag<?> listTag) {
|
||||
final int[] ids = new int[listTag.size()];
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
final String value = ((StringTag) listTag.get(i)).getValue();
|
||||
ids[i] = mappingFunction.apply(value);
|
||||
}
|
||||
return HolderSet.of(ids);
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag key.
|
||||
* Gets the tag key, not including '#'.
|
||||
*
|
||||
* @return the tag key
|
||||
* @return the tag key without a '#'
|
||||
* @see #hasTagKey()
|
||||
*/
|
||||
String tagKey();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Profile that can be either dynamically filled by the client or is already static.
|
||||
* The additional fields are optional overrides.
|
||||
*/
|
||||
public record ResolvableProfile(GameProfile profile, @Nullable String bodyTexture, @Nullable String capeTexture,
|
||||
@Nullable String elytraTexture, @Nullable Integer modelType) {
|
||||
|
||||
public ResolvableProfile(final GameProfile profile) {
|
||||
this(profile, null, null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public record Vector3d(double x, double y, double z) {
|
||||
|
||||
public static final Vector3d ZERO = new Vector3d(0, 0, 0);
|
||||
}
|
||||
@@ -45,6 +45,16 @@ public interface CodecContext {
|
||||
|
||||
Key dataComponentType(int id);
|
||||
|
||||
Key entity(int id);
|
||||
|
||||
Key blockEntity(int id);
|
||||
|
||||
Key sound(int id);
|
||||
|
||||
Key key(MappingData.MappingType mappingType, int id);
|
||||
|
||||
int id(MappingData.MappingType mappingType, String identifier);
|
||||
|
||||
static RegistryAccess of(final List<String> enchantments, final MappingData mappingData) {
|
||||
return new RegistryAccessImpl(enchantments, mappingData);
|
||||
}
|
||||
|
||||
+26
@@ -66,6 +66,32 @@ final class RegistryAccessImpl implements CodecContext.RegistryAccess {
|
||||
return key(mappingData.getDataComponentSerializerMappings(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key entity(final int id) {
|
||||
return key(mappingData.getEntityMappings(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key blockEntity(final int id) {
|
||||
return key(mappingData.getBlockEntityMappings(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key sound(final int id) {
|
||||
return key(mappingData.getFullSoundMappings(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key key(final MappingData.MappingType mappingType, final int id) {
|
||||
return key(mappingData.getFullMappings(mappingType), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id(final MappingData.MappingType mappingType, final String identifier) {
|
||||
final FullMappings mappings = mappingData.getFullMappings(mappingType);
|
||||
return mapped ? mappings.mappedId(identifier) : mappings.id(identifier);
|
||||
}
|
||||
|
||||
private Key key(final FullMappings mappings, final int id) {
|
||||
final String identifier = mapped ? mappings.mappedIdentifier(id) : mappings.identifier(id);
|
||||
return key(identifier, id);
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.minecraft.data;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.util.ArrayUtil;
|
||||
import com.viaversion.viaversion.util.Copyable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Objects;
|
||||
@@ -102,7 +103,7 @@ final class FilledStructuredData<T> implements StructuredData<T> {
|
||||
public String toString() {
|
||||
return "FilledStructuredData{" +
|
||||
"key=" + key +
|
||||
", value=" + value +
|
||||
", value=" + ArrayUtil.toString(value) +
|
||||
", id=" + id +
|
||||
'}';
|
||||
}
|
||||
|
||||
+21
-9
@@ -27,8 +27,8 @@ import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.api.minecraft.EitherHolder;
|
||||
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.PaintingVariant;
|
||||
import com.viaversion.viaversion.api.minecraft.ResolvableProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.minecraft.data.version.StructuredDataKeys1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.data.version.StructuredDataKeys1_21_2;
|
||||
@@ -39,12 +39,14 @@ import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_20_
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_21;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlocksAttacks;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Consumable1_21_2;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.CustomModelData1_21_4;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DamageResistant;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DeathProtection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DebugStickState;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantable;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||
@@ -56,15 +58,19 @@ import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_21_2;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_21_2;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ItemModel;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.JukeboxPlayable;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.LockCode;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ProvidesTrimMaterial;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Repairable;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.TooltipDisplay;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.TropicalFishPattern;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.UseCooldown;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Weapon;
|
||||
@@ -97,7 +103,7 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKey<Unit> UNBREAKABLE1_21_5 = new StructuredDataKey<>("unbreakable", Types.EMPTY);
|
||||
public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Types.TEXT_COMPONENT_TAG);
|
||||
public static final StructuredDataKey<Tag> ITEM_NAME = new StructuredDataKey<>("item_name", Types.TEXT_COMPONENT_TAG);
|
||||
public static final StructuredDataKey<Key> ITEM_MODEL = new StructuredDataKey<>("item_model", Types.RESOURCE_LOCATION);
|
||||
public static final StructuredDataKey<ItemModel> ITEM_MODEL = new StructuredDataKey<>("item_model", ItemModel.TYPE);
|
||||
public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", new ArrayType<>(Types.TEXT_COMPONENT_TAG, 256));
|
||||
public static final StructuredDataKey<Integer> RARITY = new StructuredDataKey<>("rarity", EnumTypes.RARITY);
|
||||
public static final StructuredDataKey<Enchantments> ENCHANTMENTS1_20_5 = new StructuredDataKey<>("enchantments", Enchantments.TYPE1_20_5);
|
||||
@@ -132,7 +138,7 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKey<Equippable> EQUIPPABLE1_21_2 = new StructuredDataKey<>("equippable", Equippable.TYPE1_21_2);
|
||||
public static final StructuredDataKey<Equippable> EQUIPPABLE1_21_5 = new StructuredDataKey<>("equippable", Equippable.TYPE1_21_5);
|
||||
public static final StructuredDataKey<Equippable> EQUIPPABLE1_21_6 = new StructuredDataKey<>("equippable", Equippable.TYPE1_21_6);
|
||||
public static final StructuredDataKey<HolderSet> REPAIRABLE = new StructuredDataKey<>("repairable", Types.HOLDER_SET);
|
||||
public static final StructuredDataKey<Repairable> REPAIRABLE = new StructuredDataKey<>("repairable", Repairable.TYPE);
|
||||
public static final StructuredDataKey<Unit> GLIDER = new StructuredDataKey<>("glider", Types.EMPTY);
|
||||
public static final StructuredDataKey<Key> TOOLTIP_STYLE = new StructuredDataKey<>("tooltip_style", Types.RESOURCE_LOCATION);
|
||||
public static final StructuredDataKey<DeathProtection> DEATH_PROTECTION = new StructuredDataKey<>("death_protection", DeathProtection.TYPE);
|
||||
@@ -155,10 +161,12 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKey<ArmorTrim> TRIM1_21_2 = new StructuredDataKey<>("trim", ArmorTrim.TYPE1_21_2);
|
||||
public static final StructuredDataKey<ArmorTrim> TRIM1_21_4 = new StructuredDataKey<>("trim", ArmorTrim.TYPE1_21_4);
|
||||
public static final StructuredDataKey<ArmorTrim> TRIM1_21_5 = new StructuredDataKey<>("trim", ArmorTrim.TYPE1_21_5);
|
||||
public static final StructuredDataKey<CompoundTag> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<CompoundTag> ENTITY_DATA = new StructuredDataKey<>("entity_data", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<DebugStickState> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", DebugStickState.TYPE);
|
||||
public static final StructuredDataKey<CompoundTag> ENTITY_DATA1_20_5 = new StructuredDataKey<>("entity_data", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<EntityData> ENTITY_DATA1_21_9 = new StructuredDataKey<>("entity_data", EntityData.TYPE);
|
||||
public static final StructuredDataKey<CompoundTag> BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA1_20_5 = new StructuredDataKey<>("block_entity_data", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<BlockEntityData> BLOCK_ENTITY_DATA1_21_9 = new StructuredDataKey<>("block_entity_data", BlockEntityData.TYPE);
|
||||
public static final StructuredDataKey<Holder<Instrument1_20_5>> INSTRUMENT1_20_5 = new StructuredDataKey<>("instrument", Instrument1_20_5.TYPE);
|
||||
public static final StructuredDataKey<Holder<Instrument1_21_2>> INSTRUMENT1_21_2 = new StructuredDataKey<>("instrument", Instrument1_21_2.TYPE);
|
||||
public static final StructuredDataKey<EitherHolder<Instrument1_21_2>> INSTRUMENT1_21_5 = new StructuredDataKey<>("instrument", Instrument1_21_2.EITHER_HOLDER_TYPE);
|
||||
@@ -171,14 +179,17 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKey<LodestoneTracker> LODESTONE_TRACKER = new StructuredDataKey<>("lodestone_tracker", LodestoneTracker.TYPE);
|
||||
public static final StructuredDataKey<FireworkExplosion> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE);
|
||||
public static final StructuredDataKey<Fireworks> FIREWORKS = new StructuredDataKey<>("fireworks", Fireworks.TYPE);
|
||||
public static final StructuredDataKey<GameProfile> PROFILE = new StructuredDataKey<>("profile", Types.GAME_PROFILE);
|
||||
public static final StructuredDataKey<GameProfile> PROFILE1_20_5 = new StructuredDataKey<>("profile", Types.GAME_PROFILE);
|
||||
public static final StructuredDataKey<ResolvableProfile> PROFILE1_21_9 = new StructuredDataKey<>("profile", Types.RESOLVABLE_PROFILE);
|
||||
public static final StructuredDataKey<Key> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Types.RESOURCE_LOCATION);
|
||||
public static final StructuredDataKey<BannerPatternLayer[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE);
|
||||
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", EnumTypes.DYE_COLOR);
|
||||
public static final StructuredDataKey<PotDecorations> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE);
|
||||
public static final StructuredDataKey<BlockStateProperties> BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE);
|
||||
public static final StructuredDataKey<Bee[]> BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE);
|
||||
public static final StructuredDataKey<Tag> LOCK = new StructuredDataKey<>("lock", Types.TAG);
|
||||
public static final StructuredDataKey<Bee[]> BEES1_20_5 = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE1_20_5);
|
||||
public static final StructuredDataKey<Bee[]> BEES1_21_9 = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE1_21_9);
|
||||
public static final StructuredDataKey<Tag> LOCK1_20_5 = new StructuredDataKey<>("lock", Types.TAG);
|
||||
public static final StructuredDataKey<LockCode> LOCK1_21_2 = new StructuredDataKey<>("lock", LockCode.TYPE);
|
||||
public static final StructuredDataKey<CompoundTag> CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Types.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<Holder<SoundEvent>> BREAK_SOUND = new StructuredDataKey<>("break_sound", Types.SOUND_EVENT);
|
||||
|
||||
@@ -214,6 +225,7 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKeys1_21_2 V1_21_4 = VersionedTypes.V1_21_4.structuredDataKeys();
|
||||
public static final StructuredDataKeys1_21_5 V1_21_5 = VersionedTypes.V1_21_5.structuredDataKeys();
|
||||
public static final StructuredDataKeys1_21_5 V1_21_6 = VersionedTypes.V1_21_6.structuredDataKeys();
|
||||
public static final StructuredDataKeys1_21_5 V1_21_9 = VersionedTypes.V1_21_9.structuredDataKeys();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
+9
-7
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class EntityTypes1_10 {
|
||||
|
||||
@@ -143,7 +143,7 @@ public class EntityTypes1_10 {
|
||||
SPIDER(52, ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(59, SPIDER);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<EntityType> TYPES;
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@@ -184,7 +184,9 @@ public class EntityTypes1_10 {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
final EntityType[] values = EntityType.values();
|
||||
TYPES = new Int2ObjectOpenHashMap<>(values.length);
|
||||
for (EntityType type : values) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
@@ -230,7 +232,7 @@ public class EntityTypes1_10 {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, Map<Integer, ObjectType>> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<Int2ObjectMap<ObjectType>> TYPES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final int data;
|
||||
@@ -238,7 +240,7 @@ public class EntityTypes1_10 {
|
||||
|
||||
static {
|
||||
for (ObjectType type : ObjectType.values()) {
|
||||
TYPES.computeIfAbsent(type.id, k -> new HashMap<>()).put(type.data, type);
|
||||
TYPES.computeIfAbsent(type.id, k -> new Int2ObjectOpenHashMap<>()).put(type.data, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +270,7 @@ public class EntityTypes1_10 {
|
||||
}
|
||||
|
||||
public static ObjectType findById(final int id, final int data) {
|
||||
final Map<Integer, ObjectType> types = TYPES.get(id);
|
||||
final Int2ObjectMap<ObjectType> types = TYPES.get(id);
|
||||
if (types == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+9
-7
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class EntityTypes1_11 {
|
||||
|
||||
@@ -168,7 +168,7 @@ public class EntityTypes1_11 {
|
||||
EVOKER(34, ABSTRACT_MONSTER),
|
||||
VINDICATOR(36, ABSTRACT_MONSTER);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<EntityType> TYPES;
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@@ -209,7 +209,9 @@ public class EntityTypes1_11 {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
final EntityType[] values = EntityType.values();
|
||||
TYPES = new Int2ObjectOpenHashMap<>(values.length);
|
||||
for (EntityType type : values) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
@@ -257,7 +259,7 @@ public class EntityTypes1_11 {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, Map<Integer, ObjectType>> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<Int2ObjectMap<ObjectType>> TYPES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final int data;
|
||||
@@ -265,7 +267,7 @@ public class EntityTypes1_11 {
|
||||
|
||||
static {
|
||||
for (ObjectType type : ObjectType.values()) {
|
||||
TYPES.computeIfAbsent(type.id, k -> new HashMap<>()).put(type.data, type);
|
||||
TYPES.computeIfAbsent(type.id, k -> new Int2ObjectOpenHashMap<>()).put(type.data, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +297,7 @@ public class EntityTypes1_11 {
|
||||
}
|
||||
|
||||
public static ObjectType findById(final int id, final int data) {
|
||||
final Map<Integer, ObjectType> types = TYPES.get(id);
|
||||
final Int2ObjectMap<ObjectType> types = TYPES.get(id);
|
||||
if (types == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+9
-7
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class EntityTypes1_12 {
|
||||
|
||||
@@ -174,7 +174,7 @@ public class EntityTypes1_12 {
|
||||
EVOKER(34, SPELLCASTER_ILLAGER),
|
||||
ILLUSIONER(37, SPELLCASTER_ILLAGER);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<EntityType> TYPES;
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@@ -215,7 +215,9 @@ public class EntityTypes1_12 {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
final EntityType[] values = EntityType.values();
|
||||
TYPES = new Int2ObjectOpenHashMap<>(values.length);
|
||||
for (EntityType type : values) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +265,7 @@ public class EntityTypes1_12 {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, Map<Integer, ObjectType>> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<Int2ObjectMap<ObjectType>> TYPES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final int data;
|
||||
@@ -271,7 +273,7 @@ public class EntityTypes1_12 {
|
||||
|
||||
static {
|
||||
for (ObjectType type : ObjectType.values()) {
|
||||
TYPES.computeIfAbsent(type.id, k -> new HashMap<>()).put(type.data, type);
|
||||
TYPES.computeIfAbsent(type.id, k -> new Int2ObjectOpenHashMap<>()).put(type.data, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ public class EntityTypes1_12 {
|
||||
}
|
||||
|
||||
public static ObjectType findById(final int id, final int data) {
|
||||
final Map<Integer, ObjectType> types = TYPES.get(id);
|
||||
final Int2ObjectMap<ObjectType> types = TYPES.get(id);
|
||||
if (types == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+9
-7
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class EntityTypes1_13 {
|
||||
|
||||
@@ -185,7 +185,7 @@ public class EntityTypes1_13 {
|
||||
EVOKER(21, SPELLCASTER_ILLAGER),
|
||||
ILLUSIONER(31, SPELLCASTER_ILLAGER);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<EntityType> TYPES;
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@@ -226,7 +226,9 @@ public class EntityTypes1_13 {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
final EntityType[] values = EntityType.values();
|
||||
TYPES = new Int2ObjectOpenHashMap<>(values.length);
|
||||
for (EntityType type : values) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
@@ -275,7 +277,7 @@ public class EntityTypes1_13 {
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL),
|
||||
TRIDENT(94, EntityType.TRIDENT);
|
||||
|
||||
private static final Map<Integer, Map<Integer, ObjectType>> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<Int2ObjectMap<ObjectType>> TYPES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final int data;
|
||||
@@ -283,7 +285,7 @@ public class EntityTypes1_13 {
|
||||
|
||||
static {
|
||||
for (ObjectType type : ObjectType.values()) {
|
||||
TYPES.computeIfAbsent(type.id, k -> new HashMap<>()).put(type.data, type);
|
||||
TYPES.computeIfAbsent(type.id, k -> new Int2ObjectOpenHashMap<>()).put(type.data, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +315,7 @@ public class EntityTypes1_13 {
|
||||
}
|
||||
|
||||
public static ObjectType findById(final int id, final int data) {
|
||||
final Map<Integer, ObjectType> types = TYPES.get(id);
|
||||
final Int2ObjectMap<ObjectType> types = TYPES.get(id);
|
||||
if (types == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum EntityTypes1_21_9 implements EntityType {
|
||||
|
||||
ENTITY(null, null),
|
||||
|
||||
AREA_EFFECT_CLOUD(ENTITY),
|
||||
END_CRYSTAL(ENTITY),
|
||||
EVOKER_FANGS(ENTITY),
|
||||
EXPERIENCE_ORB(ENTITY),
|
||||
EYE_OF_ENDER(ENTITY),
|
||||
FALLING_BLOCK(ENTITY),
|
||||
ITEM(ENTITY),
|
||||
TNT(ENTITY),
|
||||
OMINOUS_ITEM_SPAWNER(ENTITY),
|
||||
MARKER(ENTITY),
|
||||
LIGHTNING_BOLT(ENTITY),
|
||||
INTERACTION(ENTITY),
|
||||
|
||||
DISPLAY(ENTITY, null),
|
||||
BLOCK_DISPLAY(DISPLAY),
|
||||
ITEM_DISPLAY(DISPLAY),
|
||||
TEXT_DISPLAY(DISPLAY),
|
||||
|
||||
// Hanging entities
|
||||
HANGING_ENTITY(ENTITY, null),
|
||||
LEASH_KNOT(HANGING_ENTITY),
|
||||
PAINTING(HANGING_ENTITY),
|
||||
ITEM_FRAME(HANGING_ENTITY),
|
||||
GLOW_ITEM_FRAME(ITEM_FRAME),
|
||||
|
||||
// Projectiles
|
||||
PROJECTILE(ENTITY, null),
|
||||
ITEM_PROJECTILE(PROJECTILE, null),
|
||||
SNOWBALL(ITEM_PROJECTILE),
|
||||
ENDER_PEARL(ITEM_PROJECTILE),
|
||||
EGG(ITEM_PROJECTILE),
|
||||
EXPERIENCE_BOTTLE(ITEM_PROJECTILE),
|
||||
FIREWORK_ROCKET(PROJECTILE),
|
||||
LLAMA_SPIT(PROJECTILE),
|
||||
SHULKER_BULLET(PROJECTILE),
|
||||
FISHING_BOBBER(PROJECTILE),
|
||||
WITHER_SKULL(PROJECTILE),
|
||||
DRAGON_FIREBALL(PROJECTILE), // Doesn't actually inherit fireball
|
||||
|
||||
ABSTRACT_THROWN_POTION(ITEM_PROJECTILE, null),
|
||||
SPLASH_POTION(ABSTRACT_THROWN_POTION),
|
||||
LINGERING_POTION(ABSTRACT_THROWN_POTION),
|
||||
|
||||
ABSTRACT_ARROW(PROJECTILE, null),
|
||||
ARROW(ABSTRACT_ARROW),
|
||||
SPECTRAL_ARROW(ABSTRACT_ARROW),
|
||||
TRIDENT(ABSTRACT_ARROW),
|
||||
|
||||
ABSTRACT_FIREBALL(ENTITY, null),
|
||||
FIREBALL(ABSTRACT_FIREBALL),
|
||||
SMALL_FIREBALL(ABSTRACT_FIREBALL),
|
||||
|
||||
ABSTRACT_WIND_CHARGE(PROJECTILE, null),
|
||||
WIND_CHARGE(ABSTRACT_WIND_CHARGE),
|
||||
BREEZE_WIND_CHARGE(ABSTRACT_WIND_CHARGE),
|
||||
|
||||
// Vehicles
|
||||
VEHICLE(ENTITY, null),
|
||||
|
||||
ABSTRACT_MINECART(VEHICLE, null),
|
||||
MINECART(ABSTRACT_MINECART),
|
||||
FURNACE_MINECART(ABSTRACT_MINECART),
|
||||
COMMAND_BLOCK_MINECART(ABSTRACT_MINECART),
|
||||
TNT_MINECART(ABSTRACT_MINECART),
|
||||
SPAWNER_MINECART(ABSTRACT_MINECART),
|
||||
|
||||
ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART, null),
|
||||
CHEST_MINECART(ABSTRACT_MINECART_CONTAINER),
|
||||
HOPPER_MINECART(ABSTRACT_MINECART_CONTAINER),
|
||||
|
||||
ABSTRACT_BOAT(VEHICLE, null),
|
||||
ABSTRACT_CHEST_BOAT(ABSTRACT_BOAT, null),
|
||||
ACACIA_BOAT(ABSTRACT_BOAT),
|
||||
ACACIA_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
BAMBOO_CHEST_RAFT(ABSTRACT_CHEST_BOAT),
|
||||
BAMBOO_RAFT(ABSTRACT_BOAT),
|
||||
BIRCH_BOAT(ABSTRACT_BOAT),
|
||||
BIRCH_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
CHERRY_BOAT(ABSTRACT_BOAT),
|
||||
CHERRY_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
DARK_OAK_BOAT(ABSTRACT_BOAT),
|
||||
DARK_OAK_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
JUNGLE_BOAT(ABSTRACT_BOAT),
|
||||
JUNGLE_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
MANGROVE_BOAT(ABSTRACT_BOAT),
|
||||
MANGROVE_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
OAK_BOAT(ABSTRACT_BOAT),
|
||||
OAK_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
PALE_OAK_BOAT(ABSTRACT_BOAT),
|
||||
PALE_OAK_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
SPRUCE_BOAT(ABSTRACT_BOAT),
|
||||
SPRUCE_CHEST_BOAT(ABSTRACT_CHEST_BOAT),
|
||||
|
||||
// Living entities as a larger subclass
|
||||
LIVING_ENTITY(ENTITY, null),
|
||||
ARMOR_STAND(LIVING_ENTITY),
|
||||
|
||||
// Players
|
||||
AVATAR(LIVING_ENTITY, null),
|
||||
MANNEQUIN(AVATAR),
|
||||
PLAYER(AVATAR),
|
||||
|
||||
// Mobs as a larger subclass
|
||||
MOB(LIVING_ENTITY, null),
|
||||
ENDER_DRAGON(MOB),
|
||||
|
||||
SLIME(MOB),
|
||||
MAGMA_CUBE(SLIME),
|
||||
|
||||
// Ambient mobs
|
||||
AMBIENT_CREATURE(MOB, null),
|
||||
BAT(AMBIENT_CREATURE),
|
||||
|
||||
// Flying mobs
|
||||
FLYING_MOB(MOB, null),
|
||||
GHAST(FLYING_MOB),
|
||||
PHANTOM(FLYING_MOB),
|
||||
|
||||
// Pathfinder mobs and its subclasses
|
||||
PATHFINDER_MOB(MOB, null),
|
||||
ALLAY(PATHFINDER_MOB),
|
||||
|
||||
ABSTRACT_GOLEM(PATHFINDER_MOB, null),
|
||||
SNOW_GOLEM(ABSTRACT_GOLEM),
|
||||
IRON_GOLEM(ABSTRACT_GOLEM),
|
||||
SHULKER(ABSTRACT_GOLEM),
|
||||
COPPER_GOLEM(ABSTRACT_GOLEM),
|
||||
|
||||
// Ageable mobs and (tamable) animals
|
||||
ABSTRACT_AGEABLE(PATHFINDER_MOB, null),
|
||||
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
|
||||
VILLAGER(ABSTRACT_VILLAGER),
|
||||
WANDERING_TRADER(ABSTRACT_VILLAGER),
|
||||
|
||||
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
|
||||
AXOLOTL(ABSTRACT_ANIMAL),
|
||||
CHICKEN(ABSTRACT_ANIMAL),
|
||||
PANDA(ABSTRACT_ANIMAL),
|
||||
PIG(ABSTRACT_ANIMAL),
|
||||
POLAR_BEAR(ABSTRACT_ANIMAL),
|
||||
RABBIT(ABSTRACT_ANIMAL),
|
||||
SHEEP(ABSTRACT_ANIMAL),
|
||||
BEE(ABSTRACT_ANIMAL),
|
||||
TURTLE(ABSTRACT_ANIMAL),
|
||||
FOX(ABSTRACT_ANIMAL),
|
||||
FROG(ABSTRACT_ANIMAL),
|
||||
GOAT(ABSTRACT_ANIMAL),
|
||||
HOGLIN(ABSTRACT_ANIMAL),
|
||||
STRIDER(ABSTRACT_ANIMAL),
|
||||
SNIFFER(ABSTRACT_ANIMAL),
|
||||
ARMADILLO(ABSTRACT_ANIMAL),
|
||||
HAPPY_GHAST(ABSTRACT_ANIMAL),
|
||||
|
||||
ABSTRACT_COW(ABSTRACT_ANIMAL, null),
|
||||
COW(ABSTRACT_COW),
|
||||
MOOSHROOM(ABSTRACT_COW),
|
||||
|
||||
TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
|
||||
CAT(TAMABLE_ANIMAL),
|
||||
OCELOT(TAMABLE_ANIMAL),
|
||||
WOLF(TAMABLE_ANIMAL),
|
||||
PARROT(TAMABLE_ANIMAL),
|
||||
|
||||
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
|
||||
HORSE(ABSTRACT_HORSE),
|
||||
SKELETON_HORSE(ABSTRACT_HORSE),
|
||||
ZOMBIE_HORSE(ABSTRACT_HORSE),
|
||||
CAMEL(ABSTRACT_HORSE),
|
||||
|
||||
ABSTRACT_CHESTED_HORSE(ABSTRACT_HORSE, null),
|
||||
DONKEY(ABSTRACT_CHESTED_HORSE),
|
||||
MULE(ABSTRACT_CHESTED_HORSE),
|
||||
LLAMA(ABSTRACT_CHESTED_HORSE),
|
||||
TRADER_LLAMA(LLAMA),
|
||||
|
||||
// Monsters
|
||||
ABSTRACT_MONSTER(PATHFINDER_MOB, null),
|
||||
BLAZE(ABSTRACT_MONSTER),
|
||||
CREEPER(ABSTRACT_MONSTER),
|
||||
ENDERMITE(ABSTRACT_MONSTER),
|
||||
ENDERMAN(ABSTRACT_MONSTER),
|
||||
GIANT(ABSTRACT_MONSTER),
|
||||
SILVERFISH(ABSTRACT_MONSTER),
|
||||
VEX(ABSTRACT_MONSTER),
|
||||
WITHER(ABSTRACT_MONSTER),
|
||||
BREEZE(ABSTRACT_MONSTER),
|
||||
ZOGLIN(ABSTRACT_MONSTER),
|
||||
WARDEN(ABSTRACT_MONSTER),
|
||||
CREAKING(ABSTRACT_MONSTER),
|
||||
|
||||
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
|
||||
SKELETON(ABSTRACT_SKELETON),
|
||||
STRAY(ABSTRACT_SKELETON),
|
||||
WITHER_SKELETON(ABSTRACT_SKELETON),
|
||||
BOGGED(ABSTRACT_SKELETON),
|
||||
|
||||
ZOMBIE(ABSTRACT_MONSTER),
|
||||
DROWNED(ZOMBIE),
|
||||
HUSK(ZOMBIE),
|
||||
ZOMBIFIED_PIGLIN(ZOMBIE),
|
||||
ZOMBIE_VILLAGER(ZOMBIE),
|
||||
|
||||
GUARDIAN(ABSTRACT_MONSTER),
|
||||
ELDER_GUARDIAN(GUARDIAN),
|
||||
|
||||
SPIDER(ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(SPIDER),
|
||||
|
||||
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
|
||||
PIGLIN(ABSTRACT_PIGLIN),
|
||||
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
|
||||
|
||||
// Water mobs
|
||||
AGEABLE_WATER_CREATURE(ABSTRACT_AGEABLE, null),
|
||||
DOLPHIN(AGEABLE_WATER_CREATURE),
|
||||
|
||||
SQUID(AGEABLE_WATER_CREATURE),
|
||||
GLOW_SQUID(SQUID),
|
||||
|
||||
WATER_ANIMAL(PATHFINDER_MOB, null),
|
||||
ABSTRACT_FISH(WATER_ANIMAL, null),
|
||||
PUFFERFISH(ABSTRACT_FISH),
|
||||
TADPOLE(ABSTRACT_FISH),
|
||||
|
||||
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISH, null),
|
||||
COD(ABSTRACT_SCHOOLING_FISH),
|
||||
SALMON(ABSTRACT_SCHOOLING_FISH),
|
||||
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
|
||||
|
||||
// Raiders
|
||||
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
|
||||
WITCH(ABSTRACT_RAIDER),
|
||||
RAVAGER(ABSTRACT_RAIDER),
|
||||
|
||||
ABSTRACT_ILLAGER(ABSTRACT_RAIDER, null),
|
||||
SPELLCASTER_ILLAGER(ABSTRACT_ILLAGER, null),
|
||||
VINDICATOR(ABSTRACT_ILLAGER),
|
||||
PILLAGER(ABSTRACT_ILLAGER),
|
||||
EVOKER(SPELLCASTER_ILLAGER),
|
||||
ILLUSIONER(SPELLCASTER_ILLAGER);
|
||||
|
||||
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
|
||||
private final EntityType parent;
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
EntityTypes1_21_9(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = Key.namespaced(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
EntityTypes1_21_9(final EntityType parent, @Nullable final String identifier) {
|
||||
this.parent = parent;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
if (id == -1) {
|
||||
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable EntityType getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return identifier == null;
|
||||
}
|
||||
|
||||
public static EntityType getTypeFromId(final int typeId) {
|
||||
return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG);
|
||||
}
|
||||
|
||||
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
|
||||
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class EntityTypes1_8 {
|
||||
|
||||
@@ -135,7 +135,7 @@ public class EntityTypes1_8 {
|
||||
SPIDER(52, ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(59, SPIDER);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<EntityType> TYPES;
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@@ -176,7 +176,9 @@ public class EntityTypes1_8 {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
final EntityType[] values = EntityType.values();
|
||||
TYPES = new Int2ObjectOpenHashMap<>(values.length);
|
||||
for (EntityType type : values) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +220,7 @@ public class EntityTypes1_8 {
|
||||
ARMOR_STAND(78, EntityType.ARMOR_STAND),
|
||||
FISHIHNG_HOOK(90, EntityType.FISHING_HOOK);
|
||||
|
||||
private static final Map<Integer, Map<Integer, ObjectType>> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<Int2ObjectMap<ObjectType>> TYPES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final int data;
|
||||
@@ -226,7 +228,7 @@ public class EntityTypes1_8 {
|
||||
|
||||
static {
|
||||
for (ObjectType type : ObjectType.values()) {
|
||||
TYPES.computeIfAbsent(type.id, k -> new HashMap<>()).put(type.data, type);
|
||||
TYPES.computeIfAbsent(type.id, k -> new Int2ObjectOpenHashMap<>()).put(type.data, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +258,7 @@ public class EntityTypes1_8 {
|
||||
}
|
||||
|
||||
public static ObjectType findById(final int id, final int data) {
|
||||
final Map<Integer, ObjectType> types = TYPES.get(id);
|
||||
final Int2ObjectMap<ObjectType> types = TYPES.get(id);
|
||||
if (types == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+9
-7
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class EntityTypes1_9 {
|
||||
|
||||
@@ -142,7 +142,7 @@ public class EntityTypes1_9 {
|
||||
SPIDER(52, ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(59, SPIDER);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<EntityType> TYPES;
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@@ -183,7 +183,9 @@ public class EntityTypes1_9 {
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
final EntityType[] values = EntityType.values();
|
||||
TYPES = new Int2ObjectOpenHashMap<>(values.length);
|
||||
for (EntityType type : values) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
@@ -229,7 +231,7 @@ public class EntityTypes1_9 {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, Map<Integer, ObjectType>> TYPES = new HashMap<>();
|
||||
private static final Int2ObjectMap<Int2ObjectMap<ObjectType>> TYPES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final int data;
|
||||
@@ -237,7 +239,7 @@ public class EntityTypes1_9 {
|
||||
|
||||
static {
|
||||
for (ObjectType type : ObjectType.values()) {
|
||||
TYPES.computeIfAbsent(type.id, k -> new HashMap<>()).put(type.data, type);
|
||||
TYPES.computeIfAbsent(type.id, k -> new Int2ObjectOpenHashMap<>()).put(type.data, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +269,7 @@ public class EntityTypes1_9 {
|
||||
}
|
||||
|
||||
public static ObjectType findById(final int id, final int data) {
|
||||
final Map<Integer, ObjectType> types = TYPES.get(id);
|
||||
final Int2ObjectMap<ObjectType> types = TYPES.get(id);
|
||||
if (types == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entitydata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.PaintingVariant;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.VersionedTypesHolder;
|
||||
|
||||
public final class EntityDataTypes1_21_9 extends AbstractEntityDataTypes {
|
||||
|
||||
public final EntityDataType byteType = add(0, Types.BYTE);
|
||||
public final EntityDataType varIntType = add(1, Types.VAR_INT);
|
||||
public final EntityDataType longType = add(2, Types.VAR_LONG);
|
||||
public final EntityDataType floatType = add(3, Types.FLOAT);
|
||||
public final EntityDataType stringType = add(4, Types.STRING);
|
||||
public final EntityDataType componentType = add(5, Types.TAG);
|
||||
public final EntityDataType optionalComponentType = add(6, Types.OPTIONAL_TAG);
|
||||
public final EntityDataType itemType;
|
||||
public final EntityDataType booleanType = add(8, Types.BOOLEAN);
|
||||
public final EntityDataType rotationsType = add(9, Types.ROTATIONS);
|
||||
public final EntityDataType blockPositionType = add(10, Types.BLOCK_POSITION1_14);
|
||||
public final EntityDataType optionalBlockPositionType = add(11, Types.OPTIONAL_POSITION_1_14);
|
||||
public final EntityDataType directionType = add(12, Types.VAR_INT);
|
||||
public final EntityDataType optionalUUIDType = add(13, Types.OPTIONAL_UUID);
|
||||
public final EntityDataType blockStateType = add(14, Types.VAR_INT);
|
||||
public final EntityDataType optionalBlockStateType = add(15, Types.VAR_INT);
|
||||
public final EntityDataType particleType;
|
||||
public final EntityDataType particlesType;
|
||||
public final EntityDataType villagerDatatType = add(18, Types.VILLAGER_DATA);
|
||||
public final EntityDataType optionalVarIntType = add(19, Types.OPTIONAL_VAR_INT);
|
||||
public final EntityDataType poseType = add(20, Types.VAR_INT);
|
||||
public final EntityDataType catVariantType = add(21, Types.VAR_INT);
|
||||
public final EntityDataType cowVariantType = add(22, Types.VAR_INT);
|
||||
public final EntityDataType wolfVariantType = add(23, Types.VAR_INT);
|
||||
public final EntityDataType wolfSoundVariantType = add(24, Types.VAR_INT);
|
||||
public final EntityDataType frogVariantType = add(25, Types.VAR_INT);
|
||||
public final EntityDataType pigVariantType = add(26, Types.VAR_INT);
|
||||
public final EntityDataType chickenVariantType = add(27, Types.VAR_INT);
|
||||
public final EntityDataType optionalGlobalPosition = add(28, Types.OPTIONAL_GLOBAL_POSITION);
|
||||
public final EntityDataType paintingVariantType = add(29, PaintingVariant.TYPE1_21_2);
|
||||
public final EntityDataType snifferState = add(30, Types.VAR_INT);
|
||||
public final EntityDataType armadilloState = add(31, Types.VAR_INT);
|
||||
public final EntityDataType copperGolemState = add(32, Types.VAR_INT);
|
||||
public final EntityDataType weatheringCopperState = add(33, Types.VAR_INT);
|
||||
public final EntityDataType vector3FType = add(34, Types.VECTOR3F);
|
||||
public final EntityDataType quaternionType = add(35, Types.QUATERNION);
|
||||
public final EntityDataType mannequinProfileType = add(36, Types.RESOLVABLE_PROFILE);
|
||||
|
||||
public EntityDataTypes1_21_9(final VersionedTypesHolder types) {
|
||||
super(37);
|
||||
this.itemType = add(7, types.item());
|
||||
this.particleType = add(16, types.particle());
|
||||
this.particlesType = add(17, types.particles());
|
||||
}
|
||||
}
|
||||
@@ -30,20 +30,24 @@ import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import com.viaversion.viaversion.util.Copyable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public record Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) implements Copyable {
|
||||
public record Bee(EntityData entityData, int ticksInHive, int minTicksInHive) implements Copyable {
|
||||
|
||||
public static final Type<Bee> TYPE = new Type<>(Bee.class) {
|
||||
public Bee(final CompoundTag entityData, final int ticksInHive, final int minTicksInHive) {
|
||||
this(new EntityData(-1, entityData), ticksInHive, minTicksInHive);
|
||||
}
|
||||
|
||||
public static final Type<Bee> TYPE1_20_5 = new Type<>(Bee.class) {
|
||||
@Override
|
||||
public Bee read(final ByteBuf buffer) {
|
||||
final CompoundTag entityData = Types.COMPOUND_TAG.read(buffer);
|
||||
final int ticksInHive = Types.VAR_INT.readPrimitive(buffer);
|
||||
final int minTicksInHive = Types.VAR_INT.readPrimitive(buffer);
|
||||
return new Bee(entityData, ticksInHive, minTicksInHive);
|
||||
return new Bee(new EntityData(-1, entityData), ticksInHive, minTicksInHive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Bee value) {
|
||||
Types.COMPOUND_TAG.write(buffer, value.entityData);
|
||||
Types.COMPOUND_TAG.write(buffer, value.entityData.tag());
|
||||
Types.VAR_INT.writePrimitive(buffer, value.ticksInHive);
|
||||
Types.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
|
||||
}
|
||||
@@ -51,12 +55,38 @@ public record Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) i
|
||||
@Override
|
||||
public void write(final Ops ops, final Bee value) {
|
||||
ops.writeMap(map -> map
|
||||
.writeOptional("entity_data", Types.COMPOUND_TAG, value.entityData, new CompoundTag())
|
||||
.writeOptional("entity_data", Types.COMPOUND_TAG, value.entityData.tag(), new CompoundTag())
|
||||
.write("ticks_in_hive", Types.INT, value.ticksInHive)
|
||||
.write("min_ticks_in_hive", Types.INT, value.minTicksInHive));
|
||||
}
|
||||
};
|
||||
public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
public static final Type<Bee[]> ARRAY_TYPE1_20_5 = new ArrayType<>(TYPE1_20_5);
|
||||
|
||||
public static final Type<Bee> TYPE1_21_9 = new Type<>(Bee.class) {
|
||||
@Override
|
||||
public Bee read(final ByteBuf buffer) {
|
||||
final EntityData entityData = EntityData.TYPE.read(buffer);
|
||||
final int ticksInHive = Types.VAR_INT.readPrimitive(buffer);
|
||||
final int minTicksInHive = Types.VAR_INT.readPrimitive(buffer);
|
||||
return new Bee(entityData, ticksInHive, minTicksInHive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Bee value) {
|
||||
EntityData.TYPE.write(buffer, value.entityData);
|
||||
Types.VAR_INT.writePrimitive(buffer, value.ticksInHive);
|
||||
Types.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final Bee value) {
|
||||
ops.writeMap(map -> map
|
||||
.write("entity_data", EntityData.TYPE, value.entityData)
|
||||
.write("ticks_in_hive", Types.INT, value.ticksInHive)
|
||||
.write("min_ticks_in_hive", Types.INT, value.minTicksInHive));
|
||||
}
|
||||
};
|
||||
public static final Type<Bee[]> ARRAY_TYPE1_21_9 = new ArrayType<>(TYPE1_21_9);
|
||||
|
||||
@Override
|
||||
public Bee copy() {
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public record BlockEntityData(int type, CompoundTag tag) implements Rewritable {
|
||||
|
||||
public static final Type<BlockEntityData> TYPE = new Type<>(BlockEntityData.class) {
|
||||
@Override
|
||||
public BlockEntityData read(final ByteBuf buffer) {
|
||||
final int type = Types.VAR_INT.readPrimitive(buffer);
|
||||
final CompoundTag tag = Types.COMPOUND_TAG.read(buffer);
|
||||
return new BlockEntityData(type, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BlockEntityData value) {
|
||||
Types.VAR_INT.writePrimitive(buffer, value.type);
|
||||
Types.COMPOUND_TAG.write(buffer, value.tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final BlockEntityData data) {
|
||||
ops.writeMap(map -> map
|
||||
.write("id", Types.RESOURCE_LOCATION, ops.context().registryAccess().blockEntity(data.type))
|
||||
.writeInlinedMap(Types.COMPOUND_TAG, data.tag)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public BlockEntityData rewrite(final UserConnection connection, final Protocol<?, ?, ?, ?> protocol, final boolean clientbound) {
|
||||
final int mappedType = protocol.getMappingData().getBlockEntityMappings().getNewId(type);
|
||||
// Empty mappings might be possible for removed block entities, set a dummy value in that case. Will be handled fine by server and client without losing data
|
||||
return new BlockEntityData(mappedType != -1 ? mappedType : 0, tag);
|
||||
}
|
||||
}
|
||||
+4
@@ -44,6 +44,10 @@ public final class ContainterContents {
|
||||
ops.writeList(list -> {
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
final Item item = value[i];
|
||||
if (item.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int slot = i;
|
||||
list.writeMap(map -> map
|
||||
.write("slot", Types.INT, slot)
|
||||
|
||||
+2
-12
@@ -23,24 +23,14 @@
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.type.TransformingType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public record DamageResistant(Key typesTagKey) {
|
||||
|
||||
public static final Type<DamageResistant> TYPE = new Type<>(DamageResistant.class) {
|
||||
@Override
|
||||
public DamageResistant read(final ByteBuf buffer) {
|
||||
final Key typesTagKey = Types.RESOURCE_LOCATION.read(buffer);
|
||||
return new DamageResistant(typesTagKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final DamageResistant value) {
|
||||
Types.RESOURCE_LOCATION.write(buffer, value.typesTagKey());
|
||||
}
|
||||
public static final Type<DamageResistant> TYPE = new TransformingType<>(Types.RESOURCE_LOCATION, DamageResistant.class, DamageResistant::new, DamageResistant::typesTagKey) {
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final DamageResistant value) {
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.TransformingType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Copyable;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
|
||||
public record DebugStickState(CompoundTag tag) implements Rewritable, Copyable {
|
||||
|
||||
public static final Type<DebugStickState> TYPE = TransformingType.of(Types.COMPOUND_TAG, DebugStickState.class, DebugStickState::new, DebugStickState::tag);
|
||||
|
||||
@Override
|
||||
public DebugStickState rewrite(final UserConnection connection, final Protocol<?, ?, ?, ?> protocol, final boolean clientbound) {
|
||||
CompoundTag updatedTag = tag;
|
||||
if (clientbound && protocol.getMappingData() != null && protocol.getMappingData().changedBlocks() != null) {
|
||||
updatedTag = tag.copy();
|
||||
// Anything beyond this isn't worth the disk space/handling
|
||||
updatedTag.entrySet().removeIf(entry -> {
|
||||
final int blockId = protocol.getMappingData().getFullBlockMappings().id(entry.getKey());
|
||||
return protocol.getMappingData().changedBlocks().contains(blockId);
|
||||
});
|
||||
}
|
||||
return new DebugStickState(updatedTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DebugStickState copy() {
|
||||
return new DebugStickState(tag.copy());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Copyable;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public record EntityData(int type, CompoundTag tag) implements Rewritable, Copyable {
|
||||
|
||||
public static final Type<EntityData> TYPE = new Type<>(EntityData.class) {
|
||||
@Override
|
||||
public EntityData read(final ByteBuf buffer) {
|
||||
final int type = Types.VAR_INT.readPrimitive(buffer);
|
||||
final CompoundTag tag = Types.COMPOUND_TAG.read(buffer);
|
||||
return new EntityData(type, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final EntityData value) {
|
||||
Types.VAR_INT.writePrimitive(buffer, value.type);
|
||||
Types.COMPOUND_TAG.write(buffer, value.tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final EntityData data) {
|
||||
ops.writeMap(map -> map
|
||||
.write("id", Types.RESOURCE_LOCATION, ops.context().registryAccess().entity(data.type))
|
||||
.writeInlinedMap(Types.COMPOUND_TAG, data.tag)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public EntityData rewrite(final UserConnection connection, final Protocol<?, ?, ?, ?> protocol, final boolean clientbound) {
|
||||
final int mappedType = protocol.getMappingData().getEntityMappings().getNewId(type);
|
||||
return new EntityData(mappedType, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData copy() {
|
||||
return new EntityData(type, tag.copy());
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ public final class EnumTypes {
|
||||
public static final EnumType HORSE_VARIANT = new EnumType(Fallback.WRAP, "white", "creamy", "chestnut", "brown", "black", "gray", "dark_brown");
|
||||
public static final EnumType LLAMA_VARIANT = new EnumType(Fallback.CLAMP, "creamy", "white", "brown", "gray");
|
||||
public static final EnumType AXOLOTL_VARIANT = new EnumType("lucy", "wild", "gold", "cyan", "blue");
|
||||
public static final EnumType EQUIPMENT_SLOT = new EnumType("mainhand", "feet", "legs", "chest", "head", "offhand", "body", "saddle");
|
||||
// Enums with non-ordinal ids
|
||||
public static final FakeEnumType RABBIT_VARIANT = new FakeEnumType(List.of("brown", "white", "black", "white_splotched", "gold", "salt"), of(99, "evil"));
|
||||
// Pretty much enums, but with a resource location
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -101,6 +105,21 @@ public record Equippable(int equipmentSlot, Holder<SoundEvent> soundEvent, @Null
|
||||
buffer.writeBoolean(value.damageOnHurt());
|
||||
buffer.writeBoolean(value.equipOnInteract());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final Equippable value) {
|
||||
final Holder<SoundEvent> defaultEquipSound = Holder.of(ops.context().registryAccess().id(MappingData.MappingType.SOUND, "item.armor.equip_generic"));
|
||||
ops.writeMap(map -> map
|
||||
.write("slot", EnumTypes.EQUIPMENT_SLOT, value.equipmentSlot)
|
||||
.writeOptional("equip_sound", Types.SOUND_EVENT, value.soundEvent, defaultEquipSound)
|
||||
.writeOptional("asset_id", Types.RESOURCE_LOCATION, value.model != null ? Key.of(value.model) : null)
|
||||
.writeOptional("camera_overlay", Types.RESOURCE_LOCATION, value.cameraOverlay != null ? Key.of(value.cameraOverlay) : null)
|
||||
.writeOptional("allowed_entities", new HolderSetType(MappingData.MappingType.ENTITY), value.allowedEntities)
|
||||
.writeOptional("dispensable", Types.BOOLEAN, value.dispensable, true)
|
||||
.writeOptional("swappable", Types.BOOLEAN, value.swappable, true)
|
||||
.writeOptional("damage_on_hurt", Types.BOOLEAN, value.damageOnHurt, true)
|
||||
.writeOptional("equip_on_interact", Types.BOOLEAN, value.equipOnInteract, false));
|
||||
}
|
||||
};
|
||||
public static final Type<Equippable> TYPE1_21_6 = new Type<>(Equippable.class) {
|
||||
@Override
|
||||
@@ -133,6 +152,24 @@ public record Equippable(int equipmentSlot, Holder<SoundEvent> soundEvent, @Null
|
||||
buffer.writeBoolean(value.canBeSheared());
|
||||
Types.SOUND_EVENT.write(buffer, value.shearingSound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final Equippable value) {
|
||||
final Holder<SoundEvent> defaultSound = Holder.of(ops.context().registryAccess().id(MappingData.MappingType.SOUND, "item.armor.equip_generic"));
|
||||
final Holder<SoundEvent> defaultShearingSound = Holder.of(ops.context().registryAccess().id(MappingData.MappingType.SOUND, "item.shears.snip"));
|
||||
ops.writeMap(map -> map
|
||||
.write("slot", EnumTypes.EQUIPMENT_SLOT, value.equipmentSlot)
|
||||
.writeOptional("equip_sound", Types.SOUND_EVENT, value.soundEvent, defaultSound)
|
||||
.writeOptional("asset_id", Types.RESOURCE_LOCATION, value.model != null ? Key.of(value.model) : null)
|
||||
.writeOptional("camera_overlay", Types.RESOURCE_LOCATION, value.cameraOverlay != null ? Key.of(value.cameraOverlay) : null)
|
||||
.writeOptional("allowed_entities", new HolderSetType(MappingData.MappingType.ENTITY), value.allowedEntities)
|
||||
.writeOptional("dispensable", Types.BOOLEAN, value.dispensable, true)
|
||||
.writeOptional("swappable", Types.BOOLEAN, value.swappable, true)
|
||||
.writeOptional("damage_on_hurt", Types.BOOLEAN, value.damageOnHurt, true)
|
||||
.writeOptional("equip_on_interact", Types.BOOLEAN, value.equipOnInteract, false)
|
||||
.writeOptional("can_be_sheared", Types.BOOLEAN, value.canBeSheared, false)
|
||||
.writeOptional("shearing_sound", Types.SOUND_EVENT, value.shearingSound, defaultShearingSound));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.TransformingType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
|
||||
public record ItemModel(Key key) implements Rewritable {
|
||||
|
||||
public static final Type<ItemModel> TYPE = TransformingType.of(Types.RESOURCE_LOCATION, ItemModel.class, ItemModel::new, ItemModel::key);
|
||||
|
||||
@Override
|
||||
public ItemModel rewrite(final UserConnection connection, final Protocol<?, ?, ?, ?> protocol, final boolean clientbound) {
|
||||
// This data specifically will often be used with Vanilla items, so the key should be rewritten
|
||||
final String type = key().toString();
|
||||
final String mappedType = Rewritable.rewriteItem(protocol, clientbound, type);
|
||||
return mappedType == null || type.equals(mappedType) ? this : new ItemModel(Key.of(mappedType));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
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.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.FullMappings;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.TransformingType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Copyable;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
|
||||
public record LockCode(CompoundTag tag) implements Rewritable, Copyable {
|
||||
|
||||
public static final Type<LockCode> TYPE = TransformingType.of(Types.COMPOUND_TAG, LockCode.class, LockCode::new, LockCode::tag);
|
||||
|
||||
@Override
|
||||
public LockCode rewrite(final UserConnection connection, final Protocol<?, ?, ?, ?> protocol, final boolean clientbound) {
|
||||
CompoundTag updatedTag = tag;
|
||||
if (clientbound && protocol.getComponentRewriter() != null) {
|
||||
// Just abuse the component rewriter and keep this one-way
|
||||
updatedTag = tag.copy();
|
||||
updatedTag.putString("id", "air");
|
||||
protocol.getComponentRewriter().handleShowItem(connection, updatedTag);
|
||||
updatedTag.remove("id");
|
||||
|
||||
final FullMappings mappings = protocol.getMappingData().getFullItemMappings();
|
||||
final Tag itemsTag = updatedTag.get("items");
|
||||
if (itemsTag != null) {
|
||||
final HolderSet items = HolderSet.fromTag(itemsTag, key -> mappings.id(key));
|
||||
items.rewrite(mappings::getNewId);
|
||||
updatedTag.put("items", toTag(items, mappings));
|
||||
}
|
||||
}
|
||||
return new LockCode(updatedTag);
|
||||
}
|
||||
|
||||
private Tag toTag(final HolderSet holderSet, final FullMappings mappings) {
|
||||
if (holderSet.hasTagKey()) {
|
||||
return new StringTag("#" + holderSet.tagKey());
|
||||
}
|
||||
|
||||
final int[] ids = holderSet.ids();
|
||||
if (ids.length == 1) {
|
||||
return new StringTag(mappings.mappedIdentifier(ids[0]));
|
||||
}
|
||||
|
||||
final ListTag<StringTag> listTag = new ListTag<>(StringTag.class);
|
||||
for (final int id : ids) {
|
||||
listTag.add(new StringTag(mappings.mappedIdentifier(id)));
|
||||
}
|
||||
return listTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockCode copy() {
|
||||
return new LockCode(tag.copy());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData.MappingType;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.TransformingType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
|
||||
import com.viaversion.viaversion.util.Rewritable;
|
||||
|
||||
public record Repairable(HolderSet items) implements Rewritable {
|
||||
|
||||
public static final Type<Repairable> TYPE = new TransformingType<>(Types.HOLDER_SET, Repairable.class, Repairable::new, Repairable::items) {
|
||||
@Override
|
||||
public void write(final Ops ops, final Repairable value) {
|
||||
ops.writeMap(map -> map.write("items", new HolderSetType(MappingType.ITEM), value.items));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Repairable rewrite(final UserConnection connection, final Protocol<?, ?, ?, ?> protocol, final boolean clientbound) {
|
||||
final HolderSet items = this.items.rewrite(Rewritable.itemRewriteFunction(protocol, clientbound));
|
||||
return this.items == items ? this : new Repairable(items);
|
||||
}
|
||||
}
|
||||
@@ -100,9 +100,9 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
Preconditions.checkArgument(!initialized, "Protocol has already been initialized");
|
||||
initialized = true;
|
||||
|
||||
// Create logger if protocol does not have one
|
||||
if (getLogger() == null) {
|
||||
logger = new ProtocolLogger(getClass());
|
||||
// Create logger if the protocol doesn't have one
|
||||
if (logger == null) {
|
||||
logger = createLogger();
|
||||
}
|
||||
registerPackets();
|
||||
registerConfigurationChangeHandlers();
|
||||
@@ -128,6 +128,10 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
}
|
||||
}
|
||||
|
||||
protected ProtocolLogger createLogger() {
|
||||
return new ProtocolLogger(getClass());
|
||||
}
|
||||
|
||||
protected void registerConfigurationChangeHandlers() {
|
||||
// Register handlers for protocol state switching
|
||||
// Assuming ids will change too often, it is cleaner to register them here instead of the base protocols,
|
||||
@@ -139,7 +143,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
|
||||
final CU startConfigurationPacket = startConfigurationPacket();
|
||||
if (startConfigurationPacket != null) {
|
||||
appendClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
|
||||
appendClientbound(startConfigurationPacket, startConfigurationHandler());
|
||||
}
|
||||
|
||||
final SU finishConfigurationPacket = serverboundFinishConfigurationPacket();
|
||||
@@ -476,6 +480,16 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
return wrapper -> wrapper.user().getProtocolInfo().setServerState(state);
|
||||
}
|
||||
|
||||
private PacketHandler startConfigurationHandler() {
|
||||
return setServerStateHandler(State.CONFIGURATION).then(wrapper -> {
|
||||
// Mimic client behaviour
|
||||
final EntityTracker tracker = wrapper.user().getEntityTracker(getClass());
|
||||
if (tracker != null) {
|
||||
tracker.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
|
||||
return packetTypesProvider;
|
||||
|
||||
@@ -24,11 +24,15 @@ package com.viaversion.viaversion.api.protocol;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ProtocolPipeline extends SimpleProtocol {
|
||||
public interface ProtocolPipeline {
|
||||
|
||||
/**
|
||||
* Adds a protocol to the current pipeline.
|
||||
@@ -67,6 +71,15 @@ public interface ProtocolPipeline extends SimpleProtocol {
|
||||
@Deprecated
|
||||
@Nullable <P extends Protocol> P getProtocol(Class<P> pipeClass);
|
||||
|
||||
/**
|
||||
* Transform a packet using the protocols in this pipeline.
|
||||
*
|
||||
* @param direction The direction the packet is going in
|
||||
* @param state The current protocol state
|
||||
* @param packetWrapper The packet wrapper to transform
|
||||
*/
|
||||
void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException;
|
||||
|
||||
List<Protocol> pipes(@Nullable Class<? extends Protocol> protocolClass, boolean skipCurrentPipeline, Direction direction);
|
||||
|
||||
/**
|
||||
|
||||
+163
-96
@@ -23,152 +23,219 @@
|
||||
package com.viaversion.viaversion.api.protocol.packet;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.configuration.RateLimitConfig;
|
||||
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PacketTracker {
|
||||
private final UserConnection connection;
|
||||
private static final long SECOND_NANOS = 1_000_000_000L;
|
||||
|
||||
private final RateTracker packetTracker = new RateTracker(5);
|
||||
private final RateTracker packetSizeTracker = new RateTracker(3);
|
||||
private long startTime = System.nanoTime();
|
||||
private boolean packetLimiterEnabled = true;
|
||||
private long sentPackets;
|
||||
private long receivedPackets;
|
||||
// Used for tracking pps
|
||||
private long startTime;
|
||||
private long intervalPackets;
|
||||
private long packetsPerSecond = -1L;
|
||||
// Used for handling warnings (over time)
|
||||
private int secondsObserved;
|
||||
private int warnings;
|
||||
private final UserConnection connection;
|
||||
private long sentPacketsTotal;
|
||||
private long receivedPacketsTotal;
|
||||
|
||||
public PacketTracker(UserConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for incrementing the number of packets sent to the client.
|
||||
* Increments the number of packets sent to the client.
|
||||
*/
|
||||
public void incrementSent() {
|
||||
this.sentPackets++;
|
||||
this.sentPacketsTotal++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for incrementing the number of packets received from the client.
|
||||
*
|
||||
* @return true if the interval has reset and can now be checked for the packets sent
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public boolean incrementReceived() {
|
||||
// handle stats
|
||||
long diff = System.currentTimeMillis() - startTime;
|
||||
if (diff >= 1000) {
|
||||
packetsPerSecond = intervalPackets;
|
||||
startTime = System.currentTimeMillis();
|
||||
intervalPackets = 1;
|
||||
return true;
|
||||
} else {
|
||||
intervalPackets++;
|
||||
}
|
||||
// increase total
|
||||
this.receivedPackets++;
|
||||
return false;
|
||||
return incrementReceived(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for packet flood with the packets sent in the last second.
|
||||
* ALWAYS check for {@link #incrementReceived()} before using this method.
|
||||
* Increments the number of packets received from the client.
|
||||
*
|
||||
* @return true if the packet should be cancelled
|
||||
* @see #incrementReceived()
|
||||
* @return true if the interval has reset
|
||||
*/
|
||||
public boolean exceedsMaxPPS() {
|
||||
if (connection.isClientSide()) return false; // Don't apply PPS limiting for client-side
|
||||
ViaVersionConfig conf = Via.getConfig();
|
||||
// Max PPS Checker
|
||||
if (conf.getMaxPPS() > 0 && packetsPerSecond >= conf.getMaxPPS()) {
|
||||
connection.disconnect(conf.getMaxPPSKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
|
||||
return true; // don't send current packet
|
||||
}
|
||||
public boolean incrementReceived(int packetSize) {
|
||||
receivedPacketsTotal++;
|
||||
|
||||
// Tracking PPS Checker
|
||||
if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) {
|
||||
if (secondsObserved > conf.getTrackingPeriod()) {
|
||||
// Reset
|
||||
warnings = 0;
|
||||
secondsObserved = 1;
|
||||
} else {
|
||||
secondsObserved++;
|
||||
if (packetsPerSecond >= conf.getWarningPPS()) {
|
||||
warnings++;
|
||||
}
|
||||
|
||||
if (warnings >= conf.getMaxWarnings()) {
|
||||
connection.disconnect(conf.getMaxWarningsKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
|
||||
return true; // don't send current packet
|
||||
}
|
||||
ViaVersionConfig config = Via.getConfig();
|
||||
long currentTime = System.nanoTime();
|
||||
long elapsed = currentTime - startTime;
|
||||
if (elapsed < SECOND_NANOS) {
|
||||
// Add to current interval
|
||||
if (config.getPacketTrackerConfig().enabled()) {
|
||||
packetTracker.addIntervalValue(1);
|
||||
}
|
||||
if (config.getPacketSizeTrackerConfig().enabled()) {
|
||||
packetSizeTracker.addIntervalValue(packetSize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
// Reset interval tracking
|
||||
if (config.getPacketTrackerConfig().enabled()) {
|
||||
packetTracker.updateRate(elapsed);
|
||||
packetTracker.addIntervalValue(1);
|
||||
}
|
||||
if (config.getPacketSizeTrackerConfig().enabled()) {
|
||||
packetSizeTracker.updateRate(elapsed);
|
||||
packetSizeTracker.addIntervalValue(packetSize);
|
||||
}
|
||||
startTime = currentTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean exceedsLimits() {
|
||||
if (connection.isClientSide()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ViaVersionConfig config = Via.getConfig();
|
||||
return packetTracker.exceedsLimit(connection, config.getPacketTrackerConfig())
|
||||
|| packetSizeTracker.exceedsLimit(connection, config.getPacketSizeTrackerConfig());
|
||||
}
|
||||
|
||||
public long getSentPackets() {
|
||||
return sentPackets;
|
||||
return sentPacketsTotal;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void setSentPackets(long sentPackets) {
|
||||
this.sentPackets = sentPackets;
|
||||
this.sentPacketsTotal = sentPackets;
|
||||
}
|
||||
|
||||
public long getReceivedPackets() {
|
||||
return receivedPackets;
|
||||
return receivedPacketsTotal;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void setReceivedPackets(long receivedPackets) {
|
||||
this.receivedPackets = receivedPackets;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
this.receivedPacketsTotal = receivedPackets;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public long getIntervalPackets() {
|
||||
return intervalPackets;
|
||||
return this.packetTracker.intervalValue;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void setIntervalPackets(long intervalPackets) {
|
||||
this.intervalPackets = intervalPackets;
|
||||
this.packetTracker.intervalValue = Math.toIntExact(intervalPackets);
|
||||
}
|
||||
|
||||
public long getPacketsPerSecond() {
|
||||
return packetsPerSecond;
|
||||
}
|
||||
|
||||
public void setPacketsPerSecond(long packetsPerSecond) {
|
||||
this.packetsPerSecond = packetsPerSecond;
|
||||
}
|
||||
|
||||
public int getSecondsObserved() {
|
||||
return secondsObserved;
|
||||
}
|
||||
|
||||
public void setSecondsObserved(int secondsObserved) {
|
||||
this.secondsObserved = secondsObserved;
|
||||
}
|
||||
|
||||
public int getWarnings() {
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public void setWarnings(int warnings) {
|
||||
this.warnings = warnings;
|
||||
public int getPacketsPerSecond() {
|
||||
return packetTracker.currentRate;
|
||||
}
|
||||
|
||||
public boolean isPacketLimiterEnabled() {
|
||||
return packetLimiterEnabled;
|
||||
ViaVersionConfig config = Via.getConfig();
|
||||
return packetLimiterEnabled && config.getPacketTrackerConfig().enabled() && config.getPacketSizeTrackerConfig().enabled();
|
||||
}
|
||||
|
||||
public void setPacketLimiterEnabled(boolean packetLimiterEnabled) {
|
||||
this.packetLimiterEnabled = packetLimiterEnabled;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void setWarnings(int warnings) {
|
||||
this.packetTracker.warnings = warnings;
|
||||
}
|
||||
|
||||
private static final class RateTracker {
|
||||
private final int[] history;
|
||||
private int historyIndex;
|
||||
private int historyCount;
|
||||
private int currentRate = -1;
|
||||
|
||||
// Interval tracking
|
||||
int intervalValue;
|
||||
|
||||
// Warning system
|
||||
private long warningPeriodStart = System.nanoTime();
|
||||
private int warnings;
|
||||
|
||||
public RateTracker(int windowSize) {
|
||||
this.history = new int[windowSize];
|
||||
}
|
||||
|
||||
public void addIntervalValue(int value) {
|
||||
intervalValue += value;
|
||||
}
|
||||
|
||||
public void updateRate(long elapsedNanos) {
|
||||
// Update sliding window
|
||||
history[historyIndex] = (int) ((intervalValue * SECOND_NANOS) / elapsedNanos);
|
||||
historyIndex = (historyIndex + 1) % history.length;
|
||||
if (historyCount < history.length) {
|
||||
historyCount++;
|
||||
}
|
||||
|
||||
// Calculate smoothed average
|
||||
int sum = 0;
|
||||
for (int i = 0; i < historyCount; i++) {
|
||||
sum += history[i];
|
||||
}
|
||||
|
||||
currentRate = sum / historyCount;
|
||||
intervalValue = 0; // Reset
|
||||
}
|
||||
|
||||
public boolean exceedsLimit(UserConnection connection, RateLimitConfig limitConfig) {
|
||||
if (!limitConfig.enabled() || currentRate < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Immediate limit check
|
||||
if (limitConfig.maxRate() > 0 && currentRate >= limitConfig.maxRate()) {
|
||||
connection.disconnect(limitConfig.maxRateKickMessage().replace(limitConfig.ratePlaceholder(), Integer.toString(currentRate)));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Interval warnings
|
||||
if (limitConfig.maxWarnings() > 0 && limitConfig.trackingPeriodNanos() > 0 && limitConfig.warningRate() > 0) {
|
||||
return checkTrackedInterval(connection, limitConfig);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkTrackedInterval(UserConnection connection, RateLimitConfig config) {
|
||||
long currentTime = System.nanoTime();
|
||||
if (currentTime - warningPeriodStart >= config.trackingPeriodNanos()) {
|
||||
// Reset
|
||||
warnings = 0;
|
||||
warningPeriodStart = currentTime;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentRate >= config.warningRate() && ++warnings >= config.maxWarnings()) {
|
||||
connection.disconnect(config.warningKickMessage().replace(config.ratePlaceholder(), Integer.toString(currentRate)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
intervalValue = 0;
|
||||
currentRate = -1;
|
||||
warnings = 0;
|
||||
warningPeriodStart = System.nanoTime();
|
||||
historyIndex = 0;
|
||||
historyCount = 0;
|
||||
Arrays.fill(history, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
sentPacketsTotal = 0;
|
||||
receivedPacketsTotal = 0;
|
||||
startTime = System.nanoTime();
|
||||
packetTracker.reset();
|
||||
packetSizeTracker.reset();
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
public static final ProtocolVersion v1_21_5 = register(770, "1.21.5");
|
||||
public static final ProtocolVersion v1_21_6 = register(771, "1.21.6");
|
||||
public static final ProtocolVersion v1_21_7 = register(772, "1.21.7-1.21.8", new SubVersionRange("1.21", 7, 8));
|
||||
public static final ProtocolVersion v1_21_9 = register(773, "1.21.9-1.21.10", new SubVersionRange("1.21", 9, 10));
|
||||
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
|
||||
|
||||
static {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.rewriter;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -34,4 +35,6 @@ public interface ComponentRewriter {
|
||||
void processText(UserConnection connection, @Nullable JsonElement element);
|
||||
|
||||
JsonElement processText(UserConnection connection, @Nullable String json);
|
||||
|
||||
void handleShowItem(UserConnection connection, CompoundTag itemTag);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class TransformingType<F, T> extends Type<T> {
|
||||
private final Type<F> from;
|
||||
private final Function<F, T> mapFunction;
|
||||
private final Function<T, F> reverseFunction;
|
||||
|
||||
protected TransformingType(
|
||||
final Type<F> from, final Class<T> outputClass,
|
||||
final Function<F, T> mapFunction, final Function<T, F> reverseFunction
|
||||
) {
|
||||
super(from.getTypeName(), outputClass);
|
||||
this.from = from;
|
||||
this.mapFunction = mapFunction;
|
||||
this.reverseFunction = reverseFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a type that transforms the input to a separate output type.
|
||||
* Useful if you have wrapper classes of a single object.
|
||||
*
|
||||
* @param from type to map from
|
||||
* @param outputClass output class
|
||||
* @param mapFunction function to map from F to T
|
||||
* @param reverseFunction function to map from T to F
|
||||
* @param <F> from type
|
||||
* @param <T> to type
|
||||
* @return transforming type
|
||||
*/
|
||||
public static <F, T> Type<T> of(
|
||||
final Type<F> from, final Class<T> outputClass,
|
||||
final Function<F, T> mapFunction, final Function<T, F> reverseFunction
|
||||
) {
|
||||
return new TransformingType<>(from, outputClass, mapFunction, reverseFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(final ByteBuf buffer) {
|
||||
return mapFunction.apply(from.read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final T value) {
|
||||
from.write(buffer, reverseFunction.apply(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final T value) {
|
||||
from.write(ops, reverseFunction.apply(value));
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,10 @@ import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.Quaternion;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||
import com.viaversion.viaversion.api.minecraft.ResolvableProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3d;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3f;
|
||||
import com.viaversion.viaversion.api.minecraft.VillagerData;
|
||||
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
||||
@@ -70,6 +72,7 @@ import com.viaversion.viaversion.api.type.types.ShortType;
|
||||
import com.viaversion.viaversion.api.type.types.StringType;
|
||||
import com.viaversion.viaversion.api.type.types.UUIDType;
|
||||
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
|
||||
import com.viaversion.viaversion.api.type.types.UnsignedIntType;
|
||||
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
|
||||
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.VarIntType;
|
||||
@@ -100,6 +103,7 @@ import com.viaversion.viaversion.api.type.types.math.BlockPositionType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.math.ChunkPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.math.EulerAngleType;
|
||||
import com.viaversion.viaversion.api.type.types.math.GlobalBlockPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.math.MovementVectorType;
|
||||
import com.viaversion.viaversion.api.type.types.math.QuaternionType;
|
||||
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
|
||||
import com.viaversion.viaversion.api.type.types.math.VectorType;
|
||||
@@ -114,6 +118,7 @@ import com.viaversion.viaversion.api.type.types.misc.PlayerMessageSignatureType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ProfileKeyType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ProfilePropertyType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.SoundEventType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ResolvableProfileType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.TagKeyType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.TagType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.TextComponentTagType;
|
||||
@@ -144,6 +149,7 @@ public final class Types {
|
||||
|
||||
public static final IntType INT = new IntType();
|
||||
public static final Type<int[]> INT_ARRAY_PRIMITIVE = new IntArrayType();
|
||||
public static final UnsignedIntType UNSIGNED_INT = new UnsignedIntType();
|
||||
|
||||
public static final FloatType FLOAT = new FloatType();
|
||||
public static final FloatType.OptionalFloatType OPTIONAL_FLOAT = new FloatType.OptionalFloatType();
|
||||
@@ -192,6 +198,7 @@ public final class Types {
|
||||
public static final Type<Vector> VECTOR = new VectorType();
|
||||
public static final Type<Vector3f> VECTOR3F = new Vector3fType();
|
||||
public static final Type<Quaternion> QUATERNION = new QuaternionType();
|
||||
public static final Type<Vector3d> MOVEMENT_VECTOR = new MovementVectorType();
|
||||
|
||||
public static final Type<CompoundTag> NAMED_COMPOUND_TAG = new NamedCompoundTagType();
|
||||
public static final Type<CompoundTag> OPTIONAL_NAMED_COMPOUND_TAG = new NamedCompoundTagType.OptionalNamedCompoundTagType();
|
||||
@@ -224,6 +231,7 @@ public final class Types {
|
||||
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
||||
|
||||
public static final Type<GameProfile> GAME_PROFILE = new GameProfileType();
|
||||
public static final Type<ResolvableProfile> RESOLVABLE_PROFILE = new ResolvableProfileType();
|
||||
public static final Type<GameProfile.Property> PROFILE_PROPERTY = new ProfilePropertyType();
|
||||
public static final Type<GameProfile.Property[]> PROFILE_PROPERTY_ARRAY = new ArrayType<>(PROFILE_PROPERTY);
|
||||
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.TypeConverter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class UnsignedIntType extends Type<Long> implements TypeConverter<Long> {
|
||||
public static final long MAX_UNSIGNED_INT = 0xFFFFFFFFL;
|
||||
|
||||
public UnsignedIntType() {
|
||||
super(Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long read(ByteBuf buffer) {
|
||||
return buffer.readUnsignedInt();
|
||||
}
|
||||
|
||||
public long readPrimitive(ByteBuf buffer) {
|
||||
return buffer.readUnsignedInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Long l) {
|
||||
buffer.writeInt(l.intValue());
|
||||
}
|
||||
|
||||
public void writePrimitive(ByteBuf buffer, long l) {
|
||||
buffer.writeInt((int) l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long from(Object o) {
|
||||
if (o instanceof Number number) {
|
||||
return number.longValue();
|
||||
} else if (o instanceof Boolean boo) {
|
||||
return boo ? 1L : 0L;
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.math;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3d;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.UnsignedIntType;
|
||||
import com.viaversion.viaversion.util.MathUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class MovementVectorType extends Type<Vector3d> {
|
||||
// Using 15 bits, steal short constants for it
|
||||
private static final double MAX_QUANTIZED_VALUE = Short.MAX_VALUE - 1;
|
||||
private static final int SCALE_BITS = 2; // first 2 bits for the scale
|
||||
private static final int SCALE_BITS_MASK = 3;
|
||||
private static final int CONTINUATION_FLAG = 1 << 2; // 3rd bit to indicate more scale data
|
||||
private static final double ABS_MAX_VALUE = (1L << Integer.SIZE + SCALE_BITS) - 1; // Unsigned int + the first two scale bits
|
||||
private static final double ABS_MIN_VALUE = 1 / MAX_QUANTIZED_VALUE;
|
||||
|
||||
public MovementVectorType() {
|
||||
super(Vector3d.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3d read(final ByteBuf buffer) {
|
||||
// Pack values back into a single long
|
||||
final int first = Types.UNSIGNED_BYTE.read(buffer);
|
||||
if (first == 0) {
|
||||
return Vector3d.ZERO;
|
||||
}
|
||||
|
||||
final int second = Types.UNSIGNED_BYTE.read(buffer);
|
||||
final long remaining = Types.UNSIGNED_INT.read(buffer);
|
||||
final long packed = remaining << 16 | second << 8 | first;
|
||||
|
||||
long scale = first & SCALE_BITS_MASK;
|
||||
if ((first & CONTINUATION_FLAG) != 0) {
|
||||
// Read the remaining bits and add them to the first two
|
||||
scale |= (Types.VAR_INT.readPrimitive(buffer) & UnsignedIntType.MAX_UNSIGNED_INT) << SCALE_BITS;
|
||||
}
|
||||
|
||||
// 15 bits for each part after removing the scale bits
|
||||
return new Vector3d(
|
||||
unpack(packed >> (0 + SCALE_BITS_MASK)) * scale,
|
||||
unpack(packed >> (15 + SCALE_BITS_MASK)) * scale,
|
||||
unpack(packed >> (30 + SCALE_BITS_MASK)) * scale
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Vector3d vec) {
|
||||
final double x = sanitize(vec.x());
|
||||
final double y = sanitize(vec.y());
|
||||
final double z = sanitize(vec.z());
|
||||
|
||||
final double maxPart = Math.max(Math.abs(x), Math.max(Math.abs(y), Math.abs(z)));
|
||||
if (maxPart < ABS_MIN_VALUE) {
|
||||
buffer.writeByte(0);
|
||||
return;
|
||||
}
|
||||
|
||||
final long scale = MathUtil.ceilLong(maxPart);
|
||||
final boolean scaleTooLargeForBits = (scale & SCALE_BITS_MASK) != scale;
|
||||
final long scaleBits = scaleTooLargeForBits ? (scale & SCALE_BITS_MASK) | CONTINUATION_FLAG : scale;
|
||||
final long packed = scaleBits
|
||||
| (pack(x / scale) << (0 + SCALE_BITS_MASK))
|
||||
| (pack(y / scale) << (15 + SCALE_BITS_MASK))
|
||||
| (pack(z / scale) << (30 + SCALE_BITS_MASK));
|
||||
|
||||
buffer.writeByte((byte) packed);
|
||||
buffer.writeByte((byte) (packed >> 8));
|
||||
buffer.writeInt((int) (packed >> 16));
|
||||
|
||||
if (scaleTooLargeForBits) {
|
||||
// First two bits have already been written
|
||||
Types.VAR_INT.writePrimitive(buffer, (int) (scale >> SCALE_BITS));
|
||||
}
|
||||
}
|
||||
|
||||
private double sanitize(final double value) {
|
||||
return Double.isNaN(value) ? 0 : MathUtil.clamp(value, -ABS_MAX_VALUE, ABS_MAX_VALUE);
|
||||
}
|
||||
|
||||
private long pack(final double value) {
|
||||
// Shift to [0, 1] and quantize to 15 bits
|
||||
final double shifted = (value * 0.5) + 0.5;
|
||||
return Math.round(shifted * MAX_QUANTIZED_VALUE);
|
||||
}
|
||||
|
||||
private double unpack(final long value) {
|
||||
// Normalize to [-1, 1]
|
||||
final double clamped = Math.min(value & Short.MAX_VALUE, MAX_QUANTIZED_VALUE);
|
||||
return (clamped * 2) / MAX_QUANTIZED_VALUE - 1;
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,27 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.misc;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class HolderSetType extends Type<HolderSet> {
|
||||
|
||||
private final MappingDataBase.MappingType mappingType;
|
||||
|
||||
public HolderSetType() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public HolderSetType(final MappingDataBase.MappingType mappingType) {
|
||||
super(HolderSet.class);
|
||||
this.mappingType = mappingType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,6 +74,28 @@ public class HolderSetType extends Type<HolderSet> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final HolderSet value) {
|
||||
if (value.hasTagKey()) {
|
||||
ops.write(Types.TAG_KEY, Key.of(value.tagKey()));
|
||||
} else {
|
||||
Preconditions.checkArgument(mappingType != null, "Cannot write HolderSet with direct ids without a mapping type");
|
||||
if (value.ids().length == 1) {
|
||||
// Single entries are inlined
|
||||
final Key key = ops.context().registryAccess().key(mappingType, value.ids()[0]);
|
||||
ops.write(Types.RESOURCE_LOCATION, key);
|
||||
return;
|
||||
}
|
||||
|
||||
ops.writeList(list -> {
|
||||
for (final int id : value.ids()) {
|
||||
final Key key = ops.context().registryAccess().key(mappingType, id);
|
||||
list.write(Types.RESOURCE_LOCATION, key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static final class OptionalHolderSetType extends OptionalType<HolderSet> {
|
||||
|
||||
public OptionalHolderSetType() {
|
||||
|
||||
@@ -22,16 +22,27 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.misc;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class HolderType<T> extends Type<Holder<T>> {
|
||||
|
||||
private final MappingData.MappingType mappingType;
|
||||
|
||||
protected HolderType() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
protected HolderType(final MappingData.MappingType mappingType) {
|
||||
super(Holder.class);
|
||||
this.mappingType = mappingType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +68,24 @@ public abstract class HolderType<T> extends Type<Holder<T>> {
|
||||
|
||||
public abstract void writeDirect(final ByteBuf buffer, final T object);
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final Holder<T> value) {
|
||||
if (value.hasId()) {
|
||||
ops.write(Types.RESOURCE_LOCATION, identifier(ops, value.id()));
|
||||
} else {
|
||||
writeDirect(ops, value.value());
|
||||
}
|
||||
}
|
||||
|
||||
protected Key identifier(final Ops ops, final int id) {
|
||||
Preconditions.checkArgument(mappingType != null, "Mapping type is not defined for this HolderType");
|
||||
return ops.context().registryAccess().key(mappingType, id);
|
||||
}
|
||||
|
||||
public void writeDirect(final Ops ops, final T object) {
|
||||
throw new UnsupportedOperationException("Write operation not supported for type: " + getTypeName());
|
||||
}
|
||||
|
||||
public abstract static class OptionalHolderType<T> extends HolderType<T> {
|
||||
private final HolderType<T> type;
|
||||
|
||||
|
||||
@@ -160,6 +160,13 @@ public class ParticleType extends DynamicType<Particle> {
|
||||
particle.add(Types.INT, Types.INT.readPrimitive(buf)); // Color
|
||||
particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Duration
|
||||
};
|
||||
public static final DataReader<Particle> POWER = (buf, particle) -> {
|
||||
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf));
|
||||
};
|
||||
public static final DataReader<Particle> SPELL = (buf, particle) -> {
|
||||
particle.add(Types.INT, Types.INT.readPrimitive(buf)); // Color
|
||||
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Power
|
||||
};
|
||||
|
||||
public static DataReader<Particle> item(Type<Item> item) {
|
||||
return (buf, particle) -> particle.add(item, item.read(buf));
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.misc;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.ResolvableProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ResolvableProfileType extends Type<ResolvableProfile> {
|
||||
|
||||
public ResolvableProfileType() {
|
||||
super(ResolvableProfile.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolvableProfile read(final ByteBuf buffer) {
|
||||
final GameProfile profile;
|
||||
if (buffer.readBoolean()) {
|
||||
final UUID id = Types.UUID.read(buffer);
|
||||
final String name = Types.STRING.read(buffer);
|
||||
final GameProfile.Property[] properties = Types.PROFILE_PROPERTY_ARRAY.read(buffer);
|
||||
profile = new GameProfile(name, id, properties, false);
|
||||
} else {
|
||||
profile = Types.GAME_PROFILE.read(buffer);
|
||||
}
|
||||
|
||||
final String texture = Types.OPTIONAL_STRING.read(buffer);
|
||||
final String capeTexture = Types.OPTIONAL_STRING.read(buffer);
|
||||
final String elytraTexture = Types.OPTIONAL_STRING.read(buffer);
|
||||
final Boolean encodedModelType = Types.OPTIONAL_BOOLEAN.read(buffer); // ...
|
||||
final Integer modelType = encodedModelType != null ? (encodedModelType ? 0 : 1) : null;
|
||||
return new ResolvableProfile(profile, texture, capeTexture, elytraTexture, modelType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ResolvableProfile value) {
|
||||
final GameProfile profile = value.profile();
|
||||
if (!profile.dynamic()) {
|
||||
buffer.writeBoolean(true);
|
||||
Types.UUID.write(buffer, profile.id());
|
||||
Types.STRING.write(buffer, profile.name());
|
||||
Types.PROFILE_PROPERTY_ARRAY.write(buffer, profile.properties());
|
||||
} else {
|
||||
buffer.writeBoolean(false);
|
||||
Types.GAME_PROFILE.write(buffer, profile);
|
||||
}
|
||||
|
||||
Types.OPTIONAL_STRING.write(buffer, value.bodyTexture());
|
||||
Types.OPTIONAL_STRING.write(buffer, value.capeTexture());
|
||||
Types.OPTIONAL_STRING.write(buffer, value.elytraTexture());
|
||||
Types.OPTIONAL_BOOLEAN.write(buffer, value.modelType() != null ? value.modelType() == 0 : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final Ops ops, final ResolvableProfile value) {
|
||||
final String modelType = value.modelType() != null ? (value.modelType() == 0 ? "slim" : "wide") : null;
|
||||
ops.writeMap(map -> map
|
||||
.writeInlinedMap(Types.GAME_PROFILE, value.profile())
|
||||
.writeOptional("texture", Types.RESOURCE_LOCATION, value.bodyTexture() != null ? Key.of(value.bodyTexture()) : null)
|
||||
.writeOptional("cape", Types.RESOURCE_LOCATION, value.capeTexture() != null ? Key.of(value.capeTexture()) : null)
|
||||
.writeOptional("elytra", Types.RESOURCE_LOCATION, value.elytraTexture() != null ? Key.of(value.elytraTexture()) : null)
|
||||
.writeOptional("model", Types.OPTIONAL_STRING, modelType)
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -22,12 +22,19 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.misc;
|
||||
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.minecraft.codec.Ops;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class SoundEventType extends HolderType<SoundEvent> {
|
||||
|
||||
public SoundEventType() {
|
||||
super(MappingData.MappingType.SOUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent readDirect(final ByteBuf buffer) {
|
||||
final String resourceLocation = Types.STRING.read(buffer);
|
||||
@@ -41,6 +48,13 @@ public final class SoundEventType extends HolderType<SoundEvent> {
|
||||
Types.OPTIONAL_FLOAT.write(buffer, value.fixedRange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final Ops ops, final SoundEvent object) {
|
||||
ops.writeMap(map -> map
|
||||
.write("sound_id", Types.RESOURCE_LOCATION, Key.of(object.identifier()))
|
||||
.writeOptional("range", Types.FLOAT, object.fixedRange()));
|
||||
}
|
||||
|
||||
public static final class OptionalSoundEventType extends OptionalHolderType<SoundEvent> {
|
||||
|
||||
public OptionalSoundEventType() {
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_2;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_5;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_9;
|
||||
|
||||
/**
|
||||
* Holds versioned accessors for highly volatile types, specifically around items and data components.
|
||||
@@ -44,4 +45,5 @@ public final class VersionedTypes {
|
||||
public static final Types1_20_5<StructuredDataKeys1_21_2, EntityDataTypes1_21_2> V1_21_4 = new Types1_20_5<>(StructuredDataKeys1_21_2::new, EntityDataTypes1_21_2::new);
|
||||
public static final Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_5> V1_21_5 = new Types1_20_5<>(StructuredDataKeys1_21_5::new, EntityDataTypes1_21_5::new);
|
||||
public static final Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_5> V1_21_6 = new Types1_20_5<>(StructuredDataKeys1_21_5::new, EntityDataTypes1_21_5::new);
|
||||
public static final Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_9> V1_21_9 = new Types1_20_5<>(StructuredDataKeys1_21_5::new, EntityDataTypes1_21_9::new);
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@@ -76,4 +77,21 @@ public final class ArrayUtil {
|
||||
}
|
||||
return boxedArray;
|
||||
}
|
||||
|
||||
public static String toString(final Object o) {
|
||||
if (o == null || !o.getClass().isArray()) {
|
||||
return String.valueOf(o);
|
||||
}
|
||||
|
||||
final int length = Array.getLength(o);
|
||||
final StringBuilder builder = new StringBuilder("[");
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (i > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(Array.get(o, i));
|
||||
}
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public final class Key {
|
||||
}
|
||||
|
||||
public static boolean equals(final String firstIdentifier, final String secondIdentifier) {
|
||||
return of(firstIdentifier).equals(of(secondIdentifier));
|
||||
return firstIdentifier != null && secondIdentifier != null && of(firstIdentifier).equals(of(secondIdentifier));
|
||||
}
|
||||
|
||||
public static String namespaced(final String identifier) {
|
||||
|
||||
@@ -24,6 +24,11 @@ package com.viaversion.viaversion.util;
|
||||
|
||||
public final class MathUtil {
|
||||
|
||||
/**
|
||||
* Miniscule value below which positive floats are considered zero
|
||||
*/
|
||||
public static final float EPSILON = 1.0E-5F;
|
||||
|
||||
/**
|
||||
* Returns the ceiled integer value of the given float.
|
||||
*
|
||||
@@ -45,6 +50,11 @@ public final class MathUtil {
|
||||
return i > 0 ? 32 - Integer.numberOfLeadingZeros(i - 1) : 0;
|
||||
}
|
||||
|
||||
public static long ceilLong(final double d) {
|
||||
final long l = (long) d;
|
||||
return d > l ? l + 1 : l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the clamped number within the given range.
|
||||
*
|
||||
@@ -59,4 +69,11 @@ public final class MathUtil {
|
||||
}
|
||||
return i > max ? max : i;
|
||||
}
|
||||
|
||||
public static double clamp(final double d, final double min, final double max) {
|
||||
if (d < min) {
|
||||
return min;
|
||||
}
|
||||
return d > max ? max : d;
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
// version must be manually kept in sync with the one in root project settings.gradle.kts
|
||||
implementation("com.gradleup.shadow", "shadow-gradle-plugin", "8.3.8")
|
||||
implementation("com.gradleup.shadow:shadow-gradle-plugin:9.1.0")
|
||||
|
||||
// A nice no-conflict comment for patching in downgrading
|
||||
}
|
||||
@@ -9,7 +9,7 @@ tasks {
|
||||
val ver = project.version.toString()
|
||||
val desc = project.description
|
||||
filesMatching(listOf("plugin.yml", "META-INF/sponge_plugins.json", "fabric.mod.json")) {
|
||||
expand("version" to ver, "description" to desc)
|
||||
expand(mapOf("version" to ver, "description" to desc))
|
||||
}
|
||||
}
|
||||
javadoc {
|
||||
@@ -19,6 +19,7 @@ tasks {
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation"))
|
||||
options.isFork = true
|
||||
}
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
|
||||
@@ -13,6 +13,7 @@ tasks {
|
||||
from(project.rootProject.file("LICENSE"))
|
||||
}
|
||||
val shadowJar = named<ShadowJar>("shadowJar") {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
archiveClassifier.set("")
|
||||
configureRelocations()
|
||||
configureExcludes()
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
private static ViaVersionPlugin instance;
|
||||
private final BukkitCommandHandler commandHandler = new BukkitCommandHandler();
|
||||
private final BukkitViaConfig conf;
|
||||
private final ViaAPI<Player> api = new BukkitViaAPI(this);
|
||||
private final ViaAPI<Player> api = new BukkitViaAPI();
|
||||
private boolean lateBind;
|
||||
|
||||
public ViaVersionPlugin() {
|
||||
|
||||
-5
@@ -18,7 +18,6 @@
|
||||
package com.viaversion.viaversion.bukkit.handlers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.bukkit.platform.PaperViaInjector;
|
||||
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||
import com.viaversion.viaversion.platform.WrappedChannelInitializer;
|
||||
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
||||
@@ -74,10 +73,6 @@ public final class BukkitChannelInitializer extends ChannelInitializer<Channel>
|
||||
final UserConnection connection = new UserConnectionImpl(channel);
|
||||
new ProtocolPipelineImpl(connection);
|
||||
|
||||
if (PaperViaInjector.PAPER_PACKET_LIMITER) {
|
||||
connection.getPacketTracker().setPacketLimiterEnabled(false);
|
||||
}
|
||||
|
||||
// Add our transformers
|
||||
final ChannelPipeline pipeline = channel.pipeline();
|
||||
final String encoderName = pipeline.get(MINECRAFT_OUTBOUND_CONFIG) != null ? MINECRAFT_OUTBOUND_CONFIG : MINECRAFT_ENCODER;
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public final class BukkitDecodeHandler extends MessageToMessageDecoder<ByteBuf>
|
||||
|
||||
@Override
|
||||
protected void decode(final ChannelHandlerContext ctx, final ByteBuf bytebuf, final List<Object> out) {
|
||||
if (!connection.checkServerboundPacket()) {
|
||||
if (!connection.checkServerboundPacket(bytebuf.readableBytes())) {
|
||||
throw CancelDecoderException.generate(null);
|
||||
}
|
||||
if (!connection.shouldTransformPacket()) {
|
||||
|
||||
@@ -18,35 +18,17 @@
|
||||
package com.viaversion.viaversion.bukkit.platform;
|
||||
|
||||
import com.viaversion.viaversion.ViaAPIBase;
|
||||
import com.viaversion.viaversion.ViaVersionPlugin;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BukkitViaAPI extends ViaAPIBase<Player> {
|
||||
private final ViaVersionPlugin plugin;
|
||||
|
||||
public BukkitViaAPI(ViaVersionPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolVersion getPlayerProtocolVersion(Player player) {
|
||||
return getPlayerProtocolVersion(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolVersion getPlayerProtocolVersion(UUID uuid) {
|
||||
UserConnection connection = Via.getManager().getConnectionManager().getServerConnection(uuid);
|
||||
if (connection != null) {
|
||||
return connection.getProtocolInfo().protocolVersion();
|
||||
}
|
||||
return ProtocolVersion.unknown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
|
||||
sendRawPacket(player.getUniqueId(), packet);
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.bukkit.Bukkit;
|
||||
public final class PaperViaInjector {
|
||||
public static final boolean PAPER_INJECTION_METHOD = hasPaperInjectionMethod();
|
||||
public static final boolean PAPER_PROTOCOL_METHOD = hasServerProtocolMethod();
|
||||
public static final boolean PAPER_PACKET_LIMITER = hasPacketLimiter();
|
||||
public static final boolean PAPER_IS_STOPPING_METHOD = hasIsStoppingMethod();
|
||||
|
||||
private PaperViaInjector() {
|
||||
@@ -76,10 +75,6 @@ public final class PaperViaInjector {
|
||||
return hasMethod(Bukkit.class, "isStopping");
|
||||
}
|
||||
|
||||
private static boolean hasPacketLimiter() {
|
||||
return hasClass("com.destroystokyo.paper.PaperConfig$PacketLimit") || hasClass("io.papermc.paper.configuration.GlobalConfiguration$PacketLimiter");
|
||||
}
|
||||
|
||||
public static boolean hasClass(final String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
|
||||
+13
-4
@@ -114,14 +114,23 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
|
||||
}
|
||||
} else {
|
||||
ChannelHandlerContext context = PipelineUtil.getContextBefore("decoder", info.getChannel().pipeline());
|
||||
if (context != null) {
|
||||
if (info.get(MovementTracker.class).isGround()) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
info.getChannel().eventLoop().execute(() -> {
|
||||
MovementTracker movementTracker = info.get(MovementTracker.class);
|
||||
if (movementTracker == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (movementTracker.isGround()) {
|
||||
context.fireChannelRead(getGroundPacket());
|
||||
} else {
|
||||
context.fireChannelRead(getFlyingPacket());
|
||||
}
|
||||
info.get(MovementTracker.class).incrementIdlePacket();
|
||||
}
|
||||
movementTracker.incrementIdlePacket();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ tasks.named<Jar>("sourcesJar") {
|
||||
val prepareViaProxyFiles by tasks.registering(Copy::class) {
|
||||
dependsOn(project.tasks.shadowJar)
|
||||
|
||||
from(project.tasks.shadowJar.get().archiveFile.get().asFile)
|
||||
from(project.tasks.shadowJar.map { it.archiveFile.get().asFile })
|
||||
into(layout.projectDirectory.dir("run/jars"))
|
||||
|
||||
val projectName = project.name
|
||||
|
||||
@@ -21,31 +21,26 @@ import com.viaversion.viaversion.api.minecraft.codec.CodecContext;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.types.version.VersionedTypesHolder;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public record CodecRegistryContext(Protocol<?, ?, ?, ?> protocol, SerializerVersion serializerVersion,
|
||||
SerializerVersion mappedSerializerVersion, RegistryAccess registryAccess,
|
||||
public record CodecRegistryContext(Protocol<?, ?, ?, ?> protocol, RegistryAccess registryAccess,
|
||||
boolean mapped) implements CodecContext {
|
||||
|
||||
// Generally from hardcoded, but highly variable client data
|
||||
private static final Set<StructuredDataKey<?>> NOT_IMPLEMENTED = new ReferenceOpenHashSet<>(List.of(
|
||||
StructuredDataKey.TRIM1_21_5, StructuredDataKey.TOOL1_21_5, StructuredDataKey.PROVIDES_TRIM_MATERIAL,
|
||||
StructuredDataKey.CONSUMABLE1_21_2, StructuredDataKey.JUKEBOX_PLAYABLE1_21_5, StructuredDataKey.INSTRUMENT1_21_5,
|
||||
StructuredDataKey.EQUIPPABLE1_21_5, StructuredDataKey.REPAIRABLE, StructuredDataKey.DEATH_PROTECTION,
|
||||
StructuredDataKey.BLOCKS_ATTACKS, StructuredDataKey.SUSPICIOUS_STEW_EFFECTS,
|
||||
StructuredDataKey.BANNER_PATTERNS, StructuredDataKey.POT_DECORATIONS, StructuredDataKey.BREAK_SOUND,
|
||||
StructuredDataKey.DEATH_PROTECTION, StructuredDataKey.BLOCKS_ATTACKS, StructuredDataKey.SUSPICIOUS_STEW_EFFECTS,
|
||||
StructuredDataKey.BANNER_PATTERNS, StructuredDataKey.POT_DECORATIONS,
|
||||
StructuredDataKey.WOLF_VARIANT, StructuredDataKey.WOLF_SOUND_VARIANT, StructuredDataKey.PIG_VARIANT,
|
||||
StructuredDataKey.COW_VARIANT, StructuredDataKey.CHICKEN_VARIANT, StructuredDataKey.FROG_VARIANT,
|
||||
StructuredDataKey.PAINTING_VARIANT, StructuredDataKey.CAT_VARIANT, StructuredDataKey.EQUIPPABLE1_21_6
|
||||
StructuredDataKey.PAINTING_VARIANT, StructuredDataKey.CAT_VARIANT
|
||||
));
|
||||
|
||||
public CodecRegistryContext(final Protocol<?, ?, ?, ?> protocol, final SerializerVersion serializerVersion, final SerializerVersion mappedSerializerVersion, final RegistryAccess registryAccess, final boolean mapped) {
|
||||
public CodecRegistryContext(final Protocol<?, ?, ?, ?> protocol, final RegistryAccess registryAccess, final boolean mapped) {
|
||||
this.protocol = protocol;
|
||||
this.serializerVersion = serializerVersion;
|
||||
this.mappedSerializerVersion = mappedSerializerVersion;
|
||||
this.registryAccess = registryAccess.withMapped(mapped);
|
||||
this.mapped = mapped;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class HashOps extends OpsBase implements Hasher {
|
||||
final ListHashBuilder listHasher = hasher.new ListHashBuilder();
|
||||
consumer.accept(listHasher);
|
||||
listHasher.applyHashToParent();
|
||||
return HashOps.this.hash();
|
||||
return hasher.hash();
|
||||
}
|
||||
|
||||
protected int mapHash(final Consumer<MapSerializer> consumer) {
|
||||
@@ -190,7 +190,7 @@ public class HashOps extends OpsBase implements Hasher {
|
||||
final MapHashBuilder mapHasher = hasher.new MapHashBuilder();
|
||||
consumer.accept(mapHasher);
|
||||
mapHasher.applyHashToParent();
|
||||
return HashOps.this.hash();
|
||||
return hasher.hash();
|
||||
}
|
||||
|
||||
protected <V> int hash(final Type<V> type, final V value) {
|
||||
|
||||
+61
-18
@@ -19,12 +19,14 @@ package com.viaversion.viaversion.configuration;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.configuration.RateLimitConfig;
|
||||
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
|
||||
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
|
||||
import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl;
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
import com.viaversion.viaversion.util.ConfigSection;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
import java.io.File;
|
||||
@@ -32,6 +34,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -54,12 +57,8 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
private boolean bossbarPatch;
|
||||
private boolean bossbarAntiFlicker;
|
||||
private double hologramOffset;
|
||||
private int maxPPS;
|
||||
private String maxPPSKickMessage;
|
||||
private int trackingPeriod;
|
||||
private int warningPPS;
|
||||
private int maxPPSWarnings;
|
||||
private String maxPPSWarningsKickMessage;
|
||||
private RateLimitConfig packetTrackerConfig;
|
||||
private RateLimitConfig packetSizeTrackerConfig;
|
||||
private boolean sendSupportedVersions;
|
||||
private boolean simulatePlayerTick;
|
||||
private boolean replacePistons;
|
||||
@@ -68,6 +67,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
private boolean autoTeam;
|
||||
private BlockedProtocolVersions blockedProtocolVersions;
|
||||
private String blockedDisconnectMessage;
|
||||
private boolean logBlockedJoins;
|
||||
private String reloadDisconnectMessage;
|
||||
private boolean suppressConversionWarnings;
|
||||
private boolean suppressTextComponentConversionWarnings;
|
||||
@@ -105,6 +105,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
updateConfig();
|
||||
loadFields();
|
||||
}
|
||||
|
||||
@@ -121,12 +122,6 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
bossbarPatch = getBoolean("bossbar-patch", true);
|
||||
bossbarAntiFlicker = getBoolean("bossbar-anti-flicker", false);
|
||||
hologramOffset = getDouble("hologram-y", -0.96D);
|
||||
maxPPS = getInt("max-pps", 800);
|
||||
maxPPSKickMessage = getString("max-pps-kick-msg", "Sending packets too fast? lag?");
|
||||
trackingPeriod = getInt("tracking-period", 6);
|
||||
warningPPS = getInt("tracking-warning-pps", 120);
|
||||
maxPPSWarnings = getInt("tracking-max-warnings", 3);
|
||||
maxPPSWarningsKickMessage = getString("tracking-max-kick-msg", "You are sending too many packets, :(");
|
||||
sendSupportedVersions = getBoolean("send-supported-versions", false);
|
||||
simulatePlayerTick = getBoolean("simulate-pt", true);
|
||||
replacePistons = getBoolean("replace-pistons", false);
|
||||
@@ -135,6 +130,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
autoTeam = getBoolean("auto-team", true);
|
||||
blockedProtocolVersions = loadBlockedProtocolVersions();
|
||||
blockedDisconnectMessage = getString("block-disconnect-msg", "You are using an unsupported Minecraft version!");
|
||||
logBlockedJoins = getBoolean("log-blocked-joins", false);
|
||||
reloadDisconnectMessage = getString("reload-disconnect-msg", "Server reload, please rejoin!");
|
||||
teamColourFix = getBoolean("team-colour-fix", true);
|
||||
suppressConversionWarnings = getBoolean("suppress-conversion-warnings", false);
|
||||
@@ -167,6 +163,23 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
hideScoreboardNumbers = getBoolean("hide-scoreboard-numbers", false);
|
||||
fix1_21PlacementRotation = getBoolean("fix-1_21-placement-rotation", true);
|
||||
cancelSwingInInventory = getBoolean("cancel-swing-in-inventory", true);
|
||||
packetTrackerConfig = loadRateLimitConfig(getSection("packet-limiter"), "%pps", 1);
|
||||
packetSizeTrackerConfig = loadRateLimitConfig(getSection("packet-size-limiter"), "%bps", 1024);
|
||||
}
|
||||
|
||||
protected void updateConfig() {
|
||||
ConfigSection original = originalRootSection();
|
||||
if (original != null && original.contains("max-pps")) {
|
||||
// 5.5.0 pps changes
|
||||
ConfigSection section = getSection("packet-limiter");
|
||||
section.set("max-per-second", original.getInt("max-pps", -1));
|
||||
section.set("max-per-second-kick-message", original.getString("max-pps-kick-msg", "You are sending too many packets!"));
|
||||
section.set("sustained-max-per-second", original.getInt("tracking-warning-pps", -1));
|
||||
section.set("sustained-threshold", original.getInt("tracking-max-warnings", 3));
|
||||
section.set("sustained-period-seconds", original.getInt("tracking-period", 6));
|
||||
section.set("sustained-kick-message", original.getString("tracking-max-kick-msg", "You are sending too many packets, :("));
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
private BlockedProtocolVersions loadBlockedProtocolVersions() {
|
||||
@@ -228,6 +241,21 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
return new BlockedProtocolVersionsImpl(blockedProtocols, lowerBound, upperBound);
|
||||
}
|
||||
|
||||
private RateLimitConfig loadRateLimitConfig(ConfigSection section, String placeholder, int countMultiplier) {
|
||||
final int maxPerSecond = section.getInt("max-per-second", -1);
|
||||
final int sustainedMaxPerSecond = section.getInt("sustained-max-per-second", -1);
|
||||
return new RateLimitConfig(
|
||||
section.getBoolean("enabled", true),
|
||||
maxPerSecond != -1 ? maxPerSecond * countMultiplier : -1,
|
||||
section.getString("max-per-second-kick-message", "You are sending too many packets!"),
|
||||
sustainedMaxPerSecond != -1 ? sustainedMaxPerSecond * countMultiplier : -1,
|
||||
section.getInt("sustained-threshold", 3),
|
||||
TimeUnit.SECONDS.toNanos(section.getInt("sustained-period-seconds", 6)),
|
||||
section.getString("sustained-kick-message", "You are sending too many packets, :("),
|
||||
placeholder
|
||||
);
|
||||
}
|
||||
|
||||
private @Nullable ProtocolVersion protocolVersion(String s) {
|
||||
ProtocolVersion protocolVersion = ProtocolVersion.getClosest(s);
|
||||
if (protocolVersion == null) {
|
||||
@@ -310,32 +338,42 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
|
||||
@Override
|
||||
public int getMaxPPS() {
|
||||
return maxPPS;
|
||||
return packetTrackerConfig.maxRate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMaxPPSKickMessage() {
|
||||
return maxPPSKickMessage;
|
||||
return packetTrackerConfig.maxRateKickMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrackingPeriod() {
|
||||
return trackingPeriod;
|
||||
return (int) TimeUnit.NANOSECONDS.toSeconds(packetTrackerConfig.trackingPeriodNanos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWarningPPS() {
|
||||
return warningPPS;
|
||||
return packetTrackerConfig.warningRate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxWarnings() {
|
||||
return maxPPSWarnings;
|
||||
return packetTrackerConfig.maxWarnings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMaxWarningsKickMessage() {
|
||||
return maxPPSWarningsKickMessage;
|
||||
return packetTrackerConfig.warningKickMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RateLimitConfig getPacketTrackerConfig() {
|
||||
return packetTrackerConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RateLimitConfig getPacketSizeTrackerConfig() {
|
||||
return packetSizeTrackerConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -399,6 +437,11 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
return blockedDisconnectMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean logBlockedJoins() {
|
||||
return logBlockedJoins;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReloadDisconnectMsg() {
|
||||
return reloadDisconnectMessage;
|
||||
|
||||
+8
-4
@@ -34,7 +34,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
|
||||
|
||||
protected final Map<UUID, UserConnection> serverConnections = new ConcurrentHashMap<>();
|
||||
protected final Map<UUID, UserConnection> clientConnections = new ConcurrentHashMap<>();
|
||||
protected final Set<UserConnection> connections = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
protected final Set<UserConnection> connections = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@Override
|
||||
public void onLoginSuccess(UserConnection connection) {
|
||||
@@ -72,16 +72,20 @@ public class ConnectionManagerImpl implements ConnectionManager {
|
||||
@Override
|
||||
public void onDisconnect(UserConnection connection) {
|
||||
Objects.requireNonNull(connection, "connection is null!");
|
||||
connection.setActive(false);
|
||||
|
||||
connections.remove(connection);
|
||||
|
||||
UUID id = connection.getProtocolInfo().getUuid();
|
||||
if (connection.isServerSide()) {
|
||||
serverConnections.remove(id);
|
||||
serverConnections.remove(id, connection);
|
||||
} else {
|
||||
clientConnections.remove(id);
|
||||
clientConnections.remove(id, connection);
|
||||
}
|
||||
|
||||
connection.clearStoredObjects();
|
||||
// There might be a packet still going through the handlers after we set the connection as inactive
|
||||
// Make sure that we remove stored objects after those have been handled, otherwise this might introduce NPEs
|
||||
connection.getChannel().eventLoop().execute(connection::clearStoredObjects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+15
-12
@@ -15,35 +15,38 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocol;
|
||||
package com.viaversion.viaversion.connection;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
|
||||
/**
|
||||
* Instance of {@link Runnable} that will run {@link #run(UserConnection)} for all active user connections.
|
||||
* Instance of {@link Runnable} that will run {@link #run(UserConnection, StorableObject)} for all active user connections.
|
||||
*/
|
||||
public abstract class ProtocolRunnable implements Runnable {
|
||||
public abstract class StorableObjectTask<T extends StorableObject> implements Runnable {
|
||||
|
||||
private final Class<? extends AbstractProtocol<?, ?, ?, ?>> protocolClass;
|
||||
private final Class<T> storableObject;
|
||||
|
||||
public ProtocolRunnable(final Class<? extends AbstractProtocol<?, ?, ?, ?>> protocolClass) {
|
||||
this.protocolClass = protocolClass;
|
||||
protected StorableObjectTask(final Class<T> storableObject) {
|
||||
this.storableObject = storableObject;
|
||||
}
|
||||
|
||||
public abstract void run(final UserConnection connection);
|
||||
public abstract void run(final UserConnection connection, final T storableObject);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (final UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||
final ProtocolInfo protocolInfo = connection.getProtocolInfo();
|
||||
if (!connection.isActive() || !protocolInfo.getPipeline().contains(this.protocolClass)) {
|
||||
if (!connection.isActive() || !connection.has(storableObject)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
run(connection);
|
||||
connection.getChannel().eventLoop().execute(() -> {
|
||||
final T object = connection.get(storableObject);
|
||||
if (object != null) {
|
||||
this.run(connection, object);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,6 @@ import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.CodecException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -53,6 +52,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class UserConnectionImpl implements UserConnection {
|
||||
@@ -60,9 +60,9 @@ public class UserConnectionImpl implements UserConnection {
|
||||
private static final AtomicLong IDS = new AtomicLong();
|
||||
private final long id = IDS.incrementAndGet();
|
||||
private final Map<Class<?>, StorableObject> storedObjects = new ConcurrentHashMap<>();
|
||||
private final Map<Class<? extends Protocol>, EntityTracker> entityTrackers = new HashMap<>();
|
||||
private final Map<Class<? extends Protocol>, ItemHasher> itemHashers = new HashMap<>();
|
||||
private final Map<Class<? extends Protocol>, ClientWorld> clientWorlds = new HashMap<>();
|
||||
private final Map<Class<? extends Protocol>, EntityTracker> entityTrackers = new Reference2ObjectOpenHashMap<>();
|
||||
private final Map<Class<? extends Protocol>, ItemHasher> itemHashers = new Reference2ObjectOpenHashMap<>();
|
||||
private final Map<Class<? extends Protocol>, ClientWorld> clientWorlds = new Reference2ObjectOpenHashMap<>();
|
||||
private final PacketTracker packetTracker = new PacketTracker(this);
|
||||
private final Set<UUID> passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(10, TimeUnit.SECONDS)
|
||||
@@ -179,7 +179,7 @@ public class UserConnectionImpl implements UserConnection {
|
||||
sendRawPacketNow(packet);
|
||||
} else {
|
||||
try {
|
||||
channel.eventLoop().submit(() -> sendRawPacketNow(packet));
|
||||
channel.eventLoop().execute(() -> sendRawPacketNow(packet));
|
||||
} catch (Throwable e) {
|
||||
packet.release(); // Couldn't schedule
|
||||
e.printStackTrace();
|
||||
@@ -269,7 +269,7 @@ public class UserConnectionImpl implements UserConnection {
|
||||
fireChannelRead(context, buf);
|
||||
} else {
|
||||
try {
|
||||
channel.eventLoop().submit(() -> fireChannelRead(context, buf));
|
||||
channel.eventLoop().execute(() -> fireChannelRead(context, buf));
|
||||
} catch (Throwable t) {
|
||||
// Couldn't schedule
|
||||
buf.release();
|
||||
@@ -294,7 +294,7 @@ public class UserConnectionImpl implements UserConnection {
|
||||
writeAndFlush(packet);
|
||||
} else {
|
||||
try {
|
||||
getChannel().eventLoop().submit(() -> writeAndFlush(packet));
|
||||
getChannel().eventLoop().execute(() -> writeAndFlush(packet));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
packet.release(); // Couldn't schedule
|
||||
@@ -307,12 +307,16 @@ public class UserConnectionImpl implements UserConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkServerboundPacket() {
|
||||
public boolean checkServerboundPacket(final int bytes) {
|
||||
if (pendingDisconnect) {
|
||||
return false;
|
||||
return false; // Cancel everything while disconnecting
|
||||
}
|
||||
// Increment received + Check PPS
|
||||
return !packetTracker.isPacketLimiterEnabled() || !packetTracker.incrementReceived() || !packetTracker.exceedsMaxPPS();
|
||||
if (!packetTracker.isPacketLimiterEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
packetTracker.incrementReceived(bytes);
|
||||
return !packetTracker.exceedsLimits();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,6 +41,7 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
|
||||
private int currentWorldSectionHeight = -1;
|
||||
private int currentMinY;
|
||||
private String currentWorld;
|
||||
private int currentDimensionId = -1;
|
||||
private int biomesSent = -1;
|
||||
private Map<String, DimensionData> dimensions = Collections.emptyMap();
|
||||
private boolean instaBuild;
|
||||
@@ -106,6 +107,16 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
// Call wrapper function in case protocols need to do additional removals
|
||||
for (final int id : entities.keySet().toIntArray()) {
|
||||
removeEntity(id);
|
||||
}
|
||||
|
||||
clientEntityId = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClientEntityId() {
|
||||
return clientEntityId != null;
|
||||
@@ -172,6 +183,16 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
|
||||
this.currentWorld = currentWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int currentDimensionId() {
|
||||
return currentDimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentDimensionId(final int currentDimensionId) {
|
||||
this.currentDimensionId = currentDimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int biomesSent() {
|
||||
return biomesSent;
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.codec.CodecRegistryContext;
|
||||
import com.viaversion.viaversion.codec.hash.HashFunction;
|
||||
import com.viaversion.viaversion.codec.hash.HashOps;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -50,10 +49,10 @@ public class ItemHasherBase implements ItemHasher {
|
||||
private final CodecContext context;
|
||||
private final CodecContext mappedContext;
|
||||
|
||||
public ItemHasherBase(final Protocol<?, ?, ?, ?> protocol, final UserConnection connection, final SerializerVersion serializerVersion, final SerializerVersion mappedSerializerVersion) {
|
||||
public ItemHasherBase(final Protocol<?, ?, ?, ?> protocol, final UserConnection connection) {
|
||||
final RegistryAccess registryAccess = RegistryAccess.of(this.enchantments, protocol.getMappingData());
|
||||
this.context = new CodecRegistryContext(protocol, serializerVersion, mappedSerializerVersion, registryAccess, false);
|
||||
this.mappedContext = new CodecRegistryContext(protocol, serializerVersion, mappedSerializerVersion, registryAccess, true);
|
||||
this.context = new CodecRegistryContext(protocol, registryAccess, false);
|
||||
this.mappedContext = new CodecRegistryContext(protocol, registryAccess, true);
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.Protocol1_21_2To1_21_
|
||||
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.Protocol1_21_4To1_21_5;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.Protocol1_21_5To1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_6to1_21_7.Protocol1_21_6To1_21_7;
|
||||
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.Protocol1_21_7To1_21_9;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.Protocol1_21To1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.Protocol1_9_1To1_9_3;
|
||||
@@ -205,6 +206,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
|
||||
registerProtocol(new Protocol1_21_5To1_21_6(), ProtocolVersion.v1_21_6, ProtocolVersion.v1_21_5);
|
||||
registerProtocol(new Protocol1_21_6To1_21_7(), ProtocolVersion.v1_21_7, ProtocolVersion.v1_21_6);
|
||||
registerProtocol(new Protocol1_21_7To1_21_9(), ProtocolVersion.v1_21_9, ProtocolVersion.v1_21_7);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.debug.DebugHandler;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
@@ -40,7 +39,7 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements ProtocolPipeline {
|
||||
public class ProtocolPipelineImpl implements ProtocolPipeline {
|
||||
private final List<Protocol> protocolList = new ArrayList<>();
|
||||
private final Set<Class<? extends Protocol>> protocolSet = new HashSet<>();
|
||||
private final UserConnection userConnection;
|
||||
@@ -50,20 +49,9 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
|
||||
public ProtocolPipelineImpl(UserConnection userConnection) {
|
||||
this.userConnection = userConnection;
|
||||
userConnection.getProtocolInfo().setPipeline(this);
|
||||
registerPackets(); // Not registered as a standard "protocol", so we have to call the method manually
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
// This is a pipeline so we register basic pipes
|
||||
this.add(Via.getManager().getProtocolManager().getBaseProtocol());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
throw new UnsupportedOperationException("ProtocolPipeline can only be initialized once");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final Protocol protocol) {
|
||||
reversedProtocolList.add(baseProtocols, protocol);
|
||||
@@ -120,7 +108,6 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
|
||||
|
||||
// Apply protocols
|
||||
packetWrapper.apply(direction, state, protocolListFor(direction));
|
||||
super.transform(direction, state, packetWrapper);
|
||||
|
||||
if (debug && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
|
||||
logPacket(direction, state, packetWrapper, originalID, true);
|
||||
@@ -235,7 +222,7 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
|
||||
protocolSet.clear();
|
||||
baseProtocols = 0;
|
||||
|
||||
registerPackets();
|
||||
this.add(Via.getManager().getProtocolManager().getBaseProtocol());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
-11
@@ -29,39 +29,39 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
* Compares equal to the given origin version and allows base protocol determination via {@link #getBaseProtocolVersion()}
|
||||
* which can be null for special cases where there is no base protocol.
|
||||
*/
|
||||
public class RedirectProtocolVersion extends ProtocolVersion {
|
||||
public class SpecialProtocolVersion extends ProtocolVersion {
|
||||
|
||||
private final ProtocolVersion origin;
|
||||
private final ProtocolVersion delegate;
|
||||
|
||||
public RedirectProtocolVersion(final int version, final String name, final ProtocolVersion origin) {
|
||||
this(version, -1, name, null, origin);
|
||||
public SpecialProtocolVersion(final int version, final String name, final ProtocolVersion delegate) {
|
||||
this(version, -1, name, null, delegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link ProtocolVersion} for more information.
|
||||
*/
|
||||
public RedirectProtocolVersion(final int version, final int snapshotVersion, final String name, @Nullable final SubVersionRange versionRange, final ProtocolVersion origin) {
|
||||
public SpecialProtocolVersion(final int version, final int snapshotVersion, final String name, @Nullable final SubVersionRange versionRange, final ProtocolVersion delegate) {
|
||||
super(VersionType.SPECIAL, version, snapshotVersion, name, versionRange);
|
||||
this.origin = origin;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable Comparator<ProtocolVersion> customComparator() {
|
||||
return (o1, o2) -> {
|
||||
if (o1 == this) o1 = this.origin;
|
||||
if (o2 == this) o2 = this.origin;
|
||||
if (o1 == this) o1 = this.delegate;
|
||||
if (o2 == this) o2 = this.delegate;
|
||||
return o1.compareTo(o2);
|
||||
};
|
||||
}
|
||||
|
||||
public ProtocolVersion getOrigin() {
|
||||
return origin;
|
||||
public ProtocolVersion getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the protocol version used to determine the base protocol, null in case there is no base protocol.
|
||||
*/
|
||||
public @Nullable ProtocolVersion getBaseProtocolVersion() {
|
||||
return origin;
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -307,7 +307,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
||||
if (currentThread) {
|
||||
sendNow(protocol, skipCurrentPipeline);
|
||||
} else {
|
||||
connection.getChannel().eventLoop().submit(() -> sendNow(protocol, skipCurrentPipeline));
|
||||
connection.getChannel().eventLoop().execute(() -> sendNow(protocol, skipCurrentPipeline));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
||||
return;
|
||||
}
|
||||
|
||||
connection.getChannel().eventLoop().submit(() -> {
|
||||
connection.getChannel().eventLoop().execute(() -> {
|
||||
try {
|
||||
final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND);
|
||||
connection.sendRawPacketToServer(output);
|
||||
|
||||
+3
-3
@@ -35,7 +35,7 @@ import com.viaversion.viaversion.api.protocol.version.VersionType;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import com.viaversion.viaversion.protocol.RedirectProtocolVersion;
|
||||
import com.viaversion.viaversion.protocol.SpecialProtocolVersion;
|
||||
import com.viaversion.viaversion.protocol.version.BaseVersionProvider;
|
||||
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
|
||||
import com.viaversion.viaversion.protocols.base.packet.BasePacketTypesProvider;
|
||||
@@ -101,11 +101,11 @@ public class InitialBaseProtocol extends AbstractProtocol<BaseClientboundPacket,
|
||||
List<Protocol> alreadyAdded = new ArrayList<>(pipeline.pipes());
|
||||
|
||||
// Special versions might compare equal to normal versions and would the normal lookup,
|
||||
// platforms can use the RedirectProtocolVersion API or need to manually handle their base protocols.
|
||||
// platforms can use a SpecialProtocolVersion or need to manually handle their base protocols.
|
||||
ProtocolVersion clientboundBaseProtocolVersion = null;
|
||||
if (serverProtocol.getVersionType() != VersionType.SPECIAL) {
|
||||
clientboundBaseProtocolVersion = serverProtocol;
|
||||
} else if (serverProtocol instanceof RedirectProtocolVersion version) {
|
||||
} else if (serverProtocol instanceof SpecialProtocolVersion version) {
|
||||
clientboundBaseProtocolVersion = version.getBaseProtocolVersion();
|
||||
}
|
||||
// Add base protocols
|
||||
|
||||
+5
@@ -35,6 +35,7 @@ import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ServerboundBaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> {
|
||||
|
||||
@@ -74,6 +75,10 @@ public class ServerboundBaseProtocol1_7 extends AbstractProtocol<BaseClientbound
|
||||
// Send and close
|
||||
final ChannelFuture future = disconnectPacket.sendFutureRaw();
|
||||
future.addListener(f -> user.getChannel().close());
|
||||
|
||||
if (Via.getConfig().logBlockedJoins()) {
|
||||
Via.getPlatform().getLogger().log(Level.INFO, "Blocked join due to unsupported version from " + user.getChannel().remoteAddress() + " (" + protocol.getName() + ")");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+27
-27
@@ -22,11 +22,11 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_21_5;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPacket1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPackets1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.rewriter.RecipeDisplayRewriter1_21_5;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPacket1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPackets1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPacket1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPackets1_21_6;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||
@@ -35,7 +35,7 @@ import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||
// ChunkType1_21_5
|
||||
// RecipeDisplayRewriter
|
||||
// Types1_21_4, Types1_OLD
|
||||
final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<ClientboundPacket1_21_2, ServerboundPacket1_21_4, Protocol1_98To1_99> {
|
||||
final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<ClientboundPacket1_21_6, ServerboundPacket1_21_6, Protocol1_98To1_99> {
|
||||
|
||||
public BlockItemPacketRewriter1_99(final Protocol1_98To1_99 protocol) {
|
||||
super(protocol);
|
||||
@@ -46,32 +46,32 @@ final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<Clientbou
|
||||
// Register block and block state id changes
|
||||
// Other places using block state id mappings: Spawn particle, entity data, entity spawn (falling blocks)
|
||||
// Tags and statistics use block (!) ids
|
||||
final BlockRewriter<ClientboundPacket1_21_2> blockRewriter = BlockRewriter.for1_20_2(protocol);
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE);
|
||||
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001);
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_21_5::new);
|
||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA);
|
||||
final BlockRewriter<ClientboundPacket1_21_6> blockRewriter = BlockRewriter.for1_20_2(protocol);
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_21_6.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_21_6.BLOCK_UPDATE);
|
||||
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_6.SECTION_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_6.LEVEL_EVENT, 2001);
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_6.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_21_5::new);
|
||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_6.BLOCK_ENTITY_DATA);
|
||||
|
||||
// Registers item id changes
|
||||
// Other places using item ids are: Entity data, tags, statistics, effect
|
||||
// registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); If a new container type was added; also remove from the component rewriter registration
|
||||
registerSetCursorItem(ClientboundPackets1_21_2.SET_CURSOR_ITEM);
|
||||
registerSetPlayerInventory(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY);
|
||||
registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN);
|
||||
registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT);
|
||||
registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT);
|
||||
registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS);
|
||||
registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT);
|
||||
registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS);
|
||||
registerContainerClick1_21_5(ServerboundPackets1_21_4.CONTAINER_CLICK);
|
||||
registerSetCreativeModeSlot1_21_5(ServerboundPackets1_21_4.SET_CREATIVE_MODE_SLOT);
|
||||
// registerOpenScreen(ClientboundPackets1_21_6.OPEN_SCREEN); If a new container type was added; also remove from the component rewriter registration
|
||||
registerSetCursorItem(ClientboundPackets1_21_6.SET_CURSOR_ITEM);
|
||||
registerSetPlayerInventory(ClientboundPackets1_21_6.SET_PLAYER_INVENTORY);
|
||||
registerCooldown1_21_2(ClientboundPackets1_21_6.COOLDOWN);
|
||||
registerSetContent1_21_2(ClientboundPackets1_21_6.CONTAINER_SET_CONTENT);
|
||||
registerSetSlot1_21_2(ClientboundPackets1_21_6.CONTAINER_SET_SLOT);
|
||||
registerAdvancements1_20_3(ClientboundPackets1_21_6.UPDATE_ADVANCEMENTS);
|
||||
registerSetEquipment(ClientboundPackets1_21_6.SET_EQUIPMENT);
|
||||
registerMerchantOffers1_20_5(ClientboundPackets1_21_6.MERCHANT_OFFERS);
|
||||
registerContainerClick1_21_5(ServerboundPackets1_21_6.CONTAINER_CLICK);
|
||||
registerSetCreativeModeSlot1_21_5(ServerboundPackets1_21_6.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
final RecipeDisplayRewriter<ClientboundPacket1_21_2> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
|
||||
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_2.UPDATE_RECIPES);
|
||||
recipeRewriter.registerRecipeBookAdd(ClientboundPackets1_21_2.RECIPE_BOOK_ADD);
|
||||
recipeRewriter.registerPlaceGhostRecipe(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE);
|
||||
final RecipeDisplayRewriter<ClientboundPacket1_21_6> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
|
||||
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_6.UPDATE_RECIPES);
|
||||
recipeRewriter.registerRecipeBookAdd(ClientboundPackets1_21_6.RECIPE_BOOK_ADD);
|
||||
recipeRewriter.registerPlaceGhostRecipe(ClientboundPackets1_21_6.PLACE_GHOST_RECIPE);
|
||||
// OR do this if serialization of recipes changed and override the relevant method
|
||||
// Add new serializers to RecipeDisplayRewriter, or extend the last one for changes
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,10 +19,10 @@ package com.viaversion.viaversion.protocols.template;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPacket1_21_6;
|
||||
import com.viaversion.viaversion.rewriter.text.NBTComponentRewriter;
|
||||
|
||||
final class ComponentRewriter1_99 extends NBTComponentRewriter<ClientboundPacket1_21_2> {
|
||||
final class ComponentRewriter1_99 extends NBTComponentRewriter<ClientboundPacket1_21_6> {
|
||||
|
||||
public ComponentRewriter1_99(final Protocol1_98To1_99 protocol) {
|
||||
super(protocol);
|
||||
|
||||
+17
-18
@@ -18,19 +18,18 @@
|
||||
package com.viaversion.viaversion.protocols.template;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_4;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_9;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_9;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundConfigurationPackets1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPacket1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPackets1_21_6;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
||||
|
||||
// Replace if needed
|
||||
// Types1_OLD
|
||||
// VersionedTypes
|
||||
// EntityTypes1_21_4
|
||||
final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_21_2, Protocol1_98To1_99> {
|
||||
// EntityTypes1_21_9
|
||||
final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_21_6, Protocol1_98To1_99> {
|
||||
|
||||
public EntityPacketRewriter1_99(final Protocol1_98To1_99 protocol) {
|
||||
super(protocol);
|
||||
@@ -39,21 +38,21 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
// Tracks entities, applies entity data rewrites registered below, untracks entities
|
||||
registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_21_4.FALLING_BLOCK);
|
||||
registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA);
|
||||
registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES);
|
||||
registerPlayerAbilities(ClientboundPackets1_21_2.PLAYER_ABILITIES);
|
||||
registerGameEvent(ClientboundPackets1_21_2.GAME_EVENT);
|
||||
registerLogin1_20_5(ClientboundPackets1_21_2.LOGIN);
|
||||
registerRespawn1_20_5(ClientboundPackets1_21_2.RESPAWN);
|
||||
registerTrackerWithData1_21_9(ClientboundPackets1_21_6.ADD_ENTITY, EntityTypes1_21_9.FALLING_BLOCK);
|
||||
registerSetEntityData(ClientboundPackets1_21_6.SET_ENTITY_DATA);
|
||||
registerRemoveEntities(ClientboundPackets1_21_6.REMOVE_ENTITIES);
|
||||
registerPlayerAbilities(ClientboundPackets1_21_6.PLAYER_ABILITIES);
|
||||
registerGameEvent(ClientboundPackets1_21_6.GAME_EVENT);
|
||||
registerLogin1_20_5(ClientboundPackets1_21_6.LOGIN);
|
||||
registerRespawn1_20_5(ClientboundPackets1_21_6.RESPAWN);
|
||||
|
||||
final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol);
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle);
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_21_6.REGISTRY_DATA, registryDataRewriter::handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
final EntityDataTypes1_21_5 entityDataTypes = protocol.types().entityDataTypes();
|
||||
final EntityDataTypes1_21_9 entityDataTypes = protocol.mappedTypes().entityDataTypes();
|
||||
/* Uncomment if entity data classes changed
|
||||
filter().mapDataType(typeId -> {
|
||||
int id = typeId;
|
||||
@@ -83,6 +82,6 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(final int type) {
|
||||
return EntityTypes1_21_4.getTypeFromId(type);
|
||||
return EntityTypes1_21_9.getTypeFromId(type);
|
||||
}
|
||||
}
|
||||
+54
-56
@@ -21,8 +21,8 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.minecraft.data.version.StructuredDataKeys1_21_5;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_4;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_5;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_9;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_21_9;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||
@@ -30,76 +30,74 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.api.type.types.version.VersionedTypes;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.data.item.ItemHasherBase;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPacket1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPackets1_21_4;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundConfigurationPackets1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPacket1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPackets1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundConfigurationPackets1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPacket1_21_6;
|
||||
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPackets1_21_6;
|
||||
import com.viaversion.viaversion.rewriter.AttributeRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ParticleRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.NBTComponentRewriter;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
|
||||
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
|
||||
|
||||
// Placeholders to replace (in the entire package):
|
||||
// Protocol1_98To1_99, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99 - move the latter two to a rewriter package
|
||||
// ClientboundPacket1_21_2
|
||||
// ServerboundPacket1_21_4
|
||||
// EntityTypes1_21_4 (MAPPED type)
|
||||
// VersionedTypes.V1_21_5
|
||||
// SerializerVersion.V1_21_5
|
||||
// ClientboundPacket1_21_6
|
||||
// ServerboundPacket1_21_6
|
||||
// EntityTypes1_21_9 (MAPPED type)
|
||||
// VersionedTypes.V1_21_9
|
||||
// 1.99, 1.98
|
||||
final class Protocol1_98To1_99 extends AbstractProtocol<ClientboundPacket1_21_2, ClientboundPacket1_21_2, ServerboundPacket1_21_4, ServerboundPacket1_21_4> {
|
||||
final class Protocol1_98To1_99 extends AbstractProtocol<ClientboundPacket1_21_6, ClientboundPacket1_21_6, ServerboundPacket1_21_6, ServerboundPacket1_21_6> {
|
||||
|
||||
public static final MappingData MAPPINGS = new MappingDataBase("1.98", "1.99");
|
||||
private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this);
|
||||
private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this);
|
||||
private final ParticleRewriter<ClientboundPacket1_21_2> particleRewriter = new ParticleRewriter<>(this);
|
||||
private final TagRewriter<ClientboundPacket1_21_2> tagRewriter = new TagRewriter<>(this);
|
||||
private final NBTComponentRewriter<ClientboundPacket1_21_2> componentRewriter = new ComponentRewriter1_99(this);
|
||||
private final ParticleRewriter<ClientboundPacket1_21_6> particleRewriter = new ParticleRewriter<>(this);
|
||||
private final TagRewriter<ClientboundPacket1_21_6> tagRewriter = new TagRewriter<>(this);
|
||||
private final NBTComponentRewriter<ClientboundPacket1_21_6> componentRewriter = new ComponentRewriter1_99(this);
|
||||
|
||||
public Protocol1_98To1_99() {
|
||||
// Passing the class types into the super constructor is needed for automatic packet type id remapping, but can otherwise be omitted
|
||||
super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_4.class, ServerboundPacket1_21_4.class);
|
||||
super(ClientboundPacket1_21_6.class, ClientboundPacket1_21_6.class, ServerboundPacket1_21_6.class, ServerboundPacket1_21_6.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
super.registerPackets();
|
||||
|
||||
tagRewriter.registerGeneric(ClientboundPackets1_21_2.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundPackets1_21_6.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21_6.UPDATE_TAGS);
|
||||
|
||||
// If needed for item or component changes
|
||||
componentRewriter.registerOpenScreen1_14(ClientboundPackets1_21_2.OPEN_SCREEN);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);
|
||||
componentRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT);
|
||||
componentRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST);
|
||||
componentRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL);
|
||||
componentRewriter.registerPlayerInfoUpdate1_21_4(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT);
|
||||
componentRewriter.registerDisguisedChat(ClientboundPackets1_21_2.DISGUISED_CHAT);
|
||||
componentRewriter.registerPlayerChat1_21_5(ClientboundPackets1_21_2.PLAYER_CHAT);
|
||||
componentRewriter.registerOpenScreen1_14(ClientboundPackets1_21_6.OPEN_SCREEN);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_6.SET_ACTION_BAR_TEXT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_6.SET_TITLE_TEXT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_6.SET_SUBTITLE_TEXT);
|
||||
componentRewriter.registerBossEvent(ClientboundPackets1_21_6.BOSS_EVENT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_6.DISCONNECT);
|
||||
componentRewriter.registerTabList(ClientboundPackets1_21_6.TAB_LIST);
|
||||
componentRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_6.PLAYER_COMBAT_KILL);
|
||||
componentRewriter.registerPlayerInfoUpdate1_21_4(ClientboundPackets1_21_6.PLAYER_INFO_UPDATE);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_21_6.SYSTEM_CHAT);
|
||||
componentRewriter.registerDisguisedChat(ClientboundPackets1_21_6.DISGUISED_CHAT);
|
||||
componentRewriter.registerPlayerChat1_21_5(ClientboundPackets1_21_6.PLAYER_CHAT);
|
||||
componentRewriter.registerPing();
|
||||
|
||||
// If needed for any particle, item, or block changes. Extend ParticleRewriter for particle serializer changes
|
||||
particleRewriter.registerLevelParticles1_21_4(ClientboundPackets1_21_2.LEVEL_PARTICLES);
|
||||
particleRewriter.registerExplode1_21_2(ClientboundPackets1_21_2.EXPLODE); // Rewrites the included sound and particles
|
||||
particleRewriter.registerLevelParticles1_21_4(ClientboundPackets1_21_6.LEVEL_PARTICLES);
|
||||
particleRewriter.registerExplode1_21_9(ClientboundPackets1_21_6.EXPLODE); // Rewrites the included sound and particles
|
||||
|
||||
final SoundRewriter<ClientboundPacket1_21_2> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY);
|
||||
final SoundRewriter<ClientboundPacket1_21_6> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_6.SOUND);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_6.SOUND_ENTITY);
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
|
||||
new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES);
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_6.AWARD_STATS);
|
||||
new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_6.UPDATE_ATTRIBUTES);
|
||||
|
||||
// Uncomment if an existing type changed serialization format. Mappings for argument type keys can also be defined in mapping files
|
||||
/*new CommandRewriter1_19_4<>(this) {
|
||||
@@ -112,13 +110,13 @@ final class Protocol1_98To1_99 extends AbstractProtocol<ClientboundPacket1_21_2,
|
||||
super.handleArgument(wrapper, argumentType);
|
||||
}
|
||||
}
|
||||
}.registerDeclareCommands1_19(ClientboundPackets1_21_2.COMMANDS);*/
|
||||
}.registerDeclareCommands1_19(ClientboundPackets1_21_6.COMMANDS);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMappingDataLoaded() {
|
||||
// Uncomment this if the entity types enum has been newly added specifically for this Protocol
|
||||
// EntityTypes1_21_4.initialize(this);
|
||||
// EntityTypes1_21_9.initialize(this);
|
||||
|
||||
// Uncomment if a new particle was added = ids shifted; requires a new Types_ class copied from the last
|
||||
/*mappedTypes().particle.filler(this)
|
||||
@@ -143,8 +141,8 @@ final class Protocol1_98To1_99 extends AbstractProtocol<ClientboundPacket1_21_2,
|
||||
@Override
|
||||
public void init(final UserConnection connection) {
|
||||
// Register the entity tracker - used for entity id/entity data rewriting AND for tracking world data sent to the client (then used for chunk data rewriting)
|
||||
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_21_4.PLAYER));
|
||||
addItemHasher(connection, new ItemHasherBase(this, connection, SerializerVersion.V1_21_6, SerializerVersion.V1_21_6));
|
||||
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_21_9.PLAYER));
|
||||
addItemHasher(connection, new ItemHasherBase(this, connection));
|
||||
}
|
||||
|
||||
// Overriding these methods is important as they are relied on various rewriter classes
|
||||
@@ -165,37 +163,37 @@ final class Protocol1_98To1_99 extends AbstractProtocol<ClientboundPacket1_21_2,
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleRewriter<ClientboundPacket1_21_2> getParticleRewriter() {
|
||||
public ParticleRewriter<ClientboundPacket1_21_6> getParticleRewriter() {
|
||||
return particleRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagRewriter<ClientboundPacket1_21_2> getTagRewriter() {
|
||||
public TagRewriter<ClientboundPacket1_21_6> getTagRewriter() {
|
||||
return tagRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTComponentRewriter<ClientboundPacket1_21_2> getComponentRewriter() {
|
||||
public NBTComponentRewriter<ClientboundPacket1_21_6> getComponentRewriter() {
|
||||
return componentRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_5> types() {
|
||||
return VersionedTypes.V1_21_5;
|
||||
public Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_9> types() {
|
||||
return VersionedTypes.V1_21_9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_5> mappedTypes() {
|
||||
return VersionedTypes.V1_21_5;
|
||||
public Types1_20_5<StructuredDataKeys1_21_5, EntityDataTypes1_21_9> mappedTypes() {
|
||||
return VersionedTypes.V1_21_9;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketTypesProvider<ClientboundPacket1_21_2, ClientboundPacket1_21_2, ServerboundPacket1_21_4, ServerboundPacket1_21_4> createPacketTypesProvider() {
|
||||
protected PacketTypesProvider<ClientboundPacket1_21_6, ClientboundPacket1_21_6, ServerboundPacket1_21_6, ServerboundPacket1_21_6> createPacketTypesProvider() {
|
||||
return new SimplePacketTypesProvider<>(
|
||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
|
||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
|
||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class)
|
||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_6.class, ClientboundConfigurationPackets1_21_6.class),
|
||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_6.class, ClientboundConfigurationPackets1_21_6.class),
|
||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_6.class, ServerboundConfigurationPackets1_21_6.class),
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_6.class, ServerboundConfigurationPackets1_21_6.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -20,27 +20,28 @@ package com.viaversion.viaversion.protocols.v1_12_2to1_13.blockconnections;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class DoorConnectionHandler implements ConnectionHandler {
|
||||
private static final Int2ObjectMap<DoorData> DOOR_DATA_MAP = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<Short, Integer> CONNECTED_STATES = new HashMap<>();
|
||||
private static final Int2IntMap CONNECTED_STATES = new Int2IntOpenHashMap();
|
||||
|
||||
static ConnectionData.ConnectorInitAction init() {
|
||||
final List<String> baseDoors = new LinkedList<>();
|
||||
baseDoors.add("minecraft:oak_door");
|
||||
baseDoors.add("minecraft:birch_door");
|
||||
baseDoors.add("minecraft:jungle_door");
|
||||
baseDoors.add("minecraft:dark_oak_door");
|
||||
baseDoors.add("minecraft:acacia_door");
|
||||
baseDoors.add("minecraft:spruce_door");
|
||||
baseDoors.add("minecraft:iron_door");
|
||||
final List<String> baseDoors = Arrays.asList(
|
||||
"minecraft:oak_door",
|
||||
"minecraft:birch_door",
|
||||
"minecraft:jungle_door",
|
||||
"minecraft:dark_oak_door",
|
||||
"minecraft:acacia_door",
|
||||
"minecraft:spruce_door",
|
||||
"minecraft:iron_door"
|
||||
);
|
||||
|
||||
final DoorConnectionHandler connectionHandler = new DoorConnectionHandler();
|
||||
return blockData -> {
|
||||
@@ -100,8 +101,7 @@ public class DoorConnectionHandler implements ConnectionHandler {
|
||||
s |= lowerHalf.facing().ordinal() << 4;
|
||||
}
|
||||
|
||||
Integer newBlockState = CONNECTED_STATES.get(s);
|
||||
return newBlockState == null ? blockState : newBlockState;
|
||||
return CONNECTED_STATES.getOrDefault(s, blockState);
|
||||
}
|
||||
|
||||
private record DoorData(boolean lower, boolean rightHinge, boolean powered,
|
||||
|
||||
+24
-24
@@ -20,37 +20,38 @@ package com.viaversion.viaversion.protocols.v1_12_2to1_13.blockconnections;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class StairConnectionHandler implements ConnectionHandler {
|
||||
private static final Int2ObjectMap<StairData> STAIR_DATA_MAP = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<Short, Integer> CONNECTED_BLOCKS = new HashMap<>();
|
||||
private static final Int2IntMap CONNECTED_BLOCKS = new Int2IntOpenHashMap();
|
||||
|
||||
static ConnectionData.ConnectorInitAction init() {
|
||||
final List<String> baseStairs = new LinkedList<>();
|
||||
baseStairs.add("minecraft:oak_stairs");
|
||||
baseStairs.add("minecraft:cobblestone_stairs");
|
||||
baseStairs.add("minecraft:brick_stairs");
|
||||
baseStairs.add("minecraft:stone_brick_stairs");
|
||||
baseStairs.add("minecraft:nether_brick_stairs");
|
||||
baseStairs.add("minecraft:sandstone_stairs");
|
||||
baseStairs.add("minecraft:spruce_stairs");
|
||||
baseStairs.add("minecraft:birch_stairs");
|
||||
baseStairs.add("minecraft:jungle_stairs");
|
||||
baseStairs.add("minecraft:quartz_stairs");
|
||||
baseStairs.add("minecraft:acacia_stairs");
|
||||
baseStairs.add("minecraft:dark_oak_stairs");
|
||||
baseStairs.add("minecraft:red_sandstone_stairs");
|
||||
baseStairs.add("minecraft:purpur_stairs");
|
||||
baseStairs.add("minecraft:prismarine_stairs");
|
||||
baseStairs.add("minecraft:prismarine_brick_stairs");
|
||||
baseStairs.add("minecraft:dark_prismarine_stairs");
|
||||
final List<String> baseStairs = Arrays.asList(
|
||||
"minecraft:oak_stairs",
|
||||
"minecraft:cobblestone_stairs",
|
||||
"minecraft:brick_stairs",
|
||||
"minecraft:stone_brick_stairs",
|
||||
"minecraft:nether_brick_stairs",
|
||||
"minecraft:sandstone_stairs",
|
||||
"minecraft:spruce_stairs",
|
||||
"minecraft:birch_stairs",
|
||||
"minecraft:jungle_stairs",
|
||||
"minecraft:quartz_stairs",
|
||||
"minecraft:acacia_stairs",
|
||||
"minecraft:dark_oak_stairs",
|
||||
"minecraft:red_sandstone_stairs",
|
||||
"minecraft:purpur_stairs",
|
||||
"minecraft:prismarine_stairs",
|
||||
"minecraft:prismarine_brick_stairs",
|
||||
"minecraft:dark_prismarine_stairs"
|
||||
);
|
||||
|
||||
final StairConnectionHandler connectionHandler = new StairConnectionHandler();
|
||||
return blockData -> {
|
||||
@@ -104,8 +105,7 @@ public class StairConnectionHandler implements ConnectionHandler {
|
||||
s |= stairData.type() << 4;
|
||||
s |= stairData.facing().ordinal() << 9;
|
||||
|
||||
Integer newBlockState = CONNECTED_BLOCKS.get(s);
|
||||
return newBlockState == null ? blockState : newBlockState;
|
||||
return CONNECTED_BLOCKS.getOrDefault(s, blockState);
|
||||
}
|
||||
|
||||
private int getShape(UserConnection user, BlockPosition position, StairData stair) {
|
||||
|
||||
+456
@@ -0,0 +1,456 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2025 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.v1_12_2to1_13.data;
|
||||
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
|
||||
public final class ItemIds1_12_2 {
|
||||
|
||||
private static final Object2IntMap<String> IDS = new Object2IntOpenHashMap<>();
|
||||
|
||||
static {
|
||||
IDS.put("air", 0);
|
||||
IDS.put("stone", 1);
|
||||
IDS.put("grass", 2);
|
||||
IDS.put("dirt", 3);
|
||||
IDS.put("cobblestone", 4);
|
||||
IDS.put("planks", 5);
|
||||
IDS.put("sapling", 6);
|
||||
IDS.put("bedrock", 7);
|
||||
IDS.put("sand", 12);
|
||||
IDS.put("gravel", 13);
|
||||
IDS.put("gold_ore", 14);
|
||||
IDS.put("iron_ore", 15);
|
||||
IDS.put("coal_ore", 16);
|
||||
IDS.put("log", 17);
|
||||
IDS.put("log2", 162);
|
||||
IDS.put("leaves", 18);
|
||||
IDS.put("leaves2", 161);
|
||||
IDS.put("sponge", 19);
|
||||
IDS.put("glass", 20);
|
||||
IDS.put("lapis_ore", 21);
|
||||
IDS.put("lapis_block", 22);
|
||||
IDS.put("dispenser", 23);
|
||||
IDS.put("sandstone", 24);
|
||||
IDS.put("noteblock", 25);
|
||||
IDS.put("golden_rail", 27);
|
||||
IDS.put("detector_rail", 28);
|
||||
IDS.put("sticky_piston", 29);
|
||||
IDS.put("web", 30);
|
||||
IDS.put("tallgrass", 31);
|
||||
IDS.put("deadbush", 32);
|
||||
IDS.put("piston", 33);
|
||||
IDS.put("wool", 35);
|
||||
IDS.put("yellow_flower", 37);
|
||||
IDS.put("red_flower", 38);
|
||||
IDS.put("brown_mushroom", 39);
|
||||
IDS.put("red_mushroom", 40);
|
||||
IDS.put("gold_block", 41);
|
||||
IDS.put("iron_block", 42);
|
||||
IDS.put("stone_slab", 44);
|
||||
IDS.put("brick_block", 45);
|
||||
IDS.put("tnt", 46);
|
||||
IDS.put("bookshelf", 47);
|
||||
IDS.put("mossy_cobblestone", 48);
|
||||
IDS.put("obsidian", 49);
|
||||
IDS.put("torch", 50);
|
||||
IDS.put("end_rod", 198);
|
||||
IDS.put("chorus_plant", 199);
|
||||
IDS.put("chorus_flower", 200);
|
||||
IDS.put("purpur_block", 201);
|
||||
IDS.put("purpur_pillar", 202);
|
||||
IDS.put("purpur_stairs", 203);
|
||||
IDS.put("purpur_slab", 205);
|
||||
IDS.put("mob_spawner", 52);
|
||||
IDS.put("oak_stairs", 53);
|
||||
IDS.put("chest", 54);
|
||||
IDS.put("diamond_ore", 56);
|
||||
IDS.put("diamond_block", 57);
|
||||
IDS.put("crafting_table", 58);
|
||||
IDS.put("farmland", 60);
|
||||
IDS.put("furnace", 61);
|
||||
IDS.put("ladder", 65);
|
||||
IDS.put("rail", 66);
|
||||
IDS.put("stone_stairs", 67);
|
||||
IDS.put("lever", 69);
|
||||
IDS.put("stone_pressure_plate", 70);
|
||||
IDS.put("wooden_pressure_plate", 72);
|
||||
IDS.put("redstone_ore", 73);
|
||||
IDS.put("redstone_torch", 76);
|
||||
IDS.put("stone_button", 77);
|
||||
IDS.put("snow_layer", 78);
|
||||
IDS.put("ice", 79);
|
||||
IDS.put("snow", 80);
|
||||
IDS.put("cactus", 81);
|
||||
IDS.put("clay", 82);
|
||||
IDS.put("jukebox", 84);
|
||||
IDS.put("fence", 85);
|
||||
IDS.put("spruce_fence", 188);
|
||||
IDS.put("birch_fence", 189);
|
||||
IDS.put("jungle_fence", 190);
|
||||
IDS.put("dark_oak_fence", 191);
|
||||
IDS.put("acacia_fence", 192);
|
||||
IDS.put("pumpkin", 86);
|
||||
IDS.put("netherrack", 87);
|
||||
IDS.put("soul_sand", 88);
|
||||
IDS.put("glowstone", 89);
|
||||
IDS.put("lit_pumpkin", 91);
|
||||
IDS.put("trapdoor", 96);
|
||||
IDS.put("monster_egg", 97);
|
||||
IDS.put("stonebrick", 98);
|
||||
IDS.put("brown_mushroom_block", 99);
|
||||
IDS.put("red_mushroom_block", 100);
|
||||
IDS.put("iron_bars", 101);
|
||||
IDS.put("glass_pane", 102);
|
||||
IDS.put("melon_block", 103);
|
||||
IDS.put("vine", 106);
|
||||
IDS.put("fence_gate", 107);
|
||||
IDS.put("spruce_fence_gate", 183);
|
||||
IDS.put("birch_fence_gate", 184);
|
||||
IDS.put("jungle_fence_gate", 185);
|
||||
IDS.put("dark_oak_fence_gate", 186);
|
||||
IDS.put("acacia_fence_gate", 187);
|
||||
IDS.put("brick_stairs", 108);
|
||||
IDS.put("stone_brick_stairs", 109);
|
||||
IDS.put("mycelium", 110);
|
||||
IDS.put("waterlily", 111);
|
||||
IDS.put("nether_brick", 112);
|
||||
IDS.put("nether_brick_fence", 113);
|
||||
IDS.put("nether_brick_stairs", 114);
|
||||
IDS.put("enchanting_table", 116);
|
||||
IDS.put("end_portal_frame", 120);
|
||||
IDS.put("end_stone", 121);
|
||||
IDS.put("end_bricks", 206);
|
||||
IDS.put("dragon_egg", 122);
|
||||
IDS.put("redstone_lamp", 123);
|
||||
IDS.put("wooden_slab", 126);
|
||||
IDS.put("sandstone_stairs", 128);
|
||||
IDS.put("emerald_ore", 129);
|
||||
IDS.put("ender_chest", 130);
|
||||
IDS.put("tripwire_hook", 131);
|
||||
IDS.put("emerald_block", 133);
|
||||
IDS.put("spruce_stairs", 134);
|
||||
IDS.put("birch_stairs", 135);
|
||||
IDS.put("jungle_stairs", 136);
|
||||
IDS.put("command_block", 137);
|
||||
IDS.put("beacon", 138);
|
||||
IDS.put("cobblestone_wall", 139);
|
||||
IDS.put("wooden_button", 143);
|
||||
IDS.put("anvil", 145);
|
||||
IDS.put("trapped_chest", 146);
|
||||
IDS.put("light_weighted_pressure_plate", 147);
|
||||
IDS.put("heavy_weighted_pressure_plate", 148);
|
||||
IDS.put("daylight_detector", 151);
|
||||
IDS.put("redstone_block", 152);
|
||||
IDS.put("quartz_ore", 153);
|
||||
IDS.put("hopper", 154);
|
||||
IDS.put("quartz_block", 155);
|
||||
IDS.put("quartz_stairs", 156);
|
||||
IDS.put("activator_rail", 157);
|
||||
IDS.put("dropper", 158);
|
||||
IDS.put("stained_hardened_clay", 159);
|
||||
IDS.put("barrier", 166);
|
||||
IDS.put("iron_trapdoor", 167);
|
||||
IDS.put("hay_block", 170);
|
||||
IDS.put("carpet", 171);
|
||||
IDS.put("hardened_clay", 172);
|
||||
IDS.put("coal_block", 173);
|
||||
IDS.put("packed_ice", 174);
|
||||
IDS.put("acacia_stairs", 163);
|
||||
IDS.put("dark_oak_stairs", 164);
|
||||
IDS.put("slime", 165);
|
||||
IDS.put("grass_path", 208);
|
||||
IDS.put("double_plant", 175);
|
||||
IDS.put("stained_glass", 95);
|
||||
IDS.put("stained_glass_pane", 160);
|
||||
IDS.put("prismarine", 168);
|
||||
IDS.put("sea_lantern", 169);
|
||||
IDS.put("red_sandstone", 179);
|
||||
IDS.put("red_sandstone_stairs", 180);
|
||||
IDS.put("stone_slab2", 182);
|
||||
IDS.put("repeating_command_block", 210);
|
||||
IDS.put("chain_command_block", 211);
|
||||
IDS.put("magma", 213);
|
||||
IDS.put("nether_wart_block", 214);
|
||||
IDS.put("red_nether_brick", 215);
|
||||
IDS.put("bone_block", 216);
|
||||
IDS.put("structure_void", 217);
|
||||
IDS.put("observer", 218);
|
||||
IDS.put("white_shulker_box", 219);
|
||||
IDS.put("orange_shulker_box", 220);
|
||||
IDS.put("magenta_shulker_box", 221);
|
||||
IDS.put("light_blue_shulker_box", 222);
|
||||
IDS.put("yellow_shulker_box", 223);
|
||||
IDS.put("lime_shulker_box", 224);
|
||||
IDS.put("pink_shulker_box", 225);
|
||||
IDS.put("gray_shulker_box", 226);
|
||||
IDS.put("silver_shulker_box", 227);
|
||||
IDS.put("cyan_shulker_box", 228);
|
||||
IDS.put("purple_shulker_box", 229);
|
||||
IDS.put("blue_shulker_box", 230);
|
||||
IDS.put("brown_shulker_box", 231);
|
||||
IDS.put("green_shulker_box", 232);
|
||||
IDS.put("red_shulker_box", 233);
|
||||
IDS.put("black_shulker_box", 234);
|
||||
IDS.put("white_glazed_terracotta", 235);
|
||||
IDS.put("orange_glazed_terracotta", 236);
|
||||
IDS.put("magenta_glazed_terracotta", 237);
|
||||
IDS.put("light_blue_glazed_terracotta", 238);
|
||||
IDS.put("yellow_glazed_terracotta", 239);
|
||||
IDS.put("lime_glazed_terracotta", 240);
|
||||
IDS.put("pink_glazed_terracotta", 241);
|
||||
IDS.put("gray_glazed_terracotta", 242);
|
||||
IDS.put("silver_glazed_terracotta", 243);
|
||||
IDS.put("cyan_glazed_terracotta", 244);
|
||||
IDS.put("purple_glazed_terracotta", 245);
|
||||
IDS.put("blue_glazed_terracotta", 246);
|
||||
IDS.put("brown_glazed_terracotta", 247);
|
||||
IDS.put("green_glazed_terracotta", 248);
|
||||
IDS.put("red_glazed_terracotta", 249);
|
||||
IDS.put("black_glazed_terracotta", 250);
|
||||
IDS.put("concrete", 251);
|
||||
IDS.put("concrete_powder", 252);
|
||||
IDS.put("structure_block", 255);
|
||||
IDS.put("iron_shovel", 256);
|
||||
IDS.put("iron_pickaxe", 257);
|
||||
IDS.put("iron_axe", 258);
|
||||
IDS.put("flint_and_steel", 259);
|
||||
IDS.put("apple", 260);
|
||||
IDS.put("bow", 261);
|
||||
IDS.put("arrow", 262);
|
||||
IDS.put("coal", 263);
|
||||
IDS.put("diamond", 264);
|
||||
IDS.put("iron_ingot", 265);
|
||||
IDS.put("gold_ingot", 266);
|
||||
IDS.put("iron_sword", 267);
|
||||
IDS.put("wooden_sword", 268);
|
||||
IDS.put("wooden_shovel", 269);
|
||||
IDS.put("wooden_pickaxe", 270);
|
||||
IDS.put("wooden_axe", 271);
|
||||
IDS.put("stone_sword", 272);
|
||||
IDS.put("stone_shovel", 273);
|
||||
IDS.put("stone_pickaxe", 274);
|
||||
IDS.put("stone_axe", 275);
|
||||
IDS.put("diamond_sword", 276);
|
||||
IDS.put("diamond_shovel", 277);
|
||||
IDS.put("diamond_pickaxe", 278);
|
||||
IDS.put("diamond_axe", 279);
|
||||
IDS.put("stick", 280);
|
||||
IDS.put("bowl", 281);
|
||||
IDS.put("mushroom_stew", 282);
|
||||
IDS.put("golden_sword", 283);
|
||||
IDS.put("golden_shovel", 284);
|
||||
IDS.put("golden_pickaxe", 285);
|
||||
IDS.put("golden_axe", 286);
|
||||
IDS.put("string", 287);
|
||||
IDS.put("feather", 288);
|
||||
IDS.put("gunpowder", 289);
|
||||
IDS.put("wooden_hoe", 290);
|
||||
IDS.put("stone_hoe", 291);
|
||||
IDS.put("iron_hoe", 292);
|
||||
IDS.put("diamond_hoe", 293);
|
||||
IDS.put("golden_hoe", 294);
|
||||
IDS.put("wheat_seeds", 295);
|
||||
IDS.put("wheat", 296);
|
||||
IDS.put("bread", 297);
|
||||
IDS.put("leather_helmet", 298);
|
||||
IDS.put("leather_chestplate", 299);
|
||||
IDS.put("leather_leggings", 300);
|
||||
IDS.put("leather_boots", 301);
|
||||
IDS.put("chainmail_helmet", 302);
|
||||
IDS.put("chainmail_chestplate", 303);
|
||||
IDS.put("chainmail_leggings", 304);
|
||||
IDS.put("chainmail_boots", 305);
|
||||
IDS.put("iron_helmet", 306);
|
||||
IDS.put("iron_chestplate", 307);
|
||||
IDS.put("iron_leggings", 308);
|
||||
IDS.put("iron_boots", 309);
|
||||
IDS.put("diamond_helmet", 310);
|
||||
IDS.put("diamond_chestplate", 311);
|
||||
IDS.put("diamond_leggings", 312);
|
||||
IDS.put("diamond_boots", 313);
|
||||
IDS.put("golden_helmet", 314);
|
||||
IDS.put("golden_chestplate", 315);
|
||||
IDS.put("golden_leggings", 316);
|
||||
IDS.put("golden_boots", 317);
|
||||
IDS.put("flint", 318);
|
||||
IDS.put("porkchop", 319);
|
||||
IDS.put("cooked_porkchop", 320);
|
||||
IDS.put("painting", 321);
|
||||
IDS.put("golden_apple", 322);
|
||||
IDS.put("sign", 323);
|
||||
IDS.put("wooden_door", 324);
|
||||
IDS.put("bucket", 325);
|
||||
IDS.put("water_bucket", 326);
|
||||
IDS.put("lava_bucket", 327);
|
||||
IDS.put("minecart", 328);
|
||||
IDS.put("saddle", 329);
|
||||
IDS.put("iron_door", 330);
|
||||
IDS.put("redstone", 331);
|
||||
IDS.put("snowball", 332);
|
||||
IDS.put("boat", 333);
|
||||
IDS.put("leather", 334);
|
||||
IDS.put("milk_bucket", 335);
|
||||
IDS.put("brick", 336);
|
||||
IDS.put("clay_ball", 337);
|
||||
IDS.put("reeds", 338);
|
||||
IDS.put("paper", 339);
|
||||
IDS.put("book", 340);
|
||||
IDS.put("slime_ball", 341);
|
||||
IDS.put("chest_minecart", 342);
|
||||
IDS.put("furnace_minecart", 343);
|
||||
IDS.put("egg", 344);
|
||||
IDS.put("compass", 345);
|
||||
IDS.put("fishing_rod", 346);
|
||||
IDS.put("clock", 347);
|
||||
IDS.put("glowstone_dust", 348);
|
||||
IDS.put("fish", 349);
|
||||
IDS.put("cooked_fish", 350);
|
||||
IDS.put("dye", 351);
|
||||
IDS.put("bone", 352);
|
||||
IDS.put("sugar", 353);
|
||||
IDS.put("cake", 354);
|
||||
IDS.put("bed", 355);
|
||||
IDS.put("repeater", 356);
|
||||
IDS.put("cookie", 357);
|
||||
IDS.put("filled_map", 358);
|
||||
IDS.put("shears", 359);
|
||||
IDS.put("melon", 360);
|
||||
IDS.put("pumpkin_seeds", 361);
|
||||
IDS.put("melon_seeds", 362);
|
||||
IDS.put("beef", 363);
|
||||
IDS.put("cooked_beef", 364);
|
||||
IDS.put("chicken", 365);
|
||||
IDS.put("cooked_chicken", 366);
|
||||
IDS.put("rotten_flesh", 367);
|
||||
IDS.put("ender_pearl", 368);
|
||||
IDS.put("blaze_rod", 369);
|
||||
IDS.put("ghast_tear", 370);
|
||||
IDS.put("gold_nugget", 371);
|
||||
IDS.put("nether_wart", 372);
|
||||
IDS.put("potion", 373);
|
||||
IDS.put("glass_bottle", 374);
|
||||
IDS.put("spider_eye", 375);
|
||||
IDS.put("fermented_spider_eye", 376);
|
||||
IDS.put("blaze_powder", 377);
|
||||
IDS.put("magma_cream", 378);
|
||||
IDS.put("brewing_stand", 379);
|
||||
IDS.put("cauldron", 380);
|
||||
IDS.put("ender_eye", 381);
|
||||
IDS.put("speckled_melon", 382);
|
||||
IDS.put("spawn_egg", 383);
|
||||
IDS.put("experience_bottle", 384);
|
||||
IDS.put("fire_charge", 385);
|
||||
IDS.put("writable_book", 386);
|
||||
IDS.put("written_book", 387);
|
||||
IDS.put("emerald", 388);
|
||||
IDS.put("item_frame", 389);
|
||||
IDS.put("flower_pot", 390);
|
||||
IDS.put("carrot", 391);
|
||||
IDS.put("potato", 392);
|
||||
IDS.put("baked_potato", 393);
|
||||
IDS.put("poisonous_potato", 394);
|
||||
IDS.put("map", 395);
|
||||
IDS.put("golden_carrot", 396);
|
||||
IDS.put("skull", 397);
|
||||
IDS.put("carrot_on_a_stick", 398);
|
||||
IDS.put("nether_star", 399);
|
||||
IDS.put("pumpkin_pie", 400);
|
||||
IDS.put("fireworks", 401);
|
||||
IDS.put("firework_charge", 402);
|
||||
IDS.put("enchanted_book", 403);
|
||||
IDS.put("comparator", 404);
|
||||
IDS.put("netherbrick", 405);
|
||||
IDS.put("quartz", 406);
|
||||
IDS.put("tnt_minecart", 407);
|
||||
IDS.put("hopper_minecart", 408);
|
||||
IDS.put("prismarine_shard", 409);
|
||||
IDS.put("prismarine_crystals", 410);
|
||||
IDS.put("rabbit", 411);
|
||||
IDS.put("cooked_rabbit", 412);
|
||||
IDS.put("rabbit_stew", 413);
|
||||
IDS.put("rabbit_foot", 414);
|
||||
IDS.put("rabbit_hide", 415);
|
||||
IDS.put("armor_stand", 416);
|
||||
IDS.put("iron_horse_armor", 417);
|
||||
IDS.put("golden_horse_armor", 418);
|
||||
IDS.put("diamond_horse_armor", 419);
|
||||
IDS.put("lead", 420);
|
||||
IDS.put("name_tag", 421);
|
||||
IDS.put("command_block_minecart", 422);
|
||||
IDS.put("mutton", 423);
|
||||
IDS.put("cooked_mutton", 424);
|
||||
IDS.put("banner", 425);
|
||||
IDS.put("end_crystal", 426);
|
||||
IDS.put("spruce_door", 427);
|
||||
IDS.put("birch_door", 428);
|
||||
IDS.put("jungle_door", 429);
|
||||
IDS.put("acacia_door", 430);
|
||||
IDS.put("dark_oak_door", 431);
|
||||
IDS.put("chorus_fruit", 432);
|
||||
IDS.put("chorus_fruit_popped", 433);
|
||||
IDS.put("beetroot", 434);
|
||||
IDS.put("beetroot_seeds", 435);
|
||||
IDS.put("beetroot_soup", 436);
|
||||
IDS.put("dragon_breath", 437);
|
||||
IDS.put("splash_potion", 438);
|
||||
IDS.put("spectral_arrow", 439);
|
||||
IDS.put("tipped_arrow", 440);
|
||||
IDS.put("lingering_potion", 441);
|
||||
IDS.put("shield", 442);
|
||||
IDS.put("elytra", 443);
|
||||
IDS.put("spruce_boat", 444);
|
||||
IDS.put("birch_boat", 445);
|
||||
IDS.put("jungle_boat", 446);
|
||||
IDS.put("acacia_boat", 447);
|
||||
IDS.put("dark_oak_boat", 448);
|
||||
IDS.put("totem_of_undying", 449);
|
||||
IDS.put("shulker_shell", 450);
|
||||
IDS.put("iron_nugget", 452);
|
||||
IDS.put("knowledge_book", 453);
|
||||
IDS.put("record_13", 2256);
|
||||
IDS.put("record_cat", 2257);
|
||||
IDS.put("record_blocks", 2258);
|
||||
IDS.put("record_chirp", 2259);
|
||||
IDS.put("record_far", 2260);
|
||||
IDS.put("record_mall", 2261);
|
||||
IDS.put("record_mellohi", 2262);
|
||||
IDS.put("record_stal", 2263);
|
||||
IDS.put("record_strad", 2264);
|
||||
IDS.put("record_ward", 2265);
|
||||
IDS.put("record_11", 2266);
|
||||
IDS.put("record_wait", 2267);
|
||||
}
|
||||
|
||||
public static int getId(final String identifier, final int def) {
|
||||
int id = IDS.getOrDefault(Key.stripMinecraftNamespace(identifier), -1);
|
||||
if (id == -1) {
|
||||
try {
|
||||
final int parsedId = Integer.parseInt(identifier);
|
||||
if (IDS.containsValue(parsedId)) {
|
||||
id = parsedId;
|
||||
}
|
||||
} catch (final NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
return id != -1 ? id : def;
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -30,6 +30,8 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.ItemIds1_12_2;
|
||||
import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1;
|
||||
import com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
@@ -61,18 +63,25 @@ public class ComponentRewriter1_13<C extends ClientboundPacketType> extends Json
|
||||
return;
|
||||
}
|
||||
|
||||
final String idTag = tag.getString("id", "");
|
||||
final CompoundTag itemTag = tag.getCompoundTag("tag");
|
||||
final NumberTag damageTag = tag.getNumberTag("Damage");
|
||||
|
||||
// Call item converter
|
||||
final int id = ItemIds1_12_2.getId(idTag, 1);
|
||||
|
||||
final short damage = damageTag != null ? damageTag.asShort() : 0;
|
||||
|
||||
final Item item = new DataItem();
|
||||
item.setIdentifier(id);
|
||||
item.setData(damage);
|
||||
item.setTag(itemTag);
|
||||
protocol.getItemRewriter().handleItemToClient(null, item);
|
||||
|
||||
// Serialize again
|
||||
if (id != item.identifier()) {
|
||||
tag.putString("id", Protocol1_13To1_13_1.MAPPINGS.getFullItemMappings().identifier(item.identifier()));
|
||||
}
|
||||
if (damage != item.data()) {
|
||||
tag.put("Damage", new ShortTag(item.data()));
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class TabCompleteTracker implements StorableObject {
|
||||
wrapper.write(Types.BOOLEAN, false);
|
||||
final BlockPosition playerLookTarget = Via.getManager().getProviders().get(PlayerLookTargetProvider.class).getPlayerLookTarget(connection);
|
||||
wrapper.write(Types.OPTIONAL_POSITION1_8, playerLookTarget);
|
||||
wrapper.scheduleSendToServer(Protocol1_12_2To1_13.class);
|
||||
wrapper.sendToServer(Protocol1_12_2To1_13.class);
|
||||
lastTabComplete = null;
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -18,18 +18,17 @@
|
||||
package com.viaversion.viaversion.protocols.v1_12_2to1_13.task;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocol.ProtocolRunnable;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viaversion.connection.StorableObjectTask;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.storage.TabCompleteTracker;
|
||||
|
||||
public final class TabCompleteTask extends ProtocolRunnable {
|
||||
public final class TabCompleteTask extends StorableObjectTask<TabCompleteTracker> {
|
||||
|
||||
public TabCompleteTask() {
|
||||
super(Protocol1_12_2To1_13.class);
|
||||
super(TabCompleteTracker.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final UserConnection connection) {
|
||||
connection.get(TabCompleteTracker.class).sendPacketToServer(connection);
|
||||
public void run(final UserConnection connection, final TabCompleteTracker storableObject) {
|
||||
storableObject.sendPacketToServer(connection);
|
||||
}
|
||||
}
|
||||
+7
@@ -44,11 +44,13 @@ import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viaversion.util.ProtocolLogger;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_13, ClientboundPackets1_14, ServerboundPackets1_13, ServerboundPackets1_14> {
|
||||
|
||||
public static final MappingData1_14 MAPPINGS = new MappingData1_14();
|
||||
public static final ProtocolLogger LOGGER = new ProtocolLogger(Protocol1_13_2To1_14.class);
|
||||
private final EntityPacketRewriter1_14 entityRewriter = new EntityPacketRewriter1_14(this);
|
||||
private final ItemPacketRewriter1_14 itemRewriter = new ItemPacketRewriter1_14(this);
|
||||
private final ParticleRewriter<ClientboundPackets1_13> particleRewriter = new ParticleRewriter<>(this);
|
||||
@@ -134,6 +136,11 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolLogger getLogger() {
|
||||
return LOGGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketRewriter1_14 getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
|
||||
+63
-6
@@ -17,19 +17,76 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.ShortTag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ComponentRewriter1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import com.viaversion.viaversion.util.StringUtil;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ComponentRewriter1_14<C extends ClientboundPacketType> extends ComponentRewriter1_13<C> {
|
||||
public final class ComponentRewriter1_14<C extends ClientboundPacketType> extends JsonNBTComponentRewriter<C> {
|
||||
|
||||
public ComponentRewriter1_14(Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
public ComponentRewriter1_14(final Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol, ReadType.JSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject object, String translate) {
|
||||
// Nothing
|
||||
protected void handleHoverEvent(UserConnection connection, JsonObject hoverEvent) {
|
||||
super.handleHoverEvent(connection, hoverEvent);
|
||||
final String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
|
||||
if (!action.equals("show_item")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final JsonElement value = hoverEvent.get("value");
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CompoundTag tag;
|
||||
try {
|
||||
tag = ComponentUtil.deserializeLegacyShowItem(value, SerializerVersion.V1_13);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressTextComponentConversionWarnings()) {
|
||||
Protocol1_13_2To1_14.LOGGER.log(Level.WARNING, "Error reading NBT in show_item: " + StringUtil.forLogging(value), e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final CompoundTag itemTag = tag.getCompoundTag("tag");
|
||||
|
||||
// Call item converter
|
||||
final Item item = new DataItem();
|
||||
item.setTag(itemTag);
|
||||
protocol.getItemRewriter().handleItemToClient(null, item);
|
||||
|
||||
// Serialize again
|
||||
if (itemTag != null) {
|
||||
tag.put("tag", itemTag);
|
||||
}
|
||||
|
||||
final JsonArray newValue = new JsonArray();
|
||||
final JsonObject showItem = new JsonObject();
|
||||
newValue.add(showItem);
|
||||
try {
|
||||
showItem.addProperty("text", SerializerVersion.V1_14.toSNBT(tag));
|
||||
hoverEvent.add("value", newValue);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressTextComponentConversionWarnings()) {
|
||||
Protocol1_13_2To1_14.LOGGER.log(Level.WARNING, "Error writing NBT in show_item: " + StringUtil.forLogging(value), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
-5
@@ -52,6 +52,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.EntityPacket
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.ParticleRewriter1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ScoreboardTeamStorage;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.TagKeys;
|
||||
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
@@ -60,6 +61,9 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter;
|
||||
import com.viaversion.viaversion.util.ProtocolLogger;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
|
||||
@@ -222,6 +226,53 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
wrapper.write(Types.BOOLEAN, strictErrorHandling);
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_20_3.SET_PLAYER_TEAM, wrapper -> {
|
||||
final ScoreboardTeamStorage storage = wrapper.user().get(ScoreboardTeamStorage.class);
|
||||
|
||||
final String teamName = wrapper.passthrough(Types.STRING);
|
||||
final byte action = wrapper.passthrough(Types.BYTE);
|
||||
if (action == 0) {
|
||||
wrapper.passthrough(Types.TAG); // Display name
|
||||
wrapper.passthrough(Types.BYTE); // Flags
|
||||
wrapper.passthrough(Types.STRING); // Name Tag Visibility
|
||||
wrapper.passthrough(Types.STRING); // Collision rule
|
||||
wrapper.passthrough(Types.VAR_INT); // Color
|
||||
wrapper.passthrough(Types.TAG); // Prefix
|
||||
wrapper.passthrough(Types.TAG); // Suffix
|
||||
storage.createTeam(teamName);
|
||||
final String[] players = wrapper.passthrough(Types.STRING_ARRAY);
|
||||
storage.addPlayerToTeam(teamName, players);
|
||||
} else if (action == 1) {
|
||||
storage.removeTeam(teamName);
|
||||
} else if (action == 3) {
|
||||
final String[] players = wrapper.passthrough(Types.STRING_ARRAY);
|
||||
storage.addPlayerToTeam(teamName, players);
|
||||
}
|
||||
|
||||
if (action != 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] players = wrapper.read(Types.STRING_ARRAY);
|
||||
// Drop invalid remove packets to not break when plugins do that, since strict error handling is enforced in newer protocols.
|
||||
final Set<String> filteredPlayers = new HashSet<>();
|
||||
for (final String player : players) {
|
||||
final String team = storage.getPlayerTeam(player);
|
||||
if (!Objects.equals(team, teamName)) {
|
||||
break;
|
||||
}
|
||||
|
||||
storage.removeFromTeam(teamName, player);
|
||||
filteredPlayers.add(player);
|
||||
}
|
||||
|
||||
if (!filteredPlayers.isEmpty()) {
|
||||
wrapper.write(Types.STRING_ARRAY, filteredPlayers.toArray(new String[0]));
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
cancelServerbound(State.LOGIN, ServerboundLoginPackets.COOKIE_RESPONSE.getId());
|
||||
cancelServerbound(ServerboundConfigurationPackets1_20_5.COOKIE_RESPONSE);
|
||||
cancelServerbound(ServerboundConfigurationPackets1_20_5.SELECT_KNOWN_PACKS);
|
||||
@@ -277,13 +328,13 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
.add(StructuredDataKey.MAP_ID).add(StructuredDataKey.MAP_DECORATIONS).add(StructuredDataKey.MAP_POST_PROCESSING)
|
||||
.add(StructuredDataKey.POTION_CONTENTS1_20_5)
|
||||
.add(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS).add(StructuredDataKey.WRITABLE_BOOK_CONTENT).add(StructuredDataKey.WRITTEN_BOOK_CONTENT)
|
||||
.add(StructuredDataKey.TRIM1_20_5).add(StructuredDataKey.DEBUG_STICK_STATE).add(StructuredDataKey.ENTITY_DATA)
|
||||
.add(StructuredDataKey.BUCKET_ENTITY_DATA).add(StructuredDataKey.BLOCK_ENTITY_DATA).add(StructuredDataKey.INSTRUMENT1_20_5)
|
||||
.add(StructuredDataKey.TRIM1_20_5).add(StructuredDataKey.DEBUG_STICK_STATE).add(StructuredDataKey.ENTITY_DATA1_20_5)
|
||||
.add(StructuredDataKey.BUCKET_ENTITY_DATA).add(StructuredDataKey.BLOCK_ENTITY_DATA1_20_5).add(StructuredDataKey.INSTRUMENT1_20_5)
|
||||
.add(StructuredDataKey.RECIPES).add(StructuredDataKey.LODESTONE_TRACKER).add(StructuredDataKey.FIREWORK_EXPLOSION)
|
||||
.add(StructuredDataKey.FIREWORKS).add(StructuredDataKey.PROFILE).add(StructuredDataKey.NOTE_BLOCK_SOUND)
|
||||
.add(StructuredDataKey.FIREWORKS).add(StructuredDataKey.PROFILE1_20_5).add(StructuredDataKey.NOTE_BLOCK_SOUND)
|
||||
.add(StructuredDataKey.BANNER_PATTERNS).add(StructuredDataKey.BASE_COLOR).add(StructuredDataKey.POT_DECORATIONS)
|
||||
.add(StructuredDataKey.BLOCK_STATE).add(StructuredDataKey.BEES)
|
||||
.add(StructuredDataKey.LOCK).add(StructuredDataKey.CONTAINER_LOOT).add(StructuredDataKey.TOOL1_20_5)
|
||||
.add(StructuredDataKey.BLOCK_STATE).add(StructuredDataKey.BEES1_20_5)
|
||||
.add(StructuredDataKey.LOCK1_20_5).add(StructuredDataKey.CONTAINER_LOOT).add(StructuredDataKey.TOOL1_20_5)
|
||||
.add(StructuredDataKey.ITEM_NAME).add(StructuredDataKey.OMINOUS_BOTTLE_AMPLIFIER)
|
||||
.add(VersionedTypes.V1_20_5.structuredDataKeys().keys());
|
||||
|
||||
@@ -300,6 +351,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_20_5.PLAYER));
|
||||
connection.put(new AcknowledgedMessagesStorage());
|
||||
connection.put(new ArmorTrimStorage());
|
||||
connection.put(new ScoreboardTeamStorage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-10
@@ -21,6 +21,7 @@ import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
|
||||
import com.viaversion.viaversion.util.KeyMappings;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
@@ -30,8 +31,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public class MappingData1_20_5 extends MappingDataBase {
|
||||
|
||||
private final Object2ObjectMap<String, CompoundTag> damageTypes = new Object2ObjectOpenHashMap<>();
|
||||
private KeyMappings blocks;
|
||||
private KeyMappings sounds;
|
||||
|
||||
public MappingData1_20_5() {
|
||||
super("1.20.3", "1.20.5");
|
||||
@@ -41,10 +40,6 @@ public class MappingData1_20_5 extends MappingDataBase {
|
||||
protected void loadExtras(final CompoundTag data) {
|
||||
super.loadExtras(data);
|
||||
|
||||
final CompoundTag extraMappings = MappingDataLoader.INSTANCE.loadNBT("extra-identifiers-1.20.3.nbt");
|
||||
blocks = new KeyMappings(extraMappings.getListTag("blocks", StringTag.class));
|
||||
sounds = new KeyMappings(extraMappings.getListTag("sounds", StringTag.class));
|
||||
|
||||
final CompoundTag damageTypes = MappingDataLoader.INSTANCE.loadNBT("damage-types-1.20.3.nbt");
|
||||
for (final String key : damageTypes.keySet()) {
|
||||
this.damageTypes.put(key, damageTypes.getCompoundTag(key));
|
||||
@@ -52,19 +47,19 @@ public class MappingData1_20_5 extends MappingDataBase {
|
||||
}
|
||||
|
||||
public int blockId(final String name) {
|
||||
return blocks.keyToId(name);
|
||||
return Protocol1_20_3To1_20_5.MAPPINGS.getFullBlockMappings().id(name);
|
||||
}
|
||||
|
||||
public @Nullable String blockName(final int id) {
|
||||
return blocks.idToKey(id);
|
||||
return Protocol1_20_3To1_20_5.MAPPINGS.getFullBlockMappings().identifier(id);
|
||||
}
|
||||
|
||||
public int soundId(final String name) {
|
||||
return sounds.keyToId(name);
|
||||
return Protocol1_20_3To1_20_5.MAPPINGS.getFullSoundMappings().id(name);
|
||||
}
|
||||
|
||||
public @Nullable String soundName(final int id) {
|
||||
return sounds.idToKey(id);
|
||||
return Protocol1_20_3To1_20_5.MAPPINGS.getFullSoundMappings().identifier(id);
|
||||
}
|
||||
|
||||
public CompoundTag damageType(final String key) {
|
||||
|
||||
+8
-7
@@ -54,6 +54,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockPredicate;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DebugStickState;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FilterableComponent;
|
||||
@@ -480,7 +481,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
if (entityTag.contains("id")) {
|
||||
data.set(StructuredDataKey.ENTITY_DATA, entityTag);
|
||||
data.set(StructuredDataKey.ENTITY_DATA1_20_5, entityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,13 +503,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
|
||||
// Not always needed, e.g. shields that had the base color in a block entity tag before
|
||||
if (clonedTag.contains("id")) {
|
||||
item.dataContainer().set(StructuredDataKey.BLOCK_ENTITY_DATA, clonedTag);
|
||||
item.dataContainer().set(StructuredDataKey.BLOCK_ENTITY_DATA1_20_5, clonedTag);
|
||||
}
|
||||
}
|
||||
|
||||
final CompoundTag debugProperty = tag.getCompoundTag("DebugProperty");
|
||||
if (debugProperty != null) {
|
||||
data.set(StructuredDataKey.DEBUG_STICK_STATE, debugProperty.copy());
|
||||
data.set(StructuredDataKey.DEBUG_STICK_STATE, new DebugStickState(debugProperty.copy()));
|
||||
}
|
||||
|
||||
final NumberTag unbreakable = tag.getNumberTag("Unbreakable");
|
||||
@@ -1300,7 +1301,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
if (skullOwnerTag instanceof StringTag nameTag) {
|
||||
final String name = nameTag.getValue();
|
||||
if (isValidName(name)) {
|
||||
data.set(StructuredDataKey.PROFILE, new GameProfile(name, null, EMPTY_PROPERTIES));
|
||||
data.set(StructuredDataKey.PROFILE1_20_5, new GameProfile(name, null, EMPTY_PROPERTIES));
|
||||
}
|
||||
} else if (skullOwnerTag instanceof CompoundTag skullOwner) {
|
||||
String name = skullOwner.getString("Name", "");
|
||||
@@ -1320,7 +1321,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
updateProperties(propertiesTag, properties);
|
||||
}
|
||||
|
||||
data.set(StructuredDataKey.PROFILE, new GameProfile(name, uuid, properties.toArray(EMPTY_PROPERTIES)));
|
||||
data.set(StructuredDataKey.PROFILE1_20_5, new GameProfile(name, uuid, properties.toArray(EMPTY_PROPERTIES)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1344,7 +1345,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
return new Bee(entityData, ticksInHive, minOccupationTicks);
|
||||
}).filter(Objects::nonNull).toArray(Bee[]::new);
|
||||
|
||||
data.set(StructuredDataKey.BEES, bees);
|
||||
data.set(StructuredDataKey.BEES1_20_5, bees);
|
||||
}
|
||||
|
||||
private void updateProperties(final CompoundTag propertiesTag, final List<GameProfile.Property> properties) {
|
||||
@@ -1448,7 +1449,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
if (data != null) {
|
||||
final StringTag lockTag = tag.getStringTag("Lock");
|
||||
if (lockTag != null) {
|
||||
data.set(StructuredDataKey.LOCK, lockTag);
|
||||
data.set(StructuredDataKey.LOCK1_20_5, lockTag);
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> beesTag = tag.getListTag("Bees", CompoundTag.class);
|
||||
|
||||
+13
-12
@@ -52,6 +52,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockPredicate;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DebugStickState;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FilterableComponent;
|
||||
@@ -155,25 +156,25 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Js
|
||||
register(StructuredDataKey.WRITABLE_BOOK_CONTENT, this::writableBookContentToTag, this::writableBookContentFromTag);
|
||||
register(StructuredDataKey.WRITTEN_BOOK_CONTENT, this::writtenBookContentToTag, this::writtenBookContentFromTag);
|
||||
register(StructuredDataKey.TRIM1_20_5, this::trimToTag, this::trimFromTag);
|
||||
register(StructuredDataKey.DEBUG_STICK_STATE, this::debugStickRateToTag, this::debugStickRateFromTag);
|
||||
register(StructuredDataKey.ENTITY_DATA, this::entityDataToTag, this::entityDataFromTag);
|
||||
register(StructuredDataKey.DEBUG_STICK_STATE, this::debugStickStateToTag, this::debugStickStateFromTag);
|
||||
register(StructuredDataKey.ENTITY_DATA1_20_5, this::entityDataToTag, this::entityDataFromTag);
|
||||
register(StructuredDataKey.BUCKET_ENTITY_DATA, this::bucketEntityDataToTag, this::bucketEntityDataFromTag);
|
||||
register(StructuredDataKey.BLOCK_ENTITY_DATA, this::blockEntityDataToTag, this::blockEntityDataFromTag);
|
||||
register(StructuredDataKey.BLOCK_ENTITY_DATA1_20_5, this::blockEntityDataToTag, this::blockEntityDataFromTag);
|
||||
register(StructuredDataKey.INSTRUMENT1_20_5, this::instrumentToTag, this::instrumentFromTag);
|
||||
register(StructuredDataKey.OMINOUS_BOTTLE_AMPLIFIER, this::ominousBottleAmplifierToTag, this::ominousBottleAmplifierFromTag);
|
||||
register(StructuredDataKey.RECIPES, this::recipesToTag, this::recipesFromTag);
|
||||
register(StructuredDataKey.LODESTONE_TRACKER, this::lodestoneTrackerToTag, this::lodestoneTrackerFromTag);
|
||||
register(StructuredDataKey.FIREWORK_EXPLOSION, this::fireworkExplosionToTag, this::fireworkExplosionFromTag);
|
||||
register(StructuredDataKey.FIREWORKS, this::fireworksToTag, this::fireworksFromTag);
|
||||
register(StructuredDataKey.PROFILE, this::profileToTag, this::profileFromTag);
|
||||
register(StructuredDataKey.PROFILE1_20_5, this::profileToTag, this::profileFromTag);
|
||||
register(StructuredDataKey.NOTE_BLOCK_SOUND, this::noteBlockSoundToTag, this::noteBlockSoundFromTag);
|
||||
register(StructuredDataKey.BANNER_PATTERNS, this::bannerPatternsToTag, this::bannerPatternsFromTag);
|
||||
register(StructuredDataKey.BASE_COLOR, this::baseColorToTag, this::baseColorFromTag);
|
||||
register(StructuredDataKey.POT_DECORATIONS, this::potDecorationsToTag, this::potDecorationsFromTag);
|
||||
register(StructuredDataKey.V1_20_5.container, this::containerToTag, this::containerFromTag);
|
||||
register(StructuredDataKey.BLOCK_STATE, this::blockStateToTag, this::blockStateFromTag);
|
||||
register(StructuredDataKey.BEES, this::beesToTag, this::beesFromTag);
|
||||
register(StructuredDataKey.LOCK, this::lockToTag, this::lockFromTag);
|
||||
register(StructuredDataKey.BEES1_20_5, this::beesToTag, this::beesFromTag);
|
||||
register(StructuredDataKey.LOCK1_20_5, this::lockToTag, this::lockFromTag);
|
||||
register(StructuredDataKey.CONTAINER_LOOT, this::containerLootToTag, this::containerLootFromTag);
|
||||
}
|
||||
|
||||
@@ -1058,12 +1059,12 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Js
|
||||
return new ArmorTrim(material, pattern, showInTooltip);
|
||||
}
|
||||
|
||||
protected CompoundTag debugStickRateToTag(final CompoundTag value) {
|
||||
return value;
|
||||
protected CompoundTag debugStickStateToTag(final DebugStickState value) {
|
||||
return value.tag();
|
||||
}
|
||||
|
||||
protected CompoundTag debugStickRateFromTag(final Tag value) {
|
||||
return (CompoundTag) value;
|
||||
protected DebugStickState debugStickStateFromTag(final Tag value) {
|
||||
return new DebugStickState((CompoundTag) value);
|
||||
}
|
||||
|
||||
protected CompoundTag entityDataToTag(final CompoundTag value) {
|
||||
@@ -1386,8 +1387,8 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Js
|
||||
final ListTag<CompoundTag> tag = new ListTag<>(CompoundTag.class);
|
||||
for (final Bee bee : value) {
|
||||
final CompoundTag beeTag = new CompoundTag();
|
||||
if (!bee.entityData().isEmpty()) {
|
||||
beeTag.put("entity_data", nbtToTag(bee.entityData()));
|
||||
if (!bee.entityData().tag().isEmpty()) {
|
||||
beeTag.put("entity_data", nbtToTag(bee.entityData().tag()));
|
||||
}
|
||||
beeTag.putInt("ticks_in_hive", bee.ticksInHive());
|
||||
beeTag.putInt("min_ticks_in_hive", bee.minTicksInHive());
|
||||
|
||||
+3
@@ -48,6 +48,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundCon
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ScoreboardTeamStorage;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.KeyMappings;
|
||||
@@ -297,6 +298,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
|
||||
final byte gamemode = wrapper.passthrough(Types.BYTE);
|
||||
sendRangeAttributes(wrapper.user(), gamemode == GameMode.CREATIVE.id());
|
||||
|
||||
wrapper.user().put(new ScoreboardTeamStorage());
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_3.UPDATE_MOB_EFFECT, wrapper -> {
|
||||
|
||||
+7
-7
@@ -250,7 +250,7 @@ public final class StructuredDataConverter {
|
||||
}
|
||||
});
|
||||
register(StructuredDataKey.FIREWORK_EXPLOSION, (data, tag) -> tag.put("Explosion", convertExplosion(data)));
|
||||
register(StructuredDataKey.PROFILE, (data, tag) -> {
|
||||
register(StructuredDataKey.PROFILE1_20_5, (data, tag) -> {
|
||||
if (data.name() != null && data.id() == null && data.properties().length == 0) {
|
||||
tag.putString("SkullOwner", data.name());
|
||||
return;
|
||||
@@ -307,18 +307,18 @@ public final class StructuredDataConverter {
|
||||
tag.putString("instrument", identifier);
|
||||
}
|
||||
});
|
||||
register(StructuredDataKey.BEES, (data, tag) -> {
|
||||
register(StructuredDataKey.BEES1_20_5, (data, tag) -> {
|
||||
final ListTag<CompoundTag> bees = new ListTag<>(CompoundTag.class);
|
||||
for (final Bee bee : data) {
|
||||
final CompoundTag beeTag = new CompoundTag();
|
||||
beeTag.put("EntityData", bee.entityData());
|
||||
beeTag.put("EntityData", bee.entityData().tag());
|
||||
beeTag.putInt("TicksInHive", bee.ticksInHive());
|
||||
beeTag.putInt("MinOccupationTicks", bee.minTicksInHive());
|
||||
bees.add(beeTag);
|
||||
}
|
||||
getBlockEntityTag(tag, "beehive").put("Bees", bees);
|
||||
});
|
||||
register(StructuredDataKey.LOCK, (data, tag) -> getBlockEntityTag(tag).put("Lock", data));
|
||||
register(StructuredDataKey.LOCK1_20_5, (data, tag) -> getBlockEntityTag(tag).put("Lock", data));
|
||||
register(StructuredDataKey.NOTE_BLOCK_SOUND, (data, tag) -> getBlockEntityTag(tag, "player_head").putString("note_block_sound", data.original()));
|
||||
register(StructuredDataKey.POT_DECORATIONS, (data, tag) -> {
|
||||
IntArrayTag originalSherds = null;
|
||||
@@ -341,9 +341,9 @@ public final class StructuredDataConverter {
|
||||
}
|
||||
getBlockEntityTag(tag, "decorated_pot").put("sherds", sherds);
|
||||
});
|
||||
register(StructuredDataKey.DEBUG_STICK_STATE, (data, tag) -> tag.put("DebugProperty", data));
|
||||
register(StructuredDataKey.DEBUG_STICK_STATE, (data, tag) -> tag.put("DebugProperty", data.tag()));
|
||||
register(StructuredDataKey.RECIPES, (data, tag) -> tag.put("Recipes", data));
|
||||
register(StructuredDataKey.ENTITY_DATA, (data, tag) -> tag.put("EntityTag", data));
|
||||
register(StructuredDataKey.ENTITY_DATA1_20_5, (data, tag) -> tag.put("EntityTag", data));
|
||||
register(StructuredDataKey.BUCKET_ENTITY_DATA, (data, tag) -> {
|
||||
for (final String mobTagName : BlockItemPacketRewriter1_20_5.MOB_TAGS) {
|
||||
if (data.contains(mobTagName)) {
|
||||
@@ -351,7 +351,7 @@ public final class StructuredDataConverter {
|
||||
}
|
||||
}
|
||||
});
|
||||
register(StructuredDataKey.BLOCK_ENTITY_DATA, (data, tag) -> {
|
||||
register(StructuredDataKey.BLOCK_ENTITY_DATA1_20_5, (data, tag) -> {
|
||||
// Handling of previously block entity tags is done using the getBlockEntityTag method
|
||||
// Merge with already added tag if needed
|
||||
final CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag");
|
||||
|
||||
Loaded 100 of 197 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user