Compare commits
246 Commits
4074231a57
...
d28e7cd652
Author | SHA1 | Date |
---|---|---|
Nassim Jahnke | d28e7cd652 | |
Nassim Jahnke | f20d99fcef | |
Nassim Jahnke | a1c182f291 | |
Nassim Jahnke | 8e63fd635b | |
FlorianMichael | 676e62c71f | |
FlorianMichael | f422e03348 | |
Nassim Jahnke | fdf735420f | |
Nassim Jahnke | b13fbbe175 | |
Nassim Jahnke | 9dd3348510 | |
Nassim Jahnke | 0e97af29b4 | |
Nassim Jahnke | 3dfcd6b9b9 | |
Nassim Jahnke | 8df0c0ae2e | |
Nassim Jahnke | d2ca6a82be | |
Nassim Jahnke | 9654a613cd | |
Nassim Jahnke | c5e6fa7d0c | |
Nassim Jahnke | b78f9d350b | |
Nassim Jahnke | ebbe1b6da2 | |
Nassim Jahnke | 3aed7cb949 | |
Nassim Jahnke | e2f3dc7572 | |
Nassim Jahnke | f2b9c42590 | |
Nassim Jahnke | 9894671274 | |
Nassim Jahnke | 71ab15b331 | |
Nassim Jahnke | 34bc5b9d36 | |
Nassim Jahnke | d80fd46c2f | |
Nassim Jahnke | b47446d9f7 | |
EnZaXD | dcf741a2ba | |
Nassim Jahnke | a4adef3cec | |
Nassim Jahnke | f525ad98e7 | |
Nassim Jahnke | bc0b4470f6 | |
Nassim Jahnke | d3d6d4f1cd | |
Nassim Jahnke | 5069b26c2f | |
FlorianMichael | 079671060c | |
Nassim Jahnke | 89cd8aec1d | |
Nassim Jahnke | 7ac7ea485f | |
Nassim Jahnke | 5e4f25efeb | |
Nassim Jahnke | a152993ffd | |
Nassim Jahnke | 73daac471c | |
Nassim Jahnke | f4e9225f85 | |
EnZaXD | 1ed22327f6 | |
EnZaXD | ce2ad7d5eb | |
FlorianMichael | d7e66260de | |
FlorianMichael | dc6d581123 | |
FlorianMichael | bd3f1206e6 | |
FlorianMichael | b9e92e5c1f | |
Gero | 0acaed7c7a | |
FlorianMichael | 3055a4277d | |
Gero | bcbe69d24c | |
EnZaXD | 33cc21d6e6 | |
Nassim Jahnke | 949b3d712e | |
Nassim Jahnke | 216dcb2931 | |
Nassim Jahnke | bff1536529 | |
Nassim Jahnke | b221e47eb7 | |
EnZaXD | fb434a79bd | |
Nassim Jahnke | 1be0605f51 | |
Nassim Jahnke | c75b4d8ef5 | |
Gero | e08c263ced | |
Nassim Jahnke | 1bb85b11e9 | |
AJ Ferguson | 128e191132 | |
Nassim Jahnke | 3520f99d5a | |
RaphiMC | 7825a1e460 | |
RK_01 | bfde4b953c | |
Nassim Jahnke | 57b37457d6 | |
Nassim Jahnke | f7aa1a516e | |
Nassim Jahnke | b1468ac6d0 | |
Nassim Jahnke | 27b5fdb4ff | |
Nassim Jahnke | a99273db2e | |
Nassim Jahnke | 64f911ed4a | |
EnZaXD | 4302dd61aa | |
EnZaXD | 98c5d38d0c | |
FlorianMichael | 033d5ae49a | |
Nassim Jahnke | 8cf9114403 | |
EnZaXD | bd8e469216 | |
EnZaXD | 57d7fd59cc | |
EnZaXD | 8fe0681778 | |
EnZaXD | ea5cf3e594 | |
Nassim Jahnke | 13eec3c2ea | |
Nassim Jahnke | 31ccd2ab9b | |
FlorianMichael | 2be190d152 | |
FlorianMichael | 4e25549682 | |
FlorianMichael | 287678c12a | |
FlorianMichael | 4343aa17fc | |
FlorianMichael | 970986bc59 | |
RK_01 | 2586788bf6 | |
EnZaXD | 0c2c8400ae | |
Nassim Jahnke | ba4404fad6 | |
RK_01 | 6f53c069ea | |
Nassim Jahnke | 99f29e2597 | |
EnZaXD | 7932b79080 | |
FlorianMichael | 4b780b92ee | |
Nassim Jahnke | d04aaeb926 | |
FlorianMichael | 9f1ee27afc | |
Nassim Jahnke | 5f685884ff | |
FlorianMichael | ba2e50cc88 | |
FlorianMichael | 7b28683b6a | |
Nassim Jahnke | 510747a7cd | |
Nassim Jahnke | 8c5752bb4c | |
Nassim Jahnke | 33e2a1fc13 | |
Nassim Jahnke | dbe8a389ce | |
Nassim Jahnke | 83223c1520 | |
FlorianMichael | 935077222e | |
FlorianMichael | 8961660846 | |
Nassim Jahnke | 1fe23e4aeb | |
Nassim Jahnke | 06394c1f74 | |
Nassim Jahnke | 68c2af2795 | |
Nassim Jahnke | 35a00d0b95 | |
Nassim Jahnke | c2489c7a4c | |
Nassim Jahnke | c743c20334 | |
FlorianMichael | 228689f181 | |
Nassim Jahnke | 67e6e1a2e3 | |
Nassim Jahnke | a2c1c52f51 | |
Nassim Jahnke | fd4db24d44 | |
Nassim Jahnke | 0b7fdd4c69 | |
Nassim Jahnke | 4849ca0745 | |
Nassim Jahnke | 60b782455d | |
FlorianMichael | 3fef71db2e | |
Nassim Jahnke | 9ca02680c8 | |
FlorianMichael | 5899886b42 | |
Nassim Jahnke | c2567115d8 | |
Nassim Jahnke | 4255876c22 | |
FlorianMichael | 57a589924d | |
Nassim Jahnke | 936dcafc11 | |
Nassim Jahnke | b6489b8343 | |
Nassim Jahnke | bf11a0a7de | |
Nassim Jahnke | 7d41706026 | |
FlorianMichael | 93f081dd84 | |
Nassim Jahnke | 3f82b150d2 | |
Nassim Jahnke | 7a96498f6d | |
FlorianMichael | 817febe605 | |
Nassim Jahnke | bb4a8b73e0 | |
Nassim Jahnke | 8d3492ba30 | |
Nassim Jahnke | 658364b643 | |
Nassim Jahnke | 666b204ebb | |
Nassim Jahnke | bfab9b0c11 | |
Nassim Jahnke | 121f107ff3 | |
Nassim Jahnke | 426bd9aa99 | |
Nassim Jahnke | 7a66bb8e1c | |
Nassim Jahnke | 329abcac7d | |
Nassim Jahnke | 0961de898d | |
Nassim Jahnke | b4ee564aa2 | |
EnZaXD | 73178b504e | |
EnZaXD | d0cc531386 | |
EnZaXD | 617ef10667 | |
EnZaXD | 5569caf610 | |
EnZaXD | 868a5bd24e | |
EnZaXD | b113a82710 | |
EnZaXD | 3ee4c8ed63 | |
EnZaXD | cd65925d6b | |
Nassim Jahnke | 307414eb51 | |
EnZaXD | 51745cb2ef | |
EnZaXD | f44782d21d | |
EnZaXD | 7556f7b8fa | |
EnZaXD | abd58399cd | |
EnZaXD | 0a2fd8f296 | |
EnZaXD | f2c816df72 | |
EnZaXD | 098f7ff3c2 | |
RK_01 | 18f04bf8ea | |
Nassim Jahnke | feefe6f278 | |
Nassim Jahnke | 0a921d9bdc | |
Nassim Jahnke | b426302e76 | |
Nassim Jahnke | 55a0a70264 | |
Nassim Jahnke | 93990c8baa | |
Nassim Jahnke | 386495e168 | |
EnZaXD | 908823c612 | |
Nassim Jahnke | 2d03110f08 | |
Nassim Jahnke | 92878a39ef | |
Nassim Jahnke | aa0423c6e2 | |
Nassim Jahnke | 39180e22b8 | |
Nassim Jahnke | f68aed464d | |
Nassim Jahnke | 6ffa24b50b | |
Nassim Jahnke | e51d7b3fdb | |
Nassim Jahnke | 01bb8dedda | |
EnZaXD | 6cdca97d35 | |
RK_01 | 4cf271af81 | |
Nassim Jahnke | aa262bb0a5 | |
Nassim Jahnke | 2480eb6a7f | |
Nassim Jahnke | 56b82b049a | |
EnZaXD | 3c0930c62f | |
EnZaXD | 26a8e5fef1 | |
caramel | caa6519780 | |
caramel | 1e35c2713f | |
caramel | cd5d88c34f | |
EnZaXD | 7640342165 | |
Nassim Jahnke | 4e1d4a75b2 | |
EnZaXD | 343b403cf1 | |
RK_01 | 78aecbddf8 | |
Nassim Jahnke | 48241ba841 | |
Nassim Jahnke | a8fbb000eb | |
EnZaXD | ff25cbd6eb | |
Nassim Jahnke | e2a7e10312 | |
EnZaXD | c7baa27fd0 | |
Nassim Jahnke | 35578372a1 | |
EnZaXD | 293427c172 | |
EnZaXD | 08d8ccf6ca | |
EnZaXD | 35ceee1a47 | |
Nassim Jahnke | dccda57fc0 | |
Nassim Jahnke | 5c21f60ef7 | |
Nassim Jahnke | c124c1c809 | |
EnZaXD | 302716054d | |
Nassim Jahnke | 46a5bb16d7 | |
EnZaXD | f3f7ea7987 | |
EnZaXD | e62c4a3f9e | |
EnZaXD | d58c80cd2f | |
Nassim Jahnke | 7a6c51331b | |
Nassim Jahnke | 564286d742 | |
Nassim Jahnke | dcc0642af9 | |
EnZaXD | e449599ae7 | |
Nassim Jahnke | 621c02f974 | |
Nassim Jahnke | 22bd350e35 | |
Nassim Jahnke | a8dc5f0f07 | |
Nassim Jahnke | d76edced04 | |
Nassim Jahnke | e0f32d9f2f | |
Nassim Jahnke | 4a8bd2cca2 | |
Nassim Jahnke | 0fcb764652 | |
Nassim Jahnke | 46e322b2f3 | |
Nassim Jahnke | e020c616c9 | |
Nassim Jahnke | da87241549 | |
Nassim Jahnke | 6473b608f6 | |
Nassim Jahnke | a5bd8abe93 | |
Nassim Jahnke | c8d339ab30 | |
Nassim Jahnke | 8000561ae9 | |
Nassim Jahnke | 1dafa7d273 | |
Nassim Jahnke | ce8fab7c44 | |
Nassim Jahnke | 37561705ed | |
Nassim Jahnke | 00176c4a0c | |
Nassim Jahnke | 7b8a33cc78 | |
Nassim Jahnke | ceae2c2094 | |
Nassim Jahnke | 52b9db5029 | |
Nassim Jahnke | 27af372f79 | |
Nassim Jahnke | c4e50efa90 | |
Nassim Jahnke | fa1ae5b9c9 | |
Nassim Jahnke | 8f6784e0e2 | |
Nassim Jahnke | 5d5c98acc6 | |
Nassim Jahnke | 0946c72bdc | |
Nassim Jahnke | 05470c5f1b | |
Nassim Jahnke | 34bd15dec7 | |
Nassim Jahnke | abb05ce902 | |
Nassim Jahnke | fe0fbc7081 | |
RK_01 | 00b8d22cf6 | |
Nassim Jahnke | d62284e9cd | |
Nassim Jahnke | 3904ed4fd7 | |
RK_01 | 64c436c2e1 | |
Kichura | 84b093a997 | |
Nassim Jahnke | 794f401bd0 | |
Nassim Jahnke | dc732fac6f | |
Nassim Jahnke | 2f8114abb1 | |
Nassim Jahnke | 90781c9d27 |
|
@ -10,4 +10,7 @@ ij_java_class_count_to_use_import_on_demand = 999999
|
|||
ij_java_names_count_to_use_import_on_demand = 999999
|
||||
ij_java_imports_layout = *,|,$*
|
||||
ij_java_generate_final_locals = true
|
||||
ij_java_generate_final_parameters = true
|
||||
ij_java_generate_final_parameters = true
|
||||
|
||||
[{*.json,*.yml}]
|
||||
indent_size = 2
|
|
@ -23,7 +23,7 @@
|
|||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.protocol.version.VersionRange;
|
||||
import com.viaversion.viaversion.api.protocol.version.SubVersionRange;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.util.ArrayList;
|
||||
|
@ -42,23 +42,23 @@ public class ProtocolVersion {
|
|||
private static final Int2ObjectMap<ProtocolVersion> versions = new Int2ObjectOpenHashMap<>();
|
||||
private static final List<ProtocolVersion> versionList = new ArrayList<>();
|
||||
|
||||
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new VersionRange("1.4", 6, 7));
|
||||
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new SubVersionRange("1.4", 6, 7));
|
||||
public static final ProtocolVersion v1_5_1 = register(60, "1.5.1");
|
||||
public static final ProtocolVersion v1_5_2 = register(61, "1.5.2");
|
||||
public static final ProtocolVersion v_1_6_1 = register(73, "1.6.1");
|
||||
public static final ProtocolVersion v_1_6_2 = register(74, "1.6.2");
|
||||
public static final ProtocolVersion v_1_6_3 = register(77, "1.6.3");
|
||||
public static final ProtocolVersion v_1_6_4 = register(78, "1.6.4");
|
||||
public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5", new VersionRange("1.7", 0, 5));
|
||||
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new VersionRange("1.7", 6, 10));
|
||||
public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5", new SubVersionRange("1.7", 0, 5));
|
||||
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10));
|
||||
public static final ProtocolVersion v1_8 = register(47, "1.8.x");
|
||||
public static final ProtocolVersion v1_9 = register(107, "1.9");
|
||||
public static final ProtocolVersion v1_9_1 = register(108, "1.9.1");
|
||||
public static final ProtocolVersion v1_9_2 = register(109, "1.9.2");
|
||||
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/4", new VersionRange("1.9", 3, 4));
|
||||
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/1.9.4", new SubVersionRange("1.9", 3, 4));
|
||||
public static final ProtocolVersion v1_10 = register(210, "1.10.x");
|
||||
public static final ProtocolVersion v1_11 = register(315, "1.11");
|
||||
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/2", new VersionRange("1.11", 1, 2));
|
||||
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/1.11.2", new SubVersionRange("1.11", 1, 2));
|
||||
public static final ProtocolVersion v1_12 = register(335, "1.12");
|
||||
public static final ProtocolVersion v1_12_1 = register(338, "1.12.1");
|
||||
public static final ProtocolVersion v1_12_2 = register(340, "1.12.2");
|
||||
|
@ -77,18 +77,19 @@ public class ProtocolVersion {
|
|||
public static final ProtocolVersion v1_16_1 = register(736, "1.16.1");
|
||||
public static final ProtocolVersion v1_16_2 = register(751, "1.16.2");
|
||||
public static final ProtocolVersion v1_16_3 = register(753, "1.16.3");
|
||||
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/5", new VersionRange("1.16", 4, 5));
|
||||
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/1.16.5", new SubVersionRange("1.16", 4, 5));
|
||||
public static final ProtocolVersion v1_17 = register(755, "1.17");
|
||||
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new SubVersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
|
||||
public static final ProtocolVersion v1_19 = register(759, "1.19");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/2", new VersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/1.19.2", new SubVersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_3 = register(761, "1.19.3");
|
||||
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4));
|
||||
public static final ProtocolVersion v1_20_5 = register(766, "1.20.5");
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
|
@ -99,11 +100,11 @@ public class ProtocolVersion {
|
|||
return register(version, snapshotVersion, name, null);
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, String name, @Nullable VersionRange versionRange) {
|
||||
public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange) {
|
||||
return register(version, -1, name, versionRange);
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange);
|
||||
versionList.add(protocol);
|
||||
versions.put(protocol.getVersion(), protocol);
|
||||
|
@ -166,7 +167,7 @@ public class ProtocolVersion {
|
|||
this(version, -1, name, null);
|
||||
}
|
||||
|
||||
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
|
||||
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
this.version = version;
|
||||
this.snapshotVersion = snapshotVersion;
|
||||
this.name = name;
|
||||
|
|
|
@ -16,8 +16,6 @@ sourceSets {
|
|||
|
||||
dependencies {
|
||||
api(libs.fastutil)
|
||||
api(libs.flare)
|
||||
api(libs.flareFastutil)
|
||||
api(libs.vianbt)
|
||||
api(libs.gson)
|
||||
implementation(rootProject.libs.text) {
|
||||
|
|
|
@ -27,10 +27,13 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
|||
import com.viaversion.viaversion.api.legacy.LegacyViaAPI;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolManager;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -63,7 +66,7 @@ public interface ViaAPI<T> {
|
|||
* @return API version incremented with meaningful API changes
|
||||
*/
|
||||
default int apiVersion() {
|
||||
return 23;
|
||||
return 26;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +83,18 @@ public interface ViaAPI<T> {
|
|||
* @param player the platform's player object, e.g. Bukkit this is Player
|
||||
* @return protocol version, for example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if no longer connected
|
||||
*/
|
||||
int getPlayerVersion(T player);
|
||||
default int getPlayerVersion(T player) {
|
||||
return getPlayerProtocolVersion(player).getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol version of a player.
|
||||
* This will also retrieve the version from ProtocolSupport if it's being used.
|
||||
*
|
||||
* @param player the platform's player object, e.g. Bukkit this is Player
|
||||
* @return the protocol version object (see {@link ProtocolVersion}), or ProtocolVersion.unknown if not connected
|
||||
*/
|
||||
ProtocolVersion getPlayerProtocolVersion(T player);
|
||||
|
||||
/**
|
||||
* Returns the protocol version of a player.
|
||||
|
@ -88,7 +102,19 @@ public interface ViaAPI<T> {
|
|||
* @param uuid UUID of a player
|
||||
* @return protocol version, for example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if not connected
|
||||
*/
|
||||
int getPlayerVersion(UUID uuid);
|
||||
default int getPlayerVersion(UUID uuid) {
|
||||
return getPlayerProtocolVersion(uuid).getVersion();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the protocol version of a player.
|
||||
* This will also retrieve the version from ProtocolSupport if it's being used.
|
||||
*
|
||||
* @param uuid UUID of a player
|
||||
* @return the protocol version object (see {@link ProtocolVersion}), or ProtocolVersion.unknown if not connected
|
||||
*/
|
||||
ProtocolVersion getPlayerProtocolVersion(UUID uuid);
|
||||
|
||||
/**
|
||||
* Returns whether Via injected into this player connection.
|
||||
|
@ -131,6 +157,16 @@ public interface ViaAPI<T> {
|
|||
*/
|
||||
void sendRawPacket(UUID uuid, ByteBuf packet);
|
||||
|
||||
@Deprecated
|
||||
default SortedSet<Integer> getSupportedVersions() {
|
||||
return getSupportedProtocolVersions().stream().map(ProtocolVersion::getVersion).collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default SortedSet<Integer> getFullSupportedVersions() {
|
||||
return getFullSupportedProtocolVersions().stream().map(ProtocolVersion::getVersion).collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the supported protocol versions.
|
||||
* This method removes any blocked protocol versions.
|
||||
|
@ -138,14 +174,15 @@ public interface ViaAPI<T> {
|
|||
* @return a sorted set of protocol versions
|
||||
* @see #getFullSupportedVersions() for a full list
|
||||
*/
|
||||
SortedSet<Integer> getSupportedVersions();
|
||||
SortedSet<ProtocolVersion> getSupportedProtocolVersions();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the supported protocol versions, including blocked protocols.
|
||||
*
|
||||
* @return a sorted set of protocol versions
|
||||
*/
|
||||
SortedSet<Integer> getFullSupportedVersions();
|
||||
SortedSet<ProtocolVersion> getFullSupportedProtocolVersions();
|
||||
|
||||
/**
|
||||
* Returns legacy api only applicable on/to legacy versions.
|
||||
|
|
|
@ -27,8 +27,6 @@ import com.viaversion.viaversion.api.connection.StorableObject;
|
|||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
|
||||
import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ViaVersionConfig extends Config {
|
||||
|
||||
|
@ -235,13 +233,6 @@ public interface ViaVersionConfig extends Config {
|
|||
*/
|
||||
boolean isChunkBorderFix();
|
||||
|
||||
/**
|
||||
* Force json transform
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isForceJsonTransform();
|
||||
|
||||
/**
|
||||
* Should we fix nbt array's in json chat messages for 1.12 clients
|
||||
*
|
||||
|
@ -272,17 +263,6 @@ public interface ViaVersionConfig extends Config {
|
|||
*/
|
||||
BlockedProtocolVersions blockedProtocolVersions();
|
||||
|
||||
/**
|
||||
* Get the blocked protocols
|
||||
*
|
||||
* @return An Integer list
|
||||
* @deprecated use {@link #blockedProtocolVersions()}
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default IntSet getBlockedProtocols() {
|
||||
return blockedProtocolVersions().singleBlockedVersions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom disconnect message
|
||||
*
|
||||
|
@ -463,4 +443,18 @@ public interface ViaVersionConfig extends Config {
|
|||
* @return true if enabled
|
||||
*/
|
||||
boolean isArmorToggleFix();
|
||||
|
||||
/**
|
||||
* If disabled, tamed cats will be displayed as ocelots to 1.14+ clients on 1.13 servers. Otherwise, ocelots (tamed and untamed) will be displayed as cats.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean translateOcelotToCat();
|
||||
|
||||
/**
|
||||
* Returns the value of the "enforce secure chat" setting sent to 1.19+ clients on join.
|
||||
*
|
||||
* @return the value sent to 1.19+ clients on join
|
||||
*/
|
||||
boolean enforceSecureChat();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.connection;
|
|||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
|
@ -93,24 +94,36 @@ public interface ProtocolInfo {
|
|||
void setServerState(State serverState);
|
||||
|
||||
/**
|
||||
* Returns the user's protocol version, or -1 if not set.
|
||||
* Returns the user's protocol version, or null if not set.
|
||||
* This is set during the {@link State#HANDSHAKE} state.
|
||||
*
|
||||
* @return protocol version, or -1 if not set
|
||||
* @return protocol version, may be unknown
|
||||
* @see ProtocolVersion#isKnown()
|
||||
*/
|
||||
int getProtocolVersion();
|
||||
ProtocolVersion protocolVersion();
|
||||
|
||||
void setProtocolVersion(int protocolVersion);
|
||||
void setProtocolVersion(ProtocolVersion protocolVersion);
|
||||
|
||||
/**
|
||||
* Returns the server protocol version the user is connected to, or -1 if not set.
|
||||
* Returns the server protocol version the user is connected to.
|
||||
* This is set during the {@link State#HANDSHAKE} state.
|
||||
*
|
||||
* @return server protocol version, or -1 if not set
|
||||
* @return the server protocol version the user is connected to, may be unknown
|
||||
* @see ProtocolVersion#isKnown()
|
||||
*/
|
||||
int getServerProtocolVersion();
|
||||
ProtocolVersion serverProtocolVersion();
|
||||
|
||||
void setServerProtocolVersion(int serverProtocolVersion);
|
||||
void setServerProtocolVersion(ProtocolVersion protocolVersion);
|
||||
|
||||
@Deprecated
|
||||
default int getProtocolVersion() {
|
||||
return protocolVersion() != null ? protocolVersion().getVersion() : -1;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default int getServerProtocolVersion() {
|
||||
return serverProtocolVersion() != null ? serverProtocolVersion().getVersion() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username associated with this connection.
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
/**
|
||||
* Mappings containing the full string identifier mappings.
|
||||
*/
|
||||
public interface FullMappings extends Mappings {
|
||||
public interface FullMappings extends BiMappings {
|
||||
|
||||
/**
|
||||
* Returns the unmapped integer id for the given identifier, or -1 if not found.
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
|
@ -37,6 +38,7 @@ public class FullMappingsBase implements FullMappings {
|
|||
private final Mappings mappings;
|
||||
|
||||
public FullMappingsBase(final List<String> unmappedIdentifiers, final List<String> mappedIdentifiers, final Mappings mappings) {
|
||||
Preconditions.checkNotNull(mappings, "Mappings cannot be null");
|
||||
this.mappings = mappings;
|
||||
this.stringToId = toInverseMap(unmappedIdentifiers);
|
||||
this.mappedStringToId = toInverseMap(mappedIdentifiers);
|
||||
|
|
|
@ -79,6 +79,8 @@ public interface MappingData {
|
|||
*/
|
||||
int getNewParticleId(int id);
|
||||
|
||||
int getNewAttributeId(int id);
|
||||
|
||||
/**
|
||||
* Returns a list of tags to send if present.
|
||||
*
|
||||
|
@ -87,8 +89,21 @@ public interface MappingData {
|
|||
*/
|
||||
@Nullable List<TagData> getTags(RegistryType type);
|
||||
|
||||
/**
|
||||
* Returns item mappings.
|
||||
*
|
||||
* @return item mappings
|
||||
*/
|
||||
@Nullable BiMappings getItemMappings();
|
||||
|
||||
/**
|
||||
* Returns item mappings if they also have identifier data present.
|
||||
*
|
||||
* @return item mappings if they also have identifier data present
|
||||
* @see #getItemMappings()
|
||||
*/
|
||||
@Nullable FullMappings getFullItemMappings();
|
||||
|
||||
@Nullable ParticleMappings getParticleMappings();
|
||||
|
||||
@Nullable Mappings getBlockMappings();
|
||||
|
@ -105,9 +120,15 @@ public interface MappingData {
|
|||
|
||||
@Nullable Mappings getEnchantmentMappings();
|
||||
|
||||
@Nullable Mappings getAttributeMappings();
|
||||
|
||||
@Nullable Mappings getPaintingMappings();
|
||||
|
||||
@Nullable FullMappings getEntityMappings();
|
||||
|
||||
@Nullable FullMappings getArgumentTypeMappings();
|
||||
|
||||
@Nullable Mappings getPaintingMappings();
|
||||
@Nullable FullMappings getRecipeSerializerMappings();
|
||||
|
||||
@Nullable FullMappings getDataComponentSerializerMappings();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ package com.viaversion.viaversion.api.data;
|
|||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
|
@ -35,7 +33,6 @@ import java.util.EnumMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class MappingDataBase implements MappingData {
|
||||
|
@ -45,6 +42,8 @@ public class MappingDataBase implements MappingData {
|
|||
protected BiMappings itemMappings;
|
||||
protected FullMappings argumentTypeMappings;
|
||||
protected FullMappings entityMappings;
|
||||
protected FullMappings recipeSerializerMappings;
|
||||
protected FullMappings itemDataSerializerMappings;
|
||||
protected ParticleMappings particleMappings;
|
||||
protected Mappings blockMappings;
|
||||
protected Mappings blockStateMappings;
|
||||
|
@ -54,6 +53,7 @@ public class MappingDataBase implements MappingData {
|
|||
protected Mappings enchantmentMappings;
|
||||
protected Mappings paintingMappings;
|
||||
protected Mappings menuMappings;
|
||||
protected Mappings attributeMappings;
|
||||
protected Map<RegistryType, List<TagData>> tags;
|
||||
|
||||
public MappingDataBase(final String unmappedVersion, final String mappedVersion) {
|
||||
|
@ -67,7 +67,7 @@ public class MappingDataBase implements MappingData {
|
|||
getLogger().info("Loading " + unmappedVersion + " -> " + mappedVersion + " mappings...");
|
||||
}
|
||||
|
||||
final CompoundTag data = readNBTFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
||||
final CompoundTag data = readMappingsFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
||||
blockMappings = loadMappings(data, "blocks");
|
||||
blockStateMappings = loadMappings(data, "blockstates");
|
||||
blockEntityMappings = loadMappings(data, "blockentities");
|
||||
|
@ -76,26 +76,30 @@ public class MappingDataBase implements MappingData {
|
|||
menuMappings = loadMappings(data, "menus");
|
||||
enchantmentMappings = loadMappings(data, "enchantments");
|
||||
paintingMappings = loadMappings(data, "paintings");
|
||||
itemMappings = loadBiMappings(data, "items");
|
||||
attributeMappings = loadMappings(data, "attributes");
|
||||
|
||||
final CompoundTag unmappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + unmappedVersion + ".nbt", true);
|
||||
final CompoundTag mappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + mappedVersion + ".nbt", true);
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
final ListTag<StringTag> unmappedParticles = unmappedIdentifierData.getListTag("particles", StringTag.class);
|
||||
final ListTag<StringTag> mappedParticles = mappedIdentifierData.getListTag("particles", StringTag.class);
|
||||
final List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles");
|
||||
final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles");
|
||||
if (unmappedParticles != null && mappedParticles != null) {
|
||||
Mappings particleMappings = loadMappings(data, "particles");
|
||||
if (particleMappings == null) {
|
||||
particleMappings = new IdentityMappings(unmappedParticles.size(), mappedParticles.size());
|
||||
}
|
||||
|
||||
final List<String> identifiers = unmappedParticles.stream().map(StringTag::getValue).collect(Collectors.toList());
|
||||
final List<String> mappedIdentifiers = mappedParticles.stream().map(StringTag::getValue).collect(Collectors.toList());
|
||||
this.particleMappings = new ParticleMappings(identifiers, mappedIdentifiers, particleMappings);
|
||||
this.particleMappings = new ParticleMappings(unmappedParticles, mappedParticles, particleMappings);
|
||||
}
|
||||
} else {
|
||||
// Might not have identifiers in older versions
|
||||
itemMappings = loadBiMappings(data, "items");
|
||||
}
|
||||
|
||||
final CompoundTag tagsTag = data.getCompoundTag("tags");
|
||||
|
@ -108,16 +112,28 @@ public class MappingDataBase implements MappingData {
|
|||
loadExtras(data);
|
||||
}
|
||||
|
||||
protected @Nullable CompoundTag readNBTFile(final String name) {
|
||||
return MappingDataLoader.loadNBT(name);
|
||||
protected @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) {
|
||||
return MappingDataLoader.INSTANCE.identifiersFromGlobalIds(mappingsTag, key);
|
||||
}
|
||||
|
||||
protected @Nullable CompoundTag readMappingsFile(final String name) {
|
||||
return MappingDataLoader.INSTANCE.loadNBT(name);
|
||||
}
|
||||
|
||||
protected @Nullable CompoundTag readUnmappedIdentifiersFile(final String name) {
|
||||
return MappingDataLoader.INSTANCE.loadNBT(name, true);
|
||||
}
|
||||
|
||||
protected @Nullable CompoundTag readMappedIdentifiersFile(final String name) {
|
||||
return MappingDataLoader.INSTANCE.loadNBT(name, true);
|
||||
}
|
||||
|
||||
protected @Nullable Mappings loadMappings(final CompoundTag data, final String key) {
|
||||
return MappingDataLoader.loadMappings(data, key);
|
||||
return MappingDataLoader.INSTANCE.loadMappings(data, key);
|
||||
}
|
||||
|
||||
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
|
||||
return MappingDataLoader.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key);
|
||||
return MappingDataLoader.INSTANCE.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key);
|
||||
}
|
||||
|
||||
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
|
||||
|
@ -165,6 +181,11 @@ public class MappingDataBase implements MappingData {
|
|||
return checkValidity(id, particleMappings.getNewId(id), "particles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewAttributeId(final int id) {
|
||||
return checkValidity(id, attributeMappings.getNewId(id), "attributes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<TagData> getTags(final RegistryType type) {
|
||||
return tags != null ? tags.get(type) : null;
|
||||
|
@ -175,6 +196,14 @@ public class MappingDataBase implements MappingData {
|
|||
return itemMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getFullItemMappings() {
|
||||
if (itemMappings instanceof FullMappings) {
|
||||
return (FullMappings) itemMappings;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ParticleMappings getParticleMappings() {
|
||||
return particleMappings;
|
||||
|
@ -215,6 +244,11 @@ public class MappingDataBase implements MappingData {
|
|||
return enchantmentMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getAttributeMappings() {
|
||||
return attributeMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getEntityMappings() {
|
||||
return entityMappings;
|
||||
|
@ -225,11 +259,21 @@ public class MappingDataBase implements MappingData {
|
|||
return argumentTypeMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getDataComponentSerializerMappings() {
|
||||
return itemDataSerializerMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getPaintingMappings() {
|
||||
return paintingMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getRecipeSerializerMappings() {
|
||||
return recipeSerializerMappings;
|
||||
}
|
||||
|
||||
protected Logger getLogger() {
|
||||
return Via.getPlatform().getLogger();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
|||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.github.steveice10.opennbt.tag.io.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.io.TagReader;
|
||||
import com.google.common.annotations.Beta;
|
||||
|
@ -40,29 +41,77 @@ import com.viaversion.viaversion.api.Via;
|
|||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class MappingDataLoader {
|
||||
public class MappingDataLoader {
|
||||
|
||||
private static final Map<String, CompoundTag> MAPPINGS_CACHE = new HashMap<>();
|
||||
private static final TagReader<CompoundTag> MAPPINGS_READER = NBTIO.reader(CompoundTag.class).named();
|
||||
public static final MappingDataLoader INSTANCE = new MappingDataLoader(MappingDataLoader.class, "assets/viaversion/data/");
|
||||
public static final TagReader<CompoundTag> MAPPINGS_READER = NBTIO.reader(CompoundTag.class).named();
|
||||
private static final Map<String, String[]> GLOBAL_IDENTIFIER_INDEXES = new HashMap<>();
|
||||
private static final byte DIRECT_ID = 0;
|
||||
private static final byte SHIFTS_ID = 1;
|
||||
private static final byte CHANGES_ID = 2;
|
||||
private static final byte IDENTITY_ID = 3;
|
||||
private static boolean cacheValid = true;
|
||||
|
||||
public static void clearCache() {
|
||||
MAPPINGS_CACHE.clear();
|
||||
private final Map<String, CompoundTag> mappingsCache = new HashMap<>();
|
||||
private final Class<?> dataLoaderClass;
|
||||
private final String dataPath;
|
||||
private boolean cacheValid = true;
|
||||
|
||||
public MappingDataLoader(final Class<?> dataLoaderClass, final String dataPath) {
|
||||
this.dataLoaderClass = dataLoaderClass;
|
||||
this.dataPath = dataPath;
|
||||
}
|
||||
|
||||
public static void loadGlobalIdentifiers() {
|
||||
// Load in a file with all the identifiers we need, so that we don't need to duplicate them
|
||||
// for every single new version with only a couple of changes in them.
|
||||
final CompoundTag globalIdentifiers = INSTANCE.loadNBT("identifier-table.nbt");
|
||||
for (final Map.Entry<String, Tag> entry : globalIdentifiers.entrySet()) {
|
||||
//noinspection unchecked
|
||||
final ListTag<StringTag> value = (ListTag<StringTag>) entry.getValue();
|
||||
final String[] array = new String[value.size()];
|
||||
for (int i = 0, size = value.size(); i < size; i++) {
|
||||
array[i] = value.get(i).getValue();
|
||||
}
|
||||
GLOBAL_IDENTIFIER_INDEXES.put(entry.getKey(), array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global id of the identifier in the registry.
|
||||
*
|
||||
* @param registry registry key
|
||||
* @param globalId global id
|
||||
* @return identifier
|
||||
* @throws IllegalArgumentException if the registry key is invalid
|
||||
*/
|
||||
public @Nullable String identifierFromGlobalId(final String registry, final int globalId) {
|
||||
final String[] array = GLOBAL_IDENTIFIER_INDEXES.get(registry);
|
||||
if (array == null) {
|
||||
throw new IllegalArgumentException("Unknown global identifier key: " + registry);
|
||||
}
|
||||
if (globalId < 0 || globalId >= array.length) {
|
||||
throw new IllegalArgumentException("Unknown global identifier index: " + globalId);
|
||||
}
|
||||
return array[globalId];
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
mappingsCache.clear();
|
||||
cacheValid = false;
|
||||
}
|
||||
|
||||
|
@ -71,8 +120,8 @@ public final class MappingDataLoader {
|
|||
*
|
||||
* @return loaded json object, or null if not found or invalid
|
||||
*/
|
||||
public static @Nullable JsonObject loadFromDataDir(final String name) {
|
||||
final File file = new File(Via.getPlatform().getDataFolder(), name);
|
||||
public @Nullable JsonObject loadFromDataDir(final String name) {
|
||||
final File file = new File(getDataFolder(), name);
|
||||
if (!file.exists()) {
|
||||
return loadData(name);
|
||||
}
|
||||
|
@ -82,7 +131,7 @@ public final class MappingDataLoader {
|
|||
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
|
||||
} catch (final JsonSyntaxException e) {
|
||||
// Users might mess up the format, so let's catch the syntax error
|
||||
Via.getPlatform().getLogger().warning(name + " is badly formatted!");
|
||||
getLogger().warning(name + " is badly formatted!");
|
||||
throw new RuntimeException(e);
|
||||
} catch (final IOException | JsonIOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -94,7 +143,7 @@ public final class MappingDataLoader {
|
|||
*
|
||||
* @return loaded json object from bundled resources if present
|
||||
*/
|
||||
public static @Nullable JsonObject loadData(final String name) {
|
||||
public @Nullable JsonObject loadData(final String name) {
|
||||
final InputStream stream = getResource(name);
|
||||
if (stream == null) {
|
||||
return null;
|
||||
|
@ -107,12 +156,12 @@ public final class MappingDataLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public static @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
|
||||
public @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
|
||||
if (!cacheValid) {
|
||||
return loadNBTFromFile(name);
|
||||
}
|
||||
|
||||
CompoundTag data = MAPPINGS_CACHE.get(name);
|
||||
CompoundTag data = mappingsCache.get(name);
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
|
@ -120,29 +169,29 @@ public final class MappingDataLoader {
|
|||
data = loadNBTFromFile(name);
|
||||
|
||||
if (cache && data != null) {
|
||||
MAPPINGS_CACHE.put(name, data);
|
||||
mappingsCache.put(name, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static @Nullable CompoundTag loadNBT(final String name) {
|
||||
public @Nullable CompoundTag loadNBT(final String name) {
|
||||
return loadNBT(name, false);
|
||||
}
|
||||
|
||||
public static @Nullable CompoundTag loadNBTFromFile(final String name) {
|
||||
public @Nullable CompoundTag loadNBTFromFile(final String name) {
|
||||
final InputStream resource = getResource(name);
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (final InputStream stream = resource) {
|
||||
try (final InputStream stream = new BufferedInputStream(resource)) {
|
||||
return MAPPINGS_READER.read(stream);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
|
||||
public @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
|
||||
return loadMappings(mappingsTag, key, size -> {
|
||||
final int[] array = new int[size];
|
||||
Arrays.fill(array, -1);
|
||||
|
@ -151,12 +200,12 @@ public final class MappingDataLoader {
|
|||
}
|
||||
|
||||
@Beta
|
||||
public static <M extends Mappings, V> @Nullable Mappings loadMappings(
|
||||
final CompoundTag mappingsTag,
|
||||
final String key,
|
||||
final MappingHolderSupplier<V> holderSupplier,
|
||||
final AddConsumer<V> addConsumer,
|
||||
final MappingsSupplier<M, V> mappingsSupplier
|
||||
public <M extends Mappings, V> @Nullable Mappings loadMappings(
|
||||
final CompoundTag mappingsTag,
|
||||
final String key,
|
||||
final MappingHolderSupplier<V> holderSupplier,
|
||||
final AddConsumer<V> addConsumer,
|
||||
final MappingsSupplier<M, V> mappingsSupplier
|
||||
) {
|
||||
final CompoundTag tag = mappingsTag.getCompoundTag(key);
|
||||
if (tag == null) {
|
||||
|
@ -227,23 +276,32 @@ public final class MappingDataLoader {
|
|||
return mappingsSupplier.create(mappings, mappedSizeTag.asInt());
|
||||
}
|
||||
|
||||
public static FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
|
||||
final ListTag<StringTag> unmappedElements = unmappedIdentifiers.getListTag(key, StringTag.class);
|
||||
final ListTag<StringTag> mappedElements = mappedIdentifiers.getListTag(key, StringTag.class);
|
||||
if (unmappedElements == null || mappedElements == null) {
|
||||
public FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) {
|
||||
if (!unmappedIdentifiersTag.contains(key) || !mappedIdentifiersTag.contains(key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<String> unmappedIdentifiers = identifiersFromGlobalIds(unmappedIdentifiersTag, key);
|
||||
final List<String> mappedIdentifiers = identifiersFromGlobalIds(mappedIdentifiersTag, key);
|
||||
Mappings mappings = loadMappings(mappingsTag, key);
|
||||
if (mappings == null) {
|
||||
mappings = new IdentityMappings(unmappedElements.size(), mappedElements.size());
|
||||
mappings = new IdentityMappings(unmappedIdentifiers.size(), mappedIdentifiers.size());
|
||||
}
|
||||
|
||||
return new FullMappingsBase(
|
||||
unmappedElements.stream().map(StringTag::getValue).collect(Collectors.toList()),
|
||||
mappedElements.stream().map(StringTag::getValue).collect(Collectors.toList()),
|
||||
mappings
|
||||
);
|
||||
return new FullMappingsBase(unmappedIdentifiers, mappedIdentifiers, mappings);
|
||||
}
|
||||
|
||||
public @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) {
|
||||
final Mappings mappings = loadMappings(mappingsTag, key);
|
||||
if (mappings == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<String> identifiers = new ArrayList<>(mappings.size());
|
||||
for (int i = 0; i < mappings.size(); i++) {
|
||||
identifiers.add(identifierFromGlobalId(key, mappings.getNewId(i)));
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +310,7 @@ public final class MappingDataLoader {
|
|||
* @param object json object
|
||||
* @return map with indexes hashed by their id value
|
||||
*/
|
||||
public static Object2IntMap<String> indexedObjectToMap(final JsonObject object) {
|
||||
public Object2IntMap<String> indexedObjectToMap(final JsonObject object) {
|
||||
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(object.size(), .99F);
|
||||
map.defaultReturnValue(-1);
|
||||
for (final Map.Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
|
@ -267,7 +325,7 @@ public final class MappingDataLoader {
|
|||
* @param array json array
|
||||
* @return map with indexes hashed by their id value
|
||||
*/
|
||||
public static Object2IntMap<String> arrayToMap(final JsonArray array) {
|
||||
public Object2IntMap<String> arrayToMap(final JsonArray array) {
|
||||
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(array.size(), .99F);
|
||||
map.defaultReturnValue(-1);
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
|
@ -276,8 +334,16 @@ public final class MappingDataLoader {
|
|||
return map;
|
||||
}
|
||||
|
||||
public static @Nullable InputStream getResource(final String name) {
|
||||
return MappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name);
|
||||
public Logger getLogger() {
|
||||
return Via.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return Via.getPlatform().getDataFolder();
|
||||
}
|
||||
|
||||
public @Nullable InputStream getResource(final String name) {
|
||||
return dataLoaderClass.getClassLoader().getResourceAsStream(dataPath + name);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
|
|
@ -84,10 +84,4 @@ public interface Mappings {
|
|||
* @return mappings with keys and values swapped
|
||||
*/
|
||||
Mappings inverse();
|
||||
|
||||
@FunctionalInterface
|
||||
interface MappingsSupplier<T extends Mappings> {
|
||||
|
||||
T supply(int[] mappings, int mappedIds);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public class ParticleMappings extends FullMappingsBase {
|
|||
addBlockParticle("block");
|
||||
addBlockParticle("falling_dust");
|
||||
addBlockParticle("block_marker");
|
||||
addBlockParticle("dust_pillar");
|
||||
addItemParticle("item");
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ package com.viaversion.viaversion.api.data.entity;
|
|||
|
||||
public interface DimensionData {
|
||||
|
||||
int id();
|
||||
|
||||
int minY();
|
||||
|
||||
int height();
|
||||
|
|
|
@ -34,6 +34,7 @@ public interface EntityTracker {
|
|||
*
|
||||
* @return user connection
|
||||
*/
|
||||
@Deprecated
|
||||
UserConnection user();
|
||||
|
||||
/**
|
||||
|
@ -165,6 +166,8 @@ public interface EntityTracker {
|
|||
|
||||
@Nullable DimensionData dimensionData(String dimension);
|
||||
|
||||
@Nullable DimensionData dimensionData(int dimensionId);
|
||||
|
||||
void setDimensions(Map<String, DimensionData> dimensions);
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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 java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class GameProfile {
|
||||
|
||||
private final String name;
|
||||
private final UUID id;
|
||||
private final Property[] properties;
|
||||
|
||||
public GameProfile(@Nullable final String name, @Nullable final UUID id, final Property[] properties) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public @Nullable String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @Nullable UUID id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Property[] properties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static final class Property {
|
||||
private final String name;
|
||||
private final String value;
|
||||
private final String signature;
|
||||
|
||||
public Property(final String name, final String value, @Nullable final String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public @Nullable String signature() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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 interface Holder<T> {
|
||||
|
||||
/**
|
||||
* Returns an indirect id holder.
|
||||
*
|
||||
* @param id the id
|
||||
* @param <T> the type of the value
|
||||
* @return a new holder with the given id
|
||||
* @throws IllegalArgumentException if the id is negative
|
||||
*/
|
||||
static <T> Holder<T> of(final int id) {
|
||||
return new HolderImpl<>(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a direct value holder.
|
||||
*
|
||||
* @param value the value
|
||||
* @param <T> the type of the value
|
||||
* @return a new direct holder
|
||||
*/
|
||||
static <T> Holder<T> of(final T value) {
|
||||
return new HolderImpl<>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this holder is backed by a direct value.
|
||||
*
|
||||
* @return true if the holder is direct
|
||||
* @see #hasId()
|
||||
*/
|
||||
boolean isDirect();
|
||||
|
||||
/**
|
||||
* Returns true if this holder has an id.
|
||||
*
|
||||
* @return true if this holder has an id
|
||||
* @see #isDirect()
|
||||
*/
|
||||
boolean hasId();
|
||||
|
||||
/**
|
||||
* Returns the value of this holder.
|
||||
*
|
||||
* @return the value of this holder
|
||||
* @throws IllegalArgumentException if this holder is not direct
|
||||
* @see #isDirect()
|
||||
*/
|
||||
T value();
|
||||
|
||||
/**
|
||||
* Returns the id of this holder, or -1 if this holder is direct.
|
||||
*
|
||||
* @return the id of this holder, or -1 if this holder is direct
|
||||
* @see #hasId()
|
||||
*/
|
||||
int id();
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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 com.google.common.base.Preconditions;
|
||||
|
||||
final class HolderImpl<T> implements Holder<T> {
|
||||
|
||||
private final T value;
|
||||
private final int id;
|
||||
|
||||
HolderImpl(final int id) {
|
||||
Preconditions.checkArgument(id >= 0, "id cannot be negative");
|
||||
this.value = null;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
HolderImpl(final T value) {
|
||||
this.value = value;
|
||||
this.id = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirect() {
|
||||
return id == -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasId() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T value() {
|
||||
Preconditions.checkArgument(isDirect(), "Holder is not direct");
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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;
|
||||
|
||||
/**
|
||||
* Set of ids that either holds a string tag key or an array of ids.
|
||||
*/
|
||||
public interface HolderSet {
|
||||
|
||||
/**
|
||||
* Creates a new holder set for the given tag.
|
||||
*
|
||||
* @param tagKey the tag key
|
||||
* @return a new holder set
|
||||
*/
|
||||
static HolderSet of(final String tagKey) {
|
||||
return new HolderSetImpl(tagKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new holder set for the given ids.
|
||||
*
|
||||
* @param ids the direct ids
|
||||
* @return a new holder set
|
||||
*/
|
||||
static HolderSet of(final int[] ids) {
|
||||
return new HolderSetImpl(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag key.
|
||||
*
|
||||
* @return the tag key
|
||||
* @see #hasTagKey()
|
||||
*/
|
||||
String tagKey();
|
||||
|
||||
/**
|
||||
* Returns whether this holder set has a tag key.
|
||||
*
|
||||
* @return true if this holder set has a tag key, false if it has direct ids
|
||||
*/
|
||||
boolean hasTagKey();
|
||||
|
||||
/**
|
||||
* Gets the direct ids.
|
||||
*
|
||||
* @return direct ids
|
||||
* @see #hasIds()
|
||||
*/
|
||||
int[] ids();
|
||||
|
||||
/**
|
||||
* Returns whether this holder set has direct ids.
|
||||
*
|
||||
* @return true if this holder set has direct ids, false if it has a tag key
|
||||
*/
|
||||
boolean hasIds();
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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 com.viaversion.viaversion.util.EitherImpl;
|
||||
|
||||
final class HolderSetImpl extends EitherImpl<String, int[]> implements HolderSet {
|
||||
|
||||
HolderSetImpl(final String tagKey) {
|
||||
super(tagKey, null);
|
||||
}
|
||||
|
||||
HolderSetImpl(final int[] ids) {
|
||||
super(null, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tagKey() {
|
||||
return left();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagKey() {
|
||||
return isLeft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] ids() {
|
||||
return right();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasIds() {
|
||||
return isRight();
|
||||
}
|
||||
}
|
|
@ -24,11 +24,12 @@ package com.viaversion.viaversion.api.minecraft;
|
|||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.util.IdHolder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class Particle {
|
||||
public final class Particle implements IdHolder {
|
||||
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
|
||||
private int id;
|
||||
|
||||
|
@ -36,10 +37,16 @@ public final class Particle {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
@ -66,6 +73,18 @@ public final class Particle {
|
|||
arguments.add(index, new ParticleData<>(type, value));
|
||||
}
|
||||
|
||||
public <T> void set(final int index, final Type<T> type, final T value) {
|
||||
arguments.set(index, new ParticleData<>(type, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Particle{" +
|
||||
"arguments=" + arguments +
|
||||
", id=" + id +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static final class ParticleData<T> {
|
||||
private final Type<T> type;
|
||||
private T value;
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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 com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class RegistryEntry {
|
||||
private final String key;
|
||||
private final Tag tag;
|
||||
|
||||
public RegistryEntry(String key, @Nullable Tag tag) {
|
||||
this.key = key;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public @Nullable Tag tag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public RegistryEntry withKey(final String key) {
|
||||
return new RegistryEntry(key, tag != null ? tag.copy() : null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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;
|
||||
|
||||
public final class SoundEvent {
|
||||
|
||||
private final String identifier;
|
||||
private final Float fixedRange;
|
||||
|
||||
public SoundEvent(final String identifier, @Nullable final Float fixedRange) {
|
||||
this.identifier = identifier;
|
||||
this.fixedRange = fixedRange;
|
||||
}
|
||||
|
||||
public String identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public @Nullable Float fixedRange() {
|
||||
return fixedRange;
|
||||
}
|
||||
|
||||
public SoundEvent withIdentifier(final String identifier) {
|
||||
return new SoundEvent(identifier, this.fixedRange);
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class TagData {
|
||||
private final String identifier;
|
||||
private final int[] entries;
|
||||
|
@ -38,4 +40,12 @@ public final class TagData {
|
|||
public int[] entries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TagData{" +
|
||||
"identifier='" + identifier + '\'' +
|
||||
", entries=" + Arrays.toString(entries) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.data;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
final class EmptyStructuredData<T> implements StructuredData<T> {
|
||||
|
||||
private final StructuredDataKey<T> key;
|
||||
private int id;
|
||||
|
||||
EmptyStructuredData(final StructuredDataKey<T> key, final int id) {
|
||||
this.key = key;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final T value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructuredDataKey<T> key() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T value() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final EmptyStructuredData<?> that = (EmptyStructuredData<?>) o;
|
||||
if (id != that.id) return false;
|
||||
return key.equals(that.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = key.hashCode();
|
||||
result = 31 * result + id;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EmptyStructuredData{" +
|
||||
"key=" + key +
|
||||
", id=" + id +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.data;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Objects;
|
||||
|
||||
final class FilledStructuredData<T> implements StructuredData<T> {
|
||||
|
||||
private final StructuredDataKey<T> key;
|
||||
private T value;
|
||||
private int id;
|
||||
|
||||
FilledStructuredData(final StructuredDataKey<T> key, final T value, final int id) {
|
||||
Preconditions.checkNotNull(key);
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer) throws Exception {
|
||||
key.type().write(buffer, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructuredDataKey<T> key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final FilledStructuredData<?> that = (FilledStructuredData<?>) o;
|
||||
if (id != that.id) return false;
|
||||
if (!key.equals(that.key)) return false;
|
||||
return Objects.equals(value, that.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = key.hashCode();
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
result = 31 * result + id;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FilledStructuredData{" +
|
||||
"key=" + key +
|
||||
", value=" + value +
|
||||
", id=" + id +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.data;
|
||||
|
||||
import com.viaversion.viaversion.util.IdHolder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface StructuredData<T> extends IdHolder {
|
||||
|
||||
/**
|
||||
* Returns filled structured data, equivalent to an Optional with a value in vanilla.
|
||||
*
|
||||
* @param key serializer key
|
||||
* @param value value
|
||||
* @param id serializer id
|
||||
* @param <T> serializer type
|
||||
* @return filled structured data
|
||||
*/
|
||||
static <T> StructuredData<T> of(final StructuredDataKey<T> key, final T value, final int id) {
|
||||
return new FilledStructuredData<>(key, value, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns empty structured data, equivalent to an empty Optional in vanilla.
|
||||
*
|
||||
* @param key serializer key
|
||||
* @param id serializer id
|
||||
* @return empty structured data
|
||||
*/
|
||||
static <T> StructuredData<T> empty(final StructuredDataKey<T> key, final int id) {
|
||||
return new EmptyStructuredData<>(key, id);
|
||||
}
|
||||
|
||||
void setValue(final T value);
|
||||
|
||||
void write(final ByteBuf buffer) throws Exception;
|
||||
|
||||
void setId(final int id);
|
||||
|
||||
StructuredDataKey<T> key();
|
||||
|
||||
@Nullable T value();
|
||||
|
||||
/**
|
||||
* Returns whether the structured data is present. Even if true, the value may be null.
|
||||
*
|
||||
* @return true if the structured data is present
|
||||
*/
|
||||
default boolean isPresent() {
|
||||
return !isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the structured data is empty. Not to be confused with a null value.
|
||||
*
|
||||
* @return true if the structured data is empty
|
||||
*/
|
||||
boolean isEmpty();
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.data;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.FullMappings;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.util.Unit;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class StructuredDataContainer {
|
||||
|
||||
private final Map<StructuredDataKey<?>, StructuredData<?>> data;
|
||||
private FullMappings lookup;
|
||||
private boolean mappedNames;
|
||||
|
||||
public StructuredDataContainer(final Map<StructuredDataKey<?>, StructuredData<?>> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public StructuredDataContainer(final StructuredData<?>[] dataArray) {
|
||||
this(new Reference2ObjectOpenHashMap<>(dataArray.length));
|
||||
for (final StructuredData<?> data : dataArray) {
|
||||
add(data);
|
||||
}
|
||||
}
|
||||
|
||||
public StructuredDataContainer() {
|
||||
this(new Reference2ObjectOpenHashMap<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns structured data by id if present.
|
||||
*
|
||||
* @param key serializer id
|
||||
* @param <T> data type
|
||||
* @return structured data
|
||||
*/
|
||||
public @Nullable <T> StructuredData<T> get(final StructuredDataKey<T> key) {
|
||||
//noinspection unchecked
|
||||
return (StructuredData<T>) this.data.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns structured data by id if not empty.
|
||||
*
|
||||
* @param key serializer id
|
||||
* @param <T> data type
|
||||
* @return structured data if not empty
|
||||
*/
|
||||
public @Nullable <T> StructuredData<T> getNonEmpty(final StructuredDataKey<T> key) {
|
||||
//noinspection unchecked
|
||||
final StructuredData<T> data = (StructuredData<T>) this.data.get(key);
|
||||
return data != null && data.isPresent() ? data : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns structured data by id if not empty, or creates it.
|
||||
*
|
||||
* @param key serializer id
|
||||
* @param mappingFunction function to create structured data if not present
|
||||
* @param <T> data type
|
||||
* @return structured data if not empty
|
||||
*/
|
||||
public <T> StructuredData<T> computeIfAbsent(final StructuredDataKey<T> key, final Function<StructuredDataKey<T>, T> mappingFunction) {
|
||||
final StructuredData<T> data = this.getNonEmpty(key);
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
|
||||
final int id = serializerId(key);
|
||||
final StructuredData<T> empty = StructuredData.of(key, mappingFunction.apply(key), id);
|
||||
this.data.put(key, empty);
|
||||
return empty;
|
||||
}
|
||||
|
||||
public <T> void set(final StructuredDataKey<T> key, final T value) {
|
||||
final int id = serializerId(key);
|
||||
if (id != -1) {
|
||||
this.data.put(key, StructuredData.of(key, value, id));
|
||||
}
|
||||
}
|
||||
|
||||
public void set(final StructuredDataKey<Unit> key) {
|
||||
this.set(key, Unit.INSTANCE);
|
||||
}
|
||||
|
||||
public void addEmpty(final StructuredDataKey<?> key) {
|
||||
// Empty optional to override the Minecraft default
|
||||
this.data.put(key, StructuredData.empty(key, serializerId(key)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns structured data by the given key.
|
||||
*
|
||||
* @param key serializer key
|
||||
* @param <T> data type
|
||||
* @return removed structured data
|
||||
*/
|
||||
public @Nullable <T> StructuredData<T> remove(final StructuredDataKey<T> key) {
|
||||
final StructuredData<?> data = this.data.remove(key);
|
||||
//noinspection unchecked
|
||||
return data != null ? (StructuredData<T>) data : null;
|
||||
}
|
||||
|
||||
public boolean contains(final StructuredDataKey<?> key) {
|
||||
return this.data.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lookup for serializer ids. Required to call most of the other methods.
|
||||
*
|
||||
* @param protocol protocol to retreive the id of the serializer from
|
||||
* @param mappedNames if the names are mapped (true if structures from the mapped version are added, false for the unmapped version)
|
||||
*/
|
||||
public void setIdLookup(final Protocol<?, ?, ?, ?> protocol, final boolean mappedNames) {
|
||||
this.lookup = protocol.getMappingData().getDataComponentSerializerMappings();
|
||||
this.mappedNames = mappedNames;
|
||||
}
|
||||
|
||||
public StructuredDataContainer copy() {
|
||||
final StructuredDataContainer copy = new StructuredDataContainer(new Reference2ObjectOpenHashMap<>(data));
|
||||
copy.lookup = this.lookup;
|
||||
return copy;
|
||||
}
|
||||
|
||||
private int serializerId(final StructuredDataKey<?> key) {
|
||||
final int id = mappedNames ? lookup.mappedId(key.identifier()) : lookup.id(key.identifier());
|
||||
if (id == -1) {
|
||||
Via.getPlatform().getLogger().severe("Could not find item data serializer for type " + key);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<StructuredDataKey<?>, StructuredData<?>> data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
private <T> void add(final StructuredData<T> data) {
|
||||
set(data.key(), data.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StructuredDataContainer{" +
|
||||
"data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.data;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrim;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers;
|
||||
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.BlockStateProperties;
|
||||
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.FilterableString;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument;
|
||||
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.SuspiciousStewEffect;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.util.Unit;
|
||||
|
||||
public final class StructuredDataKey<T> {
|
||||
|
||||
public static final StructuredDataKey<CompoundTag> CUSTOM_DATA = new StructuredDataKey<>("custom_data", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<Integer> MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Integer> MAX_DAMAGE = new StructuredDataKey<>("max_damage", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Integer> DAMAGE = new StructuredDataKey<>("damage", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Unbreakable> UNBREAKABLE = new StructuredDataKey<>("unbreakable", Unbreakable.TYPE);
|
||||
public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Type.TAG);
|
||||
public static final StructuredDataKey<Tag> ITEM_NAME = new StructuredDataKey<>("item_name", Type.TAG);
|
||||
public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", Type.TAG_ARRAY);
|
||||
public static final StructuredDataKey<Integer> RARITY = new StructuredDataKey<>("rarity", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Enchantments> ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE);
|
||||
public static final StructuredDataKey<AdventureModePredicate> CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE);
|
||||
public static final StructuredDataKey<AdventureModePredicate> CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE);
|
||||
public static final StructuredDataKey<AttributeModifiers> ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers.TYPE);
|
||||
public static final StructuredDataKey<Integer> CUSTOM_MODEL_DATA = new StructuredDataKey<>("custom_model_data", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Unit> HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Type.EMPTY);
|
||||
public static final StructuredDataKey<Unit> HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Type.EMPTY);
|
||||
public static final StructuredDataKey<Integer> REPAIR_COST = new StructuredDataKey<>("repair_cost", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Unit> CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Type.EMPTY);
|
||||
public static final StructuredDataKey<Boolean> ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Type.BOOLEAN);
|
||||
public static final StructuredDataKey<Tag> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Type.TAG); // Doesn't actually hold data
|
||||
public static final StructuredDataKey<FoodProperties> FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE);
|
||||
public static final StructuredDataKey<Unit> FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Type.EMPTY);
|
||||
public static final StructuredDataKey<ToolProperties> TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE);
|
||||
public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE);
|
||||
public static final StructuredDataKey<DyedColor> DYED_COLOR = new StructuredDataKey<>("dyed_color", DyedColor.TYPE);
|
||||
public static final StructuredDataKey<Integer> MAP_COLOR = new StructuredDataKey<>("map_color", Type.INT);
|
||||
public static final StructuredDataKey<Integer> MAP_ID = new StructuredDataKey<>("map_id", Type.VAR_INT);
|
||||
public static final StructuredDataKey<CompoundTag> MAP_DECORATIONS = new StructuredDataKey<>("map_decorations", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<Integer> MAP_POST_PROCESSING = new StructuredDataKey<>("map_post_processing", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Item[]> CHARGED_PROJECTILES = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY);
|
||||
public static final StructuredDataKey<Item[]> BUNDLE_CONTENTS = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY);
|
||||
public static final StructuredDataKey<PotionContents> POTION_CONTENTS = new StructuredDataKey<>("potion_contents", PotionContents.TYPE);
|
||||
public static final StructuredDataKey<SuspiciousStewEffect[]> SUSPICIOUS_STEW_EFFECTS = new StructuredDataKey<>("suspicious_stew_effects", SuspiciousStewEffect.ARRAY_TYPE);
|
||||
public static final StructuredDataKey<FilterableString[]> WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", FilterableString.ARRAY_TYPE);
|
||||
public static final StructuredDataKey<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE);
|
||||
public static final StructuredDataKey<ArmorTrim> TRIM = new StructuredDataKey<>("trim", ArmorTrim.TYPE);
|
||||
public static final StructuredDataKey<CompoundTag> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<CompoundTag> ENTITY_DATA = new StructuredDataKey<>("entity_data", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<CompoundTag> BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<Holder<Instrument>> INSTRUMENT = new StructuredDataKey<>("instrument", Instrument.TYPE);
|
||||
public static final StructuredDataKey<Integer> OMINOUS_BOTTLE_AMPLIFIER = new StructuredDataKey<>("ominous_bottle_amplifier", Type.VAR_INT);
|
||||
public static final StructuredDataKey<Tag> RECIPES = new StructuredDataKey<>("recipes", Type.TAG);
|
||||
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", Type.GAME_PROFILE);
|
||||
public static final StructuredDataKey<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Type.STRING);
|
||||
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", Type.VAR_INT);
|
||||
public static final StructuredDataKey<PotDecorations> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE);
|
||||
public static final StructuredDataKey<Item[]> CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY);
|
||||
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", Type.TAG);
|
||||
public static final StructuredDataKey<CompoundTag> CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Type.COMPOUND_TAG);
|
||||
|
||||
private final String identifier;
|
||||
private final Type<T> type;
|
||||
|
||||
public StructuredDataKey(final String identifier, final Type<T> type) {
|
||||
this.identifier = identifier;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type<T> type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StructuredDataKey{" +
|
||||
"identifier='" + identifier + '\'' +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,288 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 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 java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum EntityTypes1_20_5 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),
|
||||
FIREWORK_ROCKET(ENTITY),
|
||||
ITEM(ENTITY),
|
||||
LLAMA_SPIT(ENTITY),
|
||||
TNT(ENTITY),
|
||||
SHULKER_BULLET(ENTITY),
|
||||
FISHING_BOBBER(ENTITY),
|
||||
OMINOUS_ITEM_SPAWNER(ENTITY),
|
||||
|
||||
LIVINGENTITY(ENTITY, null),
|
||||
ARMOR_STAND(LIVINGENTITY),
|
||||
MARKER(ENTITY),
|
||||
PLAYER(LIVINGENTITY),
|
||||
|
||||
DISPLAY(ENTITY, null),
|
||||
BLOCK_DISPLAY(DISPLAY),
|
||||
ITEM_DISPLAY(DISPLAY),
|
||||
TEXT_DISPLAY(DISPLAY),
|
||||
INTERACTION(ENTITY),
|
||||
|
||||
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
|
||||
ENDER_DRAGON(ABSTRACT_INSENTIENT),
|
||||
|
||||
BEE(ABSTRACT_INSENTIENT),
|
||||
|
||||
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
|
||||
|
||||
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
|
||||
VILLAGER(ABSTRACT_AGEABLE),
|
||||
WANDERING_TRADER(ABSTRACT_AGEABLE),
|
||||
|
||||
// Animals
|
||||
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
|
||||
AXOLOTL(ABSTRACT_ANIMAL),
|
||||
DOLPHIN(ABSTRACT_INSENTIENT),
|
||||
CHICKEN(ABSTRACT_ANIMAL),
|
||||
COW(ABSTRACT_ANIMAL),
|
||||
MOOSHROOM(COW),
|
||||
PANDA(ABSTRACT_INSENTIENT),
|
||||
PIG(ABSTRACT_ANIMAL),
|
||||
POLAR_BEAR(ABSTRACT_ANIMAL),
|
||||
RABBIT(ABSTRACT_ANIMAL),
|
||||
SHEEP(ABSTRACT_ANIMAL),
|
||||
TURTLE(ABSTRACT_ANIMAL),
|
||||
FOX(ABSTRACT_ANIMAL),
|
||||
FROG(ABSTRACT_ANIMAL),
|
||||
GOAT(ABSTRACT_ANIMAL),
|
||||
SNIFFER(ABSTRACT_ANIMAL),
|
||||
ARMADILLO(ABSTRACT_ANIMAL),
|
||||
|
||||
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
|
||||
CAT(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
|
||||
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
|
||||
PARROT(ABSTRACT_PARROT),
|
||||
|
||||
// Horses
|
||||
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
|
||||
CHESTED_HORSE(ABSTRACT_HORSE, null),
|
||||
DONKEY(CHESTED_HORSE),
|
||||
MULE(CHESTED_HORSE),
|
||||
LLAMA(CHESTED_HORSE),
|
||||
TRADER_LLAMA(LLAMA),
|
||||
HORSE(ABSTRACT_HORSE),
|
||||
SKELETON_HORSE(ABSTRACT_HORSE),
|
||||
ZOMBIE_HORSE(ABSTRACT_HORSE),
|
||||
CAMEL(ABSTRACT_HORSE),
|
||||
|
||||
// Golem
|
||||
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
|
||||
SNOW_GOLEM(ABSTRACT_GOLEM),
|
||||
IRON_GOLEM(ABSTRACT_GOLEM),
|
||||
SHULKER(ABSTRACT_GOLEM),
|
||||
|
||||
// Fish
|
||||
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
|
||||
COD(ABSTRACT_FISHES),
|
||||
PUFFERFISH(ABSTRACT_FISHES),
|
||||
SALMON(ABSTRACT_FISHES),
|
||||
TROPICAL_FISH(ABSTRACT_FISHES),
|
||||
|
||||
// Monsters
|
||||
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
|
||||
BLAZE(ABSTRACT_MONSTER),
|
||||
CREEPER(ABSTRACT_MONSTER),
|
||||
ENDERMITE(ABSTRACT_MONSTER),
|
||||
ENDERMAN(ABSTRACT_MONSTER),
|
||||
GIANT(ABSTRACT_MONSTER),
|
||||
SILVERFISH(ABSTRACT_MONSTER),
|
||||
VEX(ABSTRACT_MONSTER),
|
||||
WITCH(ABSTRACT_MONSTER),
|
||||
WITHER(ABSTRACT_MONSTER),
|
||||
RAVAGER(ABSTRACT_MONSTER),
|
||||
BREEZE(ABSTRACT_MONSTER),
|
||||
|
||||
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
|
||||
|
||||
PIGLIN(ABSTRACT_PIGLIN),
|
||||
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
|
||||
|
||||
HOGLIN(ABSTRACT_ANIMAL),
|
||||
STRIDER(ABSTRACT_ANIMAL),
|
||||
TADPOLE(ABSTRACT_FISHES),
|
||||
ZOGLIN(ABSTRACT_MONSTER),
|
||||
WARDEN(ABSTRACT_MONSTER),
|
||||
|
||||
// Illagers
|
||||
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
|
||||
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
|
||||
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
|
||||
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
|
||||
VINDICATOR(ABSTRACT_ILLAGER_BASE),
|
||||
PILLAGER(ABSTRACT_ILLAGER_BASE),
|
||||
|
||||
// Skeletons
|
||||
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
|
||||
SKELETON(ABSTRACT_SKELETON),
|
||||
STRAY(ABSTRACT_SKELETON),
|
||||
WITHER_SKELETON(ABSTRACT_SKELETON),
|
||||
BOGGED(ABSTRACT_SKELETON),
|
||||
|
||||
// Guardians
|
||||
GUARDIAN(ABSTRACT_MONSTER),
|
||||
ELDER_GUARDIAN(GUARDIAN),
|
||||
|
||||
// Spiders
|
||||
SPIDER(ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(SPIDER),
|
||||
|
||||
// Zombies
|
||||
ZOMBIE(ABSTRACT_MONSTER),
|
||||
DROWNED(ZOMBIE),
|
||||
HUSK(ZOMBIE),
|
||||
ZOMBIFIED_PIGLIN(ZOMBIE),
|
||||
ZOMBIE_VILLAGER(ZOMBIE),
|
||||
|
||||
// Flying entities
|
||||
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
|
||||
GHAST(ABSTRACT_FLYING),
|
||||
PHANTOM(ABSTRACT_FLYING),
|
||||
|
||||
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
|
||||
BAT(ABSTRACT_AMBIENT),
|
||||
ALLAY(ABSTRACT_CREATURE),
|
||||
|
||||
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
|
||||
SQUID(ABSTRACT_WATERMOB),
|
||||
GLOW_SQUID(SQUID),
|
||||
|
||||
// Slimes
|
||||
SLIME(ABSTRACT_INSENTIENT),
|
||||
MAGMA_CUBE(SLIME),
|
||||
|
||||
// Hangable objects
|
||||
ABSTRACT_HANGING(ENTITY, null),
|
||||
LEASH_KNOT(ABSTRACT_HANGING),
|
||||
ITEM_FRAME(ABSTRACT_HANGING),
|
||||
GLOW_ITEM_FRAME(ITEM_FRAME),
|
||||
PAINTING(ABSTRACT_HANGING),
|
||||
|
||||
ABSTRACT_LIGHTNING(ENTITY, null),
|
||||
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
|
||||
|
||||
// Arrows
|
||||
ABSTRACT_ARROW(ENTITY, null),
|
||||
ARROW(ABSTRACT_ARROW),
|
||||
SPECTRAL_ARROW(ABSTRACT_ARROW),
|
||||
TRIDENT(ABSTRACT_ARROW),
|
||||
|
||||
// Fireballs
|
||||
ABSTRACT_FIREBALL(ENTITY, null),
|
||||
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
|
||||
FIREBALL(ABSTRACT_FIREBALL),
|
||||
SMALL_FIREBALL(ABSTRACT_FIREBALL),
|
||||
WITHER_SKULL(ABSTRACT_FIREBALL),
|
||||
|
||||
// Projectiles
|
||||
PROJECTILE_ABSTRACT(ENTITY, null),
|
||||
SNOWBALL(PROJECTILE_ABSTRACT),
|
||||
ENDER_PEARL(PROJECTILE_ABSTRACT),
|
||||
EGG(PROJECTILE_ABSTRACT),
|
||||
POTION(PROJECTILE_ABSTRACT),
|
||||
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
|
||||
ABSTRACT_WIND_CHARGE(PROJECTILE_ABSTRACT, null),
|
||||
WIND_CHARGE(ABSTRACT_WIND_CHARGE),
|
||||
BREEZE_WIND_CHARGE(ABSTRACT_WIND_CHARGE),
|
||||
|
||||
// Vehicles
|
||||
MINECART_ABSTRACT(ENTITY, null),
|
||||
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
|
||||
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
|
||||
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
|
||||
MINECART(MINECART_ABSTRACT),
|
||||
FURNACE_MINECART(MINECART_ABSTRACT),
|
||||
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
|
||||
TNT_MINECART(MINECART_ABSTRACT),
|
||||
SPAWNER_MINECART(MINECART_ABSTRACT),
|
||||
BOAT(ENTITY),
|
||||
CHEST_BOAT(BOAT);
|
||||
|
||||
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
|
||||
private final EntityType parent;
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
EntityTypes1_20_5(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
EntityTypes1_20_5(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, ENTITY);
|
||||
}
|
||||
|
||||
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
|
||||
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item;
|
|||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
|
@ -91,6 +92,11 @@ public class DataItem implements Item {
|
|||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructuredDataContainer structuredData() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item copy() {
|
||||
return new DataItem(identifier, amount, data, tag);
|
||||
|
@ -119,10 +125,10 @@ public class DataItem implements Item {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "Item{" +
|
||||
"identifier=" + identifier +
|
||||
", amount=" + amount +
|
||||
", data=" + data +
|
||||
", tag=" + tag +
|
||||
'}';
|
||||
"identifier=" + identifier +
|
||||
", amount=" + amount +
|
||||
", data=" + data +
|
||||
", tag=" + tag +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
package com.viaversion.viaversion.api.minecraft.item;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface Item {
|
||||
|
@ -79,7 +80,8 @@ public interface Item {
|
|||
*
|
||||
* @return item tag
|
||||
*/
|
||||
@Nullable CompoundTag tag();
|
||||
@Nullable
|
||||
CompoundTag tag();
|
||||
|
||||
/**
|
||||
* Sets the item compound tag.
|
||||
|
@ -88,10 +90,21 @@ public interface Item {
|
|||
*/
|
||||
void setTag(@Nullable CompoundTag tag);
|
||||
|
||||
StructuredDataContainer structuredData();
|
||||
|
||||
/**
|
||||
* Returns a copy of the item.
|
||||
*
|
||||
* @return copy of the item
|
||||
*/
|
||||
Item copy();
|
||||
|
||||
/**
|
||||
* Returns true if the item is empty.
|
||||
*
|
||||
* @return true if the item is empty
|
||||
*/
|
||||
default boolean isEmpty() {
|
||||
return identifier() == 0 || amount() <= 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class StructuredItem implements Item {
|
||||
private final StructuredDataContainer data;
|
||||
private int identifier;
|
||||
private int amount;
|
||||
|
||||
public StructuredItem(final int identifier, final int amount) {
|
||||
this(identifier, amount, new StructuredDataContainer());
|
||||
}
|
||||
|
||||
public StructuredItem(final int identifier, final int amount, final StructuredDataContainer data) {
|
||||
this.identifier = identifier;
|
||||
this.amount = amount;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdentifier(final int identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int amount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmount(final int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CompoundTag tag() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTag(@Nullable final CompoundTag tag) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructuredDataContainer structuredData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructuredItem copy() {
|
||||
return new StructuredItem(identifier, amount, data.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final StructuredItem that = (StructuredItem) o;
|
||||
if (identifier != that.identifier) return false;
|
||||
if (amount != that.amount) return false;
|
||||
return data.equals(that.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = data.hashCode();
|
||||
result = 31 * result + identifier;
|
||||
result = 31 * result + amount;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StructuredItem{" +
|
||||
"data=" + data +
|
||||
", identifier=" + identifier +
|
||||
", amount=" + amount +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class AdventureModePredicate {
|
||||
|
||||
public static final Type<AdventureModePredicate> TYPE = new Type<AdventureModePredicate>(AdventureModePredicate.class) {
|
||||
@Override
|
||||
public AdventureModePredicate read(final ByteBuf buffer) throws Exception {
|
||||
final BlockPredicate[] predicates = BlockPredicate.ARRAY_TYPE.read(buffer);
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
return new AdventureModePredicate(predicates, showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final AdventureModePredicate value) throws Exception {
|
||||
BlockPredicate.ARRAY_TYPE.write(buffer, value.predicates);
|
||||
buffer.writeBoolean(value.showInTooltip);
|
||||
}
|
||||
};
|
||||
|
||||
private final BlockPredicate[] predicates;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public AdventureModePredicate(final BlockPredicate[] predicates, final boolean showInTooltip) {
|
||||
this.predicates = predicates;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public BlockPredicate[] predicates() {
|
||||
return predicates;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class ArmorTrim {
|
||||
|
||||
public static final Type<ArmorTrim> TYPE = new Type<ArmorTrim>(ArmorTrim.class) {
|
||||
@Override
|
||||
public ArmorTrim read(final ByteBuf buffer) throws Exception {
|
||||
final Holder<ArmorTrimMaterial> material = ArmorTrimMaterial.TYPE.read(buffer);
|
||||
final Holder<ArmorTrimPattern> pattern = ArmorTrimPattern.TYPE.read(buffer);
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
return new ArmorTrim(material, pattern, showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ArmorTrim value) throws Exception {
|
||||
ArmorTrimMaterial.TYPE.write(buffer, value.material);
|
||||
ArmorTrimPattern.TYPE.write(buffer, value.pattern);
|
||||
buffer.writeBoolean(value.showInTooltip);
|
||||
}
|
||||
};
|
||||
|
||||
private final Holder<ArmorTrimMaterial> material;
|
||||
private final Holder<ArmorTrimPattern> pattern;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public ArmorTrim(final Holder<ArmorTrimMaterial> material, final Holder<ArmorTrimPattern> pattern, final boolean showInTooltip) {
|
||||
this.material = material;
|
||||
this.pattern = pattern;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public Holder<ArmorTrimMaterial> material() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public Holder<ArmorTrimPattern> pattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public final class ArmorTrimMaterial {
|
||||
|
||||
public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<ArmorTrimMaterial>() {
|
||||
@Override
|
||||
public ArmorTrimMaterial readDirect(final ByteBuf buffer) throws Exception {
|
||||
final String assetName = Type.STRING.read(buffer);
|
||||
final int item = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float itemModelIndex = buffer.readFloat();
|
||||
|
||||
final int overrideArmorMaterialsSize = Type.VAR_INT.readPrimitive(buffer);
|
||||
final Int2ObjectMap<String> overrideArmorMaterials = new Int2ObjectOpenHashMap<>(overrideArmorMaterialsSize);
|
||||
for (int i = 0; i < overrideArmorMaterialsSize; i++) {
|
||||
final int key = Type.VAR_INT.readPrimitive(buffer);
|
||||
final String value = Type.STRING.read(buffer);
|
||||
overrideArmorMaterials.put(key, value);
|
||||
}
|
||||
|
||||
final Tag description = Type.TAG.read(buffer);
|
||||
return new ArmorTrimMaterial(assetName, item, itemModelIndex, overrideArmorMaterials, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) throws Exception {
|
||||
Type.STRING.write(buffer, value.assetName());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.itemId());
|
||||
buffer.writeFloat(value.itemModelIndex());
|
||||
|
||||
Type.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size());
|
||||
for (final Int2ObjectMap.Entry<String> entry : value.overrideArmorMaterials().int2ObjectEntrySet()) {
|
||||
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
|
||||
Type.STRING.write(buffer, entry.getValue());
|
||||
}
|
||||
|
||||
Type.TAG.write(buffer, value.description());
|
||||
}
|
||||
};
|
||||
|
||||
private final String assetName;
|
||||
private final int itemId;
|
||||
private final float itemModelIndex;
|
||||
private final Int2ObjectMap<String> overrideArmorMaterials;
|
||||
private final Tag description;
|
||||
|
||||
public ArmorTrimMaterial(final String assetName, final int itemId, final float itemModelIndex, final Int2ObjectMap<String> overrideArmorMaterials, final Tag description) {
|
||||
this.assetName = assetName;
|
||||
this.itemId = itemId;
|
||||
this.itemModelIndex = itemModelIndex;
|
||||
this.overrideArmorMaterials = overrideArmorMaterials;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String assetName() {
|
||||
return assetName;
|
||||
}
|
||||
|
||||
public int itemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public float itemModelIndex() {
|
||||
return itemModelIndex;
|
||||
}
|
||||
|
||||
public Int2ObjectMap<String> overrideArmorMaterials() {
|
||||
return overrideArmorMaterials;
|
||||
}
|
||||
|
||||
public Tag description() {
|
||||
return description;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class ArmorTrimPattern {
|
||||
|
||||
public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<ArmorTrimPattern>() {
|
||||
@Override
|
||||
public ArmorTrimPattern readDirect(final ByteBuf buffer) throws Exception {
|
||||
final String assetName = Type.STRING.read(buffer);
|
||||
final int itemId = Type.VAR_INT.readPrimitive(buffer);
|
||||
final Tag description = Type.TAG.read(buffer);
|
||||
final boolean decal = buffer.readBoolean();
|
||||
return new ArmorTrimPattern(assetName, itemId, description, decal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) throws Exception {
|
||||
Type.STRING.write(buffer, value.assetName());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.itemId());
|
||||
Type.TAG.write(buffer, value.description());
|
||||
buffer.writeBoolean(value.decal());
|
||||
}
|
||||
};
|
||||
|
||||
private final String assetName;
|
||||
private final int itemId;
|
||||
private final Tag description;
|
||||
private final boolean decal;
|
||||
|
||||
public ArmorTrimPattern(final String assetName, final int itemId, final Tag description, final boolean decal) {
|
||||
this.assetName = assetName;
|
||||
this.itemId = itemId;
|
||||
this.description = description;
|
||||
this.decal = decal;
|
||||
}
|
||||
|
||||
public String assetName() {
|
||||
return assetName;
|
||||
}
|
||||
|
||||
public int itemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public Tag description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean decal() {
|
||||
return decal;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class AttributeModifier {
|
||||
|
||||
public static final Type<AttributeModifier> TYPE = new Type<AttributeModifier>(AttributeModifier.class) {
|
||||
@Override
|
||||
public AttributeModifier read(final ByteBuf buffer) throws Exception {
|
||||
final int attribute = Type.VAR_INT.readPrimitive(buffer);
|
||||
final ModifierData modifier = ModifierData.TYPE.read(buffer);
|
||||
final int slot = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new AttributeModifier(attribute, modifier, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final AttributeModifier value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.attribute);
|
||||
ModifierData.TYPE.write(buffer, value.modifier);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.slotType);
|
||||
}
|
||||
};
|
||||
public static final Type<AttributeModifier[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int attribute;
|
||||
private final ModifierData modifier;
|
||||
private final int slotType;
|
||||
|
||||
public AttributeModifier(final int attribute, final ModifierData modifier, final int slotType) {
|
||||
this.attribute = attribute;
|
||||
this.modifier = modifier;
|
||||
this.slotType = slotType;
|
||||
}
|
||||
|
||||
public int attribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
public ModifierData modifier() {
|
||||
return modifier;
|
||||
}
|
||||
|
||||
public int slotType() {
|
||||
return slotType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class AttributeModifiers {
|
||||
|
||||
public static final Type<AttributeModifiers> TYPE = new Type<AttributeModifiers>(AttributeModifiers.class) {
|
||||
@Override
|
||||
public AttributeModifiers read(final ByteBuf buffer) throws Exception {
|
||||
final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer);
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
return new AttributeModifiers(modifiers, showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final AttributeModifiers value) throws Exception {
|
||||
AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers());
|
||||
buffer.writeBoolean(value.showInTooltip());
|
||||
}
|
||||
};
|
||||
|
||||
private final AttributeModifier[] modifiers;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public AttributeModifiers(final AttributeModifier[] modifiers, final boolean showInTooltip) {
|
||||
this.modifiers = modifiers;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public AttributeModifier[] modifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class BannerPattern {
|
||||
|
||||
public static final HolderType<BannerPattern> TYPE = new HolderType<BannerPattern>() {
|
||||
@Override
|
||||
public BannerPattern readDirect(final ByteBuf buffer) throws Exception {
|
||||
final String assetId = Type.STRING.read(buffer);
|
||||
final String translationKey = Type.STRING.read(buffer);
|
||||
return new BannerPattern(assetId, translationKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final BannerPattern value) throws Exception {
|
||||
Type.STRING.write(buffer, value.assetId);
|
||||
Type.STRING.write(buffer, value.translationKey);
|
||||
}
|
||||
};
|
||||
|
||||
private final String assetId;
|
||||
private final String translationKey;
|
||||
|
||||
public BannerPattern(final String assetId, final String translationKey) {
|
||||
this.assetId = assetId;
|
||||
this.translationKey = translationKey;
|
||||
}
|
||||
|
||||
public String assetId() {
|
||||
return assetId;
|
||||
}
|
||||
|
||||
public String translationKey() {
|
||||
return translationKey;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class BannerPatternLayer {
|
||||
|
||||
public static final Type<BannerPatternLayer> TYPE = new Type<BannerPatternLayer>(BannerPatternLayer.class) {
|
||||
@Override
|
||||
public BannerPatternLayer read(final ByteBuf buffer) throws Exception {
|
||||
final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer);
|
||||
final int color = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new BannerPatternLayer(pattern, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BannerPatternLayer value) throws Exception {
|
||||
BannerPattern.TYPE.write(buffer, value.pattern);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.dyeColor);
|
||||
}
|
||||
};
|
||||
public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final Holder<BannerPattern> pattern;
|
||||
private final int dyeColor;
|
||||
|
||||
public BannerPatternLayer(final Holder<BannerPattern> pattern, final int dyeColor) {
|
||||
this.pattern = pattern;
|
||||
this.dyeColor = dyeColor;
|
||||
}
|
||||
|
||||
public Holder<BannerPattern> pattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public int dyeColor() {
|
||||
return dyeColor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Bee {
|
||||
|
||||
public static final Type<Bee> TYPE = new Type<Bee>(Bee.class) {
|
||||
@Override
|
||||
public Bee read(final ByteBuf buffer) throws Exception {
|
||||
final CompoundTag entityData = Type.COMPOUND_TAG.read(buffer);
|
||||
final int ticksInHive = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int minTicksInHive = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new Bee(entityData, ticksInHive, minTicksInHive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Bee value) throws Exception {
|
||||
Type.COMPOUND_TAG.write(buffer, value.entityData);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.ticksInHive);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
|
||||
}
|
||||
};
|
||||
public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final CompoundTag entityData;
|
||||
private final int ticksInHive;
|
||||
private final int minTicksInHive;
|
||||
|
||||
public Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) {
|
||||
this.entityData = entityData;
|
||||
this.ticksInHive = ticksInHive;
|
||||
this.minTicksInHive = minTicksInHive;
|
||||
}
|
||||
|
||||
public CompoundTag entityData() {
|
||||
return entityData;
|
||||
}
|
||||
|
||||
public int ticksInHive() {
|
||||
return ticksInHive;
|
||||
}
|
||||
|
||||
public int minTicksInHive() {
|
||||
return minTicksInHive;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class BlockPredicate {
|
||||
|
||||
public static final Type<BlockPredicate> TYPE = new Type<BlockPredicate>(BlockPredicate.class) {
|
||||
@Override
|
||||
public BlockPredicate read(final ByteBuf buffer) throws Exception {
|
||||
final HolderSet holders = Type.OPTIONAL_HOLDER_SET.read(buffer);
|
||||
final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null;
|
||||
final CompoundTag tag = Type.OPTIONAL_COMPOUND_TAG.read(buffer);
|
||||
return new BlockPredicate(holders, propertyMatchers, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BlockPredicate value) throws Exception {
|
||||
Type.OPTIONAL_HOLDER_SET.write(buffer, value.holderSet);
|
||||
|
||||
buffer.writeBoolean(value.propertyMatchers != null);
|
||||
if (value.propertyMatchers != null) {
|
||||
StatePropertyMatcher.ARRAY_TYPE.write(buffer, value.propertyMatchers);
|
||||
}
|
||||
|
||||
Type.OPTIONAL_COMPOUND_TAG.write(buffer, value.tag);
|
||||
}
|
||||
};
|
||||
public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final HolderSet holderSet;
|
||||
private final StatePropertyMatcher[] propertyMatchers;
|
||||
private final CompoundTag tag;
|
||||
|
||||
public BlockPredicate(@Nullable final HolderSet holderSet, final StatePropertyMatcher @Nullable [] propertyMatchers, @Nullable final CompoundTag tag) {
|
||||
this.holderSet = holderSet;
|
||||
this.propertyMatchers = propertyMatchers;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public @Nullable HolderSet holderSet() {
|
||||
return holderSet;
|
||||
}
|
||||
|
||||
public StatePropertyMatcher @Nullable [] propertyMatchers() {
|
||||
return propertyMatchers;
|
||||
}
|
||||
|
||||
public @Nullable CompoundTag tag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class BlockStateProperties {
|
||||
|
||||
public static final Type<BlockStateProperties> TYPE = new Type<BlockStateProperties>(BlockStateProperties.class) {
|
||||
@Override
|
||||
public BlockStateProperties read(final ByteBuf buffer) throws Exception {
|
||||
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||
final Map<String, String> properties = new Object2ObjectOpenHashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
properties.put(Type.STRING.read(buffer), Type.STRING.read(buffer));
|
||||
}
|
||||
return new BlockStateProperties(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BlockStateProperties value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.properties.size());
|
||||
for (final Map.Entry<String, String> entry : value.properties.entrySet()) {
|
||||
Type.STRING.write(buffer, entry.getKey());
|
||||
Type.STRING.write(buffer, entry.getValue());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public BlockStateProperties(final Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Map<String, String> properties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class DyedColor {
|
||||
|
||||
public static final Type<DyedColor> TYPE = new Type<DyedColor>(DyedColor.class) {
|
||||
@Override
|
||||
public DyedColor read(final ByteBuf buffer) {
|
||||
final int rgb = buffer.readInt();
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
return new DyedColor(rgb, showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final DyedColor value) {
|
||||
buffer.writeInt(value.rgb);
|
||||
buffer.writeBoolean(value.showInTooltip);
|
||||
}
|
||||
};
|
||||
|
||||
private final int rgb;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public DyedColor(final int rgb, final boolean showInTooltip) {
|
||||
this.rgb = rgb;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public int rgb() {
|
||||
return this.rgb;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public final class Enchantments {
|
||||
|
||||
public static final Type<Enchantments> TYPE = new Type<Enchantments>(Enchantments.class) {
|
||||
@Override
|
||||
public Enchantments read(final ByteBuf buffer) {
|
||||
final Int2IntMap enchantments = new Int2IntOpenHashMap();
|
||||
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||
for (int i = 0; i < size; i++) {
|
||||
final int id = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int level = Type.VAR_INT.readPrimitive(buffer);
|
||||
enchantments.put(id, level);
|
||||
}
|
||||
|
||||
return new Enchantments(enchantments, buffer.readBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Enchantments value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.enchantments.size());
|
||||
for (final Int2IntMap.Entry entry : value.enchantments.int2IntEntrySet()) {
|
||||
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
|
||||
Type.VAR_INT.writePrimitive(buffer, entry.getIntValue());
|
||||
}
|
||||
buffer.writeBoolean(value.showInTooltip());
|
||||
}
|
||||
};
|
||||
|
||||
private final Int2IntMap enchantments;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public Enchantments(final Int2IntMap enchantments, final boolean showInTooltip) {
|
||||
this.enchantments = enchantments;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public Enchantments(final boolean showInTooltip) {
|
||||
this(new Int2IntOpenHashMap(), showInTooltip);
|
||||
}
|
||||
|
||||
public Int2IntMap enchantments() {
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return enchantments.size();
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
|
||||
public void add(final int id, final int level) {
|
||||
enchantments.put(id, level);
|
||||
}
|
||||
|
||||
public void remove(final int id) {
|
||||
enchantments.remove(id);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
enchantments.clear();
|
||||
}
|
||||
|
||||
public int getLevel(final int id) {
|
||||
return enchantments.getOrDefault(id, -1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class Filterable<T> {
|
||||
private final T raw;
|
||||
private final T filtered;
|
||||
|
||||
protected Filterable(final T raw, @Nullable final T filtered) {
|
||||
this.raw = raw;
|
||||
this.filtered = filtered;
|
||||
}
|
||||
|
||||
public T raw() {
|
||||
return raw;
|
||||
}
|
||||
|
||||
public boolean isFiltered() {
|
||||
return filtered != null;
|
||||
}
|
||||
|
||||
public @Nullable T filtered() {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return filtered != null ? filtered : raw;
|
||||
}
|
||||
|
||||
public abstract static class FilterableType<T, F extends Filterable<T>> extends Type<F> {
|
||||
private final Type<T> elementType;
|
||||
private final Type<T> optionalElementType;
|
||||
|
||||
protected FilterableType(final Type<T> elementType, final Type<T> optionalElementType, final Class<F> outputClass) {
|
||||
super(outputClass);
|
||||
this.elementType = elementType;
|
||||
this.optionalElementType = optionalElementType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public F read(final ByteBuf buffer) throws Exception {
|
||||
final T raw = elementType.read(buffer);
|
||||
final T filtered = optionalElementType.read(buffer);
|
||||
return create(raw, filtered);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final F value) throws Exception {
|
||||
elementType.write(buffer, value.raw());
|
||||
optionalElementType.write(buffer, value.filtered());
|
||||
}
|
||||
|
||||
protected abstract F create(T raw, T filtered);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class FilterableComponent extends Filterable<Tag> {
|
||||
|
||||
public static final Type<FilterableComponent> TYPE = new FilterableType<Tag, FilterableComponent>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) {
|
||||
@Override
|
||||
protected FilterableComponent create(final Tag raw, final Tag filtered) {
|
||||
return new FilterableComponent(raw, filtered);
|
||||
}
|
||||
};
|
||||
public static final Type<FilterableComponent[]> ARRAY_TYPE = new ArrayType<>(FilterableComponent.TYPE);
|
||||
|
||||
public FilterableComponent(final Tag raw, @Nullable final Tag filtered) {
|
||||
super(raw, filtered);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class FilterableString extends Filterable<String> {
|
||||
|
||||
public static final Type<FilterableString> TYPE = new FilterableType<String, FilterableString>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) {
|
||||
@Override
|
||||
protected FilterableString create(final String raw, final String filtered) {
|
||||
return new FilterableString(raw, filtered);
|
||||
}
|
||||
};
|
||||
public static final Type<FilterableString[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
public FilterableString(final String raw, @Nullable final String filtered) {
|
||||
super(raw, filtered);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class FireworkExplosion {
|
||||
public static final Type<FireworkExplosion> TYPE = new Type<FireworkExplosion>(FireworkExplosion.class) {
|
||||
@Override
|
||||
public FireworkExplosion read(final ByteBuf buffer) throws Exception {
|
||||
final int shape = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int[] colors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
|
||||
final int[] fadeColors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
|
||||
final boolean hasTrail = buffer.readBoolean();
|
||||
final boolean hasTwinkle = buffer.readBoolean();
|
||||
return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FireworkExplosion value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.shape);
|
||||
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.colors);
|
||||
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors);
|
||||
buffer.writeBoolean(value.hasTrail);
|
||||
buffer.writeBoolean(value.hasTwinkle);
|
||||
}
|
||||
};
|
||||
public static final Type<FireworkExplosion[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int shape;
|
||||
private final int[] colors;
|
||||
private final int[] fadeColors;
|
||||
private final boolean hasTrail;
|
||||
private final boolean hasTwinkle;
|
||||
|
||||
public FireworkExplosion(final int shape, final int[] colors, final int[] fadeColors, final boolean hasTrail, final boolean hasTwinkle) {
|
||||
this.shape = shape;
|
||||
this.colors = colors;
|
||||
this.fadeColors = fadeColors;
|
||||
this.hasTrail = hasTrail;
|
||||
this.hasTwinkle = hasTwinkle;
|
||||
}
|
||||
|
||||
public int shape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public int[] colors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public int[] fadeColors() {
|
||||
return fadeColors;
|
||||
}
|
||||
|
||||
public boolean hasTrail() {
|
||||
return hasTrail;
|
||||
}
|
||||
|
||||
public boolean hasTwinkle() {
|
||||
return hasTwinkle;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Fireworks {
|
||||
|
||||
public static final Type<Fireworks> TYPE = new Type<Fireworks>(Fireworks.class) {
|
||||
@Override
|
||||
public Fireworks read(final ByteBuf buffer) throws Exception {
|
||||
final int flightDuration = Type.VAR_INT.readPrimitive(buffer);
|
||||
final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer);
|
||||
return new Fireworks(flightDuration, explosions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Fireworks value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.flightDuration);
|
||||
FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions);
|
||||
}
|
||||
};
|
||||
|
||||
private final FireworkExplosion[] explosions;
|
||||
private final int flightDuration;
|
||||
|
||||
public Fireworks(final int flightDuration, final FireworkExplosion[] explosions) {
|
||||
this.flightDuration = flightDuration;
|
||||
this.explosions = explosions;
|
||||
}
|
||||
|
||||
public int flightDuration() {
|
||||
return flightDuration;
|
||||
}
|
||||
|
||||
public FireworkExplosion[] explosions() {
|
||||
return explosions;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class FoodEffect {
|
||||
|
||||
public static final Type<FoodEffect> TYPE = new Type<FoodEffect>(FoodEffect.class) {
|
||||
@Override
|
||||
public FoodEffect read(final ByteBuf buffer) throws Exception {
|
||||
final PotionEffect effect = PotionEffect.TYPE.read(buffer);
|
||||
final float probability = buffer.readFloat();
|
||||
return new FoodEffect(effect, probability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FoodEffect value) throws Exception {
|
||||
PotionEffect.TYPE.write(buffer, value.effect);
|
||||
buffer.writeFloat(value.probability);
|
||||
}
|
||||
};
|
||||
public static final Type<FoodEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final PotionEffect effect;
|
||||
private final float probability;
|
||||
|
||||
public FoodEffect(final PotionEffect effect, final float probability) {
|
||||
this.effect = effect;
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public PotionEffect effect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public float probability() {
|
||||
return probability;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class FoodProperties {
|
||||
|
||||
public static final Type<FoodProperties> TYPE = new Type<FoodProperties>(FoodProperties.class) {
|
||||
@Override
|
||||
public FoodProperties read(final ByteBuf buffer) throws Exception {
|
||||
final int nutrition = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float saturationModifier = buffer.readFloat();
|
||||
final boolean canAlwaysEat = buffer.readBoolean();
|
||||
final float eatSeconds = buffer.readFloat();
|
||||
final FoodEffect[] possibleEffects = FoodEffect.ARRAY_TYPE.read(buffer);
|
||||
return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, possibleEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FoodProperties value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.nutrition);
|
||||
buffer.writeFloat(value.saturationModifier);
|
||||
buffer.writeBoolean(value.canAlwaysEat);
|
||||
buffer.writeFloat(value.eatSeconds);
|
||||
FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects);
|
||||
}
|
||||
};
|
||||
|
||||
private final int nutrition;
|
||||
private final float saturationModifier;
|
||||
private final boolean canAlwaysEat;
|
||||
private final float eatSeconds;
|
||||
private final FoodEffect[] possibleEffects;
|
||||
|
||||
public FoodProperties(final int nutrition, final float saturationModifier, final boolean canAlwaysEat, final float eatSeconds, final FoodEffect[] possibleEffects) {
|
||||
this.nutrition = nutrition;
|
||||
this.saturationModifier = saturationModifier;
|
||||
this.canAlwaysEat = canAlwaysEat;
|
||||
this.eatSeconds = eatSeconds;
|
||||
this.possibleEffects = possibleEffects;
|
||||
}
|
||||
|
||||
public int nutrition() {
|
||||
return nutrition;
|
||||
}
|
||||
|
||||
public float saturationModifier() {
|
||||
return saturationModifier;
|
||||
}
|
||||
|
||||
public boolean canAlwaysEat() {
|
||||
return canAlwaysEat;
|
||||
}
|
||||
|
||||
public float eatSeconds() {
|
||||
return eatSeconds;
|
||||
}
|
||||
|
||||
public FoodEffect[] possibleEffects() {
|
||||
return possibleEffects;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Instrument {
|
||||
|
||||
public static final HolderType<Instrument> TYPE = new HolderType<Instrument>() {
|
||||
@Override
|
||||
public Instrument readDirect(final ByteBuf buffer) throws Exception {
|
||||
final Holder<SoundEvent> soundEvent = Type.SOUND_EVENT.read(buffer);
|
||||
final int useDuration = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float range = buffer.readFloat();
|
||||
return new Instrument(soundEvent, useDuration, range);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final Instrument value) throws Exception {
|
||||
Type.SOUND_EVENT.write(buffer, value.soundEvent());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.useDuration());
|
||||
buffer.writeFloat(value.range());
|
||||
}
|
||||
};
|
||||
|
||||
private final Holder<SoundEvent> soundEvent;
|
||||
private final int useDuration;
|
||||
private final float range;
|
||||
|
||||
public Instrument(final Holder<SoundEvent> soundEvent, final int useDuration, final float range) {
|
||||
this.soundEvent = soundEvent;
|
||||
this.useDuration = useDuration;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public Holder<SoundEvent> soundEvent() {
|
||||
return soundEvent;
|
||||
}
|
||||
|
||||
public int useDuration() {
|
||||
return useDuration;
|
||||
}
|
||||
|
||||
public float range() {
|
||||
return range;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.minecraft.GlobalPosition;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class LodestoneTracker {
|
||||
|
||||
public static final Type<LodestoneTracker> TYPE = new Type<LodestoneTracker>(LodestoneTracker.class) {
|
||||
@Override
|
||||
public LodestoneTracker read(final ByteBuf buffer) throws Exception {
|
||||
final GlobalPosition position = Type.OPTIONAL_GLOBAL_POSITION.read(buffer);
|
||||
final boolean tracked = buffer.readBoolean();
|
||||
return new LodestoneTracker(position, tracked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final LodestoneTracker value) throws Exception {
|
||||
Type.OPTIONAL_GLOBAL_POSITION.write(buffer, value.position);
|
||||
buffer.writeBoolean(value.tracked);
|
||||
}
|
||||
};
|
||||
|
||||
private final GlobalPosition position;
|
||||
private final boolean tracked;
|
||||
|
||||
public LodestoneTracker(@Nullable final GlobalPosition position, final boolean tracked) {
|
||||
this.position = position;
|
||||
this.tracked = tracked;
|
||||
}
|
||||
|
||||
public @Nullable GlobalPosition pos() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public boolean tracked() {
|
||||
return this.tracked;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class MapDecoration {
|
||||
|
||||
public static final Type<MapDecoration> TYPE = new Type<MapDecoration>(MapDecoration.class) {
|
||||
@Override
|
||||
public MapDecoration read(final ByteBuf buffer) throws Exception {
|
||||
final String type = Type.STRING.read(buffer);
|
||||
final double x = Type.DOUBLE.readPrimitive(buffer);
|
||||
final double z = Type.DOUBLE.readPrimitive(buffer);
|
||||
final float rotation = Type.FLOAT.readPrimitive(buffer);
|
||||
return new MapDecoration(type, x, z, rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final MapDecoration value) throws Exception {
|
||||
Type.STRING.write(buffer, value.type);
|
||||
buffer.writeDouble(value.x);
|
||||
buffer.writeDouble(value.z);
|
||||
buffer.writeFloat(value.rotation);
|
||||
}
|
||||
};
|
||||
|
||||
private final String type;
|
||||
private final double x;
|
||||
private final double z;
|
||||
private final float rotation;
|
||||
|
||||
public MapDecoration(final String type, final double x, final double z, final float rotation) {
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public String type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public double x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public float rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class MapDecorations {
|
||||
|
||||
public static final Type<MapDecorations> TYPE = new Type<MapDecorations>(MapDecorations.class) {
|
||||
@Override
|
||||
public MapDecorations read(final ByteBuf buffer) throws Exception {
|
||||
final Object2ObjectMap<String, MapDecoration> decorations = new Object2ObjectOpenHashMap<>();
|
||||
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||
for (int i = 0; i < size; i++) {
|
||||
final String id = Type.STRING.read(buffer);
|
||||
final MapDecoration decoration = MapDecoration.TYPE.read(buffer);
|
||||
decorations.put(id, decoration);
|
||||
}
|
||||
return new MapDecorations(decorations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final MapDecorations value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.decorations.size());
|
||||
for (final Map.Entry<String, MapDecoration> entry : value.decorations.entrySet()) {
|
||||
Type.STRING.write(buffer, entry.getKey());
|
||||
MapDecoration.TYPE.write(buffer, entry.getValue());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<String, MapDecoration> decorations;
|
||||
|
||||
public MapDecorations(final Map<String, MapDecoration> decorations) {
|
||||
this.decorations = decorations;
|
||||
}
|
||||
|
||||
public Map<String, MapDecoration> decorations() {
|
||||
return decorations;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ModifierData {
|
||||
|
||||
public static final Type<ModifierData> TYPE = new Type<ModifierData>(ModifierData.class) {
|
||||
@Override
|
||||
public ModifierData read(final ByteBuf buffer) throws Exception {
|
||||
final UUID uuid = Type.UUID.read(buffer);
|
||||
final String name = Type.STRING.read(buffer);
|
||||
final double amount = buffer.readDouble();
|
||||
final int operation = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new ModifierData(uuid, name, amount, operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ModifierData value) throws Exception {
|
||||
Type.UUID.write(buffer, value.uuid);
|
||||
Type.STRING.write(buffer, value.name);
|
||||
buffer.writeDouble(value.amount);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.operation);
|
||||
}
|
||||
};
|
||||
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final double amount;
|
||||
private final int operation;
|
||||
|
||||
public ModifierData(final UUID uuid, final String name, final double amount, final int operation) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public UUID uuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double amount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int operation() {
|
||||
return operation;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class PotDecorations {
|
||||
|
||||
public static final Type<PotDecorations> TYPE = new Type<PotDecorations>(PotDecorations.class) {
|
||||
@Override
|
||||
public PotDecorations read(final ByteBuf buffer) throws Exception {
|
||||
return new PotDecorations(Type.VAR_INT_ARRAY_PRIMITIVE.read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotDecorations value) throws Exception {
|
||||
Type.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds());
|
||||
}
|
||||
};
|
||||
|
||||
private final int[] itemIds;
|
||||
|
||||
public PotDecorations(final int[] itemIds) {
|
||||
this.itemIds = itemIds;
|
||||
}
|
||||
|
||||
public PotDecorations(final int backItem, final int leftItem, final int rightItem, final int frontItem) {
|
||||
this.itemIds = new int[]{backItem, leftItem, rightItem, frontItem};
|
||||
}
|
||||
|
||||
public int[] itemIds() {
|
||||
return itemIds;
|
||||
}
|
||||
|
||||
public int backItem() {
|
||||
return item(0);
|
||||
}
|
||||
|
||||
public int leftItem() {
|
||||
return item(1);
|
||||
}
|
||||
|
||||
public int rightItem() {
|
||||
return item(2);
|
||||
}
|
||||
|
||||
public int frontItem() {
|
||||
return item(3);
|
||||
}
|
||||
|
||||
private int item(final int index) {
|
||||
return index < 0 || index >= itemIds.length ? -1 : itemIds[index];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class PotionContents {
|
||||
|
||||
public static final Type<PotionContents> TYPE = new Type<PotionContents>(PotionContents.class) {
|
||||
@Override
|
||||
public PotionContents read(final ByteBuf buffer) throws Exception {
|
||||
final Integer potion = buffer.readBoolean() ? Type.VAR_INT.readPrimitive(buffer) : null;
|
||||
final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null;
|
||||
final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer);
|
||||
return new PotionContents(potion, customColor, customEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotionContents value) throws Exception {
|
||||
buffer.writeBoolean(value.potion != null);
|
||||
if (value.potion != null) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.potion);
|
||||
}
|
||||
|
||||
buffer.writeBoolean(value.customColor != null);
|
||||
if (value.customColor != null) {
|
||||
buffer.writeInt(value.customColor);
|
||||
}
|
||||
|
||||
PotionEffect.ARRAY_TYPE.write(buffer, value.customEffects);
|
||||
}
|
||||
};
|
||||
|
||||
private final Integer potion;
|
||||
private final Integer customColor;
|
||||
private final PotionEffect[] customEffects;
|
||||
|
||||
public PotionContents(@Nullable final Integer potion, @Nullable final Integer customColor, final PotionEffect[] customEffects) {
|
||||
this.potion = potion;
|
||||
this.customColor = customColor;
|
||||
this.customEffects = customEffects;
|
||||
}
|
||||
|
||||
public @Nullable Integer potion() {
|
||||
return potion;
|
||||
}
|
||||
|
||||
public @Nullable Integer customColor() {
|
||||
return customColor;
|
||||
}
|
||||
|
||||
public PotionEffect[] customEffects() {
|
||||
return customEffects;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class PotionEffect {
|
||||
|
||||
public static final Type<PotionEffect> TYPE = new Type<PotionEffect>(PotionEffect.class) {
|
||||
@Override
|
||||
public PotionEffect read(final ByteBuf buffer) throws Exception {
|
||||
final int effect = Type.VAR_INT.readPrimitive(buffer);
|
||||
final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer);
|
||||
return new PotionEffect(effect, effectData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotionEffect value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.effect);
|
||||
PotionEffectData.TYPE.write(buffer, value.effectData);
|
||||
}
|
||||
};
|
||||
public static final Type<PotionEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int effect;
|
||||
private final PotionEffectData effectData;
|
||||
|
||||
public PotionEffect(final int effect, final PotionEffectData effectData) {
|
||||
this.effect = effect;
|
||||
this.effectData = effectData;
|
||||
}
|
||||
|
||||
public int effect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public PotionEffectData effectData() {
|
||||
return effectData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class PotionEffectData {
|
||||
|
||||
public static final Type<PotionEffectData> TYPE = new Type<PotionEffectData>(PotionEffectData.class) {
|
||||
@Override
|
||||
public PotionEffectData read(final ByteBuf buffer) throws Exception {
|
||||
final int amplifier = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int duration = Type.VAR_INT.readPrimitive(buffer);
|
||||
final boolean ambient = buffer.readBoolean();
|
||||
final boolean showParticles = buffer.readBoolean();
|
||||
final boolean showIcon = buffer.readBoolean();
|
||||
final PotionEffectData hiddenEffect = OPTIONAL_TYPE.read(buffer);
|
||||
return new PotionEffectData(amplifier, duration, ambient, showParticles, showIcon, hiddenEffect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotionEffectData value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.amplifier);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.duration);
|
||||
buffer.writeBoolean(value.ambient);
|
||||
buffer.writeBoolean(value.showParticles);
|
||||
buffer.writeBoolean(value.showIcon);
|
||||
OPTIONAL_TYPE.write(buffer, value.hiddenEffect);
|
||||
}
|
||||
};
|
||||
public static final Type<PotionEffectData> OPTIONAL_TYPE = new OptionalType<PotionEffectData>(TYPE) {
|
||||
};
|
||||
|
||||
private final int amplifier;
|
||||
private final int duration;
|
||||
private final boolean ambient;
|
||||
private final boolean showParticles;
|
||||
private final boolean showIcon;
|
||||
private final PotionEffectData hiddenEffect;
|
||||
|
||||
public PotionEffectData(final int amplifier, final int duration, final boolean ambient, final boolean showParticles,
|
||||
final boolean showIcon, @Nullable final PotionEffectData hiddenEffect) {
|
||||
this.amplifier = amplifier;
|
||||
this.duration = duration;
|
||||
this.ambient = ambient;
|
||||
this.showParticles = showParticles;
|
||||
this.showIcon = showIcon;
|
||||
this.hiddenEffect = hiddenEffect;
|
||||
}
|
||||
|
||||
public int amplifier() {
|
||||
return amplifier;
|
||||
}
|
||||
|
||||
public int duration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public boolean ambient() {
|
||||
return ambient;
|
||||
}
|
||||
|
||||
public boolean showParticles() {
|
||||
return showParticles;
|
||||
}
|
||||
|
||||
public boolean showIcon() {
|
||||
return showIcon;
|
||||
}
|
||||
|
||||
public @Nullable PotionEffectData hiddenEffect() {
|
||||
return hiddenEffect;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import com.viaversion.viaversion.util.Either;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class StatePropertyMatcher {
|
||||
|
||||
// TODO Abstract Either reading
|
||||
public static final Type<StatePropertyMatcher> TYPE = new Type<StatePropertyMatcher>(StatePropertyMatcher.class) {
|
||||
@Override
|
||||
public StatePropertyMatcher read(final ByteBuf buffer) throws Exception {
|
||||
final String name = Type.STRING.read(buffer);
|
||||
if (buffer.readBoolean()) {
|
||||
final String value = Type.STRING.read(buffer);
|
||||
return new StatePropertyMatcher(name, Either.left(value));
|
||||
} else {
|
||||
final String minValue = Type.OPTIONAL_STRING.read(buffer);
|
||||
final String maxValue = Type.OPTIONAL_STRING.read(buffer);
|
||||
return new StatePropertyMatcher(name, Either.right(new RangedMatcher(minValue, maxValue)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final StatePropertyMatcher value) throws Exception {
|
||||
Type.STRING.write(buffer, value.name);
|
||||
if (value.matcher.isLeft()) {
|
||||
buffer.writeBoolean(true);
|
||||
Type.STRING.write(buffer, value.matcher.left());
|
||||
} else {
|
||||
buffer.writeBoolean(false);
|
||||
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().minValue());
|
||||
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().maxValue());
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final Type<StatePropertyMatcher[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final String name;
|
||||
private final Either<String, RangedMatcher> matcher;
|
||||
|
||||
public StatePropertyMatcher(final String name, final Either<String, RangedMatcher> matcher) {
|
||||
this.name = name;
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Either<String, RangedMatcher> matcher() {
|
||||
return matcher;
|
||||
}
|
||||
|
||||
public static final class RangedMatcher {
|
||||
private final String minValue;
|
||||
private final String maxValue;
|
||||
|
||||
public RangedMatcher(@Nullable final String minValue, @Nullable final String maxValue) {
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public @Nullable String minValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public @Nullable String maxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class SuspiciousStewEffect {
|
||||
|
||||
public static final Type<SuspiciousStewEffect> TYPE = new Type<SuspiciousStewEffect>(SuspiciousStewEffect.class) {
|
||||
@Override
|
||||
public SuspiciousStewEffect read(final ByteBuf buffer) {
|
||||
final int effect = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int duration = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new SuspiciousStewEffect(effect, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final SuspiciousStewEffect value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.effect);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.duration);
|
||||
}
|
||||
};
|
||||
public static final Type<SuspiciousStewEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int effect;
|
||||
private final int duration;
|
||||
|
||||
public SuspiciousStewEffect(final int effect, final int duration) {
|
||||
this.effect = effect;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public int mobEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public int duration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class ToolProperties {
|
||||
|
||||
public static final Type<ToolProperties> TYPE = new Type<ToolProperties>(ToolProperties.class) {
|
||||
@Override
|
||||
public ToolProperties read(final ByteBuf buffer) throws Exception {
|
||||
final ToolRule[] rules = ToolRule.ARRAY_TYPE.read(buffer);
|
||||
final float defaultMiningSpeed = buffer.readFloat();
|
||||
final int damagePerBlock = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new ToolProperties(rules, defaultMiningSpeed, damagePerBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ToolProperties value) throws Exception {
|
||||
ToolRule.ARRAY_TYPE.write(buffer, value.rules());
|
||||
buffer.writeFloat(value.defaultMiningSpeed());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.damagePerBlock());
|
||||
}
|
||||
};
|
||||
|
||||
private final ToolRule[] rules;
|
||||
private final float defaultMiningSpeed;
|
||||
private final int damagePerBlock;
|
||||
|
||||
public ToolProperties(final ToolRule[] rules, final float defaultMiningSpeed, final int damagePerBlock) {
|
||||
this.rules = rules;
|
||||
this.defaultMiningSpeed = defaultMiningSpeed;
|
||||
this.damagePerBlock = damagePerBlock;
|
||||
}
|
||||
|
||||
public ToolRule[] rules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public float defaultMiningSpeed() {
|
||||
return defaultMiningSpeed;
|
||||
}
|
||||
|
||||
public int damagePerBlock() {
|
||||
return damagePerBlock;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class ToolRule {
|
||||
|
||||
public static final Type<ToolRule> TYPE = new Type<ToolRule>(ToolRule.class) {
|
||||
@Override
|
||||
public ToolRule read(final ByteBuf buffer) throws Exception {
|
||||
final HolderSet blocks = Type.HOLDER_SET.read(buffer);
|
||||
final Float speed = Type.OPTIONAL_FLOAT.read(buffer);
|
||||
final Boolean correctForDrops = Type.OPTIONAL_BOOLEAN.read(buffer);
|
||||
return new ToolRule(blocks, speed, correctForDrops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ToolRule value) throws Exception {
|
||||
Type.HOLDER_SET.write(buffer, value.blocks);
|
||||
Type.OPTIONAL_FLOAT.write(buffer, value.speed);
|
||||
Type.OPTIONAL_BOOLEAN.write(buffer, value.correctForDrops);
|
||||
}
|
||||
};
|
||||
public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final HolderSet blocks;
|
||||
private final Float speed;
|
||||
private final Boolean correctForDrops;
|
||||
|
||||
public ToolRule(final HolderSet blocks, @Nullable final Float speed, @Nullable final Boolean correctForDrops) {
|
||||
this.blocks = blocks;
|
||||
this.speed = speed;
|
||||
this.correctForDrops = correctForDrops;
|
||||
}
|
||||
|
||||
public HolderSet blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public @Nullable Float speed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public @Nullable Boolean correctForDrops() {
|
||||
return correctForDrops;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Unbreakable {
|
||||
|
||||
public static final Type<Unbreakable> TYPE = new Type<Unbreakable>(Unbreakable.class) {
|
||||
@Override
|
||||
public Unbreakable read(final ByteBuf buffer) {
|
||||
return new Unbreakable(buffer.readBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Unbreakable value) {
|
||||
buffer.writeBoolean(value.showInTooltip());
|
||||
}
|
||||
};
|
||||
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public Unbreakable(final boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class WrittenBook {
|
||||
|
||||
public static final Type<WrittenBook> TYPE = new Type<WrittenBook>(WrittenBook.class) {
|
||||
@Override
|
||||
public WrittenBook read(final ByteBuf buffer) throws Exception {
|
||||
final FilterableString title = FilterableString.TYPE.read(buffer);
|
||||
final String author = Type.STRING.read(buffer);
|
||||
final int generation = Type.VAR_INT.readPrimitive(buffer);
|
||||
final FilterableComponent[] pages = FilterableComponent.ARRAY_TYPE.read(buffer);
|
||||
final boolean resolved = buffer.readBoolean();
|
||||
return new WrittenBook(title, author, generation, pages, resolved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final WrittenBook value) throws Exception {
|
||||
FilterableString.TYPE.write(buffer, value.title);
|
||||
Type.STRING.write(buffer, value.author);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.generation);
|
||||
FilterableComponent.ARRAY_TYPE.write(buffer, value.pages);
|
||||
buffer.writeBoolean(value.resolved);
|
||||
}
|
||||
};
|
||||
|
||||
private final FilterableString title;
|
||||
private final String author;
|
||||
private final int generation;
|
||||
private final FilterableComponent[] pages;
|
||||
private final boolean resolved;
|
||||
|
||||
public WrittenBook(final FilterableString title, final String author, final int generation, final FilterableComponent[] pages, final boolean resolved) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.generation = generation;
|
||||
this.pages = pages;
|
||||
this.resolved = resolved;
|
||||
}
|
||||
|
||||
public FilterableString title() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String author() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public int generation() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
public FilterableComponent[] pages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public boolean resolved() {
|
||||
return resolved;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
|
||||
public interface MetaType {
|
||||
|
@ -49,6 +50,7 @@ public interface MetaType {
|
|||
private final Type<?> type;
|
||||
|
||||
MetaTypeImpl(final int typeId, final Type<?> type) {
|
||||
Preconditions.checkNotNull(type);
|
||||
this.typeId = typeId;
|
||||
this.type = type;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
|||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.VoidType;
|
||||
|
||||
public enum MetaType1_8 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
|
@ -34,9 +33,7 @@ public enum MetaType1_8 implements MetaType {
|
|||
String(4, Type.STRING),
|
||||
Slot(5, Type.ITEM1_8),
|
||||
Position(6, Type.VECTOR),
|
||||
Rotation(7, Type.ROTATION),
|
||||
@Deprecated
|
||||
NonExistent(-1, new VoidType());
|
||||
Rotation(7, Type.ROTATION);
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 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.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
|
||||
public final class MetaTypes1_20_5 extends AbstractMetaTypes {
|
||||
|
||||
public final MetaType byteType = add(0, Type.BYTE);
|
||||
public final MetaType varIntType = add(1, Type.VAR_INT);
|
||||
public final MetaType longType = add(2, Type.VAR_LONG);
|
||||
public final MetaType floatType = add(3, Type.FLOAT);
|
||||
public final MetaType stringType = add(4, Type.STRING);
|
||||
public final MetaType componentType = add(5, Type.TAG);
|
||||
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG);
|
||||
public final MetaType itemType = add(7, Types1_20_5.ITEM);
|
||||
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(9, Type.ROTATION);
|
||||
public final MetaType positionType = add(10, Type.POSITION1_14);
|
||||
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14);
|
||||
public final MetaType directionType = add(12, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(14, Type.VAR_INT);
|
||||
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(16, Type.COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType particlesType;
|
||||
public final MetaType villagerDatatType = add(19, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(20, Type.OPTIONAL_VAR_INT);
|
||||
public final MetaType poseType = add(21, Type.VAR_INT);
|
||||
public final MetaType catVariantType = add(22, Type.VAR_INT);
|
||||
public final MetaType wolfVariantType = add(23, Type.VAR_INT);
|
||||
public final MetaType frogVariantType = add(24, Type.VAR_INT);
|
||||
public final MetaType optionalGlobalPosition = add(25, Type.OPTIONAL_GLOBAL_POSITION);
|
||||
public final MetaType paintingVariantType = add(26, Type.VAR_INT);
|
||||
public final MetaType snifferState = add(27, Type.VAR_INT);
|
||||
public final MetaType armadilloState = add(28, Type.VAR_INT);
|
||||
public final MetaType vectorType = add(29, Type.VECTOR3F);
|
||||
public final MetaType quaternionType = add(30, Type.QUATERNION);
|
||||
|
||||
public MetaTypes1_20_5(final ParticleType particleType, final ArrayType<Particle> particlesType) {
|
||||
super(31);
|
||||
this.particleType = add(17, particleType);
|
||||
this.particlesType = add(18, particlesType);
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1;
|
|||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
|
||||
import net.lenni0451.mcstructs.text.utils.JsonUtils;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
@ -62,7 +62,7 @@ public class MessageBody {
|
|||
dataOutputStream.write(this.content.plain().getBytes(StandardCharsets.UTF_8));
|
||||
dataOutputStream.write(HASH_SEPARATOR_BYTE);
|
||||
if (this.content.isDecorated()) {
|
||||
dataOutputStream.write(JsonUtils.toSortedString(this.content.decorated(), null).getBytes(StandardCharsets.UTF_8));
|
||||
dataOutputStream.write(GsonUtil.sort(this.content.decorated()).toString().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
for (PlayerMessageSignature lastSeenMessage : this.lastSeenMessages) {
|
||||
|
|
|
@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.minecraft.signature.storage;
|
|||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||
import net.lenni0451.mcstructs.text.utils.JsonUtils;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
@ -48,7 +48,7 @@ public class ChatSession1_19_0 extends ChatSession {
|
|||
buffer.putLong(metadata.sender().getMostSignificantBits()).putLong(metadata.sender().getLeastSignificantBits());
|
||||
buffer.putLong(metadata.timestamp().getEpochSecond());
|
||||
signer.accept(data);
|
||||
signer.accept(JsonUtils.toSortedString(content.decorated(), null).getBytes(StandardCharsets.UTF_8));
|
||||
signer.accept(GsonUtil.sort(content.decorated()).toString().getBytes(StandardCharsets.UTF_8));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
|
||||
public interface ProtocolDetectorService {
|
||||
|
@ -32,7 +33,7 @@ public interface ProtocolDetectorService {
|
|||
* @param serverName name of the proxied server
|
||||
* @return protocol version of the proxied server, or -1 if unknown
|
||||
*/
|
||||
int serverProtocolVersion(String serverName);
|
||||
ProtocolVersion serverProtocolVersion(String serverName);
|
||||
|
||||
/**
|
||||
* Probes all registered proxied servers for their protocol version.
|
||||
|
|
|
@ -23,8 +23,9 @@
|
|||
package com.viaversion.viaversion.api.platform;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSortedSets;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
|
||||
import java.util.SortedSet;
|
||||
|
||||
public interface ViaInjector {
|
||||
|
||||
|
@ -60,7 +61,7 @@ public interface ViaInjector {
|
|||
* @throws Exception if there is an error with getting this info, e.g. not binded
|
||||
* @see ViaPlatform#isProxy()
|
||||
*/
|
||||
int getServerProtocolVersion() throws Exception;
|
||||
ProtocolVersion getServerProtocolVersion() throws Exception;
|
||||
|
||||
/**
|
||||
* Returns the supported server protocol versions.
|
||||
|
@ -69,8 +70,10 @@ public interface ViaInjector {
|
|||
* @throws Exception if there is an error with getting this info, e.g. not binded
|
||||
* @see ViaPlatform#isProxy()
|
||||
*/
|
||||
default IntSortedSet getServerProtocolVersions() throws Exception {
|
||||
return IntSortedSets.singleton(getServerProtocolVersion());
|
||||
default SortedSet<ProtocolVersion> getServerProtocolVersions() throws Exception {
|
||||
final SortedSet<ProtocolVersion> versions = new ObjectLinkedOpenHashSet<>();
|
||||
versions.add(getServerProtocolVersion());
|
||||
return versions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,11 +38,11 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypeMap;
|
|||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.rewriter.MappingDataListener;
|
||||
import com.viaversion.viaversion.api.rewriter.Rewriter;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import com.viaversion.viaversion.util.ProtocolUtil;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
@ -50,6 +50,8 @@ import java.util.function.Predicate;
|
|||
import java.util.logging.Level;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
|
||||
|
||||
/**
|
||||
* Abstract protocol class to handle packet transformation between two protocol versions.
|
||||
*
|
||||
|
@ -125,24 +127,42 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
// even if there will be multiple of these handlers
|
||||
final SU configurationAcknowledgedPacket = configurationAcknowledgedPacket();
|
||||
if (configurationAcknowledgedPacket != null) {
|
||||
registerServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
|
||||
appendServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
|
||||
}
|
||||
|
||||
final CU startConfigurationPacket = startConfigurationPacket();
|
||||
if (startConfigurationPacket != null) {
|
||||
registerClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
|
||||
appendClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
|
||||
}
|
||||
|
||||
final ServerboundPacketType finishConfigurationPacket = serverboundFinishConfigurationPacket();
|
||||
final SU finishConfigurationPacket = serverboundFinishConfigurationPacket();
|
||||
if (finishConfigurationPacket != null) {
|
||||
final int id = finishConfigurationPacket.getId();
|
||||
registerServerbound(State.CONFIGURATION, id, id, setClientStateHandler(State.PLAY));
|
||||
appendServerbound(finishConfigurationPacket, setClientStateHandler(State.PLAY));
|
||||
}
|
||||
|
||||
final ClientboundPacketType clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
|
||||
final CU clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
|
||||
if (clientboundFinishConfigurationPacket != null) {
|
||||
final int id = clientboundFinishConfigurationPacket.getId();
|
||||
registerClientbound(State.CONFIGURATION, id, id, setServerStateHandler(State.PLAY));
|
||||
appendClientbound(clientboundFinishConfigurationPacket, setServerStateHandler(State.PLAY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendClientbound(final CU type, final PacketHandler handler) {
|
||||
final PacketMapping mapping = clientboundMappings.mappedPacket(type.state(), type.getId());
|
||||
if (mapping != null) {
|
||||
mapping.appendHandler(handler);
|
||||
} else {
|
||||
registerClientbound(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendServerbound(final SU type, final PacketHandler handler) {
|
||||
final PacketMapping mapping = serverboundMappings.mappedPacket(type.state(), type.getId());
|
||||
if (mapping != null) {
|
||||
mapping.appendHandler(handler);
|
||||
} else {
|
||||
registerServerbound(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,18 +174,19 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
) {
|
||||
for (Map.Entry<State, PacketTypeMap<M>> entry : mappedPacketTypes.entrySet()) {
|
||||
PacketTypeMap<M> mappedTypes = entry.getValue();
|
||||
for (U unmappedType : unmappedPacketTypes.get(entry.getKey()).types()) {
|
||||
PacketTypeMap<U> unmappedTypes = unmappedPacketTypes.get(entry.getKey());
|
||||
for (U unmappedType : unmappedTypes.types()) {
|
||||
M mappedType = mappedTypes.typeByName(unmappedType.getName());
|
||||
if (mappedType == null) {
|
||||
// No mapped packet of the same name exists
|
||||
Preconditions.checkArgument(registeredPredicate.test(unmappedType),
|
||||
"Packet %s in %s has no mapping - it needs to be manually cancelled or remapped", unmappedType, getClass());
|
||||
Preconditions.checkArgument(registeredPredicate.test(unmappedType), "Packet %s in %s has no mapping - it needs to be manually cancelled or remapped", unmappedType, getClass());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Register if no custom handler exists and ids are different
|
||||
if (unmappedType.getId() != mappedType.getId() && !registeredPredicate.test(unmappedType)) {
|
||||
registerConsumer.accept(unmappedType, mappedType);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,6 +214,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
protected void onMappingDataLoaded() {
|
||||
callOnMappingDataLoaded(getEntityRewriter());
|
||||
callOnMappingDataLoaded(getItemRewriter());
|
||||
callOnMappingDataLoaded(getTagRewriter());
|
||||
}
|
||||
|
||||
private void callRegister(@Nullable Rewriter<?> rewriter) {
|
||||
|
@ -201,7 +223,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
}
|
||||
}
|
||||
|
||||
private void callOnMappingDataLoaded(@Nullable Rewriter<?> rewriter) {
|
||||
private void callOnMappingDataLoaded(@Nullable MappingDataListener rewriter) {
|
||||
if (rewriter != null) {
|
||||
rewriter.onMappingDataLoaded();
|
||||
}
|
||||
|
@ -213,10 +235,10 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
|
||||
protected PacketTypesProvider<CU, CM, SM, SU> createPacketTypesProvider() {
|
||||
return new SimplePacketTypesProvider<>(
|
||||
packetTypeMap(unmappedClientboundPacketType),
|
||||
packetTypeMap(mappedClientboundPacketType),
|
||||
packetTypeMap(mappedServerboundPacketType),
|
||||
packetTypeMap(unmappedServerboundPacketType)
|
||||
packetTypeMap(unmappedClientboundPacketType, unmappedClientboundPacketType),
|
||||
packetTypeMap(mappedClientboundPacketType, mappedClientboundPacketType),
|
||||
packetTypeMap(mappedServerboundPacketType, mappedServerboundPacketType),
|
||||
packetTypeMap(unmappedServerboundPacketType, unmappedServerboundPacketType)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -228,35 +250,20 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
return PacketMappings.arrayMappings();
|
||||
}
|
||||
|
||||
private <P extends PacketType> Map<State, PacketTypeMap<P>> packetTypeMap(Class<P> packetTypeClass) {
|
||||
if (packetTypeClass != null) {
|
||||
Map<State, PacketTypeMap<P>> map = new EnumMap<>(State.class);
|
||||
map.put(State.PLAY, PacketTypeMap.of(packetTypeClass));
|
||||
return map;
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
protected @Nullable SU configurationAcknowledgedPacket() {
|
||||
final Map<State, PacketTypeMap<SU>> packetTypes = packetTypesProvider.unmappedServerboundPacketTypes();
|
||||
final PacketTypeMap<SU> packetTypeMap = packetTypes.get(State.PLAY);
|
||||
return packetTypeMap != null ? packetTypeMap.typeByName("CONFIGURATION_ACKNOWLEDGED") : null;
|
||||
return packetTypesProvider.unmappedServerboundType(State.PLAY, "CONFIGURATION_ACKNOWLEDGED");
|
||||
}
|
||||
|
||||
protected @Nullable CU startConfigurationPacket() {
|
||||
final Map<State, PacketTypeMap<CU>> packetTypes = packetTypesProvider.unmappedClientboundPacketTypes();
|
||||
final PacketTypeMap<CU> packetTypeMap = packetTypes.get(State.PLAY);
|
||||
return packetTypeMap != null ? packetTypeMap.typeByName("START_CONFIGURATION") : null;
|
||||
return packetTypesProvider.unmappedClientboundType(State.PLAY, "START_CONFIGURATION");
|
||||
}
|
||||
|
||||
protected @Nullable ServerboundPacketType serverboundFinishConfigurationPacket() {
|
||||
// To be overridden
|
||||
return null;
|
||||
protected @Nullable SU serverboundFinishConfigurationPacket() {
|
||||
return packetTypesProvider.unmappedServerboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
|
||||
}
|
||||
|
||||
protected @Nullable ClientboundPacketType clientboundFinishConfigurationPacket() {
|
||||
// To be overridden
|
||||
return null;
|
||||
protected @Nullable CU clientboundFinishConfigurationPacket() {
|
||||
return packetTypesProvider.unmappedClientboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
@ -391,19 +398,17 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
try {
|
||||
handler.handle(packetWrapper);
|
||||
} catch (CancelException e) {
|
||||
// Pass through CancelExceptions
|
||||
throw e;
|
||||
throw e; // Pass through CancelExceptions
|
||||
} catch (InformativeException e) {
|
||||
// Catch InformativeExceptions
|
||||
e.addSource(handler.getClass());
|
||||
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
|
||||
return;
|
||||
printRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// Wrap other exceptions during packet handling
|
||||
InformativeException ex = new InformativeException(e);
|
||||
ex.addSource(handler.getClass());
|
||||
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), ex);
|
||||
return;
|
||||
printRemapError(direction, state, unmappedId, packetWrapper.getId(), ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
if (packetWrapper.isCancelled()) {
|
||||
|
@ -412,36 +417,22 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
}
|
||||
}
|
||||
|
||||
protected void throwRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) throws InformativeException {
|
||||
private void printRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) {
|
||||
// Don't print errors during handshake/login/status
|
||||
if (state != State.PLAY && direction == Direction.SERVERBOUND && !Via.getManager().debugHandler().enabled()) {
|
||||
e.setShouldBePrinted(false);
|
||||
throw e;
|
||||
return;
|
||||
}
|
||||
|
||||
PacketType packetType = direction == Direction.CLIENTBOUND ? unmappedClientboundPacketType(state, unmappedPacketId) : unmappedServerboundPacketType(state, unmappedPacketId);
|
||||
PacketType packetType = direction == Direction.CLIENTBOUND
|
||||
? packetTypesProvider.unmappedClientboundType(state, unmappedPacketId)
|
||||
: packetTypesProvider.unmappedServerboundType(state, unmappedPacketId);
|
||||
if (packetType != null) {
|
||||
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(unmappedPacketId) + ")");
|
||||
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + ProtocolUtil.toNiceHex(unmappedPacketId) + ")");
|
||||
} else {
|
||||
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
|
||||
+ " IN REMAP OF " + state + " " + toNiceHex(unmappedPacketId) + "->" + toNiceHex(mappedPacketId));
|
||||
+ " IN REMAP OF " + state + " " + ProtocolUtil.toNiceHex(unmappedPacketId) + "->" + ProtocolUtil.toNiceHex(mappedPacketId));
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
private @Nullable CU unmappedClientboundPacketType(final State state, final int packetId) {
|
||||
PacketTypeMap<CU> map = packetTypesProvider.unmappedClientboundPacketTypes().get(state);
|
||||
return map != null ? map.typeById(packetId) : null;
|
||||
}
|
||||
|
||||
private @Nullable SU unmappedServerboundPacketType(final State state, final int packetId) {
|
||||
PacketTypeMap<SU> map = packetTypesProvider.unmappedServerboundPacketTypes().get(state);
|
||||
return map != null ? map.typeById(packetId) : null;
|
||||
}
|
||||
|
||||
public static String toNiceHex(int id) {
|
||||
String hex = Integer.toHexString(id).toUpperCase();
|
||||
return (hex.length() == 1 ? "0x0" : "0x") + hex;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -455,16 +446,16 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
}
|
||||
}
|
||||
|
||||
protected PacketHandler setClientStateHandler(final State state) {
|
||||
private PacketHandler setClientStateHandler(final State state) {
|
||||
return wrapper -> wrapper.user().getProtocolInfo().setClientState(state);
|
||||
}
|
||||
|
||||
protected PacketHandler setServerStateHandler(final State state) {
|
||||
private PacketHandler setServerStateHandler(final State state) {
|
||||
return wrapper -> wrapper.user().getProtocolInfo().setServerState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
|
||||
public final PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
|
||||
return packetTypesProvider;
|
||||
}
|
||||
|
||||
|
@ -479,10 +470,6 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
|||
storedObjects.put(object.getClass(), object);
|
||||
}
|
||||
|
||||
public PacketTypesProvider<CU, CM, SM, SU> packetTypesProvider() {
|
||||
return packetTypesProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Protocol:" + getClass().getSimpleName();
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
|
@ -37,6 +36,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
|||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -51,24 +52,25 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
*/
|
||||
public interface Protocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
|
||||
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
|
||||
}
|
||||
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
|
||||
}
|
||||
|
||||
default void registerClientbound(State state, ClientboundPacketType packetType, PacketHandler handler) {
|
||||
default void registerClientbound(State state, ClientboundPacketType packetType, @Nullable PacketHandler handler) {
|
||||
Preconditions.checkArgument(packetType.state() == state);
|
||||
registerClientbound(state, packetType.getId(), packetType.getId(), handler, false);
|
||||
}
|
||||
|
||||
default void registerServerbound(State state, ServerboundPacketType packetType, PacketHandler handler) {
|
||||
default void registerServerbound(State state, ServerboundPacketType packetType, @Nullable PacketHandler handler) {
|
||||
Preconditions.checkArgument(packetType.state() == state);
|
||||
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
|
||||
}
|
||||
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a serverbound packet, with id transformation and remapper.
|
||||
*
|
||||
|
@ -79,15 +81,16 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
|||
* @param override whether an existing mapper should be overridden
|
||||
* @see #registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketHandler, boolean)
|
||||
*/
|
||||
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override);
|
||||
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
|
||||
|
||||
void cancelServerbound(State state, int mappedPacketId);
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
registerClientbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
|
||||
}
|
||||
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) {
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
|
||||
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
|||
* @param override whether an existing mapper should be overridden
|
||||
* @see #registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketHandler, boolean)
|
||||
*/
|
||||
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override);
|
||||
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -239,6 +242,28 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
|||
*/
|
||||
boolean hasRegisteredServerbound(State state, int unmappedPacketId);
|
||||
|
||||
/**
|
||||
* Appends a clientbound packet type handler with another, as opposed to replacing it entirely.
|
||||
* <p>
|
||||
* Use {@link PacketWrapper#set(Type, int, Object)} to change individual parts, or call
|
||||
* {@link PacketWrapper#resetReader()} to reset the reader index.
|
||||
*
|
||||
* @param type clientbound packet type
|
||||
* @param handler packet handler
|
||||
*/
|
||||
void appendClientbound(CU type, PacketHandler handler);
|
||||
|
||||
/**
|
||||
* Appends a serverbound packet type handler with another, as opposed to replacing it entirely.
|
||||
* <p>
|
||||
* Use {@link PacketWrapper#set(Type, int, Object)} to change individual parts, or call
|
||||
* {@link PacketWrapper#resetReader()} to reset the reader index.
|
||||
*
|
||||
* @param type serverbound packet type
|
||||
* @param handler packet handler
|
||||
*/
|
||||
void appendServerbound(SU type, PacketHandler handler);
|
||||
|
||||
/**
|
||||
* Transform a packet using this protocol
|
||||
*
|
||||
|
@ -255,7 +280,6 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
|||
*
|
||||
* @return the packet types provider
|
||||
*/
|
||||
@Beta
|
||||
PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider();
|
||||
|
||||
/**
|
||||
|
@ -265,13 +289,16 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
|||
* @param <T> type
|
||||
* @return object if present, else null
|
||||
*/
|
||||
@Nullable <T> T get(Class<T> objectClass);
|
||||
@Deprecated
|
||||
@Nullable
|
||||
<T> T get(Class<T> objectClass);
|
||||
|
||||
/**
|
||||
* Caches an object, retrievable by using {@link #get(Class)}.
|
||||
*
|
||||
* @param object object to cache
|
||||
*/
|
||||
@Deprecated
|
||||
void put(Object object);
|
||||
|
||||
/**
|
||||
|
@ -348,6 +375,15 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol's tag rewriter if present.
|
||||
*
|
||||
* @return tag rewriter
|
||||
*/
|
||||
default @Nullable TagRewriter getTagRewriter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol is a base protocol.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
|||
import com.viaversion.viaversion.api.protocol.packet.VersionedPacketTransformer;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
|
||||
import com.viaversion.viaversion.api.protocol.version.VersionType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -62,21 +63,8 @@ public interface ProtocolManager {
|
|||
* @param clientVersion client protocol version
|
||||
* @param serverVersion server protocol version
|
||||
* @return protocol if present, else null
|
||||
* @see #getProtocolPath(int, int) to get a full path of Protocols between a larger gap of versions
|
||||
*/
|
||||
default @Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion) {
|
||||
return getProtocol(clientVersion.getVersion(), serverVersion.getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a protocol transforming packets for server version to the given client version.
|
||||
*
|
||||
* @param clientVersion client protocol version
|
||||
* @param serverVersion server protocol version
|
||||
* @return protocol if present, else null
|
||||
* @see #getProtocolPath(int, int) to get a full path of Protocols between a larger gap of versions
|
||||
*/
|
||||
@Nullable Protocol getProtocol(int clientVersion, int serverVersion);
|
||||
@Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion);
|
||||
|
||||
/**
|
||||
* Returns the base protocol handling serverbound handshake packets.
|
||||
|
@ -90,10 +78,9 @@ public interface ProtocolManager {
|
|||
* The standard base protocols deal with status and login packets for userconnection initialization.
|
||||
*
|
||||
* @param serverVersion server protocol version
|
||||
* @return base protocol for the given server protocol version
|
||||
* @throws IllegalStateException if no base protocol could be found
|
||||
* @return base protocol for the given server protocol version if present, else null
|
||||
*/
|
||||
Protocol getBaseProtocol(int serverVersion);
|
||||
@Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion);
|
||||
|
||||
/**
|
||||
* Returns an immutable collection of registered protocols.
|
||||
|
@ -128,7 +115,7 @@ public interface ProtocolManager {
|
|||
* @param serverVersion output server protocol version the protocol converts to
|
||||
* @throws IllegalArgumentException if a supported client protocol version is equal to the server protocol version
|
||||
*/
|
||||
void registerProtocol(Protocol protocol, List<Integer> supportedClientVersion, int serverVersion);
|
||||
void registerProtocol(Protocol protocol, List<ProtocolVersion> supportedClientVersion, ProtocolVersion serverVersion);
|
||||
|
||||
/**
|
||||
* Registers and initializes a base protocol. Base Protocols registered later have higher priority.
|
||||
|
@ -138,7 +125,7 @@ public interface ProtocolManager {
|
|||
* @param supportedProtocols protocol versions supported by the base protocol
|
||||
* @throws IllegalArgumentException if the protocol is not a base protocol as given by {@link Protocol#isBaseProtocol()}
|
||||
*/
|
||||
void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols);
|
||||
void registerBaseProtocol(Protocol baseProtocol, Range<ProtocolVersion> supportedProtocols);
|
||||
|
||||
/**
|
||||
* Calculates and returns the protocol path from a client protocol version to server protocol version.
|
||||
|
@ -148,7 +135,12 @@ public interface ProtocolManager {
|
|||
* @param serverVersion desired output server protocol version
|
||||
* @return path generated, or null if not supported or the length exceeds {@link #getMaxProtocolPathSize()}
|
||||
*/
|
||||
@Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion);
|
||||
@Nullable List<ProtocolPathEntry> getProtocolPath(ProtocolVersion clientVersion, ProtocolVersion serverVersion);
|
||||
|
||||
@Deprecated
|
||||
default @Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion) {
|
||||
return getProtocolPath(ProtocolVersion.getProtocol(clientVersion), ProtocolVersion.getProtocol(serverVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a versioned packet transformer to transform and send packets from a given base version to any client version supported by Via.
|
||||
|
@ -175,10 +167,10 @@ public interface ProtocolManager {
|
|||
* @throws IllegalArgumentException if both packet classes are null
|
||||
*/
|
||||
<C extends ClientboundPacketType,
|
||||
S extends ServerboundPacketType
|
||||
> VersionedPacketTransformer<C, S> createPacketTransformer(ProtocolVersion inputVersion,
|
||||
@Nullable Class<C> clientboundPacketsClass,
|
||||
@Nullable Class<S> serverboundPacketsClass);
|
||||
S extends ServerboundPacketType
|
||||
> VersionedPacketTransformer<C, S> createPacketTransformer(ProtocolVersion inputVersion,
|
||||
@Nullable Class<C> clientboundPacketsClass,
|
||||
@Nullable Class<S> serverboundPacketsClass);
|
||||
|
||||
/**
|
||||
* Sets the max delta the path calculation allows the distance to the target protocol version to increase.
|
||||
|
@ -226,14 +218,14 @@ public interface ProtocolManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
|
||||
* Returns the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
|
||||
*
|
||||
* @return maximum protocol path size
|
||||
*/
|
||||
int getMaxProtocolPathSize();
|
||||
|
||||
/**
|
||||
* Sets the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
|
||||
* Sets the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
|
||||
* Its default is 50.
|
||||
*
|
||||
* @param maxProtocolPathSize maximum protocol path size
|
||||
|
@ -245,7 +237,7 @@ public interface ProtocolManager {
|
|||
*
|
||||
* @return sorted, immutable set of supported protocol versions
|
||||
*/
|
||||
SortedSet<Integer> getSupportedVersions();
|
||||
SortedSet<ProtocolVersion> getSupportedVersions();
|
||||
|
||||
/**
|
||||
* Check if this plugin is useful to the server.
|
||||
|
@ -318,4 +310,11 @@ public interface ProtocolManager {
|
|||
*/
|
||||
@Deprecated
|
||||
PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection);
|
||||
|
||||
/**
|
||||
* Returns whether the mappings have been loaded and the mapping loader executor shutdown.
|
||||
*
|
||||
* @return whether the mappings have been loaded
|
||||
*/
|
||||
boolean hasLoadedMappings();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
public interface ProtocolPathEntry {
|
||||
|
||||
/**
|
||||
|
@ -30,7 +32,7 @@ public interface ProtocolPathEntry {
|
|||
*
|
||||
* @return output protocol version after transformation
|
||||
*/
|
||||
int outputProtocolVersion();
|
||||
ProtocolVersion outputProtocolVersion();
|
||||
|
||||
/**
|
||||
* Returns the protocol to be applied with this entry.
|
||||
|
@ -39,13 +41,4 @@ public interface ProtocolPathEntry {
|
|||
*/
|
||||
Protocol<?, ?, ?, ?> protocol();
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getOutputProtocolVersion() {
|
||||
return outputProtocolVersion();
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default Protocol getProtocol() {
|
||||
return protocol();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
public interface ProtocolPathKey {
|
||||
|
||||
/**
|
||||
|
@ -29,22 +31,13 @@ public interface ProtocolPathKey {
|
|||
*
|
||||
* @return client protocol version
|
||||
*/
|
||||
int clientProtocolVersion();
|
||||
ProtocolVersion clientProtocolVersion();
|
||||
|
||||
/**
|
||||
* Returns the server protocol version.
|
||||
*
|
||||
* @return server protocol version
|
||||
*/
|
||||
int serverProtocolVersion();
|
||||
ProtocolVersion serverProtocolVersion();
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getClientProtocolVersion() {
|
||||
return clientProtocolVersion();
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getServerProtocolVersion() {
|
||||
return serverProtocolVersion();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
package com.viaversion.viaversion.api.protocol;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
@ -61,25 +62,34 @@ public interface ProtocolPipeline extends SimpleProtocol {
|
|||
* @param pipeClass protocol class
|
||||
* @param <P> protocol
|
||||
* @return protocol from class
|
||||
* @see #contains(Class)
|
||||
* @see ProtocolManager#getProtocol(Class) for a faster implementation
|
||||
* @deprecated use {@link ProtocolManager#getProtocol(Class)} and/or {@link #contains(Class)}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable <P extends Protocol> P getProtocol(Class<P> pipeClass);
|
||||
|
||||
List<Protocol> pipes(@Nullable Class<? extends Protocol> protocolClass, boolean skipCurrentPipeline, Direction direction);
|
||||
|
||||
/**
|
||||
* Returns the list of protocols this pipeline contains.
|
||||
* Returns the list of protocols this pipeline contains, lead by base protocols.
|
||||
*
|
||||
* @return immutable list of protocols in this pipe
|
||||
*/
|
||||
List<Protocol> pipes();
|
||||
|
||||
/**
|
||||
* Returns the list of protocols this pipeline contains in reversed order.
|
||||
* Returns the list of protocols this pipeline contains in reversed order, although still lead by base protocols.
|
||||
*
|
||||
* @return immutable list of protocols in reversed direction
|
||||
*/
|
||||
List<Protocol> reversedPipes();
|
||||
|
||||
/**
|
||||
* Returns the number of base protocols in this pipeline.
|
||||
*
|
||||
* @return the number of base protocols in this pipeline
|
||||
*/
|
||||
int baseProtocolCount();
|
||||
|
||||
/**
|
||||
* Returns whether this pipe has protocols that are not base protocols, as given by {@link Protocol#isBaseProtocol()}.
|
||||
*
|
||||
|
|
|
@ -92,6 +92,7 @@ public interface PacketWrapper {
|
|||
* @param index The index of the part (relative to the type)
|
||||
* @return True if the type is at the index
|
||||
*/
|
||||
@Deprecated
|
||||
boolean is(Type type, int index);
|
||||
|
||||
/**
|
||||
|
@ -212,11 +213,11 @@ public interface PacketWrapper {
|
|||
* (Sends it after current)
|
||||
* Also returns the packets ChannelFuture
|
||||
*
|
||||
* @param packetProtocol The protocol version of the packet.
|
||||
* @return The packets ChannelFuture
|
||||
* @param protocolClass the protocol class to start from in the pipeline
|
||||
* @return new ChannelFuture for the write operation
|
||||
* @throws Exception if it fails to write
|
||||
*/
|
||||
ChannelFuture sendFuture(Class<? extends Protocol> packetProtocol) throws Exception;
|
||||
ChannelFuture sendFuture(Class<? extends Protocol> protocolClass) throws Exception;
|
||||
|
||||
/**
|
||||
* @deprecated misleading; use {@link #sendRaw()}. This method will be removed in 5.0.0
|
||||
|
@ -287,18 +288,24 @@ public interface PacketWrapper {
|
|||
*
|
||||
* @param direction protocol direction
|
||||
* @param state protocol state
|
||||
* @param index index to start from, will be reversed depending on the reverse parameter
|
||||
* @param pipeline protocol pipeline
|
||||
* @param reverse whether the array should be looped in reverse, will also reverse the given index
|
||||
* @return The current packetwrapper
|
||||
* @throws Exception If it fails to transform a packet, exception will be thrown
|
||||
*/
|
||||
void apply(Direction direction, State state, List<Protocol> pipeline) throws Exception;
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #apply(Direction, State, List)}
|
||||
*/
|
||||
@Deprecated
|
||||
PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline, boolean reverse) throws Exception;
|
||||
|
||||
/**
|
||||
* @see #apply(Direction, State, int, List, boolean)
|
||||
* @deprecated use {@link #apply(Direction, State, List)}
|
||||
*/
|
||||
PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception;
|
||||
@Deprecated
|
||||
default PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception {
|
||||
return apply(direction, state, index, pipeline, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this packet is cancelled.
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
|
||||
final class PacketIdMapping implements PacketMapping {
|
||||
private final int mappedPacketId;
|
||||
private final PacketHandler handler;
|
||||
private PacketHandler handler;
|
||||
|
||||
PacketIdMapping(int mappedPacketId, @Nullable PacketHandler handler) {
|
||||
this.mappedPacketId = mappedPacketId;
|
||||
|
@ -41,6 +41,15 @@ final class PacketIdMapping implements PacketMapping {
|
|||
wrapper.setId(mappedPacketId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHandler(final PacketHandler handler) {
|
||||
if (this.handler == null) {
|
||||
this.handler = handler;
|
||||
} else {
|
||||
this.handler = this.handler.then(handler);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PacketHandler handler() {
|
||||
return handler;
|
||||
|
|
|
@ -46,6 +46,13 @@ public interface PacketMapping {
|
|||
*/
|
||||
@Nullable PacketHandler handler();
|
||||
|
||||
/**
|
||||
* Appends a packet transformer to the current packet transformer.
|
||||
*
|
||||
* @param handler packet transformer
|
||||
*/
|
||||
void appendHandler(PacketHandler handler);
|
||||
|
||||
static PacketMapping of(final int mappedPacketId, @Nullable final PacketHandler handler) {
|
||||
return new PacketIdMapping(mappedPacketId, handler);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
|
||||
final class PacketTypeMapping implements PacketMapping {
|
||||
private final PacketType mappedPacketType;
|
||||
private final PacketHandler handler;
|
||||
private PacketHandler handler;
|
||||
|
||||
PacketTypeMapping(@Nullable PacketType mappedPacketType, @Nullable PacketHandler handler) {
|
||||
this.mappedPacketType = mappedPacketType;
|
||||
|
@ -43,6 +43,15 @@ final class PacketTypeMapping implements PacketMapping {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHandler(final PacketHandler handler) {
|
||||
if (this.handler == null) {
|
||||
this.handler = handler;
|
||||
} else {
|
||||
this.handler = this.handler.then(handler);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PacketHandler handler() {
|
||||
return handler;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol.packet.provider;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import java.util.Collection;
|
||||
|
@ -54,14 +55,11 @@ public interface PacketTypeMap<P extends PacketType> {
|
|||
*/
|
||||
Collection<P> types();
|
||||
|
||||
static <S extends PacketType, T extends S> PacketTypeMap<S> of(final Class<T> enumClass) {
|
||||
if (!enumClass.isEnum()) {
|
||||
throw new IllegalArgumentException("Given class is not an enum");
|
||||
}
|
||||
|
||||
final S[] types = enumClass.getEnumConstants();
|
||||
final Map<String, S> byName = new HashMap<>(types.length);
|
||||
for (final S type : types) {
|
||||
static <T extends PacketType, E extends T> PacketTypeMap<T> of(final Class<E> enumClass) {
|
||||
final T[] types = enumClass.getEnumConstants();
|
||||
Preconditions.checkArgument(types != null, "%s is not an enum", enumClass);
|
||||
final Map<String, T> byName = new HashMap<>(types.length);
|
||||
for (final T type : types) {
|
||||
byName.put(type.getName(), type);
|
||||
}
|
||||
return of(byName, types);
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol.packet.provider;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Provides unmapped and mapped packet types for a Protocol.
|
||||
|
@ -37,7 +37,6 @@ import java.util.Map;
|
|||
* @param <SU> unmapped serverbound packet type
|
||||
* @see SimplePacketTypesProvider
|
||||
*/
|
||||
@Beta
|
||||
public interface PacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
|
||||
|
||||
/**
|
||||
|
@ -69,4 +68,24 @@ public interface PacketTypesProvider<CU extends ClientboundPacketType, CM extend
|
|||
* @return map of mapped serverbound packet types
|
||||
*/
|
||||
Map<State, PacketTypeMap<SM>> mappedServerboundPacketTypes();
|
||||
|
||||
default @Nullable CU unmappedClientboundType(final State state, final String typeName) {
|
||||
PacketTypeMap<CU> map = unmappedClientboundPacketTypes().get(state);
|
||||
return map != null ? map.typeByName(typeName) : null;
|
||||
}
|
||||
|
||||
default @Nullable SU unmappedServerboundType(final State state, final String typeName) {
|
||||
PacketTypeMap<SU> map = unmappedServerboundPacketTypes().get(state);
|
||||
return map != null ? map.typeByName(typeName) : null;
|
||||
}
|
||||
|
||||
default @Nullable CU unmappedClientboundType(final State state, final int packetId) {
|
||||
PacketTypeMap<CU> map = unmappedClientboundPacketTypes().get(state);
|
||||
return map != null ? map.typeById(packetId) : null;
|
||||
}
|
||||
|
||||
default @Nullable SU unmappedServerboundType(final State state, final int packetId) {
|
||||
PacketTypeMap<SU> map = unmappedServerboundPacketTypes().get(state);
|
||||
return map != null ? map.typeById(packetId) : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,11 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol.packet.provider;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import java.util.Map;
|
||||
|
||||
@Beta
|
||||
public final class SimplePacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> implements PacketTypesProvider<CU, CM, SM, SU> {
|
||||
private final Map<State, PacketTypeMap<CU>> unmappedClientboundPacketTypes;
|
||||
private final Map<State, PacketTypeMap<CM>> mappedClientboundPacketTypes;
|
||||
|
|
|
@ -34,4 +34,17 @@ public interface PacketHandler {
|
|||
* @throws Exception if an error occurs during the packet handling
|
||||
*/
|
||||
void handle(PacketWrapper wrapper) throws Exception;
|
||||
|
||||
/**
|
||||
* Returns a new packet handler that runs the provided handler after this one.
|
||||
*
|
||||
* @param handler packet handler to run aftet this one
|
||||
* @return a new packet handler that runs the provided handler after this one
|
||||
*/
|
||||
default PacketHandler then(final PacketHandler handler) {
|
||||
return wrapper -> {
|
||||
this.handle(wrapper);
|
||||
handler.handle(wrapper);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,13 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class PacketHandlers implements PacketHandler {
|
||||
private final List<PacketHandler> packetHandlers = new ArrayList<>();
|
||||
|
@ -128,6 +130,24 @@ public abstract class PacketHandlers implements PacketHandler {
|
|||
packetHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a packet handler which will suppress any exceptions thrown by the handler.
|
||||
*
|
||||
* @param handler packet handler
|
||||
*/
|
||||
public void handlerSoftFail(PacketHandler handler) {
|
||||
packetHandlers.add(h -> {
|
||||
try {
|
||||
handler.handle(h);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
h.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a value.
|
||||
*
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol.version;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import java.util.Set;
|
||||
|
||||
public interface BlockedProtocolVersions {
|
||||
|
||||
|
@ -32,26 +32,26 @@ public interface BlockedProtocolVersions {
|
|||
* @param protocolVersion protocol version
|
||||
* @return whether the given protocol version is blocked
|
||||
*/
|
||||
boolean contains(int protocolVersion);
|
||||
boolean contains(ProtocolVersion protocolVersion);
|
||||
|
||||
/**
|
||||
* Returns the boundary below which protocol versions are blocked, or -1 if none is set.
|
||||
*
|
||||
* @return exclusive boundary below which protocol versions are blocked, or -1 if none
|
||||
*/
|
||||
int blocksBelow();
|
||||
ProtocolVersion blocksBelow();
|
||||
|
||||
/**
|
||||
* Returns the boundary above which protocol versions are blocked, or -1 if none is set.
|
||||
*
|
||||
* @return exclusive boundary above which protocol versions are blocked, or -1 if none
|
||||
*/
|
||||
int blocksAbove();
|
||||
ProtocolVersion blocksAbove();
|
||||
|
||||
/**
|
||||
* Returns a set of blocked protocol versions between the outer block ranges.
|
||||
*
|
||||
* @return set of blocked protocol versions between the outer block ranges
|
||||
*/
|
||||
IntSet singleBlockedVersions();
|
||||
Set<ProtocolVersion> singleBlockedVersions();
|
||||
}
|
||||
|
|
|
@ -27,35 +27,32 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ProtocolVersion {
|
||||
private static final Int2ObjectMap<ProtocolVersion> VERSIONS = new Int2ObjectOpenHashMap<>();
|
||||
public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
|
||||
// These need to be at the top of the class to be initialized first
|
||||
private static final Map<VersionType, Int2ObjectMap<ProtocolVersion>> VERSIONS = new EnumMap<>(VersionType.class);
|
||||
private static final List<ProtocolVersion> VERSION_LIST = new ArrayList<>();
|
||||
|
||||
// Before the Netty rewrite
|
||||
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new VersionRange("1.4", 6, 7));
|
||||
public static final ProtocolVersion v1_5_1 = register(60, "1.5/1.5.1", new VersionRange("1.5", 0, 1));
|
||||
public static final ProtocolVersion v1_5_2 = register(61, "1.5.2");
|
||||
public static final ProtocolVersion v_1_6_1 = register(73, "1.6.1");
|
||||
public static final ProtocolVersion v_1_6_2 = register(74, "1.6.2");
|
||||
public static final ProtocolVersion v_1_6_3 = register(77, "1.6.3");
|
||||
public static final ProtocolVersion v_1_6_4 = register(78, "1.6.4");
|
||||
// After the Netty rewrite
|
||||
public static final ProtocolVersion v1_7_1 = register(4, "1.7.2-1.7.5", new VersionRange("1.7", 2, 5));
|
||||
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new VersionRange("1.7", 6, 10));
|
||||
public static final ProtocolVersion v1_8 = register(47, "1.8.x");
|
||||
public static final ProtocolVersion v1_7_2 = register(4, "1.7.2-1.7.5", new SubVersionRange("1.7", 2, 5));
|
||||
@Deprecated/*(forRemoval=true)*/ public static final ProtocolVersion v1_7_1 = v1_7_2;
|
||||
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10));
|
||||
public static final ProtocolVersion v1_8 = register(47, "1.8.x", new SubVersionRange("1.8", 0, 9));
|
||||
public static final ProtocolVersion v1_9 = register(107, "1.9");
|
||||
public static final ProtocolVersion v1_9_1 = register(108, "1.9.1");
|
||||
public static final ProtocolVersion v1_9_2 = register(109, "1.9.2");
|
||||
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/4", new VersionRange("1.9", 3, 4));
|
||||
public static final ProtocolVersion v1_10 = register(210, "1.10.x");
|
||||
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3-1.9.4", new SubVersionRange("1.9", 3, 4));
|
||||
public static final ProtocolVersion v1_10 = register(210, "1.10.x", new SubVersionRange("1.10", 0, 2));
|
||||
public static final ProtocolVersion v1_11 = register(315, "1.11");
|
||||
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/2", new VersionRange("1.11", 1, 2));
|
||||
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1-1.11.2", new SubVersionRange("1.11", 1, 2));
|
||||
public static final ProtocolVersion v1_12 = register(335, "1.12");
|
||||
public static final ProtocolVersion v1_12_1 = register(338, "1.12.1");
|
||||
public static final ProtocolVersion v1_12_2 = register(340, "1.12.2");
|
||||
|
@ -74,49 +71,51 @@ public class ProtocolVersion {
|
|||
public static final ProtocolVersion v1_16_1 = register(736, "1.16.1");
|
||||
public static final ProtocolVersion v1_16_2 = register(751, "1.16.2");
|
||||
public static final ProtocolVersion v1_16_3 = register(753, "1.16.3");
|
||||
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/5", new VersionRange("1.16", 4, 5));
|
||||
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4-1.16.5", new SubVersionRange("1.16", 4, 5));
|
||||
public static final ProtocolVersion v1_17 = register(755, "1.17");
|
||||
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18-1.18.1", new SubVersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
|
||||
public static final ProtocolVersion v1_19 = register(759, "1.19");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/2", new VersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1-1.19.2", new SubVersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_3 = register(761, "1.19.3");
|
||||
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20-1.20.1", new SubVersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new VersionRange("1.20", 3, 4));
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3-1.20.4", new SubVersionRange("1.20", 3, 4));
|
||||
public static final ProtocolVersion v1_20_5 = register(766, "1.20.5-1.20.6", new SubVersionRange("1.20", 5, 6));
|
||||
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
return register(version, -1, name);
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name) {
|
||||
return register(version, snapshotVersion, name, null);
|
||||
final ProtocolVersion protocolVersion = new ProtocolVersion(VersionType.RELEASE, version, snapshotVersion, name, null);
|
||||
register(protocolVersion);
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, String name, @Nullable VersionRange versionRange) {
|
||||
return register(version, -1, name, versionRange);
|
||||
public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange) {
|
||||
final ProtocolVersion protocolVersion = new ProtocolVersion(VersionType.RELEASE, version, -1, name, versionRange);
|
||||
register(protocolVersion);
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a protocol version.
|
||||
*
|
||||
* @param version release protocol version
|
||||
* @param snapshotVersion snapshot protocol version, or -1 if not a snapshot
|
||||
* @param name version name
|
||||
* @param versionRange range of versions that are supported by this protocol version, null if not a range
|
||||
* @return registered ProtocolVersion
|
||||
* @param protocolVersion protocol version to register
|
||||
*/
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
|
||||
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange);
|
||||
VERSION_LIST.add(protocol);
|
||||
VERSIONS.put(protocol.getVersion(), protocol);
|
||||
if (protocol.isSnapshot()) {
|
||||
VERSIONS.put(protocol.getFullSnapshotVersion(), protocol);
|
||||
public static void register(ProtocolVersion protocolVersion) {
|
||||
VERSION_LIST.add(protocolVersion);
|
||||
VERSION_LIST.sort(ProtocolVersion::compareTo);
|
||||
|
||||
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.computeIfAbsent(protocolVersion.versionType, $ -> new Int2ObjectOpenHashMap<>());
|
||||
versions.put(protocolVersion.version, protocolVersion);
|
||||
if (protocolVersion.isSnapshot()) {
|
||||
versions.put(protocolVersion.getFullSnapshotVersion(), protocolVersion);
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,24 +124,36 @@ public class ProtocolVersion {
|
|||
* @param version protocol version
|
||||
* @return true if this protocol version has been registered
|
||||
*/
|
||||
public static boolean isRegistered(final VersionType versionType, final int version) {
|
||||
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.get(versionType);
|
||||
return versions != null && versions.containsKey(version);
|
||||
}
|
||||
|
||||
public static boolean isRegistered(int version) {
|
||||
return VERSIONS.containsKey(version);
|
||||
return isRegistered(VersionType.RELEASE, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ProtocolVersion instance, even if this protocol version
|
||||
* has not been registered. See {@link #isRegistered(int)} berorehand or {@link #isKnown()}.
|
||||
* has not been registered. See {@link #isRegistered(VersionType, int)} beforehand or {@link #isKnown()}.
|
||||
*
|
||||
* @param version protocol version
|
||||
* @param versionType protocol version type
|
||||
* @param version protocol version
|
||||
* @return registered or unknown ProtocolVersion
|
||||
*/
|
||||
public static @NonNull ProtocolVersion getProtocol(int version) {
|
||||
ProtocolVersion protocolVersion = VERSIONS.get(version);
|
||||
if (protocolVersion != null) {
|
||||
return protocolVersion;
|
||||
} else {
|
||||
return new ProtocolVersion(version, "Unknown (" + version + ")");
|
||||
public static @NonNull ProtocolVersion getProtocol(final VersionType versionType, final int version) {
|
||||
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.get(versionType);
|
||||
if (versions != null) {
|
||||
final ProtocolVersion protocolVersion = versions.get(version);
|
||||
if (protocolVersion != null) {
|
||||
return protocolVersion;
|
||||
}
|
||||
}
|
||||
return new ProtocolVersion(VersionType.SPECIAL, version, -1, "Unknown (" + version + ")", null);
|
||||
}
|
||||
|
||||
public static @NonNull ProtocolVersion getProtocol(final int version) {
|
||||
return getProtocol(VersionType.RELEASE, version);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,7 +161,9 @@ public class ProtocolVersion {
|
|||
*
|
||||
* @param version protocol version instance
|
||||
* @return internal index of the stored protocol version
|
||||
* @deprecated comparison should be done via the comparison methods
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public static int getIndex(ProtocolVersion version) {
|
||||
return VERSION_LIST.indexOf(version);
|
||||
}
|
||||
|
@ -166,59 +179,58 @@ public class ProtocolVersion {
|
|||
|
||||
/**
|
||||
* Returns the registered protocol version if present, else null.
|
||||
* This accepts the actual registered names (like "1.16.4/5") as well as
|
||||
* This accepts the actual registered names (like "1.16.4/1.16.5") as well as
|
||||
* included versions for version ranges and wildcards.
|
||||
*
|
||||
* @param protocol version name, e.g. "1.16.3"
|
||||
* @return registered protocol version if present, else null
|
||||
*/
|
||||
public static @Nullable ProtocolVersion getClosest(String protocol) {
|
||||
for (ProtocolVersion version : VERSIONS.values()) {
|
||||
for (ProtocolVersion version : VERSION_LIST) {
|
||||
String name = version.getName();
|
||||
if (name.equals(protocol)) {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (version.isVersionWildcard()) {
|
||||
// Test against the major version with and without a minor version
|
||||
String majorVersion = name.substring(0, name.length() - 2);
|
||||
if (majorVersion.equals(protocol) || (protocol.startsWith(name.substring(0, name.length() - 1)))) {
|
||||
return version;
|
||||
}
|
||||
} else if (version.isRange() && version.getIncludedVersions().contains(protocol)) {
|
||||
if (name.equals(protocol) || version.isRange() && version.getIncludedVersions().contains(protocol)) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final VersionType versionType;
|
||||
private final int version;
|
||||
private final int snapshotVersion;
|
||||
private final String name;
|
||||
private final boolean versionWildcard;
|
||||
private final Set<String> includedVersions;
|
||||
|
||||
/**
|
||||
* @param version protocol version
|
||||
* @param name version name
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public ProtocolVersion(int version, String name) {
|
||||
this(version, -1, name, null);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
this(VersionType.RELEASE, version, snapshotVersion, name, versionRange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ProtocolVersion instance.
|
||||
*
|
||||
* @param versionType protocol version type
|
||||
* @param version protocol version
|
||||
* @param snapshotVersion actual snapshot protocol version, -1 if not a snapshot
|
||||
* @param name version name
|
||||
* @param versionRange range of versions that are supported by this protocol version, null if not a range
|
||||
*/
|
||||
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
|
||||
public ProtocolVersion(VersionType versionType, int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
this.versionType = versionType;
|
||||
this.version = version;
|
||||
this.snapshotVersion = snapshotVersion;
|
||||
this.name = name;
|
||||
this.versionWildcard = name.endsWith(".x");
|
||||
|
||||
Preconditions.checkArgument(!versionWildcard || versionRange == null, "A version cannot be a wildcard and a range at the same time!");
|
||||
Preconditions.checkArgument(!(isVersionWildcard() && versionRange == null), "A wildcard name must have a version range");
|
||||
if (versionRange != null) {
|
||||
includedVersions = new LinkedHashSet<>();
|
||||
for (int i = versionRange.rangeFrom(); i <= versionRange.rangeTo(); i++) {
|
||||
|
@ -233,6 +245,16 @@ public class ProtocolVersion {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of version (excluding whether it is a snapshot).
|
||||
*
|
||||
* @return version type
|
||||
* @see #isSnapshot()
|
||||
*/
|
||||
public VersionType getVersionType() {
|
||||
return versionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the release protocol version.
|
||||
*
|
||||
|
@ -312,7 +334,7 @@ public class ProtocolVersion {
|
|||
* @return true if the protocol includes an entire major version range
|
||||
*/
|
||||
public boolean isVersionWildcard() {
|
||||
return versionWildcard;
|
||||
return this.name.endsWith(".x");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -333,22 +355,127 @@ public class ProtocolVersion {
|
|||
return snapshotVersion != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is equal to the other protocol version.
|
||||
*
|
||||
* @param other other protocol version
|
||||
* @return true if this protocol version is equal to the other protocol version
|
||||
*/
|
||||
public boolean equalTo(final ProtocolVersion other) {
|
||||
return this.compareTo(other) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is higher than the other protocol version.
|
||||
*
|
||||
* @param other other protocol version
|
||||
* @return true if this protocol version is higher than the other protocol version
|
||||
*/
|
||||
public boolean newerThan(final ProtocolVersion other) {
|
||||
return this.compareTo(other) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is higher than or equal to the other protocol version.
|
||||
*
|
||||
* @param other other protocol version
|
||||
* @return true if this protocol version is higher than or equal to the other protocol version
|
||||
*/
|
||||
public boolean newerThanOrEqualTo(final ProtocolVersion other) {
|
||||
return this.compareTo(other) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is lower than the other protocol version.
|
||||
*
|
||||
* @param other other protocol version
|
||||
* @return true if this protocol version is lower than the other protocol version
|
||||
*/
|
||||
public boolean olderThan(final ProtocolVersion other) {
|
||||
return this.compareTo(other) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is lower than or equal to the other protocol version.
|
||||
*
|
||||
* @param other other protocol version
|
||||
* @return true if this protocol version is lower than or equal to the other protocol version
|
||||
*/
|
||||
public boolean olderThanOrEqualTo(final ProtocolVersion other) {
|
||||
return this.compareTo(other) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is between the given protocol versions, inclusive.
|
||||
*
|
||||
* @param min minimum version
|
||||
* @param max maximum version
|
||||
* @return true if this protocol version is between the given protocol versions, inclusive
|
||||
*/
|
||||
public boolean betweenInclusive(final ProtocolVersion min, final ProtocolVersion max) {
|
||||
return this.newerThanOrEqualTo(min) && this.olderThanOrEqualTo(max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this protocol version is between the given protocol versions, exclusive.
|
||||
*
|
||||
* @param min minimum version
|
||||
* @param max maximum version
|
||||
* @return true if this protocol version is between the given protocol versions, exclusive
|
||||
*/
|
||||
public boolean betweenExclusive(final ProtocolVersion min, final ProtocolVersion max) {
|
||||
return this.newerThan(min) && this.olderThan(max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a custom comparator used to compare protocol versions.
|
||||
* Must be overridden if the version type is {@link VersionType#SPECIAL}
|
||||
*
|
||||
* @return custom comparator
|
||||
*/
|
||||
protected @Nullable Comparator<ProtocolVersion> customComparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ProtocolVersion that = (ProtocolVersion) o;
|
||||
return version == that.version;
|
||||
final ProtocolVersion that = (ProtocolVersion) o;
|
||||
return version == that.version && versionType == that.versionType && snapshotVersion == that.snapshotVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return version;
|
||||
int result = versionType.hashCode();
|
||||
result = 31 * result + version;
|
||||
result = 31 * result + snapshotVersion;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s (%d)", this.name, this.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ProtocolVersion other) {
|
||||
// Cursed custom comparators
|
||||
if (this.versionType == VersionType.SPECIAL && customComparator() != null) {
|
||||
return customComparator().compare(this, other);
|
||||
} else if (other.versionType == VersionType.SPECIAL && other.customComparator() != null) {
|
||||
return other.customComparator().compare(this, other);
|
||||
}
|
||||
|
||||
if (this.versionType != other.versionType) {
|
||||
// Compare by version type first since version ids have reset multiple times
|
||||
return this.versionType.ordinal() < other.versionType.ordinal() ? -1 : 1;
|
||||
} else if (this.version != other.version) {
|
||||
// Compare by release version
|
||||
return this.version < other.version ? -1 : 1;
|
||||
}
|
||||
// Finally, compare by snapshot version
|
||||
return Integer.compare(this.snapshotVersion, other.snapshotVersion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.protocol.version;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Wrapper class file for {@link com.google.common.collect.Range} to support multiple ranges. This class is used to
|
||||
* compare {@link ProtocolVersion} objects.
|
||||
*/
|
||||
public class ProtocolVersionRange {
|
||||
|
||||
private List<Range<ProtocolVersion>> ranges;
|
||||
|
||||
private ProtocolVersionRange(final List<Range<ProtocolVersion>> ranges) {
|
||||
if (ranges != null) {
|
||||
this.ranges = new ArrayList<>(ranges);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range that contains all versions.
|
||||
*
|
||||
* @return the range
|
||||
*/
|
||||
public static ProtocolVersionRange all() {
|
||||
return new ProtocolVersionRange(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range that contains only the given version.
|
||||
*
|
||||
* @param min the version
|
||||
* @param max the version
|
||||
* @return the range
|
||||
*/
|
||||
public static ProtocolVersionRange of(final ProtocolVersion min, final ProtocolVersion max) {
|
||||
return new ProtocolVersionRange(Collections.singletonList(Range.open(min, max)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range that contains only the given version.
|
||||
*
|
||||
* @param range the version
|
||||
* @return the range
|
||||
*/
|
||||
public static ProtocolVersionRange of(final Range<ProtocolVersion> range) {
|
||||
return new ProtocolVersionRange(Collections.singletonList(range));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range that contains only the given version. The list can be immutable.
|
||||
*
|
||||
* @param ranges the version
|
||||
* @return the range
|
||||
*/
|
||||
public static ProtocolVersionRange of(final List<Range<ProtocolVersion>> ranges) {
|
||||
return new ProtocolVersionRange(ranges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new range to this range. This method is only available if the range is not already containing all versions.
|
||||
*
|
||||
* @param range the range to add
|
||||
* @return this range
|
||||
*/
|
||||
public ProtocolVersionRange add(final Range<ProtocolVersion> range) {
|
||||
if (ranges == null) {
|
||||
throw new UnsupportedOperationException("Range already contains all versions. Cannot add a new range.");
|
||||
}
|
||||
ranges.add(range);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given version is included in this range.
|
||||
*
|
||||
* @param version the version
|
||||
* @return {@code true} if the version is included
|
||||
*/
|
||||
public boolean contains(final ProtocolVersion version) {
|
||||
if (this.ranges == null) return true;
|
||||
return this.ranges.stream().anyMatch(range -> range.contains(version));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.ranges != null) {
|
||||
StringBuilder rangeString = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Range<ProtocolVersion> range : this.ranges) {
|
||||
i++;
|
||||
final ProtocolVersion min = range.hasLowerBound() ? range.lowerEndpoint() : null;
|
||||
final ProtocolVersion max = range.hasUpperBound() ? range.upperEndpoint() : null;
|
||||
|
||||
if (min == null) rangeString.append("<= ").append(max.getName());
|
||||
else if (max == null) rangeString.append(">= ").append(min.getName());
|
||||
else if (Objects.equals(min, max)) rangeString.append(min.getName());
|
||||
else rangeString.append(min.getName()).append(" - ").append(max.getName());
|
||||
|
||||
if (i != this.ranges.size()) {
|
||||
rangeString.append(", ");
|
||||
}
|
||||
}
|
||||
return rangeString.toString();
|
||||
}
|
||||
return "*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (this == object) return true;
|
||||
if (object == null || getClass() != object.getClass()) return false;
|
||||
ProtocolVersionRange that = (ProtocolVersionRange) object;
|
||||
return Objects.equals(ranges, that.ranges);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(ranges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a range from a string.
|
||||
*
|
||||
* @param str the string
|
||||
* @return the range
|
||||
*/
|
||||
public static ProtocolVersionRange fromString(final String str) {
|
||||
if ("*".equals(str)) return all();
|
||||
else if (str.contains(",")) {
|
||||
String[] rangeParts = str.split(", ");
|
||||
ProtocolVersionRange versionRange = null;
|
||||
|
||||
for (String part : rangeParts) {
|
||||
if (versionRange == null) versionRange = of(parseSinglePart(part));
|
||||
else versionRange.add(parseSinglePart(part));
|
||||
}
|
||||
return versionRange;
|
||||
} else {
|
||||
return of(parseSinglePart(str));
|
||||
}
|
||||
}
|
||||
|
||||
private static Range<ProtocolVersion> parseSinglePart(final String part) {
|
||||
if (part.startsWith("<= ")) return Range.atMost(ProtocolVersion.getClosest(part.substring(3)));
|
||||
else if (part.startsWith(">= ")) return Range.atLeast(ProtocolVersion.getClosest(part.substring(3)));
|
||||
else if (part.contains(" - ")) {
|
||||
String[] rangeParts = part.split(" - ");
|
||||
ProtocolVersion min = ProtocolVersion.getClosest(rangeParts[0]);
|
||||
ProtocolVersion max = ProtocolVersion.getClosest(rangeParts[1]);
|
||||
return Range.open(min, max);
|
||||
} else return Range.singleton(ProtocolVersion.getClosest(part));
|
||||
}
|
||||
|
||||
}
|
|
@ -22,25 +22,27 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.protocol.version;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||
import java.util.SortedSet;
|
||||
|
||||
public interface ServerProtocolVersion {
|
||||
|
||||
/**
|
||||
* Returns the lowest supported protocol version by this server.
|
||||
* This and {@link #highestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
|
||||
* This and {@link #highestSupportedProtocolVersion()} should only differ on proxy servers supporting multiple versions.
|
||||
*
|
||||
* @return lowest supported protocol version
|
||||
*/
|
||||
int lowestSupportedVersion();
|
||||
ProtocolVersion lowestSupportedProtocolVersion();
|
||||
|
||||
/**
|
||||
* Returns the highest supported protocol version by this server.
|
||||
* This and {@link #lowestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
|
||||
* This and {@link #lowestSupportedProtocolVersion()} should only differ on proxy servers supporting multiple versions.
|
||||
*
|
||||
* @return highest supported protocol version
|
||||
*/
|
||||
int highestSupportedVersion();
|
||||
ProtocolVersion highestSupportedProtocolVersion();
|
||||
|
||||
/**
|
||||
* Returns a sorted set of all supported protocol version by this server.
|
||||
|
@ -48,7 +50,7 @@ public interface ServerProtocolVersion {
|
|||
*
|
||||
* @return sorted set of supported protocol versions
|
||||
*/
|
||||
IntSortedSet supportedVersions();
|
||||
SortedSet<ProtocolVersion> supportedProtocolVersions();
|
||||
|
||||
/**
|
||||
* Returns true if the actual protocol version has not yet been identified.
|
||||
|
@ -57,6 +59,22 @@ public interface ServerProtocolVersion {
|
|||
* @return true if set, false if unknown (yet)
|
||||
*/
|
||||
default boolean isKnown() {
|
||||
return lowestSupportedVersion() != -1 && highestSupportedVersion() != -1;
|
||||
return lowestSupportedProtocolVersion().isKnown() && highestSupportedProtocolVersion().isKnown();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default int lowestSupportedVersion() {
|
||||
return lowestSupportedProtocolVersion().getVersion();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default int highestSupportedVersion() {
|
||||
return highestSupportedProtocolVersion().getVersion();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default IntSortedSet supportedVersions() {
|
||||
return supportedProtocolVersions().stream().mapToInt(ProtocolVersion::getVersion)
|
||||
.collect(IntLinkedOpenHashSet::new, IntSortedSet::add, IntSortedSet::addAll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.protocol.version;
|
|||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public class VersionRange {
|
||||
public class SubVersionRange {
|
||||
private final String baseVersion;
|
||||
private final int rangeFrom;
|
||||
private final int rangeTo;
|
||||
|
@ -36,7 +36,7 @@ public class VersionRange {
|
|||
* @param rangeFrom minor version the range begins at, must be greater than or equal to 0
|
||||
* @param rangeTo minor version the range ends at, must be greater than {@code rangeFrom}
|
||||
*/
|
||||
public VersionRange(String baseVersion, int rangeFrom, int rangeTo) {
|
||||
public SubVersionRange(String baseVersion, int rangeFrom, int rangeTo) {
|
||||
Preconditions.checkNotNull(baseVersion);
|
||||
Preconditions.checkArgument(rangeFrom >= 0);
|
||||
Preconditions.checkArgument(rangeTo > rangeFrom);
|
||||
|
@ -72,18 +72,4 @@ public class VersionRange {
|
|||
return rangeTo;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public String getBaseVersion() {
|
||||
return baseVersion;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public int getRangeFrom() {
|
||||
return rangeFrom;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public int getRangeTo() {
|
||||
return rangeTo;
|
||||
}
|
||||
}
|
|
@ -35,5 +35,5 @@ public interface VersionProvider extends Provider {
|
|||
* @param connection connection
|
||||
* @return closest server protocol version to the user's protocol version
|
||||
*/
|
||||
int getClosestServerProtocol(UserConnection connection) throws Exception;
|
||||
ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.protocol.version;
|
||||
|
||||
/**
|
||||
* Categories of Minecraft versions from classic to modern releases, ordered by date.
|
||||
*/
|
||||
public enum VersionType {
|
||||
|
||||
/**
|
||||
* Classic versions of Minecraft (Classic 0.0.2a to 0.30).
|
||||
*/
|
||||
CLASSIC,
|
||||
/**
|
||||
* Alpha versions of Minecraft (Alpha 1.0.0 to 1.0.17).
|
||||
*/
|
||||
ALPHA_INITIAL,
|
||||
/**
|
||||
* Alpha versions of Minecraft (Alpha 1.1.0 to 1.2.6).
|
||||
*/
|
||||
ALPHA_LATER,
|
||||
/**
|
||||
* Beta versions of Minecraft (Beta 1.0 to 1.1_02).
|
||||
*/
|
||||
BETA_INITIAL,
|
||||
/**
|
||||
* Beta versions of Minecraft (Beta 1.2 to 1.9-pre6/1.0.0-RC2).
|
||||
*/
|
||||
BETA_LATER,
|
||||
/**
|
||||
* Pre-netty release versions of Minecraft (1.0.0 to the 1.7.2 snapshot 13w39b).
|
||||
*/
|
||||
RELEASE_INITIAL,
|
||||
/**
|
||||
* Modern release versions of Minecraft (13w41a to latest).
|
||||
*/
|
||||
RELEASE,
|
||||
/**
|
||||
* Any version that doesn't fit in the above categories (e.g. April Fools).
|
||||
* <p>
|
||||
* Protocol versions using this type must override the compareTo method.
|
||||
* Protocol versions using this type must add base protocols to the pipeline manually.
|
||||
*/
|
||||
SPECIAL
|
||||
}
|
|
@ -22,8 +22,10 @@
|
|||
*/
|
||||
package com.viaversion.viaversion.api.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ItemRewriter<T extends Protocol> extends Rewriter<T> {
|
||||
|
@ -31,16 +33,79 @@ public interface ItemRewriter<T extends Protocol> extends Rewriter<T> {
|
|||
/**
|
||||
* Returns the rewritten item, which may or may not be the same given Item instance.
|
||||
*
|
||||
* @param item item
|
||||
* @param connection user connection
|
||||
* @param item item
|
||||
* @return rewritten item
|
||||
*/
|
||||
@Nullable Item handleItemToClient(@Nullable Item item);
|
||||
@Nullable
|
||||
Item handleItemToClient(UserConnection connection, @Nullable Item item);
|
||||
|
||||
/**
|
||||
* Returns the rewritten item, which may or may not be the same given Item instance.
|
||||
*
|
||||
* @param item item
|
||||
* @param connection user connection
|
||||
* @param item item
|
||||
* @return rewritten item
|
||||
*/
|
||||
@Nullable Item handleItemToServer(@Nullable Item item);
|
||||
@Nullable
|
||||
Item handleItemToServer(UserConnection connection, @Nullable Item item);
|
||||
|
||||
/**
|
||||
* Returns the item type of the current protocol.
|
||||
*
|
||||
* @return item type
|
||||
*/
|
||||
@Nullable
|
||||
default Type<Item> itemType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item array type of the current protocol.
|
||||
*
|
||||
* @return item array type
|
||||
*/
|
||||
@Nullable
|
||||
default Type<Item[]> itemArrayType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapped item type of the target protocol.
|
||||
*
|
||||
* @return mapped item type
|
||||
*/
|
||||
@Nullable
|
||||
default Type<Item> mappedItemType() {
|
||||
return itemType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapped item array type of the target protocol.
|
||||
*
|
||||
* @return mapped item array type
|
||||
*/
|
||||
@Nullable
|
||||
default Type<Item[]> mappedItemArrayType() {
|
||||
return itemArrayType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NBT tag name used for storing original item data.
|
||||
*
|
||||
* @return NBT tag name
|
||||
*/
|
||||
default String nbtTagName() {
|
||||
return "VV|" + protocol().getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefixes the NBT tag name with the current protocol's {@link #nbtTagName()}.
|
||||
*
|
||||
* @param nbt NBT tag name
|
||||
* @return prefixed NBT tag name
|
||||
*/
|
||||
default String nbtTagName(final String nbt) {
|
||||
return nbtTagName() + "|" + nbt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.rewriter;
|
||||
|
||||
public interface MappingDataListener {
|
||||
|
||||
default void onMappingDataLoaded() {
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.rewriter;
|
|||
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
|
||||
public interface Rewriter<T extends Protocol> {
|
||||
public interface Rewriter<T extends Protocol> extends MappingDataListener {
|
||||
|
||||
/**
|
||||
* Registers any packet handlers or rewrites needed.
|
||||
|
@ -37,7 +37,4 @@ public interface Rewriter<T extends Protocol> {
|
|||
* @return protocol of the rewriter
|
||||
*/
|
||||
T protocol();
|
||||
|
||||
default void onMappingDataLoaded() {
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue