diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/FullMappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappings.java index e9081ef20..be319a37a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/FullMappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappings.java @@ -53,6 +53,14 @@ public interface FullMappings extends BiMappings { */ @Nullable String identifier(int id); + /** + * Returns the unmapped string identifier for the given mapped identifier. + * + * @param mappedIdentifier mapped identifier + * @return unmapped string identifier, or null if not found + */ + @Nullable String identifier(String mappedIdentifier); + /** * Returns the mapped string identifier for the given mapped id. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingsBase.java b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingsBase.java index 9c4e7fccb..2ddb6c44c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingsBase.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingsBase.java @@ -83,6 +83,17 @@ public class FullMappingsBase implements FullMappings { return Key.namespaced(identifier); } + @Override + public @Nullable String identifier(final String mappedIdentifier) { + final int mappedId = mappedId(mappedIdentifier); + if (mappedId == -1) { + return null; + } + + final int id = mappings.inverse().getNewId(mappedId); + return id != -1 ? identifier(id) : null; + } + @Override public String mappedIdentifier(final int mappedId) { if (mappedId < 0 || mappedId >= mappedIdToString.length) { 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 e6835b092..f2829dda1 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 @@ -35,12 +35,14 @@ import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_21; import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer; import com.viaversion.viaversion.api.minecraft.item.data.Bee; import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties; +import com.viaversion.viaversion.api.minecraft.item.data.Consumable1_21_2; import com.viaversion.viaversion.api.minecraft.item.data.DyedColor; import com.viaversion.viaversion.api.minecraft.item.data.Enchantments; import com.viaversion.viaversion.api.minecraft.item.data.FilterableString; import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion; import com.viaversion.viaversion.api.minecraft.item.data.Fireworks; -import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties; +import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_20_5; +import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_21_2; import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_20_5; import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_21_2; import com.viaversion.viaversion.api.minecraft.item.data.JukeboxPlayable; @@ -50,6 +52,7 @@ 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.UseCooldown; import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; @@ -81,8 +84,12 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Types.EMPTY); public static final StructuredDataKey ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Types.BOOLEAN); public static final StructuredDataKey INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Types.TAG); // Doesn't actually hold data - public static final StructuredDataKey FOOD1_20_5 = new StructuredDataKey<>("food", FoodProperties.TYPE1_20_5); - public static final StructuredDataKey FOOD1_21 = new StructuredDataKey<>("food", FoodProperties.TYPE1_21); + public static final StructuredDataKey FOOD1_20_5 = new StructuredDataKey<>("food", FoodProperties1_20_5.TYPE1_20_5); + public static final StructuredDataKey FOOD1_21 = new StructuredDataKey<>("food", FoodProperties1_20_5.TYPE1_21); + public static final StructuredDataKey FOOD1_21_2 = new StructuredDataKey<>("food", FoodProperties1_21_2.TYPE); + public static final StructuredDataKey CONSUMABLE1_21_2 = new StructuredDataKey<>("consumable", Consumable1_21_2.TYPE); + public static final StructuredDataKey USE_REMAINDER = new StructuredDataKey<>("use_remainder", Types1_21_2.ITEM); + public static final StructuredDataKey USE_COOLDOWN = new StructuredDataKey<>("use_cooldown", UseCooldown.TYPE); public static final StructuredDataKey FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Types.EMPTY); public static final StructuredDataKey TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE); public static final StructuredDataKey ENCHANTABLE = new StructuredDataKey<>("enchantable", Types.VAR_INT); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Consumable1_21_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Consumable1_21_2.java new file mode 100644 index 000000000..caf9106e0 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Consumable1_21_2.java @@ -0,0 +1,112 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.item.data; + +import com.viaversion.viaversion.api.minecraft.Holder; +import com.viaversion.viaversion.api.minecraft.SoundEvent; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.ArrayType; +import io.netty.buffer.ByteBuf; + +public record Consumable1_21_2(float consumeSeconds, int animationType, Holder sound, + boolean hasConsumeParticles, ConsumeEffect[] consumeEffects) { + + public static final Type[] EFFECT_TYPES = { + ApplyStatusEffects.TYPE, + Types.HOLDER_SET, // remove effects + Types.EMPTY, // clear all effects + Types.FLOAT, // teleport randomly + Types.SOUND_EVENT // play sound + }; + + public static final Type TYPE = new Type<>(Consumable1_21_2.class) { + @Override + public Consumable1_21_2 read(final ByteBuf buffer) { + final float consumeSeconds = buffer.readFloat(); + final int animationType = Types.VAR_INT.readPrimitive(buffer); + final Holder sound = Types.SOUND_EVENT.read(buffer); + final boolean hasConsumeParticles = buffer.readBoolean(); + final ConsumeEffect[] consumeEffects = ConsumeEffect.ARRAY_TYPE.read(buffer); + return new Consumable1_21_2(consumeSeconds, animationType, sound, hasConsumeParticles, consumeEffects); + } + + @Override + public void write(final ByteBuf buffer, final Consumable1_21_2 value) { + buffer.writeFloat(value.consumeSeconds); + Types.VAR_INT.writePrimitive(buffer, value.animationType); + Types.SOUND_EVENT.write(buffer, value.sound); + buffer.writeBoolean(value.hasConsumeParticles); + ConsumeEffect.ARRAY_TYPE.write(buffer, value.consumeEffects); + } + }; + + public record ConsumeEffect(int id, Type type, T value) { + + public static final Type> TYPE = new Type<>(ConsumeEffect.class) { + @Override + public ConsumeEffect read(final ByteBuf buffer) { + // Oh no... + final int effectType = Types.VAR_INT.readPrimitive(buffer); + final Type type = EFFECT_TYPES[effectType]; + final Object value = type.read(buffer); + return ConsumeEffect.of(effectType, type, value); + } + + @Override + public void write(final ByteBuf buffer, final ConsumeEffect value) { + Types.VAR_INT.writePrimitive(buffer, value.id); + value.write(buffer); + } + }; + public static final Type[]> ARRAY_TYPE = new ArrayType<>(TYPE); + + static ConsumeEffect of(final int id, final Type type, final Object value) { + //noinspection unchecked + return new ConsumeEffect<>(id, type, (T) value); + } + + void write(final ByteBuf buf) { + Types.VAR_INT.writePrimitive(buf, id); + type.write(buf, value); + } + } + + public record ApplyStatusEffects(PotionEffect[] effects, float probability) { + + public static final Type TYPE = new Type<>(ApplyStatusEffects.class) { + @Override + public ApplyStatusEffects read(final ByteBuf buffer) { + final PotionEffect[] effects = PotionEffect.ARRAY_TYPE.read(buffer); + final float probability = buffer.readFloat(); + return new ApplyStatusEffects(effects, probability); + } + + @Override + public void write(final ByteBuf buffer, final ApplyStatusEffects value) { + PotionEffect.ARRAY_TYPE.write(buffer, value.effects); + buffer.writeFloat(value.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/FoodProperties1_20_5.java similarity index 65% rename from api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java rename to api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties1_20_5.java index c344d3c34..483f949ca 100644 --- 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/FoodProperties1_20_5.java @@ -25,25 +25,26 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.ArrayType; import com.viaversion.viaversion.api.type.types.version.Types1_21; import io.netty.buffer.ByteBuf; -public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds, - Item usingConvertsTo, FoodEffect[] possibleEffects) { +public record FoodProperties1_20_5(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds, + Item usingConvertsTo, FoodEffect[] possibleEffects) { - public static final Type TYPE1_20_5 = new Type<>(FoodProperties.class) { + public static final Type TYPE1_20_5 = new Type<>(FoodProperties1_20_5.class) { @Override - public FoodProperties read(final ByteBuf buffer) { + public FoodProperties1_20_5 read(final ByteBuf buffer) { final int nutrition = Types.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, null, possibleEffects); + return new FoodProperties1_20_5(nutrition, saturationModifier, canAlwaysEat, eatSeconds, null, possibleEffects); } @Override - public void write(final ByteBuf buffer, final FoodProperties value) { + public void write(final ByteBuf buffer, final FoodProperties1_20_5 value) { Types.VAR_INT.writePrimitive(buffer, value.nutrition); buffer.writeFloat(value.saturationModifier); buffer.writeBoolean(value.canAlwaysEat); @@ -51,20 +52,20 @@ public record FoodProperties(int nutrition, float saturationModifier, boolean ca FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects); } }; - public static final Type TYPE1_21 = new Type(FoodProperties.class) { + public static final Type TYPE1_21 = new Type<>(FoodProperties1_20_5.class) { @Override - public FoodProperties read(final ByteBuf buffer) { + public FoodProperties1_20_5 read(final ByteBuf buffer) { final int nutrition = Types.VAR_INT.readPrimitive(buffer); final float saturationModifier = buffer.readFloat(); final boolean canAlwaysEat = buffer.readBoolean(); final float eatSeconds = buffer.readFloat(); final Item usingConvertsTo = Types1_21.OPTIONAL_ITEM.read(buffer); final FoodEffect[] possibleEffects = FoodEffect.ARRAY_TYPE.read(buffer); - return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, usingConvertsTo, possibleEffects); + return new FoodProperties1_20_5(nutrition, saturationModifier, canAlwaysEat, eatSeconds, usingConvertsTo, possibleEffects); } @Override - public void write(final ByteBuf buffer, final FoodProperties value) { + public void write(final ByteBuf buffer, final FoodProperties1_20_5 value) { Types.VAR_INT.writePrimitive(buffer, value.nutrition); buffer.writeFloat(value.saturationModifier); buffer.writeBoolean(value.canAlwaysEat); @@ -73,4 +74,23 @@ public record FoodProperties(int nutrition, float saturationModifier, boolean ca FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects); } }; + + public record FoodEffect(PotionEffect effect, float probability) { + + public static final Type TYPE = new Type<>(FoodEffect.class) { + @Override + public FoodEffect read(final ByteBuf buffer) { + 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) { + PotionEffect.TYPE.write(buffer, value.effect); + buffer.writeFloat(value.probability); + } + }; + public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); + } } 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/FoodProperties1_21_2.java similarity index 62% rename from api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java rename to api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties1_21_2.java index 3051ce390..d6182e113 100644 --- 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/FoodProperties1_21_2.java @@ -23,25 +23,25 @@ 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.api.type.Types; import io.netty.buffer.ByteBuf; -public record FoodEffect(PotionEffect effect, float probability) { +public record FoodProperties1_21_2(int nutrition, float saturationModifier, boolean canAlwaysEat) { - public static final Type TYPE = new Type<>(FoodEffect.class) { + public static final Type TYPE = new Type<>(FoodProperties1_21_2.class) { @Override - public FoodEffect read(final ByteBuf buffer) { - final PotionEffect effect = PotionEffect.TYPE.read(buffer); - final float probability = buffer.readFloat(); - return new FoodEffect(effect, probability); + public FoodProperties1_21_2 read(final ByteBuf buffer) { + final int nutrition = Types.VAR_INT.readPrimitive(buffer); + final float saturationModifier = buffer.readFloat(); + final boolean canAlwaysEat = buffer.readBoolean(); + return new FoodProperties1_21_2(nutrition, saturationModifier, canAlwaysEat); } @Override - public void write(final ByteBuf buffer, final FoodEffect value) { - PotionEffect.TYPE.write(buffer, value.effect); - buffer.writeFloat(value.probability); + public void write(final ByteBuf buffer, final FoodProperties1_21_2 value) { + Types.VAR_INT.writePrimitive(buffer, value.nutrition); + buffer.writeFloat(value.saturationModifier); + buffer.writeBoolean(value.canAlwaysEat); } }; - public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/UseCooldown.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/UseCooldown.java new file mode 100644 index 000000000..db8cff8f9 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/UseCooldown.java @@ -0,0 +1,56 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.item.data; + +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.Types; +import io.netty.buffer.ByteBuf; +import java.util.function.Function; +import org.checkerframework.checker.nullness.qual.Nullable; + +public record UseCooldown(float seconds, @Nullable String cooldownGroup) { + + public static final Type TYPE = new Type<>(UseCooldown.class) { + @Override + public UseCooldown read(final ByteBuf buffer) { + final float seconds = buffer.readFloat(); + final String cooldownGroup = Types.OPTIONAL_STRING.read(buffer); + return new UseCooldown(seconds, cooldownGroup); + } + + @Override + public void write(final ByteBuf buffer, final UseCooldown value) { + buffer.writeFloat(value.seconds()); + Types.OPTIONAL_STRING.write(buffer, value.cooldownGroup()); + } + }; + + public UseCooldown rewrite(final Function idRewriter) { + if (cooldownGroup == null) { + return this; + } + + final String mappedCooldownGroup = idRewriter.apply(cooldownGroup); + return new UseCooldown(seconds, mappedCooldownGroup); + } +} 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 25073d75b..602804cf8 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 @@ -86,7 +86,7 @@ public class ProtocolVersion implements Comparable { public static final ProtocolVersion v1_20_3 = register(765, "1.20.3-1.20.4", new SubVersionRange("1.20", 3, 4)); public static final ProtocolVersion v1_20_5 = register(766, "1.20.5-1.20.6", new SubVersionRange("1.20", 5, 6)); public static final ProtocolVersion v1_21 = register(767, "1.21-1.21.1", new SubVersionRange("1.21", 0, 1)); - public static final ProtocolVersion v1_21_2 = register(768, 205, "1.21.2"); + public static final ProtocolVersion v1_21_2 = register(768, 206, "1.21.2"); public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null); public static ProtocolVersion register(int version, String name) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java index 1a340a153..cb74338a4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java @@ -58,7 +58,7 @@ final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter extends Co return convertUnit(); } - protected CompoundTag convertFood(final FoodProperties value) { + protected CompoundTag convertFood(final FoodProperties1_20_5 value) { final CompoundTag tag = new CompoundTag(); tag.put("nutrition", convertNonNegativeInt(value.nutrition())); tag.putFloat("saturation", value.saturationModifier()); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java index 13d008cb8..8233cae93 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java @@ -44,7 +44,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.Enchantments; import com.viaversion.viaversion.api.minecraft.item.data.FilterableComponent; 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.FoodEffect; +import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_20_5.FoodEffect; import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_20_5; import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect; import com.viaversion.viaversion.api.minecraft.item.data.PotionEffectData; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java index 3c5ff7029..668c5bb53 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvide import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.ParticleType; -import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.api.type.types.version.Types1_21_2; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; @@ -126,8 +125,9 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol { + final MappingData mappingData = protocol.getMappingData(); + final int itemId = wrapper.read(Types.VAR_INT); + final int mappedItemId = mappingData.getNewItemId(itemId); + wrapper.write(Types.STRING, mappingData.getFullItemMappings().mappedIdentifier(mappedItemId)); + }); + protocol.registerClientbound(ClientboundPackets1_21.CONTAINER_SET_CONTENT, wrapper -> { updateContainerId(wrapper); wrapper.passthrough(Types.VAR_INT); // State id @@ -106,6 +117,17 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< passthroughServerboundItem(wrapper); }); + protocol.registerServerbound(ServerboundPackets1_21_2.USE_ITEM_ON, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Hand + wrapper.passthrough(Types.BLOCK_POSITION1_14); // Block position + wrapper.passthrough(Types.VAR_INT); // Direction + wrapper.passthrough(Types.FLOAT); // X + wrapper.passthrough(Types.FLOAT); // Y + wrapper.passthrough(Types.FLOAT); // Z + wrapper.passthrough(Types.BOOLEAN); // Inside + wrapper.read(Types.BOOLEAN); // World border hit + }); + protocol.registerClientbound(ClientboundPackets1_21.EXPLODE, wrapper -> { wrapper.passthrough(Types.DOUBLE); // Center X wrapper.passthrough(Types.DOUBLE); // Center Y @@ -248,6 +270,13 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< final Instrument1_20_5 value = instrument.value(); return Holder.of(new Instrument1_21_2(value.soundEvent(), value.useDuration(), value.range(), null)); }); + dataContainer.replace(StructuredDataKey.FOOD1_21, StructuredDataKey.FOOD1_21_2, food -> { + // Just assume the item type default for CONSUMABLE; add USE_REMAINDER from old food properties + if (food.usingConvertsTo() != null) { + dataContainer.set(StructuredDataKey.USE_REMAINDER, food.usingConvertsTo()); + } + return new FoodProperties1_21_2(food.nutrition(), food.saturationModifier(), food.canAlwaysEat()); + }); dataContainer.replaceKey(StructuredDataKey.CONTAINER1_21, StructuredDataKey.CONTAINER1_21_2); dataContainer.replaceKey(StructuredDataKey.CHARGED_PROJECTILES1_21, StructuredDataKey.CHARGED_PROJECTILES1_21_2); dataContainer.replaceKey(StructuredDataKey.BUNDLE_CONTENTS1_21, StructuredDataKey.BUNDLE_CONTENTS1_21_2); @@ -262,10 +291,20 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< final Instrument1_21_2 value = instrument.value(); return Holder.of(new Instrument1_20_5(value.soundEvent(), (int) value.useDuration(), value.range())); }); + dataContainer.replace(StructuredDataKey.FOOD1_21_2, StructuredDataKey.FOOD1_21, food -> { + final StructuredData consumableData = dataContainer.getNonEmpty(StructuredDataKey.CONSUMABLE1_21_2); + final StructuredData useRemainderData = dataContainer.getNonEmpty(StructuredDataKey.USE_REMAINDER); + final Item usingConvertsTo = useRemainderData != null ? useRemainderData.value() : null; + final float eatSeconds = consumableData != null ? consumableData.value().consumeSeconds() : 1.6F; + return new FoodProperties1_20_5(food.nutrition(), food.saturationModifier(), food.canAlwaysEat(), eatSeconds, usingConvertsTo, new FoodProperties1_20_5.FoodEffect[0]); + }); dataContainer.replaceKey(StructuredDataKey.CONTAINER1_21_2, StructuredDataKey.CONTAINER1_21); dataContainer.replaceKey(StructuredDataKey.CHARGED_PROJECTILES1_21_2, StructuredDataKey.CHARGED_PROJECTILES1_21); dataContainer.replaceKey(StructuredDataKey.BUNDLE_CONTENTS1_21_2, StructuredDataKey.BUNDLE_CONTENTS1_21); dataContainer.remove(StructuredDataKey.REPAIRABLE); dataContainer.remove(StructuredDataKey.ENCHANTABLE); + dataContainer.remove(StructuredDataKey.CONSUMABLE1_21_2); + dataContainer.remove(StructuredDataKey.USE_REMAINDER); + dataContainer.remove(StructuredDataKey.USE_COOLDOWN); } } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java index 20d6ee5a4..c9d657ec8 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java @@ -20,6 +20,7 @@ package com.viaversion.viaversion.rewriter; import com.google.gson.JsonElement; import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.data.FullMappings; import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.minecraft.Particle; @@ -261,6 +262,15 @@ public class ItemRewriter { + String itemIdentifier = wrapper.read(Types.OPTIONAL_STRING); + if (itemIdentifier != null) { + itemIdentifier = mappedIdentifier(protocol.getMappingData().getFullItemMappings(), itemIdentifier); + } + wrapper.write(Types.OPTIONAL_STRING, itemIdentifier); + }); + } public void registerCustomPayloadTradeList(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @@ -631,6 +641,21 @@ public class ItemRewriter itemType() { return itemType; diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java index 95e148a6b..d4cdbba98 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java @@ -36,6 +36,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.type.Type; import it.unimi.dsi.fastutil.ints.Int2IntFunction; import java.util.Map; +import java.util.function.Function; import org.checkerframework.checker.nullness.qual.Nullable; public class StructuredItemRewriter value.rewrite(itemIdRewriter)); container.replace(StructuredDataKey.REPAIRABLE, value -> value.rewrite(itemIdRewriter)); } + if (mappingData.getFullItemMappings() != null) { + final Function itemIdRewriter = clientbound ? id -> mappedIdentifier(mappingData.getFullItemMappings(), id) : id -> unmappedIdentifier(mappingData.getFullItemMappings(), id); + container.updateIfPresent(StructuredDataKey.USE_COOLDOWN, value -> value.rewrite(itemIdRewriter)); + } if (mappingData.getBlockMappings() != null) { final Int2IntFunction blockIdRewriter = clientbound ? mappingData::getNewBlockId : mappingData::getOldBlockId; container.replace(StructuredDataKey.TOOL, value -> value.rewrite(blockIdRewriter)); diff --git a/common/src/main/resources/assets/viaversion/data/identifier-table.nbt b/common/src/main/resources/assets/viaversion/data/identifier-table.nbt index c907e3756..b3b72fc76 100644 Binary files a/common/src/main/resources/assets/viaversion/data/identifier-table.nbt and b/common/src/main/resources/assets/viaversion/data/identifier-table.nbt differ diff --git a/common/src/main/resources/assets/viaversion/data/identifiers-1.21.2.nbt b/common/src/main/resources/assets/viaversion/data/identifiers-1.21.2.nbt index 8cecf0dd4..7c40bbfbc 100644 Binary files a/common/src/main/resources/assets/viaversion/data/identifiers-1.21.2.nbt and b/common/src/main/resources/assets/viaversion/data/identifiers-1.21.2.nbt differ diff --git a/common/src/main/resources/assets/viaversion/data/mappings-1.21to1.21.2.nbt b/common/src/main/resources/assets/viaversion/data/mappings-1.21to1.21.2.nbt index c649cf9ba..3feade9f1 100644 Binary files a/common/src/main/resources/assets/viaversion/data/mappings-1.21to1.21.2.nbt and b/common/src/main/resources/assets/viaversion/data/mappings-1.21to1.21.2.nbt differ diff --git a/gradle.properties b/gradle.properties index 68358c406..25570d1a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ projectVersion=5.1.0-SNAPSHOT # Smile emoji -mcVersions=1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9 -mcVersionRange=1.8-1.21.1 +mcVersions=1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9 +mcVersionRange=1.8-1.21.2 velocityVersion=3.3 # Gradle properties