Compare commits

..

No commits in common. "d28e7cd6527b051ce2e2687682928b28f5ba7c75" and "4074231a57c61daf14838deebfa9d1d2a88cb6dc" have entirely different histories.

385 changed files with 2434 additions and 15124 deletions

View File

@ -10,7 +10,4 @@ ij_java_class_count_to_use_import_on_demand = 999999
ij_java_names_count_to_use_import_on_demand = 999999
ij_java_imports_layout = *,|,$*
ij_java_generate_final_locals = true
ij_java_generate_final_parameters = true
[{*.json,*.yml}]
indent_size = 2
ij_java_generate_final_parameters = true

View File

@ -23,7 +23,7 @@
package us.myles.ViaVersion.api.protocol;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.version.SubVersionRange;
import com.viaversion.viaversion.api.protocol.version.VersionRange;
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 SubVersionRange("1.4", 6, 7));
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");
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 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_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_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/1.9.4", new SubVersionRange("1.9", 3, 4));
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_11 = register(315, "1.11");
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_11_1 = register(316, "1.11.1/2", new VersionRange("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,19 +77,18 @@ 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/1.16.5", new SubVersionRange("1.16", 4, 5));
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/5", new VersionRange("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 SubVersionRange("1.18", 0, 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_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/1.19.2", new SubVersionRange("1.19", 1, 2));
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_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 SubVersionRange("1.20", 0, 1));
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_2 = register(764, "1.20.2");
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 v1_20_3 = register(765, "1.20.3");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
public static ProtocolVersion register(int version, String name) {
@ -100,11 +99,11 @@ public class ProtocolVersion {
return register(version, snapshotVersion, name, null);
}
public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange) {
public static ProtocolVersion register(int version, String name, @Nullable VersionRange versionRange) {
return register(version, -1, name, versionRange);
}
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange);
versionList.add(protocol);
versions.put(protocol.getVersion(), protocol);
@ -167,7 +166,7 @@ public class ProtocolVersion {
this(version, -1, name, null);
}
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
this.version = version;
this.snapshotVersion = snapshotVersion;
this.name = name;

View File

@ -16,6 +16,8 @@ sourceSets {
dependencies {
api(libs.fastutil)
api(libs.flare)
api(libs.flareFastutil)
api(libs.vianbt)
api(libs.gson)
implementation(rootProject.libs.text) {

View File

@ -27,13 +27,10 @@ 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;
/**
@ -66,7 +63,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes
*/
default int apiVersion() {
return 26;
return 23;
}
/**
@ -83,18 +80,7 @@ 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
*/
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);
int getPlayerVersion(T player);
/**
* Returns the protocol version of a player.
@ -102,19 +88,7 @@ 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
*/
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);
int getPlayerVersion(UUID uuid);
/**
* Returns whether Via injected into this player connection.
@ -157,16 +131,6 @@ 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.
@ -174,15 +138,14 @@ public interface ViaAPI<T> {
* @return a sorted set of protocol versions
* @see #getFullSupportedVersions() for a full list
*/
SortedSet<ProtocolVersion> getSupportedProtocolVersions();
SortedSet<Integer> getSupportedVersions();
/**
* Returns the supported protocol versions, including blocked protocols.
*
* @return a sorted set of protocol versions
*/
SortedSet<ProtocolVersion> getFullSupportedProtocolVersions();
SortedSet<Integer> getFullSupportedVersions();
/**
* Returns legacy api only applicable on/to legacy versions.

View File

@ -27,6 +27,8 @@ 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 {
@ -233,6 +235,13 @@ 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
*
@ -263,6 +272,17 @@ 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
*
@ -443,18 +463,4 @@ 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();
}

View File

@ -25,7 +25,6 @@ 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;
@ -94,36 +93,24 @@ public interface ProtocolInfo {
void setServerState(State serverState);
/**
* Returns the user's protocol version, or null if not set.
* Returns the user's protocol version, or -1 if not set.
* This is set during the {@link State#HANDSHAKE} state.
*
* @return protocol version, may be unknown
* @see ProtocolVersion#isKnown()
* @return protocol version, or -1 if not set
*/
ProtocolVersion protocolVersion();
int getProtocolVersion();
void setProtocolVersion(ProtocolVersion protocolVersion);
void setProtocolVersion(int protocolVersion);
/**
* Returns the server protocol version the user is connected to.
* Returns the server protocol version the user is connected to, or -1 if not set.
* This is set during the {@link State#HANDSHAKE} state.
*
* @return the server protocol version the user is connected to, may be unknown
* @see ProtocolVersion#isKnown()
* @return server protocol version, or -1 if not set
*/
ProtocolVersion serverProtocolVersion();
int getServerProtocolVersion();
void setServerProtocolVersion(ProtocolVersion protocolVersion);
@Deprecated
default int getProtocolVersion() {
return protocolVersion() != null ? protocolVersion().getVersion() : -1;
}
@Deprecated
default int getServerProtocolVersion() {
return serverProtocolVersion() != null ? serverProtocolVersion().getVersion() : -1;
}
void setServerProtocolVersion(int serverProtocolVersion);
/**
* Returns the username associated with this connection.

View File

@ -27,7 +27,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Mappings containing the full string identifier mappings.
*/
public interface FullMappings extends BiMappings {
public interface FullMappings extends Mappings {
/**
* Returns the unmapped integer id for the given identifier, or -1 if not found.

View File

@ -22,7 +22,6 @@
*/
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;
@ -38,7 +37,6 @@ 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);

View File

@ -79,8 +79,6 @@ public interface MappingData {
*/
int getNewParticleId(int id);
int getNewAttributeId(int id);
/**
* Returns a list of tags to send if present.
*
@ -89,21 +87,8 @@ 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();
@ -120,15 +105,9 @@ public interface MappingData {
@Nullable Mappings getEnchantmentMappings();
@Nullable Mappings getAttributeMappings();
@Nullable Mappings getPaintingMappings();
@Nullable FullMappings getEntityMappings();
@Nullable FullMappings getArgumentTypeMappings();
@Nullable FullMappings getRecipeSerializerMappings();
@Nullable FullMappings getDataComponentSerializerMappings();
@Nullable Mappings getPaintingMappings();
}

View File

@ -24,6 +24,8 @@ 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;
@ -33,6 +35,7 @@ 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 {
@ -42,8 +45,6 @@ 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;
@ -53,7 +54,6 @@ 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 = readMappingsFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
final CompoundTag data = readNBTFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
blockMappings = loadMappings(data, "blocks");
blockStateMappings = loadMappings(data, "blockstates");
blockEntityMappings = loadMappings(data, "blockentities");
@ -76,30 +76,26 @@ public class MappingDataBase implements MappingData {
menuMappings = loadMappings(data, "menus");
enchantmentMappings = loadMappings(data, "enchantments");
paintingMappings = loadMappings(data, "paintings");
attributeMappings = loadMappings(data, "attributes");
itemMappings = loadBiMappings(data, "items");
final CompoundTag unmappedIdentifierData = readUnmappedIdentifiersFile("identifiers-" + unmappedVersion + ".nbt");
final CompoundTag mappedIdentifierData = readMappedIdentifiersFile("identifiers-" + mappedVersion + ".nbt");
final CompoundTag unmappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + unmappedVersion + ".nbt", true);
final CompoundTag mappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + mappedVersion + ".nbt", true);
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 List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles");
final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles");
final ListTag<StringTag> unmappedParticles = unmappedIdentifierData.getListTag("particles", StringTag.class);
final ListTag<StringTag> mappedParticles = mappedIdentifierData.getListTag("particles", StringTag.class);
if (unmappedParticles != null && mappedParticles != null) {
Mappings particleMappings = loadMappings(data, "particles");
if (particleMappings == null) {
particleMappings = new IdentityMappings(unmappedParticles.size(), mappedParticles.size());
}
this.particleMappings = new ParticleMappings(unmappedParticles, mappedParticles, particleMappings);
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);
}
} else {
// Might not have identifiers in older versions
itemMappings = loadBiMappings(data, "items");
}
final CompoundTag tagsTag = data.getCompoundTag("tags");
@ -112,28 +108,16 @@ public class MappingDataBase implements MappingData {
loadExtras(data);
}
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 CompoundTag readNBTFile(final String name) {
return MappingDataLoader.loadNBT(name);
}
protected @Nullable Mappings loadMappings(final CompoundTag data, final String key) {
return MappingDataLoader.INSTANCE.loadMappings(data, key);
return MappingDataLoader.loadMappings(data, key);
}
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
return MappingDataLoader.INSTANCE.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key);
return MappingDataLoader.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key);
}
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
@ -181,11 +165,6 @@ 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;
@ -196,14 +175,6 @@ 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;
@ -244,11 +215,6 @@ public class MappingDataBase implements MappingData {
return enchantmentMappings;
}
@Override
public @Nullable Mappings getAttributeMappings() {
return attributeMappings;
}
@Override
public @Nullable FullMappings getEntityMappings() {
return entityMappings;
@ -259,21 +225,11 @@ 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();
}

View File

@ -28,7 +28,6 @@ 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;
@ -41,77 +40,29 @@ 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 class MappingDataLoader {
public final class MappingDataLoader {
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 Map<String, CompoundTag> MAPPINGS_CACHE = new HashMap<>();
private static final TagReader<CompoundTag> MAPPINGS_READER = NBTIO.reader(CompoundTag.class).named();
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;
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();
public static void clearCache() {
MAPPINGS_CACHE.clear();
cacheValid = false;
}
@ -120,8 +71,8 @@ public class MappingDataLoader {
*
* @return loaded json object, or null if not found or invalid
*/
public @Nullable JsonObject loadFromDataDir(final String name) {
final File file = new File(getDataFolder(), name);
public static @Nullable JsonObject loadFromDataDir(final String name) {
final File file = new File(Via.getPlatform().getDataFolder(), name);
if (!file.exists()) {
return loadData(name);
}
@ -131,7 +82,7 @@ public 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
getLogger().warning(name + " is badly formatted!");
Via.getPlatform().getLogger().warning(name + " is badly formatted!");
throw new RuntimeException(e);
} catch (final IOException | JsonIOException e) {
throw new RuntimeException(e);
@ -143,7 +94,7 @@ public class MappingDataLoader {
*
* @return loaded json object from bundled resources if present
*/
public @Nullable JsonObject loadData(final String name) {
public static @Nullable JsonObject loadData(final String name) {
final InputStream stream = getResource(name);
if (stream == null) {
return null;
@ -156,12 +107,12 @@ public class MappingDataLoader {
}
}
public @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
public static @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
if (!cacheValid) {
return loadNBTFromFile(name);
}
CompoundTag data = mappingsCache.get(name);
CompoundTag data = MAPPINGS_CACHE.get(name);
if (data != null) {
return data;
}
@ -169,29 +120,29 @@ public class MappingDataLoader {
data = loadNBTFromFile(name);
if (cache && data != null) {
mappingsCache.put(name, data);
MAPPINGS_CACHE.put(name, data);
}
return data;
}
public @Nullable CompoundTag loadNBT(final String name) {
public static @Nullable CompoundTag loadNBT(final String name) {
return loadNBT(name, false);
}
public @Nullable CompoundTag loadNBTFromFile(final String name) {
public static @Nullable CompoundTag loadNBTFromFile(final String name) {
final InputStream resource = getResource(name);
if (resource == null) {
return null;
}
try (final InputStream stream = new BufferedInputStream(resource)) {
try (final InputStream stream = resource) {
return MAPPINGS_READER.read(stream);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
public @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
public static @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
return loadMappings(mappingsTag, key, size -> {
final int[] array = new int[size];
Arrays.fill(array, -1);
@ -200,12 +151,12 @@ public class MappingDataLoader {
}
@Beta
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
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
) {
final CompoundTag tag = mappingsTag.getCompoundTag(key);
if (tag == null) {
@ -276,32 +227,23 @@ public class MappingDataLoader {
return mappingsSupplier.create(mappings, mappedSizeTag.asInt());
}
public FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) {
if (!unmappedIdentifiersTag.contains(key) || !mappedIdentifiersTag.contains(key)) {
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) {
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(unmappedIdentifiers.size(), mappedIdentifiers.size());
mappings = new IdentityMappings(unmappedElements.size(), mappedElements.size());
}
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;
return new FullMappingsBase(
unmappedElements.stream().map(StringTag::getValue).collect(Collectors.toList()),
mappedElements.stream().map(StringTag::getValue).collect(Collectors.toList()),
mappings
);
}
/**
@ -310,7 +252,7 @@ public class MappingDataLoader {
* @param object json object
* @return map with indexes hashed by their id value
*/
public Object2IntMap<String> indexedObjectToMap(final JsonObject object) {
public static 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()) {
@ -325,7 +267,7 @@ public class MappingDataLoader {
* @param array json array
* @return map with indexes hashed by their id value
*/
public Object2IntMap<String> arrayToMap(final JsonArray array) {
public static 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++) {
@ -334,16 +276,8 @@ public class MappingDataLoader {
return map;
}
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);
public static @Nullable InputStream getResource(final String name) {
return MappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name);
}
@FunctionalInterface

View File

@ -84,4 +84,10 @@ public interface Mappings {
* @return mappings with keys and values swapped
*/
Mappings inverse();
@FunctionalInterface
interface MappingsSupplier<T extends Mappings> {
T supply(int[] mappings, int mappedIds);
}
}

View File

@ -35,7 +35,6 @@ public class ParticleMappings extends FullMappingsBase {
addBlockParticle("block");
addBlockParticle("falling_dust");
addBlockParticle("block_marker");
addBlockParticle("dust_pillar");
addItemParticle("item");
}

View File

@ -24,8 +24,6 @@ package com.viaversion.viaversion.api.data.entity;
public interface DimensionData {
int id();
int minY();
int height();

View File

@ -34,7 +34,6 @@ public interface EntityTracker {
*
* @return user connection
*/
@Deprecated
UserConnection user();
/**
@ -166,8 +165,6 @@ public interface EntityTracker {
@Nullable DimensionData dimensionData(String dimension);
@Nullable DimensionData dimensionData(int dimensionId);
void setDimensions(Map<String, DimensionData> dimensions);
/**

View File

@ -1,75 +0,0 @@
/*
* 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;
}
}
}

View File

@ -1,82 +0,0 @@
/*
* 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();
}

View File

@ -1,63 +0,0 @@
/*
* 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;
}
}

View File

@ -1,79 +0,0 @@
/*
* 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();
}

View File

@ -1,56 +0,0 @@
/*
* 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();
}
}

View File

@ -24,12 +24,11 @@ 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 implements IdHolder {
public final class Particle {
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
private int id;
@ -37,16 +36,10 @@ public final class Particle implements IdHolder {
this.id = id;
}
@Deprecated
public int getId() {
return id;
}
@Override
public int id() {
return id;
}
public void setId(final int id) {
this.id = id;
}
@ -73,18 +66,6 @@ public final class Particle implements IdHolder {
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;

View File

@ -1,48 +0,0 @@
/*
* 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);
}
}

View File

@ -1,48 +0,0 @@
/*
* 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);
}
}

View File

@ -22,8 +22,6 @@
*/
package com.viaversion.viaversion.api.minecraft;
import java.util.Arrays;
public final class TagData {
private final String identifier;
private final int[] entries;
@ -40,12 +38,4 @@ public final class TagData {
public int[] entries() {
return entries;
}
@Override
public String toString() {
return "TagData{" +
"identifier='" + identifier + '\'' +
", entries=" + Arrays.toString(entries) +
'}';
}
}

View File

@ -1,94 +0,0 @@
/*
* 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 +
'}';
}
}

View File

@ -1,103 +0,0 @@
/*
* 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 +
'}';
}
}

View File

@ -1,80 +0,0 @@
/*
* 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();
}

View File

@ -1,172 +0,0 @@
/*
* 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 +
'}';
}
}

View File

@ -1,136 +0,0 @@
/*
* 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 +
'}';
}
}

View File

@ -1,288 +0,0 @@
/*
* 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);
}
}

View File

@ -24,7 +24,6 @@ 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;
@ -92,11 +91,6 @@ 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);
@ -125,10 +119,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 +
'}';
}
}

View File

@ -23,7 +23,6 @@
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 {
@ -80,8 +79,7 @@ public interface Item {
*
* @return item tag
*/
@Nullable
CompoundTag tag();
@Nullable CompoundTag tag();
/**
* Sets the item compound tag.
@ -90,21 +88,10 @@ 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;
}
}

View File

@ -1,110 +0,0 @@
/*
* 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 +
'}';
}
}

View File

@ -1,60 +0,0 @@
/*
* 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;
}
}

View File

@ -1,69 +0,0 @@
/*
* 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;
}
}

View File

@ -1,102 +0,0 @@
/*
* 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;
}
}

View File

@ -1,78 +0,0 @@
/*
* 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;
}
}

View File

@ -1,70 +0,0 @@
/*
* 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;
}
}

View File

@ -1,60 +0,0 @@
/*
* 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;
}
}

View File

@ -1,61 +0,0 @@
/*
* 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;
}
}

View File

@ -1,63 +0,0 @@
/*
* 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;
}
}

View File

@ -1,71 +0,0 @@
/*
* 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;
}
}

View File

@ -1,78 +0,0 @@
/*
* 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;
}
}

View File

@ -1,62 +0,0 @@
/*
* 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;
}
}

View File

@ -1,60 +0,0 @@
/*
* 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;
}
}

View File

@ -1,96 +0,0 @@
/*
* 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);
}
}

View File

@ -1,79 +0,0 @@
/*
* 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);
}
}

View File

@ -1,43 +0,0 @@
/*
* 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);
}
}

View File

@ -1,42 +0,0 @@
/*
* 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);
}
}

View File

@ -1,85 +0,0 @@
/*
* 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;
}
}

View File

@ -1,60 +0,0 @@
/*
* 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;
}
}

View File

@ -1,62 +0,0 @@
/*
* 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;
}
}

View File

@ -1,84 +0,0 @@
/*
* 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;
}
}

View File

@ -1,71 +0,0 @@
/*
* 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;
}
}

View File

@ -1,62 +0,0 @@
/*
* 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;
}
}

View File

@ -1,77 +0,0 @@
/*
* 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;
}
}

View File

@ -1,65 +0,0 @@
/*
* 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;
}
}

View File

@ -1,77 +0,0 @@
/*
* 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;
}
}

View File

@ -1,75 +0,0 @@
/*
* 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];
}
}

View File

@ -1,77 +0,0 @@
/*
* 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;
}
}

View File

@ -1,62 +0,0 @@
/*
* 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;
}
}

View File

@ -1,97 +0,0 @@
/*
* 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;
}
}

View File

@ -1,96 +0,0 @@
/*
* 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;
}
}
}

View File

@ -1,62 +0,0 @@
/*
* 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;
}
}

View File

@ -1,68 +0,0 @@
/*
* 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;
}
}

View File

@ -1,72 +0,0 @@
/*
* 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;
}
}

View File

@ -1,51 +0,0 @@
/*
* 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;
}
}

View File

@ -1,84 +0,0 @@
/*
* 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;
}
}

View File

@ -22,7 +22,6 @@
*/
package com.viaversion.viaversion.api.minecraft.metadata;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.type.Type;
public interface MetaType {
@ -50,7 +49,6 @@ public interface MetaType {
private final Type<?> type;
MetaTypeImpl(final int typeId, final Type<?> type) {
Preconditions.checkNotNull(type);
this.typeId = typeId;
this.type = type;
}

View File

@ -24,6 +24,7 @@ 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),
@ -33,7 +34,9 @@ public enum MetaType1_8 implements MetaType {
String(4, Type.STRING),
Slot(5, Type.ITEM1_8),
Position(6, Type.VECTOR),
Rotation(7, Type.ROTATION);
Rotation(7, Type.ROTATION),
@Deprecated
NonExistent(-1, new VoidType());
private final int typeID;
private final Type type;

View File

@ -1,71 +0,0 @@
/*
* 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);
}
}

View File

@ -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 com.viaversion.viaversion.util.GsonUtil;
import net.lenni0451.mcstructs.text.utils.JsonUtils;
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(GsonUtil.sort(this.content.decorated()).toString().getBytes(StandardCharsets.UTF_8));
dataOutputStream.write(JsonUtils.toSortedString(this.content.decorated(), null).getBytes(StandardCharsets.UTF_8));
}
for (PlayerMessageSignature lastSeenMessage : this.lastSeenMessages) {

View File

@ -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 com.viaversion.viaversion.util.GsonUtil;
import net.lenni0451.mcstructs.text.utils.JsonUtils;
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(GsonUtil.sort(content.decorated()).toString().getBytes(StandardCharsets.UTF_8));
signer.accept(JsonUtils.toSortedString(content.decorated(), null).getBytes(StandardCharsets.UTF_8));
});
}

View File

@ -22,7 +22,6 @@
*/
package com.viaversion.viaversion.api.platform;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
public interface ProtocolDetectorService {
@ -33,7 +32,7 @@ public interface ProtocolDetectorService {
* @param serverName name of the proxied server
* @return protocol version of the proxied server, or -1 if unknown
*/
ProtocolVersion serverProtocolVersion(String serverName);
int serverProtocolVersion(String serverName);
/**
* Probes all registered proxied servers for their protocol version.

View File

@ -23,9 +23,8 @@
package com.viaversion.viaversion.api.platform;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import java.util.SortedSet;
import it.unimi.dsi.fastutil.ints.IntSortedSet;
import it.unimi.dsi.fastutil.ints.IntSortedSets;
public interface ViaInjector {
@ -61,7 +60,7 @@ public interface ViaInjector {
* @throws Exception if there is an error with getting this info, e.g. not binded
* @see ViaPlatform#isProxy()
*/
ProtocolVersion getServerProtocolVersion() throws Exception;
int getServerProtocolVersion() throws Exception;
/**
* Returns the supported server protocol versions.
@ -70,10 +69,8 @@ public interface ViaInjector {
* @throws Exception if there is an error with getting this info, e.g. not binded
* @see ViaPlatform#isProxy()
*/
default SortedSet<ProtocolVersion> getServerProtocolVersions() throws Exception {
final SortedSet<ProtocolVersion> versions = new ObjectLinkedOpenHashSet<>();
versions.add(getServerProtocolVersion());
return versions;
default IntSortedSet getServerProtocolVersions() throws Exception {
return IntSortedSets.singleton(getServerProtocolVersion());
}
/**

View File

@ -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 com.viaversion.viaversion.util.ProtocolUtil;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
@ -50,8 +50,6 @@ 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.
*
@ -127,42 +125,24 @@ 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) {
appendServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
registerServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
}
final CU startConfigurationPacket = startConfigurationPacket();
if (startConfigurationPacket != null) {
appendClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
registerClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
}
final SU finishConfigurationPacket = serverboundFinishConfigurationPacket();
final ServerboundPacketType finishConfigurationPacket = serverboundFinishConfigurationPacket();
if (finishConfigurationPacket != null) {
appendServerbound(finishConfigurationPacket, setClientStateHandler(State.PLAY));
final int id = finishConfigurationPacket.getId();
registerServerbound(State.CONFIGURATION, id, id, setClientStateHandler(State.PLAY));
}
final CU clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
final ClientboundPacketType clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
if (clientboundFinishConfigurationPacket != null) {
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);
final int id = clientboundFinishConfigurationPacket.getId();
registerClientbound(State.CONFIGURATION, id, id, setServerStateHandler(State.PLAY));
}
}
@ -174,19 +154,18 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
) {
for (Map.Entry<State, PacketTypeMap<M>> entry : mappedPacketTypes.entrySet()) {
PacketTypeMap<M> mappedTypes = entry.getValue();
PacketTypeMap<U> unmappedTypes = unmappedPacketTypes.get(entry.getKey());
for (U unmappedType : unmappedTypes.types()) {
for (U unmappedType : unmappedPacketTypes.get(entry.getKey()).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);
}
}
}
@ -214,7 +193,6 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
protected void onMappingDataLoaded() {
callOnMappingDataLoaded(getEntityRewriter());
callOnMappingDataLoaded(getItemRewriter());
callOnMappingDataLoaded(getTagRewriter());
}
private void callRegister(@Nullable Rewriter<?> rewriter) {
@ -223,7 +201,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
private void callOnMappingDataLoaded(@Nullable MappingDataListener rewriter) {
private void callOnMappingDataLoaded(@Nullable Rewriter<?> rewriter) {
if (rewriter != null) {
rewriter.onMappingDataLoaded();
}
@ -235,10 +213,10 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
protected PacketTypesProvider<CU, CM, SM, SU> createPacketTypesProvider() {
return new SimplePacketTypesProvider<>(
packetTypeMap(unmappedClientboundPacketType, unmappedClientboundPacketType),
packetTypeMap(mappedClientboundPacketType, mappedClientboundPacketType),
packetTypeMap(mappedServerboundPacketType, mappedServerboundPacketType),
packetTypeMap(unmappedServerboundPacketType, unmappedServerboundPacketType)
packetTypeMap(unmappedClientboundPacketType),
packetTypeMap(mappedClientboundPacketType),
packetTypeMap(mappedServerboundPacketType),
packetTypeMap(unmappedServerboundPacketType)
);
}
@ -250,20 +228,35 @@ 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() {
return packetTypesProvider.unmappedServerboundType(State.PLAY, "CONFIGURATION_ACKNOWLEDGED");
final Map<State, PacketTypeMap<SU>> packetTypes = packetTypesProvider.unmappedServerboundPacketTypes();
final PacketTypeMap<SU> packetTypeMap = packetTypes.get(State.PLAY);
return packetTypeMap != null ? packetTypeMap.typeByName("CONFIGURATION_ACKNOWLEDGED") : null;
}
protected @Nullable CU startConfigurationPacket() {
return packetTypesProvider.unmappedClientboundType(State.PLAY, "START_CONFIGURATION");
final Map<State, PacketTypeMap<CU>> packetTypes = packetTypesProvider.unmappedClientboundPacketTypes();
final PacketTypeMap<CU> packetTypeMap = packetTypes.get(State.PLAY);
return packetTypeMap != null ? packetTypeMap.typeByName("START_CONFIGURATION") : null;
}
protected @Nullable SU serverboundFinishConfigurationPacket() {
return packetTypesProvider.unmappedServerboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
protected @Nullable ServerboundPacketType serverboundFinishConfigurationPacket() {
// To be overridden
return null;
}
protected @Nullable CU clientboundFinishConfigurationPacket() {
return packetTypesProvider.unmappedClientboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
protected @Nullable ClientboundPacketType clientboundFinishConfigurationPacket() {
// To be overridden
return null;
}
// ---------------------------------------------------------------------------------
@ -398,17 +391,19 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
try {
handler.handle(packetWrapper);
} catch (CancelException e) {
throw e; // Pass through CancelExceptions
} catch (InformativeException e) {
e.addSource(handler.getClass());
printRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
// Pass through CancelExceptions
throw e;
} catch (InformativeException e) {
// Catch InformativeExceptions
e.addSource(handler.getClass());
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
return;
} catch (Exception e) {
// Wrap other exceptions during packet handling
InformativeException ex = new InformativeException(e);
ex.addSource(handler.getClass());
printRemapError(direction, state, unmappedId, packetWrapper.getId(), ex);
throw ex;
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), ex);
return;
}
if (packetWrapper.isCancelled()) {
@ -417,22 +412,36 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
private void printRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) {
protected void throwRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) throws InformativeException {
// Don't print errors during handshake/login/status
if (state != State.PLAY && direction == Direction.SERVERBOUND && !Via.getManager().debugHandler().enabled()) {
e.setShouldBePrinted(false);
return;
throw e;
}
PacketType packetType = direction == Direction.CLIENTBOUND
? packetTypesProvider.unmappedClientboundType(state, unmappedPacketId)
: packetTypesProvider.unmappedServerboundType(state, unmappedPacketId);
PacketType packetType = direction == Direction.CLIENTBOUND ? unmappedClientboundPacketType(state, unmappedPacketId) : unmappedServerboundPacketType(state, unmappedPacketId);
if (packetType != null) {
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + ProtocolUtil.toNiceHex(unmappedPacketId) + ")");
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(unmappedPacketId) + ")");
} else {
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
+ " IN REMAP OF " + state + " " + ProtocolUtil.toNiceHex(unmappedPacketId) + "->" + ProtocolUtil.toNiceHex(mappedPacketId));
+ " IN REMAP OF " + state + " " + toNiceHex(unmappedPacketId) + "->" + 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;
}
/**
@ -446,16 +455,16 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
private PacketHandler setClientStateHandler(final State state) {
protected PacketHandler setClientStateHandler(final State state) {
return wrapper -> wrapper.user().getProtocolInfo().setClientState(state);
}
private PacketHandler setServerStateHandler(final State state) {
protected PacketHandler setServerStateHandler(final State state) {
return wrapper -> wrapper.user().getProtocolInfo().setServerState(state);
}
@Override
public final PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
public PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
return packetTypesProvider;
}
@ -470,6 +479,10 @@ 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();

View File

@ -22,6 +22,7 @@
*/
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;
@ -36,8 +37,6 @@ 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;
/**
@ -52,25 +51,24 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
public interface Protocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
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, @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) {
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) {
Preconditions.checkArgument(packetType.state() == state);
registerClientbound(state, packetType.getId(), packetType.getId(), handler, false);
}
default void registerServerbound(State state, ServerboundPacketType packetType, PacketHandler handler) {
Preconditions.checkArgument(packetType.state() == state);
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
}
/**
* Registers a serverbound packet, with id transformation and remapper.
*
@ -81,16 +79,15 @@ 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, @Nullable PacketHandler handler, boolean override);
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, 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, @Nullable PacketHandler handler) {
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) {
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
@ -106,7 +103,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, @Nullable PacketHandler handler, boolean override);
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override);
// ---------------------------------------------------------------------------------------
@ -242,28 +239,6 @@ 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
*
@ -280,6 +255,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
*
* @return the packet types provider
*/
@Beta
PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider();
/**
@ -289,16 +265,13 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param <T> type
* @return object if present, else null
*/
@Deprecated
@Nullable
<T> T get(Class<T> objectClass);
@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);
/**
@ -375,15 +348,6 @@ 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.
*

View File

@ -31,7 +31,6 @@ 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;
@ -63,8 +62,21 @@ 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
*/
@Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion);
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);
/**
* Returns the base protocol handling serverbound handshake packets.
@ -78,9 +90,10 @@ 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 if present, else null
* @return base protocol for the given server protocol version
* @throws IllegalStateException if no base protocol could be found
*/
@Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion);
Protocol getBaseProtocol(int serverVersion);
/**
* Returns an immutable collection of registered protocols.
@ -115,7 +128,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<ProtocolVersion> supportedClientVersion, ProtocolVersion serverVersion);
void registerProtocol(Protocol protocol, List<Integer> supportedClientVersion, int serverVersion);
/**
* Registers and initializes a base protocol. Base Protocols registered later have higher priority.
@ -125,7 +138,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<ProtocolVersion> supportedProtocols);
void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols);
/**
* Calculates and returns the protocol path from a client protocol version to server protocol version.
@ -135,12 +148,7 @@ 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(ProtocolVersion clientVersion, ProtocolVersion serverVersion);
@Deprecated
default @Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion) {
return getProtocolPath(ProtocolVersion.getProtocol(clientVersion), ProtocolVersion.getProtocol(serverVersion));
}
@Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion);
/**
* Returns a versioned packet transformer to transform and send packets from a given base version to any client version supported by Via.
@ -167,10 +175,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.
@ -218,14 +226,14 @@ public interface ProtocolManager {
}
/**
* Returns the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
* Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
*
* @return maximum protocol path size
*/
int getMaxProtocolPathSize();
/**
* Sets the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
* Sets the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
* Its default is 50.
*
* @param maxProtocolPathSize maximum protocol path size
@ -237,7 +245,7 @@ public interface ProtocolManager {
*
* @return sorted, immutable set of supported protocol versions
*/
SortedSet<ProtocolVersion> getSupportedVersions();
SortedSet<Integer> getSupportedVersions();
/**
* Check if this plugin is useful to the server.
@ -310,11 +318,4 @@ 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();
}

View File

@ -22,8 +22,6 @@
*/
package com.viaversion.viaversion.api.protocol;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
public interface ProtocolPathEntry {
/**
@ -32,7 +30,7 @@ public interface ProtocolPathEntry {
*
* @return output protocol version after transformation
*/
ProtocolVersion outputProtocolVersion();
int outputProtocolVersion();
/**
* Returns the protocol to be applied with this entry.
@ -41,4 +39,13 @@ public interface ProtocolPathEntry {
*/
Protocol<?, ?, ?, ?> protocol();
@Deprecated/*(forRemoval = true)*/
default int getOutputProtocolVersion() {
return outputProtocolVersion();
}
@Deprecated/*(forRemoval = true)*/
default Protocol getProtocol() {
return protocol();
}
}

View File

@ -22,8 +22,6 @@
*/
package com.viaversion.viaversion.api.protocol;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
public interface ProtocolPathKey {
/**
@ -31,13 +29,22 @@ public interface ProtocolPathKey {
*
* @return client protocol version
*/
ProtocolVersion clientProtocolVersion();
int clientProtocolVersion();
/**
* Returns the server protocol version.
*
* @return server protocol version
*/
ProtocolVersion serverProtocolVersion();
int serverProtocolVersion();
@Deprecated/*(forRemoval = true)*/
default int getClientProtocolVersion() {
return clientProtocolVersion();
}
@Deprecated/*(forRemoval = true)*/
default int getServerProtocolVersion() {
return serverProtocolVersion();
}
}

View File

@ -23,7 +23,6 @@
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;
@ -62,34 +61,25 @@ public interface ProtocolPipeline extends SimpleProtocol {
* @param pipeClass protocol class
* @param <P> protocol
* @return protocol from class
* @deprecated use {@link ProtocolManager#getProtocol(Class)} and/or {@link #contains(Class)}
* @see #contains(Class)
* @see ProtocolManager#getProtocol(Class) for a faster implementation
*/
@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, lead by base protocols.
* Returns the list of protocols this pipeline contains.
*
* @return immutable list of protocols in this pipe
*/
List<Protocol> pipes();
/**
* Returns the list of protocols this pipeline contains in reversed order, although still lead by base protocols.
* Returns the list of protocols this pipeline contains in reversed order.
*
* @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()}.
*

View File

@ -92,7 +92,6 @@ 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);
/**
@ -213,11 +212,11 @@ public interface PacketWrapper {
* (Sends it after current)
* Also returns the packets ChannelFuture
*
* @param protocolClass the protocol class to start from in the pipeline
* @return new ChannelFuture for the write operation
* @param packetProtocol The protocol version of the packet.
* @return The packets ChannelFuture
* @throws Exception if it fails to write
*/
ChannelFuture sendFuture(Class<? extends Protocol> protocolClass) throws Exception;
ChannelFuture sendFuture(Class<? extends Protocol> packetProtocol) throws Exception;
/**
* @deprecated misleading; use {@link #sendRaw()}. This method will be removed in 5.0.0
@ -288,24 +287,18 @@ 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;
/**
* @deprecated use {@link #apply(Direction, State, List)}
* @see #apply(Direction, State, int, List, boolean)
*/
@Deprecated
default PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception {
return apply(direction, state, index, pipeline, false);
}
PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception;
/**
* Check if this packet is cancelled.

View File

@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
final class PacketIdMapping implements PacketMapping {
private final int mappedPacketId;
private PacketHandler handler;
private final PacketHandler handler;
PacketIdMapping(int mappedPacketId, @Nullable PacketHandler handler) {
this.mappedPacketId = mappedPacketId;
@ -41,15 +41,6 @@ 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;

View File

@ -46,13 +46,6 @@ 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);
}

View File

@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
final class PacketTypeMapping implements PacketMapping {
private final PacketType mappedPacketType;
private PacketHandler handler;
private final PacketHandler handler;
PacketTypeMapping(@Nullable PacketType mappedPacketType, @Nullable PacketHandler handler) {
this.mappedPacketType = mappedPacketType;
@ -43,15 +43,6 @@ 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;

View File

@ -22,7 +22,6 @@
*/
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;
@ -55,11 +54,14 @@ public interface PacketTypeMap<P extends PacketType> {
*/
Collection<P> 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) {
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) {
byName.put(type.getName(), type);
}
return of(byName, types);

View File

@ -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,6 +37,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* @param <SU> unmapped serverbound packet type
* @see SimplePacketTypesProvider
*/
@Beta
public interface PacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
/**
@ -68,24 +69,4 @@ 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;
}
}

View File

@ -22,11 +22,13 @@
*/
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;

View File

@ -34,17 +34,4 @@ 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);
};
}
}

View File

@ -22,13 +22,11 @@
*/
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<>();
@ -130,24 +128,6 @@ 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.
*

View File

@ -22,7 +22,7 @@
*/
package com.viaversion.viaversion.api.protocol.version;
import java.util.Set;
import it.unimi.dsi.fastutil.ints.IntSet;
public interface BlockedProtocolVersions {
@ -32,26 +32,26 @@ public interface BlockedProtocolVersions {
* @param protocolVersion protocol version
* @return whether the given protocol version is blocked
*/
boolean contains(ProtocolVersion protocolVersion);
boolean contains(int 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
*/
ProtocolVersion blocksBelow();
int 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
*/
ProtocolVersion blocksAbove();
int blocksAbove();
/**
* Returns a set of blocked protocol versions between the outer block ranges.
*
* @return set of blocked protocol versions between the outer block ranges
*/
Set<ProtocolVersion> singleBlockedVersions();
IntSet singleBlockedVersions();
}

View File

@ -27,32 +27,35 @@ 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 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);
public class ProtocolVersion {
private static final Int2ObjectMap<ProtocolVersion> VERSIONS = new Int2ObjectOpenHashMap<>();
private static final List<ProtocolVersion> VERSION_LIST = new ArrayList<>();
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));
// 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_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-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_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_11 = register(315, "1.11");
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_11_1 = register(316, "1.11.1/2", new VersionRange("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");
@ -71,51 +74,49 @@ public class ProtocolVersion implements Comparable<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-1.16.5", new SubVersionRange("1.16", 4, 5));
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/5", new VersionRange("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 SubVersionRange("1.18", 0, 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_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-1.19.2", new SubVersionRange("1.19", 1, 2));
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_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 SubVersionRange("1.20", 0, 1));
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_2 = register(764, "1.20.2");
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 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 ProtocolVersion register(int version, String name) {
return register(version, -1, name);
}
public static ProtocolVersion register(int version, int snapshotVersion, String name) {
final ProtocolVersion protocolVersion = new ProtocolVersion(VersionType.RELEASE, version, snapshotVersion, name, null);
register(protocolVersion);
return protocolVersion;
return register(version, snapshotVersion, name, null);
}
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;
public static ProtocolVersion register(int version, String name, @Nullable VersionRange versionRange) {
return register(version, -1, name, versionRange);
}
/**
* Registers a protocol version.
*
* @param protocolVersion protocol version to register
* @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
*/
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);
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);
}
return protocol;
}
/**
@ -124,36 +125,24 @@ public class ProtocolVersion implements Comparable<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 isRegistered(VersionType.RELEASE, version);
return VERSIONS.containsKey(version);
}
/**
* Returns a ProtocolVersion instance, even if this protocol version
* has not been registered. See {@link #isRegistered(VersionType, int)} beforehand or {@link #isKnown()}.
* has not been registered. See {@link #isRegistered(int)} berorehand or {@link #isKnown()}.
*
* @param versionType protocol version type
* @param version protocol version
* @param version protocol version
* @return registered or unknown ProtocolVersion
*/
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;
}
public static @NonNull ProtocolVersion getProtocol(int version) {
ProtocolVersion protocolVersion = VERSIONS.get(version);
if (protocolVersion != null) {
return protocolVersion;
} else {
return new ProtocolVersion(version, "Unknown (" + version + ")");
}
return new ProtocolVersion(VersionType.SPECIAL, version, -1, "Unknown (" + version + ")", null);
}
public static @NonNull ProtocolVersion getProtocol(final int version) {
return getProtocol(VersionType.RELEASE, version);
}
/**
@ -161,9 +150,7 @@ public class ProtocolVersion implements Comparable<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);
}
@ -179,58 +166,59 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
/**
* Returns the registered protocol version if present, else null.
* This accepts the actual registered names (like "1.16.4/1.16.5") as well as
* This accepts the actual registered names (like "1.16.4/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 : VERSION_LIST) {
for (ProtocolVersion version : VERSIONS.values()) {
String name = version.getName();
if (name.equals(protocol) || version.isRange() && version.getIncludedVersions().contains(protocol)) {
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)) {
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(VersionType versionType, int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
this.versionType = versionType;
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
this.version = version;
this.snapshotVersion = snapshotVersion;
this.name = name;
this.versionWildcard = name.endsWith(".x");
Preconditions.checkArgument(!(isVersionWildcard() && versionRange == null), "A wildcard name must have a version range");
Preconditions.checkArgument(!versionWildcard || versionRange == null, "A version cannot be a wildcard and a range at the same time!");
if (versionRange != null) {
includedVersions = new LinkedHashSet<>();
for (int i = versionRange.rangeFrom(); i <= versionRange.rangeTo(); i++) {
@ -245,16 +233,6 @@ public class ProtocolVersion implements Comparable<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.
*
@ -334,7 +312,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
* @return true if the protocol includes an entire major version range
*/
public boolean isVersionWildcard() {
return this.name.endsWith(".x");
return versionWildcard;
}
/**
@ -355,127 +333,22 @@ public class ProtocolVersion implements Comparable<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(final Object o) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final ProtocolVersion that = (ProtocolVersion) o;
return version == that.version && versionType == that.versionType && snapshotVersion == that.snapshotVersion;
ProtocolVersion that = (ProtocolVersion) o;
return version == that.version;
}
@Override
public int hashCode() {
int result = versionType.hashCode();
result = 31 * result + version;
result = 31 * result + snapshotVersion;
return result;
return version;
}
@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);
}
}

View File

@ -1,180 +0,0 @@
/*
* 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));
}
}

View File

@ -22,27 +22,25 @@
*/
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 #highestSupportedProtocolVersion()} should only differ on proxy servers supporting multiple versions.
* This and {@link #highestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
*
* @return lowest supported protocol version
*/
ProtocolVersion lowestSupportedProtocolVersion();
int lowestSupportedVersion();
/**
* Returns the highest supported protocol version by this server.
* This and {@link #lowestSupportedProtocolVersion()} should only differ on proxy servers supporting multiple versions.
* This and {@link #lowestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
*
* @return highest supported protocol version
*/
ProtocolVersion highestSupportedProtocolVersion();
int highestSupportedVersion();
/**
* Returns a sorted set of all supported protocol version by this server.
@ -50,7 +48,7 @@ public interface ServerProtocolVersion {
*
* @return sorted set of supported protocol versions
*/
SortedSet<ProtocolVersion> supportedProtocolVersions();
IntSortedSet supportedVersions();
/**
* Returns true if the actual protocol version has not yet been identified.
@ -59,22 +57,6 @@ public interface ServerProtocolVersion {
* @return true if set, false if unknown (yet)
*/
default boolean isKnown() {
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);
return lowestSupportedVersion() != -1 && highestSupportedVersion() != -1;
}
}

View File

@ -35,5 +35,5 @@ public interface VersionProvider extends Provider {
* @param connection connection
* @return closest server protocol version to the user's protocol version
*/
ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception;
int getClosestServerProtocol(UserConnection connection) throws Exception;
}

View File

@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.protocol.version;
import com.google.common.base.Preconditions;
public class SubVersionRange {
public class VersionRange {
private final String baseVersion;
private final int rangeFrom;
private final int rangeTo;
@ -36,7 +36,7 @@ public class SubVersionRange {
* @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 SubVersionRange(String baseVersion, int rangeFrom, int rangeTo) {
public VersionRange(String baseVersion, int rangeFrom, int rangeTo) {
Preconditions.checkNotNull(baseVersion);
Preconditions.checkArgument(rangeFrom >= 0);
Preconditions.checkArgument(rangeTo > rangeFrom);
@ -72,4 +72,18 @@ public class SubVersionRange {
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;
}
}

View File

@ -1,65 +0,0 @@
/*
* 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
}

View File

@ -22,10 +22,8 @@
*/
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> {
@ -33,79 +31,16 @@ 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 connection user connection
* @param item item
* @param item item
* @return rewritten item
*/
@Nullable
Item handleItemToClient(UserConnection connection, @Nullable Item item);
@Nullable Item handleItemToClient(@Nullable Item item);
/**
* Returns the rewritten item, which may or may not be the same given Item instance.
*
* @param connection user connection
* @param item item
* @param item item
* @return rewritten 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;
}
@Nullable Item handleItemToServer(@Nullable Item item);
}

View File

@ -1,29 +0,0 @@
/*
* 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() {
}
}

View File

@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.rewriter;
import com.viaversion.viaversion.api.protocol.Protocol;
public interface Rewriter<T extends Protocol> extends MappingDataListener {
public interface Rewriter<T extends Protocol> {
/**
* Registers any packet handlers or rewrites needed.
@ -37,4 +37,7 @@ public interface Rewriter<T extends Protocol> extends MappingDataListener {
* @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