mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-28 13:05:25 +01:00
24w34a
This commit is contained in:
parent
ffc5584b1c
commit
ec4aa0637e
@ -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.
|
||||
*
|
||||
|
@ -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) {
|
||||
|
@ -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<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKey<Unit> CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Types.EMPTY);
|
||||
public static final StructuredDataKey<Boolean> ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Types.BOOLEAN);
|
||||
public static final StructuredDataKey<Tag> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Types.TAG); // Doesn't actually hold data
|
||||
public static final StructuredDataKey<FoodProperties> FOOD1_20_5 = new StructuredDataKey<>("food", FoodProperties.TYPE1_20_5);
|
||||
public static final StructuredDataKey<FoodProperties> FOOD1_21 = new StructuredDataKey<>("food", FoodProperties.TYPE1_21);
|
||||
public static final StructuredDataKey<FoodProperties1_20_5> FOOD1_20_5 = new StructuredDataKey<>("food", FoodProperties1_20_5.TYPE1_20_5);
|
||||
public static final StructuredDataKey<FoodProperties1_20_5> FOOD1_21 = new StructuredDataKey<>("food", FoodProperties1_20_5.TYPE1_21);
|
||||
public static final StructuredDataKey<FoodProperties1_21_2> FOOD1_21_2 = new StructuredDataKey<>("food", FoodProperties1_21_2.TYPE);
|
||||
public static final StructuredDataKey<Consumable1_21_2> CONSUMABLE1_21_2 = new StructuredDataKey<>("consumable", Consumable1_21_2.TYPE);
|
||||
public static final StructuredDataKey<Item> USE_REMAINDER = new StructuredDataKey<>("use_remainder", Types1_21_2.ITEM);
|
||||
public static final StructuredDataKey<UseCooldown> USE_COOLDOWN = new StructuredDataKey<>("use_cooldown", UseCooldown.TYPE);
|
||||
public static final StructuredDataKey<Unit> FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Types.EMPTY);
|
||||
public static final StructuredDataKey<ToolProperties> TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE);
|
||||
public static final StructuredDataKey<Integer> ENCHANTABLE = new StructuredDataKey<>("enchantable", Types.VAR_INT);
|
||||
|
@ -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<SoundEvent> 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<Consumable1_21_2> 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<SoundEvent> 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<T>(int id, Type<T> type, T value) {
|
||||
|
||||
public static final Type<ConsumeEffect<?>> 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<ConsumeEffect<?>[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
static <T> ConsumeEffect<T> of(final int id, final Type<T> 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<ApplyStatusEffects> 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -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,
|
||||
public record FoodProperties1_20_5(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds,
|
||||
Item usingConvertsTo, FoodEffect[] possibleEffects) {
|
||||
|
||||
public static final Type<FoodProperties> TYPE1_20_5 = new Type<>(FoodProperties.class) {
|
||||
public static final Type<FoodProperties1_20_5> 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<FoodProperties> TYPE1_21 = new Type<FoodProperties>(FoodProperties.class) {
|
||||
public static final Type<FoodProperties1_20_5> 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<FoodEffect> 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<FoodEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
}
|
||||
}
|
@ -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<FoodEffect> TYPE = new Type<>(FoodEffect.class) {
|
||||
public static final Type<FoodProperties1_21_2> 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<FoodEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
}
|
@ -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<UseCooldown> 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<String, String> idRewriter) {
|
||||
if (cooldownGroup == null) {
|
||||
return this;
|
||||
}
|
||||
|
||||
final String mappedCooldownGroup = idRewriter.apply(cooldownGroup);
|
||||
return new UseCooldown(seconds, mappedCooldownGroup);
|
||||
}
|
||||
}
|
@ -86,7 +86,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
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) {
|
||||
|
@ -58,7 +58,7 @@ final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<Clientbou
|
||||
// Registers item id changes
|
||||
// Other places using item ids are: Entity data, tags, statistics, effect
|
||||
// registerOpenWindow(ClientboundPackets1_21.OPEN_WINDOW); - If a new container type was added
|
||||
registerCooldown(ClientboundPackets1_21.COOLDOWN);
|
||||
registerCooldown1_21_2(ClientboundPackets1_21.COOLDOWN);
|
||||
registerSetContent1_21_2(ClientboundPackets1_21.CONTAINER_SET_CONTENT);
|
||||
registerSetSlot1_21_2(ClientboundPackets1_21.CONTAINER_SET_SLOT);
|
||||
registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS);
|
||||
|
@ -60,8 +60,8 @@ 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.Fireworks;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FoodEffect;
|
||||
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_20_5.FoodEffect;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
|
||||
@ -628,7 +628,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
if (serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (item.identifier() == 814 || item.identifier() == 819 || item.identifier() == 824 || item.identifier() == 829 || item.identifier() == 834) { // swords
|
||||
// Make sword "eatable" to enable clientside instant blocking on 1.8. Consume time is set really high, so the eating animation doesn't play
|
||||
item.dataContainer().set(StructuredDataKey.FOOD1_20_5, new FoodProperties(0, 0F, true, 3600, null, new FoodEffect[0]));
|
||||
item.dataContainer().set(StructuredDataKey.FOOD1_20_5, new FoodProperties1_20_5(0, 0F, true, 3600, null, new FoodEffect[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -756,7 +756,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
effect.getFloat("probability")
|
||||
));
|
||||
}
|
||||
data.set(StructuredDataKey.FOOD1_20_5, new FoodProperties(nutrition, saturation, canAlwaysEat, eatSeconds, null, possibleEffects.toArray(new FoodEffect[0])));
|
||||
data.set(StructuredDataKey.FOOD1_20_5, new FoodProperties1_20_5(nutrition, saturation, canAlwaysEat, eatSeconds, null, possibleEffects.toArray(new FoodEffect[0])));
|
||||
}
|
||||
|
||||
private void restoreToolFromBackup(final CompoundTag tool, final StructuredDataContainer data) {
|
||||
|
@ -55,8 +55,8 @@ 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.Fireworks;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FoodEffect;
|
||||
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_20_5.FoodEffect;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
|
||||
@ -502,7 +502,7 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> 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());
|
||||
|
@ -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;
|
||||
|
@ -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<ClientboundPack
|
||||
.add(StructuredDataKey.BLOCK_STATE).add(StructuredDataKey.BEES)
|
||||
.add(StructuredDataKey.LOCK).add(StructuredDataKey.CONTAINER_LOOT).add(StructuredDataKey.TOOL)
|
||||
.add(StructuredDataKey.ITEM_NAME).add(StructuredDataKey.OMINOUS_BOTTLE_AMPLIFIER)
|
||||
.add(StructuredDataKey.FOOD1_21).add(StructuredDataKey.JUKEBOX_PLAYABLE).add(StructuredDataKey.ATTRIBUTE_MODIFIERS1_21)
|
||||
.add(StructuredDataKey.REPAIRABLE).add(StructuredDataKey.ENCHANTABLE)
|
||||
.add(StructuredDataKey.FOOD1_21_2).add(StructuredDataKey.JUKEBOX_PLAYABLE).add(StructuredDataKey.ATTRIBUTE_MODIFIERS1_21)
|
||||
.add(StructuredDataKey.REPAIRABLE).add(StructuredDataKey.ENCHANTABLE).add(StructuredDataKey.CONSUMABLE1_21_2)
|
||||
.add(StructuredDataKey.USE_REMAINDER).add(StructuredDataKey.USE_COOLDOWN)
|
||||
.add(StructuredDataKey.CHARGED_PROJECTILES1_21_2).add(StructuredDataKey.BUNDLE_CONTENTS1_21_2).add(StructuredDataKey.CONTAINER1_21_2);
|
||||
super.onMappingDataLoaded();
|
||||
}
|
||||
|
@ -18,12 +18,17 @@
|
||||
package com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Consumable1_21_2;
|
||||
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.protocol.packet.PacketWrapper;
|
||||
@ -62,13 +67,19 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
|
||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA);
|
||||
|
||||
registerCooldown(ClientboundPackets1_21.COOLDOWN);
|
||||
registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS);
|
||||
registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT);
|
||||
registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT);
|
||||
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.COOLDOWN, wrapper -> {
|
||||
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<Consumable1_21_2> consumableData = dataContainer.getNonEmpty(StructuredDataKey.CONSUMABLE1_21_2);
|
||||
final StructuredData<Item> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<C extends ClientboundPacketType, S extends Serverbound
|
||||
});
|
||||
}
|
||||
|
||||
public void registerCooldown1_21_2(C packetType) {
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
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<C extends ClientboundPacketType, S extends Serverbound
|
||||
particle.setId(protocol.getMappingData().getNewParticleId(id));
|
||||
}
|
||||
|
||||
protected @Nullable String mappedIdentifier(final FullMappings mappings, final String identifier) {
|
||||
// Check if the original exists before mapping
|
||||
if (mappings.id(identifier) == -1) {
|
||||
return identifier;
|
||||
}
|
||||
return mappings.mappedIdentifier(identifier);
|
||||
}
|
||||
|
||||
protected @Nullable String unmappedIdentifier(final FullMappings mappings, final String mappedIdentifier) {
|
||||
if (mappings.mappedId(mappedIdentifier) == -1) {
|
||||
return mappedIdentifier;
|
||||
}
|
||||
return mappings.identifier(mappedIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<Item> itemType() {
|
||||
return itemType;
|
||||
|
@ -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<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
@ -120,6 +121,10 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
container.replace(StructuredDataKey.POT_DECORATIONS, value -> value.rewrite(itemIdRewriter));
|
||||
container.replace(StructuredDataKey.REPAIRABLE, value -> value.rewrite(itemIdRewriter));
|
||||
}
|
||||
if (mappingData.getFullItemMappings() != null) {
|
||||
final Function<String, String> 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));
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user