diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java index 15037e5b4..3f2433a7f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java @@ -38,11 +38,13 @@ 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; @@ -52,20 +54,27 @@ import com.viaversion.viaversion.util.Unit; public final class StructuredDataKey { public static final StructuredDataKey CUSTOM_DATA = new StructuredDataKey<>("custom_data", Type.COMPOUND_TAG); + public static final StructuredDataKey MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Type.VAR_INT); + public static final StructuredDataKey MAX_DAMAGE = new StructuredDataKey<>("max_damage", Type.VAR_INT); public static final StructuredDataKey DAMAGE = new StructuredDataKey<>("damage", Type.VAR_INT); public static final StructuredDataKey UNBREAKABLE = new StructuredDataKey<>("unbreakable", Unbreakable.TYPE); public static final StructuredDataKey CUSTOM_NAME = new StructuredDataKey<>("custom_name", Type.TAG); public static final StructuredDataKey LORE = new StructuredDataKey<>("lore", Type.TAG_ARRAY); + public static final StructuredDataKey RARITY = new StructuredDataKey<>("rarity", Type.VAR_INT); public static final StructuredDataKey ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE); public static final StructuredDataKey CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE); public static final StructuredDataKey CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE); public static final StructuredDataKey ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers.TYPE); public static final StructuredDataKey CUSTOM_MODEL_DATA = new StructuredDataKey<>("custom_model_data", Type.VAR_INT); public static final StructuredDataKey HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Type.EMPTY); + public static final StructuredDataKey HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Type.EMPTY); public static final StructuredDataKey REPAIR_COST = new StructuredDataKey<>("repair_cost", Type.VAR_INT); public static final StructuredDataKey CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Type.EMPTY); public static final StructuredDataKey ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Type.BOOLEAN); public static final StructuredDataKey INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Type.EMPTY); + public static final StructuredDataKey FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE); + public static final StructuredDataKey FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Type.EMPTY); + public static final StructuredDataKey TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE); public static final StructuredDataKey STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE); public static final StructuredDataKey DYED_COLOR = new StructuredDataKey<>("dyed_color", DyedColor.TYPE); public static final StructuredDataKey MAP_COLOR = new StructuredDataKey<>("map_color", Type.INT); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java new file mode 100644 index 000000000..f26eeedb5 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java @@ -0,0 +1,62 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.item.data; + +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.ArrayType; +import io.netty.buffer.ByteBuf; + +public final class FoodEffect { + + public static final Type TYPE = new Type(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 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; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java new file mode 100644 index 000000000..4784cc005 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java @@ -0,0 +1,84 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.item.data; + +import com.viaversion.viaversion.api.type.Type; +import io.netty.buffer.ByteBuf; + +public final class FoodProperties { + + public static final Type TYPE = new Type(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; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java new file mode 100644 index 000000000..db692a5fc --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java @@ -0,0 +1,68 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.item.data; + +import com.viaversion.viaversion.api.type.Type; +import io.netty.buffer.ByteBuf; + +public final class ToolProperties { + + public static final Type TYPE = new Type(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; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java new file mode 100644 index 000000000..5bd271bc8 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java @@ -0,0 +1,72 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.item.data; + +import com.viaversion.viaversion.api.minecraft.HolderSet; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.ArrayType; +import io.netty.buffer.ByteBuf; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class ToolRule { + + public static final Type TYPE = new Type(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 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; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java index 615d77cdd..5f38ffe73 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java @@ -83,7 +83,7 @@ public class ProtocolVersion implements Comparable { public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1)); public static final ProtocolVersion v1_20_2 = register(764, "1.20.2"); public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4)); - public static final ProtocolVersion v1_20_5 = register(766, 180, "1.20.5"); + public static final ProtocolVersion v1_20_5 = register(766, 181, "1.20.5"); public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null); public static ProtocolVersion register(int version, String name) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index f1831e197..7cb49cb00 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -128,6 +128,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type LONG_ARRAY_PRIMITIVE = new LongArrayType(); public static final BooleanType BOOLEAN = new BooleanType(); + public static final BooleanType.OptionalBooleanType OPTIONAL_BOOLEAN = new BooleanType.OptionalBooleanType(); /* Other Types */ public static final Type COMPONENT = new ComponentType(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java index af518124b..61434d492 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java @@ -22,6 +22,7 @@ */ package com.viaversion.viaversion.api.type.types; +import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.TypeConverter; import io.netty.buffer.ByteBuf; @@ -49,4 +50,12 @@ public class BooleanType extends Type implements TypeConverter } return (Boolean) o; } + + // Lol + public static final class OptionalBooleanType extends OptionalType { + + public OptionalBooleanType() { + super(Type.BOOLEAN); + } + } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java index 90f6e7837..e8b1f5474 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java @@ -116,7 +116,9 @@ public final class Protocol1_20_5To1_20_3 extends AbstractProtocol