Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 16:40:10 +01:00
The endless pit continues to be endless
Dieser Commit ist enthalten in:
Ursprung
f68aed464d
Commit
39180e22b8
@ -20,44 +20,13 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.minecraft.item.data;
|
package com.viaversion.viaversion.api.minecraft;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class GameProfile {
|
public final class GameProfile {
|
||||||
|
|
||||||
public static final Type<GameProfile> TYPE = new Type<GameProfile>(GameProfile.class) {
|
|
||||||
@Override
|
|
||||||
public GameProfile read(final ByteBuf buffer) throws Exception {
|
|
||||||
final String name = Type.STRING.read(buffer);
|
|
||||||
final UUID id = Type.OPTIONAL_UUID.read(buffer);
|
|
||||||
final int propertyCount = Type.VAR_INT.readPrimitive(buffer);
|
|
||||||
final Property[] properties = new Property[propertyCount];
|
|
||||||
for (int i = 0; i < propertyCount; i++) {
|
|
||||||
final String propertyName = Type.STRING.read(buffer);
|
|
||||||
final String propertyValue = Type.STRING.read(buffer);
|
|
||||||
final String propertySignature = Type.OPTIONAL_STRING.read(buffer);
|
|
||||||
properties[i] = new Property(propertyName, propertyValue, propertySignature);
|
|
||||||
}
|
|
||||||
return new GameProfile(name, id, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(final ByteBuf buffer, final GameProfile value) throws Exception {
|
|
||||||
Type.STRING.write(buffer, value.name);
|
|
||||||
Type.OPTIONAL_UUID.write(buffer, value.id);
|
|
||||||
Type.VAR_INT.writePrimitive(buffer, value.properties.length);
|
|
||||||
for (final Property property : value.properties) {
|
|
||||||
Type.STRING.write(buffer, property.name);
|
|
||||||
Type.STRING.write(buffer, property.value);
|
|
||||||
Type.OPTIONAL_STRING.write(buffer, property.signature);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final UUID id;
|
private final UUID id;
|
||||||
private final Property[] properties;
|
private final Property[] properties;
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.util.Either;
|
||||||
|
|
||||||
|
public final class HolderSet {
|
||||||
|
|
||||||
|
private final Either<String, int[]> values;
|
||||||
|
|
||||||
|
public HolderSet(final String tagKey) {
|
||||||
|
this.values = Either.left(tagKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HolderSet(final int[] ids) {
|
||||||
|
this.values = Either.right(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Either<String, int[]> values() {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
}
|
@ -24,14 +24,20 @@ package com.viaversion.viaversion.api.minecraft.data;
|
|||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.BannerPattern;
|
import com.viaversion.viaversion.api.minecraft.item.data.BannerPattern;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
|
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.BlockStateProperties;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
|
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.Enchantments;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.GameProfile;
|
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.LodestoneTarget;
|
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTarget;
|
||||||
|
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.WrittenBook;
|
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||||
@ -45,15 +51,15 @@ public final class StructuredDataKey<T> {
|
|||||||
public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Type.TAG);
|
public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Type.TAG);
|
||||||
public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", Type.TAG_ARRAY);
|
public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", Type.TAG_ARRAY);
|
||||||
public static final StructuredDataKey<Enchantments> ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE);
|
public static final StructuredDataKey<Enchantments> ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE);
|
||||||
public static final StructuredDataKey<?> CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", Type.UNIT); // TODO
|
public static final StructuredDataKey<AdventureModePredicate> CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE);
|
||||||
public static final StructuredDataKey<?> CAN_BREAK = new StructuredDataKey<>("can_break", Type.UNIT); // TODO
|
public static final StructuredDataKey<AdventureModePredicate> CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE);
|
||||||
public static final StructuredDataKey<?> ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", Type.UNIT); // TODO
|
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<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.UNIT);
|
public static final StructuredDataKey<Unit> HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Type.EMPTY);
|
||||||
public static final StructuredDataKey<Integer> REPAIR_COST = new StructuredDataKey<>("repair_cost", Type.VAR_INT);
|
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.UNIT);
|
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<Boolean> ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Type.BOOLEAN);
|
||||||
public static final StructuredDataKey<Unit> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Type.UNIT);
|
public static final StructuredDataKey<Unit> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Type.EMPTY);
|
||||||
public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("storded_enchantments", Enchantments.TYPE);
|
public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("storded_enchantments", Enchantments.TYPE);
|
||||||
public static final StructuredDataKey<DyedColor> DYED_COLOR = new StructuredDataKey<>("dyed_color", DyedColor.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_COLOR = new StructuredDataKey<>("map_color", Type.INT);
|
||||||
@ -62,21 +68,21 @@ public final class StructuredDataKey<T> {
|
|||||||
public static final StructuredDataKey<Integer> MAP_POST_PROCESSING = new StructuredDataKey<>("map_post_processing", Type.VAR_INT);
|
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[]> 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<Item[]> BUNDLE_CONTENTS = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY);
|
||||||
public static final StructuredDataKey<?> POTION_CONTENTS = new StructuredDataKey<>("potion_contents", Type.UNIT); // TODO
|
public static final StructuredDataKey<PotionContents> POTION_CONTENTS = new StructuredDataKey<>("potion_contents", PotionContents.TYPE);
|
||||||
public static final StructuredDataKey<?> SUSPICIOUS_STEW_EFFECTS = new StructuredDataKey<>("suspicious_stew_effects", Type.UNIT); // TODO
|
public static final StructuredDataKey<SuspiciousStewEffect[]> SUSPICIOUS_STEW_EFFECTS = new StructuredDataKey<>("suspicious_stew_effects", SuspiciousStewEffect.ARRAY_TYPE);
|
||||||
public static final StructuredDataKey<String[]> WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", Type.STRING_ARRAY);
|
public static final StructuredDataKey<String[]> WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", Type.STRING_ARRAY);
|
||||||
public static final StructuredDataKey<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE);
|
public static final StructuredDataKey<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE);
|
||||||
public static final StructuredDataKey<?> TRIM = new StructuredDataKey<>("trim", Type.UNIT); // TODO
|
public static final StructuredDataKey<?> TRIM = new StructuredDataKey<>("trim", Type.EMPTY); // TODO
|
||||||
public static final StructuredDataKey<CompoundTag> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Type.COMPOUND_TAG);
|
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> 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> 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<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Type.COMPOUND_TAG);
|
||||||
public static final StructuredDataKey<?> INSTRUMENT = new StructuredDataKey<>("instrument", Type.UNIT); // TODO
|
public static final StructuredDataKey<?> INSTRUMENT = new StructuredDataKey<>("instrument", Type.EMPTY); // TODO
|
||||||
public static final StructuredDataKey<String[]> RECIPES = new StructuredDataKey<>("recipes", Type.STRING_ARRAY);
|
public static final StructuredDataKey<String[]> RECIPES = new StructuredDataKey<>("recipes", Type.STRING_ARRAY);
|
||||||
public static final StructuredDataKey<LodestoneTarget> LODESTONE_TARGET = new StructuredDataKey<>("lodestone_target", LodestoneTarget.TYPE);
|
public static final StructuredDataKey<LodestoneTarget> LODESTONE_TARGET = new StructuredDataKey<>("lodestone_target", LodestoneTarget.TYPE);
|
||||||
public static final StructuredDataKey<?> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", Type.UNIT); // TODO
|
public static final StructuredDataKey<FireworkExplosion> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE);
|
||||||
public static final StructuredDataKey<?> FIREWORKS = new StructuredDataKey<>("fireworks", Type.UNIT); // TODO
|
public static final StructuredDataKey<Fireworks> FIREWORKS = new StructuredDataKey<>("fireworks", Fireworks.TYPE);
|
||||||
public static final StructuredDataKey<GameProfile> PROFILE = new StructuredDataKey<>("profile", GameProfile.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<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Type.STRING);
|
||||||
public static final StructuredDataKey<BannerPattern[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPattern.ARRAY_TYPE);
|
public static final StructuredDataKey<BannerPattern[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPattern.ARRAY_TYPE);
|
||||||
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Type.VAR_INT);
|
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Type.VAR_INT);
|
||||||
@ -90,7 +96,7 @@ public final class StructuredDataKey<T> {
|
|||||||
private final String identifier;
|
private final String identifier;
|
||||||
private final Type<T> type;
|
private final Type<T> type;
|
||||||
|
|
||||||
public StructuredDataKey(final String identifier, Type<T> type) {
|
public StructuredDataKey(final String identifier, final Type<T> type) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
// This goes DEEEP
|
||||||
|
public final class AdventureModePredicate {
|
||||||
|
|
||||||
|
public static final Type<AdventureModePredicate> TYPE = new Type<AdventureModePredicate>(AdventureModePredicate.class) {
|
||||||
|
@Override
|
||||||
|
public AdventureModePredicate read(final ByteBuf buffer) throws Exception {
|
||||||
|
final BlockPredicate[] predicates = BlockPredicate.ARRAY_TYPE.read(buffer);
|
||||||
|
final boolean showInTooltip = buffer.readBoolean();
|
||||||
|
return new AdventureModePredicate(predicates, showInTooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final AdventureModePredicate value) throws Exception {
|
||||||
|
BlockPredicate.ARRAY_TYPE.write(buffer, value.predicates);
|
||||||
|
buffer.writeBoolean(value.showInTooltip);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final BlockPredicate[] predicates;
|
||||||
|
private final boolean showInTooltip;
|
||||||
|
|
||||||
|
public AdventureModePredicate(final BlockPredicate[] predicates, final boolean showInTooltip) {
|
||||||
|
this.predicates = predicates;
|
||||||
|
this.showInTooltip = showInTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPredicate[] predicates() {
|
||||||
|
return predicates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showInTooltip() {
|
||||||
|
return showInTooltip;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class AttributeModifier {
|
||||||
|
|
||||||
|
public static final Type<AttributeModifier> TYPE = new Type<AttributeModifier>(AttributeModifier.class) {
|
||||||
|
@Override
|
||||||
|
public AttributeModifier read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int attribute = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final ModifierData modifier = ModifierData.TYPE.read(buffer);
|
||||||
|
final int slot = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
return new AttributeModifier(attribute, modifier, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final AttributeModifier value) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.attribute);
|
||||||
|
ModifierData.TYPE.write(buffer, value.modifier);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.slot);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<AttributeModifier[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final int attribute;
|
||||||
|
private final ModifierData modifier;
|
||||||
|
private final int slot;
|
||||||
|
|
||||||
|
public AttributeModifier(final int attribute, final ModifierData modifier, final int slot) {
|
||||||
|
this.attribute = attribute;
|
||||||
|
this.modifier = modifier;
|
||||||
|
this.slot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int attribute() {
|
||||||
|
return attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModifierData modifier() {
|
||||||
|
return modifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int slot() {
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class AttributeModifiers {
|
||||||
|
|
||||||
|
public static final Type<AttributeModifiers> TYPE = new Type<AttributeModifiers>(AttributeModifiers.class) {
|
||||||
|
@Override
|
||||||
|
public AttributeModifiers read(final ByteBuf buffer) throws Exception {
|
||||||
|
final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer);
|
||||||
|
final boolean showInTooltip = buffer.readBoolean();
|
||||||
|
return new AttributeModifiers(modifiers, showInTooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final AttributeModifiers value) throws Exception {
|
||||||
|
AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers());
|
||||||
|
buffer.writeBoolean(value.showInTooltip());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final AttributeModifier[] modifiers;
|
||||||
|
private final boolean showInTooltip;
|
||||||
|
|
||||||
|
public AttributeModifiers(final AttributeModifier[] modifiers, final boolean showInTooltip) {
|
||||||
|
this.modifiers = modifiers;
|
||||||
|
this.showInTooltip = showInTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttributeModifier[] modifiers() {
|
||||||
|
return modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showInTooltip() {
|
||||||
|
return showInTooltip;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public final class BlockPredicate {
|
||||||
|
|
||||||
|
public static final Type<BlockPredicate> TYPE = new Type<BlockPredicate>(BlockPredicate.class) {
|
||||||
|
@Override
|
||||||
|
public BlockPredicate read(final ByteBuf buffer) throws Exception {
|
||||||
|
final HolderSet holders = Type.OPTIONAL_HOLDER_SET.read(buffer);
|
||||||
|
final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null;
|
||||||
|
final CompoundTag tag = Type.OPTIONAL_COMPOUND_TAG.read(buffer);
|
||||||
|
return new BlockPredicate(holders, propertyMatchers, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final BlockPredicate value) throws Exception {
|
||||||
|
Type.OPTIONAL_HOLDER_SET.write(buffer, value.holders);
|
||||||
|
|
||||||
|
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 holders;
|
||||||
|
private final StatePropertyMatcher[] propertyMatchers;
|
||||||
|
private final CompoundTag tag;
|
||||||
|
|
||||||
|
public BlockPredicate(@Nullable final HolderSet holders, final StatePropertyMatcher @Nullable [] propertyMatchers, @Nullable final CompoundTag tag) {
|
||||||
|
this.holders = holders;
|
||||||
|
this.propertyMatchers = propertyMatchers;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable HolderSet predicates() {
|
||||||
|
return holders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatePropertyMatcher @Nullable [] propertyMatchers() {
|
||||||
|
return propertyMatchers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable CompoundTag tag() {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class FireworkExplosion {
|
||||||
|
public static final Type<FireworkExplosion> TYPE = new Type<FireworkExplosion>(FireworkExplosion.class) {
|
||||||
|
@Override
|
||||||
|
public FireworkExplosion read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int shape = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final int[] colors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
|
||||||
|
final int[] fadeColors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
|
||||||
|
final boolean hasTrail = buffer.readBoolean();
|
||||||
|
final boolean hasTwinkle = buffer.readBoolean();
|
||||||
|
return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final FireworkExplosion value) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.shape);
|
||||||
|
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.colors);
|
||||||
|
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors);
|
||||||
|
buffer.writeBoolean(value.hasTrail);
|
||||||
|
buffer.writeBoolean(value.hasTwinkle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<FireworkExplosion[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final int shape;
|
||||||
|
private final int[] colors;
|
||||||
|
private final int[] fadeColors;
|
||||||
|
private final boolean hasTrail;
|
||||||
|
private final boolean hasTwinkle;
|
||||||
|
|
||||||
|
public FireworkExplosion(final int shape, final int[] colors, final int[] fadeColors, final boolean hasTrail, final boolean hasTwinkle) {
|
||||||
|
this.shape = shape;
|
||||||
|
this.colors = colors;
|
||||||
|
this.fadeColors = fadeColors;
|
||||||
|
this.hasTrail = hasTrail;
|
||||||
|
this.hasTwinkle = hasTwinkle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int shape() {
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] colors() {
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] fadeColors() {
|
||||||
|
return fadeColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTrail() {
|
||||||
|
return hasTrail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTwinkle() {
|
||||||
|
return hasTwinkle;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class Fireworks {
|
||||||
|
|
||||||
|
public static final Type<Fireworks> TYPE = new Type<Fireworks>(Fireworks.class) {
|
||||||
|
@Override
|
||||||
|
public Fireworks read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int flightDuration = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer);
|
||||||
|
return new Fireworks(flightDuration, explosions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final Fireworks value) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.flightDuration);
|
||||||
|
FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final FireworkExplosion[] explosions;
|
||||||
|
private final int flightDuration;
|
||||||
|
|
||||||
|
public Fireworks(final int flightDuration, final FireworkExplosion[] explosions) {
|
||||||
|
this.flightDuration = flightDuration;
|
||||||
|
this.explosions = explosions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int flightDuration() {
|
||||||
|
return flightDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FireworkExplosion[] explosions() {
|
||||||
|
return explosions;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class ModifierData {
|
||||||
|
|
||||||
|
public static final Type<ModifierData> TYPE = new Type<ModifierData>(ModifierData.class) {
|
||||||
|
@Override
|
||||||
|
public ModifierData read(final ByteBuf buffer) throws Exception {
|
||||||
|
final UUID uuid = Type.UUID.read(buffer);
|
||||||
|
final String name = Type.STRING.read(buffer);
|
||||||
|
final double amount = buffer.readDouble();
|
||||||
|
final int operation = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
return new ModifierData(uuid, name, amount, operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final ModifierData value) throws Exception {
|
||||||
|
Type.UUID.write(buffer, value.uuid);
|
||||||
|
Type.STRING.write(buffer, value.name);
|
||||||
|
buffer.writeDouble(value.amount);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.operation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final UUID uuid;
|
||||||
|
private final String name;
|
||||||
|
private final double amount;
|
||||||
|
private final int operation;
|
||||||
|
|
||||||
|
public ModifierData(final UUID uuid, final String name, final double amount, final int operation) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.amount = amount;
|
||||||
|
this.operation = operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID uuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double amount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int operation() {
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public final class PotionContents {
|
||||||
|
|
||||||
|
public static final Type<PotionContents> TYPE = new Type<PotionContents>(PotionContents.class) {
|
||||||
|
@Override
|
||||||
|
public PotionContents read(final ByteBuf buffer) throws Exception {
|
||||||
|
final Integer potion = buffer.readBoolean() ? Type.VAR_INT.readPrimitive(buffer) : null;
|
||||||
|
final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null;
|
||||||
|
final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer);
|
||||||
|
return new PotionContents(potion, customColor, customEffects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final PotionContents value) throws Exception {
|
||||||
|
buffer.writeBoolean(value.potion != null);
|
||||||
|
if (value.potion != null) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.potion);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeBoolean(value.customColor != null);
|
||||||
|
if (value.customColor != null) {
|
||||||
|
buffer.writeInt(value.customColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
PotionEffect.ARRAY_TYPE.write(buffer, value.customEffects);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final Integer potion;
|
||||||
|
private final Integer customColor;
|
||||||
|
private final PotionEffect[] customEffects;
|
||||||
|
|
||||||
|
public PotionContents(@Nullable final Integer potion, @Nullable final Integer customColor, final PotionEffect[] customEffects) {
|
||||||
|
this.potion = potion;
|
||||||
|
this.customColor = customColor;
|
||||||
|
this.customEffects = customEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Integer potion() {
|
||||||
|
return potion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Integer customColor() {
|
||||||
|
return customColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PotionEffect[] customEffects() {
|
||||||
|
return customEffects;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class PotionEffect {
|
||||||
|
|
||||||
|
public static final Type<PotionEffect> TYPE = new Type<PotionEffect>(PotionEffect.class) {
|
||||||
|
@Override
|
||||||
|
public PotionEffect read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int effect = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer);
|
||||||
|
return new PotionEffect(effect, effectData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final PotionEffect value) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.effect);
|
||||||
|
PotionEffectData.TYPE.write(buffer, value.effectData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<PotionEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final int effect;
|
||||||
|
private final PotionEffectData effectData;
|
||||||
|
|
||||||
|
public PotionEffect(final int effect, final PotionEffectData effectData) {
|
||||||
|
this.effect = effect;
|
||||||
|
this.effectData = effectData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int effect() {
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PotionEffectData effectData() {
|
||||||
|
return effectData;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
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; // RECURSIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVESIVE
|
||||||
|
|
||||||
|
public PotionEffectData(final int amplifier, final int duration, final boolean ambient, final boolean showParticles,
|
||||||
|
final boolean showIcon, @Nullable final PotionEffectData hiddenEffect) {
|
||||||
|
this.amplifier = amplifier;
|
||||||
|
this.duration = duration;
|
||||||
|
this.ambient = ambient;
|
||||||
|
this.showParticles = showParticles;
|
||||||
|
this.showIcon = showIcon;
|
||||||
|
this.hiddenEffect = hiddenEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int amplifier() {
|
||||||
|
return amplifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int duration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean ambient() {
|
||||||
|
return ambient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showParticles() {
|
||||||
|
return showParticles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showIcon() {
|
||||||
|
return showIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable PotionEffectData hiddenEffect() {
|
||||||
|
return hiddenEffect;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import com.viaversion.viaversion.util.Either;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public final class StatePropertyMatcher {
|
||||||
|
|
||||||
|
// TODO Abstract Either reading
|
||||||
|
public static final Type<StatePropertyMatcher> TYPE = new Type<StatePropertyMatcher>(StatePropertyMatcher.class) {
|
||||||
|
@Override
|
||||||
|
public StatePropertyMatcher read(final ByteBuf buffer) throws Exception {
|
||||||
|
final String name = Type.STRING.read(buffer);
|
||||||
|
if (buffer.readBoolean()) {
|
||||||
|
final String value = Type.STRING.read(buffer);
|
||||||
|
return new StatePropertyMatcher(name, Either.left(value));
|
||||||
|
} else {
|
||||||
|
final String minValue = Type.OPTIONAL_STRING.read(buffer);
|
||||||
|
final String maxValue = Type.OPTIONAL_STRING.read(buffer);
|
||||||
|
return new StatePropertyMatcher(name, Either.right(new RangedMatcher(minValue, maxValue)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final StatePropertyMatcher value) throws Exception {
|
||||||
|
Type.STRING.write(buffer, value.name);
|
||||||
|
if (value.matcher.isLeft()) {
|
||||||
|
buffer.writeBoolean(true);
|
||||||
|
Type.STRING.write(buffer, value.matcher.left());
|
||||||
|
} else {
|
||||||
|
buffer.writeBoolean(false);
|
||||||
|
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().minValue());
|
||||||
|
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().maxValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<StatePropertyMatcher[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Either<String, RangedMatcher> matcher;
|
||||||
|
|
||||||
|
public StatePropertyMatcher(final String name, final Either<String, RangedMatcher> matcher) {
|
||||||
|
this.name = name;
|
||||||
|
this.matcher = matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Either<String, RangedMatcher> matcher() {
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class RangedMatcher {
|
||||||
|
private final String minValue;
|
||||||
|
private final String maxValue;
|
||||||
|
|
||||||
|
public RangedMatcher(@Nullable final String minValue, @Nullable final String maxValue) {
|
||||||
|
this.minValue = minValue;
|
||||||
|
this.maxValue = maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String minValue() {
|
||||||
|
return minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String maxValue() {
|
||||||
|
return maxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class SuspiciousStewEffect {
|
||||||
|
|
||||||
|
public static final Type<SuspiciousStewEffect> TYPE = new Type<SuspiciousStewEffect>(SuspiciousStewEffect.class) {
|
||||||
|
@Override
|
||||||
|
public SuspiciousStewEffect read(final ByteBuf buffer) {
|
||||||
|
final int effect = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final int duration = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
return new SuspiciousStewEffect(effect, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final SuspiciousStewEffect value) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.effect);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.duration);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<SuspiciousStewEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final int effect;
|
||||||
|
private final int duration;
|
||||||
|
|
||||||
|
public SuspiciousStewEffect(final int effect, final int duration) {
|
||||||
|
this.effect = effect;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int mobEffect() {
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int duration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,9 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||||
import com.viaversion.viaversion.api.minecraft.EulerAngle;
|
import com.viaversion.viaversion.api.minecraft.EulerAngle;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||||
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
|
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
import com.viaversion.viaversion.api.minecraft.Position;
|
||||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||||
@ -47,6 +49,7 @@ import com.viaversion.viaversion.api.type.types.ByteType;
|
|||||||
import com.viaversion.viaversion.api.type.types.ComponentType;
|
import com.viaversion.viaversion.api.type.types.ComponentType;
|
||||||
import com.viaversion.viaversion.api.type.types.DoubleType;
|
import com.viaversion.viaversion.api.type.types.DoubleType;
|
||||||
import com.viaversion.viaversion.api.type.types.FloatType;
|
import com.viaversion.viaversion.api.type.types.FloatType;
|
||||||
|
import com.viaversion.viaversion.api.type.types.IntArrayType;
|
||||||
import com.viaversion.viaversion.api.type.types.IntType;
|
import com.viaversion.viaversion.api.type.types.IntType;
|
||||||
import com.viaversion.viaversion.api.type.types.LongArrayType;
|
import com.viaversion.viaversion.api.type.types.LongArrayType;
|
||||||
import com.viaversion.viaversion.api.type.types.LongType;
|
import com.viaversion.viaversion.api.type.types.LongType;
|
||||||
@ -56,7 +59,7 @@ import com.viaversion.viaversion.api.type.types.ShortByteArrayType;
|
|||||||
import com.viaversion.viaversion.api.type.types.ShortType;
|
import com.viaversion.viaversion.api.type.types.ShortType;
|
||||||
import com.viaversion.viaversion.api.type.types.StringType;
|
import com.viaversion.viaversion.api.type.types.StringType;
|
||||||
import com.viaversion.viaversion.api.type.types.UUIDType;
|
import com.viaversion.viaversion.api.type.types.UUIDType;
|
||||||
import com.viaversion.viaversion.api.type.types.UnitType;
|
import com.viaversion.viaversion.api.type.types.EmptyType;
|
||||||
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
|
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
|
||||||
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
|
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
|
||||||
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
|
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
|
||||||
@ -76,6 +79,8 @@ import com.viaversion.viaversion.api.type.types.math.GlobalPositionType;
|
|||||||
import com.viaversion.viaversion.api.type.types.item.ItemType1_20_2;
|
import com.viaversion.viaversion.api.type.types.item.ItemType1_20_2;
|
||||||
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_8;
|
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_8;
|
||||||
import com.viaversion.viaversion.api.type.types.item.ItemType1_8;
|
import com.viaversion.viaversion.api.type.types.item.ItemType1_8;
|
||||||
|
import com.viaversion.viaversion.api.type.types.misc.GameProfileType;
|
||||||
|
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
|
||||||
import com.viaversion.viaversion.api.type.types.misc.NamedCompoundTagType;
|
import com.viaversion.viaversion.api.type.types.misc.NamedCompoundTagType;
|
||||||
import com.viaversion.viaversion.api.type.types.OptionalVarIntType;
|
import com.viaversion.viaversion.api.type.types.OptionalVarIntType;
|
||||||
import com.viaversion.viaversion.api.type.types.misc.PlayerMessageSignatureType;
|
import com.viaversion.viaversion.api.type.types.misc.PlayerMessageSignatureType;
|
||||||
@ -98,7 +103,7 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||||
|
|
||||||
public static final Type<Unit> UNIT = new UnitType();
|
public static final Type<Unit> EMPTY = new EmptyType();
|
||||||
|
|
||||||
public static final ByteType BYTE = new ByteType();
|
public static final ByteType BYTE = new ByteType();
|
||||||
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
|
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
|
||||||
@ -106,6 +111,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
|||||||
public static final Type<byte[]> OPTIONAL_BYTE_ARRAY_PRIMITIVE = new ByteArrayType.OptionalByteArrayType();
|
public static final Type<byte[]> OPTIONAL_BYTE_ARRAY_PRIMITIVE = new ByteArrayType.OptionalByteArrayType();
|
||||||
public static final Type<byte[]> SHORT_BYTE_ARRAY = new ShortByteArrayType();
|
public static final Type<byte[]> SHORT_BYTE_ARRAY = new ShortByteArrayType();
|
||||||
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
|
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
|
||||||
|
public static final Type<int[]> INT_ARRAY_PRIMITIVE = new IntArrayType();
|
||||||
|
|
||||||
public static final ShortType SHORT = new ShortType();
|
public static final ShortType SHORT = new ShortType();
|
||||||
public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType();
|
public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType();
|
||||||
@ -174,6 +180,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
|||||||
|
|
||||||
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
||||||
|
|
||||||
|
public static final Type<GameProfile> GAME_PROFILE = new GameProfileType();
|
||||||
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
|
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
|
||||||
public static final Type<ProfileKey> OPTIONAL_PROFILE_KEY = new ProfileKeyType.OptionalProfileKeyType();
|
public static final Type<ProfileKey> OPTIONAL_PROFILE_KEY = new ProfileKeyType.OptionalProfileKeyType();
|
||||||
|
|
||||||
@ -188,6 +195,9 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
|||||||
public static final Type<RegistryEntry> REGISTRY_ENTRY = new RegistryEntryType();
|
public static final Type<RegistryEntry> REGISTRY_ENTRY = new RegistryEntryType();
|
||||||
public static final Type<RegistryEntry[]> REGISTRY_ENTRY_ARRAY = new ArrayType<>(REGISTRY_ENTRY);
|
public static final Type<RegistryEntry[]> REGISTRY_ENTRY_ARRAY = new ArrayType<>(REGISTRY_ENTRY);
|
||||||
|
|
||||||
|
public static final Type<HolderSet> HOLDER_SET = new HolderSetType();
|
||||||
|
public static final Type<HolderSet> OPTIONAL_HOLDER_SET = new HolderSetType.OptionalHolderSetType();
|
||||||
|
|
||||||
public static final Type<Item> ITEM1_8 = new ItemType1_8();
|
public static final Type<Item> ITEM1_8 = new ItemType1_8();
|
||||||
public static final Type<Item> ITEM1_13 = new ItemType1_13();
|
public static final Type<Item> ITEM1_13 = new ItemType1_13();
|
||||||
public static final Type<Item> ITEM1_13_2 = new ItemType1_13_2();
|
public static final Type<Item> ITEM1_13_2 = new ItemType1_13_2();
|
||||||
|
@ -26,9 +26,9 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import com.viaversion.viaversion.util.Unit;
|
import com.viaversion.viaversion.util.Unit;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
public final class UnitType extends Type<Unit> {
|
public final class EmptyType extends Type<Unit> {
|
||||||
|
|
||||||
public UnitType() {
|
public EmptyType() {
|
||||||
super(Unit.class);
|
super(Unit.class);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.type.types;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.viaversion.viaversion.api.type.OptionalType;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class IntArrayType extends Type<int[]> {
|
||||||
|
|
||||||
|
private final int length;
|
||||||
|
|
||||||
|
public IntArrayType(final int length) {
|
||||||
|
super(int[].class);
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntArrayType() {
|
||||||
|
super(int[].class);
|
||||||
|
this.length = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final int[] object) throws Exception {
|
||||||
|
if (this.length != -1) {
|
||||||
|
Preconditions.checkArgument(length == object.length, "Length does not match expected length");
|
||||||
|
} else {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, object.length);
|
||||||
|
}
|
||||||
|
for (final int i : object) {
|
||||||
|
buffer.writeInt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int length = this.length == -1 ? Type.VAR_INT.readPrimitive(buffer) : this.length;
|
||||||
|
Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes");
|
||||||
|
final int[] array = new int[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
array[i] = buffer.readInt();
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.type.types.misc;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class GameProfileType extends Type<GameProfile> {
|
||||||
|
|
||||||
|
public GameProfileType() {
|
||||||
|
super(GameProfile.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameProfile read(final ByteBuf buffer) throws Exception {
|
||||||
|
final String name = Type.STRING.read(buffer);
|
||||||
|
final java.util.UUID id = Type.OPTIONAL_UUID.read(buffer);
|
||||||
|
final int propertyCount = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final GameProfile.Property[] properties = new GameProfile.Property[propertyCount];
|
||||||
|
for (int i = 0; i < propertyCount; i++) {
|
||||||
|
final String propertyName = Type.STRING.read(buffer);
|
||||||
|
final String propertyValue = Type.STRING.read(buffer);
|
||||||
|
final String propertySignature = Type.OPTIONAL_STRING.read(buffer);
|
||||||
|
properties[i] = new GameProfile.Property(propertyName, propertyValue, propertySignature);
|
||||||
|
}
|
||||||
|
return new GameProfile(name, id, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final GameProfile value) throws Exception {
|
||||||
|
Type.STRING.write(buffer, value.name());
|
||||||
|
Type.OPTIONAL_UUID.write(buffer, value.id());
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.properties().length);
|
||||||
|
for (final GameProfile.Property property : value.properties()) {
|
||||||
|
Type.STRING.write(buffer, property.name());
|
||||||
|
Type.STRING.write(buffer, property.value());
|
||||||
|
Type.OPTIONAL_STRING.write(buffer, property.signature());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.type.types.misc;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||||
|
import com.viaversion.viaversion.api.type.OptionalType;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class HolderSetType extends Type<HolderSet> {
|
||||||
|
|
||||||
|
public HolderSetType() {
|
||||||
|
super(HolderSet.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HolderSet read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
if (size == -1) {
|
||||||
|
final String tag = Type.STRING.read(buffer);
|
||||||
|
return new HolderSet(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
final int[] values = new int[size];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
values[i] = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
}
|
||||||
|
return new HolderSet(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final HolderSet object) throws Exception {
|
||||||
|
if (object.values().isLeft()) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, -1);
|
||||||
|
Type.STRING.write(buffer, object.values().left());
|
||||||
|
} else {
|
||||||
|
final int[] values = object.values().right();
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, values.length);
|
||||||
|
for (final int value : values) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class OptionalHolderSetType extends OptionalType<HolderSet> {
|
||||||
|
|
||||||
|
public OptionalHolderSetType() {
|
||||||
|
super(Type.HOLDER_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
85
api/src/main/java/com/viaversion/viaversion/util/Either.java
Normale Datei
85
api/src/main/java/com/viaversion/viaversion/util/Either.java
Normale Datei
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.util;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import java.util.Objects;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public final class Either<X, Y> {
|
||||||
|
private final X left;
|
||||||
|
private final Y right;
|
||||||
|
|
||||||
|
private Either(final X left, final Y value) {
|
||||||
|
this.left = left;
|
||||||
|
this.right = value;
|
||||||
|
Preconditions.checkArgument(left == null || value == null, "Either.left and Either.right are both present");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <X, Y> Either<X, Y> left(final X left) {
|
||||||
|
Preconditions.checkNotNull(left);
|
||||||
|
return new Either<>(left, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <X, Y> Either<X, Y> right(final Y right) {
|
||||||
|
Preconditions.checkNotNull(right);
|
||||||
|
return new Either<>(null, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLeft() {
|
||||||
|
return left != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRight() {
|
||||||
|
return right != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable X left() {
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Y right() {
|
||||||
|
return right;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Either{" + left + ", " + right + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
final Either<?, ?> pair = (Either<?, ?>) o;
|
||||||
|
if (!Objects.equals(left, pair.left)) return false;
|
||||||
|
return Objects.equals(right, pair.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = left != null ? left.hashCode() : 0;
|
||||||
|
result = 31 * result + (right != null ? right.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -55,7 +55,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
|||||||
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
||||||
}
|
}
|
||||||
if (mappingData.getDataComponentSerializerMappings() != null) {
|
if (mappingData.getDataComponentSerializerMappings() != null) {
|
||||||
item.structuredData().setIdLookup(protocol, false);
|
item.structuredData().setIdLookup(protocol, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
@ -73,7 +73,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
|||||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||||
}
|
}
|
||||||
if (mappingData.getDataComponentSerializerMappings() != null) {
|
if (mappingData.getDataComponentSerializerMappings() != null) {
|
||||||
item.structuredData().setIdLookup(protocol, true);
|
item.structuredData().setIdLookup(protocol, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren