We continue to fall

This commit is contained in:
Nassim Jahnke 2024-03-01 13:46:26 +01:00
parent aa0423c6e2
commit 92878a39ef
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
17 changed files with 687 additions and 117 deletions

View File

@ -0,0 +1,69 @@
/*
* 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 Holder<T> implements Either<Integer, T> {
private final T value;
private final int id;
public Holder(final int id) {
this.value = null;
this.id = id;
}
public Holder(final T value) {
this.value = value;
this.id = -1;
}
public boolean isDirect() {
return id != -1;
}
@Override
public boolean isLeft() {
return value != null;
}
@Override
public boolean isRight() {
return value == null;
}
@Override
public Integer left() {
return id;
}
@Override
public T right() {
return value;
}
public int id() {
return id;
}
}

View File

@ -22,21 +22,15 @@
*/
package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.util.Either;
import com.viaversion.viaversion.util.EitherImpl;
public final class HolderSet {
private final Either<String, int[]> values;
public final class HolderSet extends EitherImpl<String, int[]> {
public HolderSet(final String tagKey) {
this.values = Either.left(tagKey);
super(tagKey, null);
}
public HolderSet(final int[] ids) {
this.values = Either.right(ids);
}
public Either<String, int[]> values() {
return values;
super(null, ids);
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class SoundEvent {
private final String resourceLocation;
private final Float fixedRange;
public SoundEvent(final String resourceLocation, @Nullable final Float fixedRange) {
this.resourceLocation = resourceLocation;
this.fixedRange = fixedRange;
}
public String resourceLocation() {
return resourceLocation;
}
public @Nullable Float fixedRange() {
return fixedRange;
}
}

View File

@ -25,16 +25,19 @@ package com.viaversion.viaversion.api.minecraft.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate;
import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrim;
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers;
import com.viaversion.viaversion.api.minecraft.item.data.BannerPattern;
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.AdventureModePredicate;
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.FireworkExplosion;
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
import com.viaversion.viaversion.api.minecraft.item.data.Instrument;
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;
@ -72,12 +75,12 @@ public final class StructuredDataKey<T> {
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<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE);
public static final StructuredDataKey<?> TRIM = new StructuredDataKey<>("trim", Type.EMPTY); // TODO
public static final StructuredDataKey<ArmorTrim> TRIM = new StructuredDataKey<>("trim", ArmorTrim.TYPE);
public static final StructuredDataKey<CompoundTag> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Type.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> ENTITY_DATA = new StructuredDataKey<>("entity_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<?> INSTRUMENT = new StructuredDataKey<>("instrument", Type.EMPTY); // TODO
public static final StructuredDataKey<Holder<Instrument>> INSTRUMENT = new StructuredDataKey<>("instrument", Instrument.TYPE);
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<FireworkExplosion> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE);

View File

@ -0,0 +1,69 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class ArmorTrim {
public static final Type<ArmorTrim> TYPE = new Type<ArmorTrim>(ArmorTrim.class) {
@Override
public ArmorTrim read(final ByteBuf buffer) throws Exception {
final Holder<ArmorTrimMaterial> material = ArmorTrimMaterial.TYPE.read(buffer);
final Holder<ArmorTrimPattern> pattern = ArmorTrimPattern.TYPE.read(buffer);
final boolean showInTooltip = buffer.readBoolean();
return new ArmorTrim(material, pattern, showInTooltip);
}
@Override
public void write(final ByteBuf buffer, final ArmorTrim value) throws Exception {
ArmorTrimMaterial.TYPE.write(buffer, value.material);
ArmorTrimPattern.TYPE.write(buffer, value.pattern);
buffer.writeBoolean(value.showInTooltip);
}
};
private final Holder<ArmorTrimMaterial> material;
private final Holder<ArmorTrimPattern> pattern;
private final boolean showInTooltip;
public ArmorTrim(final Holder<ArmorTrimMaterial> material, final Holder<ArmorTrimPattern> pattern, final boolean showInTooltip) {
this.material = material;
this.pattern = pattern;
this.showInTooltip = showInTooltip;
}
public Holder<ArmorTrimMaterial> material() {
return material;
}
public Holder<ArmorTrimPattern> pattern() {
return pattern;
}
public boolean showInTooltip() {
return showInTooltip;
}
}

View File

@ -0,0 +1,102 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public final class ArmorTrimMaterial {
public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<ArmorTrimMaterial>() {
@Override
public ArmorTrimMaterial readDirect(final ByteBuf buffer) throws Exception {
final String assetName = Type.STRING.read(buffer);
final int item = Type.VAR_INT.readPrimitive(buffer);
final float itemModelIndex = buffer.readFloat();
final int overrideArmorMaterialsSize = Type.VAR_INT.readPrimitive(buffer);
final Int2ObjectMap<String> overrideArmorMaterials = new Int2ObjectOpenHashMap<>(overrideArmorMaterialsSize);
for (int i = 0; i < overrideArmorMaterialsSize; i++) {
final int key = Type.VAR_INT.readPrimitive(buffer);
final String value = Type.STRING.read(buffer);
overrideArmorMaterials.put(key, value);
}
final Tag description = Type.TAG.read(buffer);
return new ArmorTrimMaterial(assetName, item, itemModelIndex, overrideArmorMaterials, description);
}
@Override
public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) throws Exception {
Type.STRING.write(buffer, value.assetName());
Type.VAR_INT.writePrimitive(buffer, value.itemId());
buffer.writeFloat(value.itemModelIndex());
Type.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size());
for (final Int2ObjectMap.Entry<String> entry : value.overrideArmorMaterials().int2ObjectEntrySet()) {
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
Type.STRING.write(buffer, entry.getValue());
}
Type.TAG.write(buffer, value.description());
}
};
private final String assetName;
private final int itemId;
private final float itemModelIndex;
private final Int2ObjectMap<String> overrideArmorMaterials;
private final Tag description;
public ArmorTrimMaterial(final String assetName, final int itemId, final float itemModelIndex, final Int2ObjectMap<String> overrideArmorMaterials, final Tag description) {
this.assetName = assetName;
this.itemId = itemId;
this.itemModelIndex = itemModelIndex;
this.overrideArmorMaterials = overrideArmorMaterials;
this.description = description;
}
public String assetName() {
return assetName;
}
public int itemId() {
return itemId;
}
public float itemModelIndex() {
return itemModelIndex;
}
public Int2ObjectMap<String> overrideArmorMaterials() {
return overrideArmorMaterials;
}
public Tag description() {
return description;
}
}

View File

@ -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.Tag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
public final class ArmorTrimPattern {
public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<ArmorTrimPattern>() {
@Override
public ArmorTrimPattern readDirect(final ByteBuf buffer) throws Exception {
final String assetName = Type.STRING.read(buffer);
final int itemId = Type.VAR_INT.readPrimitive(buffer);
final Tag description = Type.TAG.read(buffer);
final boolean decal = buffer.readBoolean();
return new ArmorTrimPattern(assetName, itemId, description, decal);
}
@Override
public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) throws Exception {
Type.STRING.write(buffer, value.assetName());
Type.VAR_INT.writePrimitive(buffer, value.itemId());
Type.TAG.write(buffer, value.description());
buffer.writeBoolean(value.decal());
}
};
private final String assetName;
private final int itemId;
private final Tag description;
private final boolean decal;
public ArmorTrimPattern(final String assetName, final int itemId, final Tag description, final boolean decal) {
this.assetName = assetName;
this.itemId = itemId;
this.description = description;
this.decal = decal;
}
public String assetName() {
return assetName;
}
public int itemId() {
return itemId;
}
public Tag description() {
return description;
}
public boolean decal() {
return decal;
}
}

View File

@ -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.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.SoundEvent;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
public final class Instrument {
public static final HolderType<Instrument> TYPE = new HolderType<Instrument>() {
@Override
public Instrument readDirect(final ByteBuf buffer) throws Exception {
final Holder<SoundEvent> soundEvent = Type.SOUND_EVENT.read(buffer);
final int useDuration = Type.VAR_INT.readPrimitive(buffer);
final float range = buffer.readFloat();
return new Instrument(soundEvent, useDuration, range);
}
@Override
public void writeDirect(final ByteBuf buffer, final Instrument value) throws Exception {
Type.SOUND_EVENT.write(buffer, value.soundEvent());
Type.VAR_INT.writePrimitive(buffer, value.useDuration());
buffer.writeFloat(value.range());
}
};
private final Holder<SoundEvent> soundEvent;
private final int useDuration;
private final float range;
public Instrument(final Holder<SoundEvent> soundEvent, final int useDuration, final float range) {
this.soundEvent = soundEvent;
this.useDuration = useDuration;
this.range = range;
}
public Holder<SoundEvent> soundEvent() {
return soundEvent;
}
public int useDuration() {
return useDuration;
}
public float range() {
return range;
}
}

View File

@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.minecraft.Quaternion;
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.api.minecraft.SoundEvent;
import com.viaversion.viaversion.api.minecraft.Vector;
import com.viaversion.viaversion.api.minecraft.Vector3f;
import com.viaversion.viaversion.api.minecraft.VillagerData;
@ -48,18 +49,19 @@ import com.viaversion.viaversion.api.type.types.ByteArrayType;
import com.viaversion.viaversion.api.type.types.ByteType;
import com.viaversion.viaversion.api.type.types.ComponentType;
import com.viaversion.viaversion.api.type.types.DoubleType;
import com.viaversion.viaversion.api.type.types.EmptyType;
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.LongArrayType;
import com.viaversion.viaversion.api.type.types.LongType;
import com.viaversion.viaversion.api.type.types.OptionalVarIntType;
import com.viaversion.viaversion.api.type.types.RegistryEntryType;
import com.viaversion.viaversion.api.type.types.RemainingBytesType;
import com.viaversion.viaversion.api.type.types.ShortByteArrayType;
import com.viaversion.viaversion.api.type.types.ShortType;
import com.viaversion.viaversion.api.type.types.StringType;
import com.viaversion.viaversion.api.type.types.UUIDType;
import com.viaversion.viaversion.api.type.types.EmptyType;
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
@ -68,30 +70,31 @@ import com.viaversion.viaversion.api.type.types.VarLongType;
import com.viaversion.viaversion.api.type.types.block.BlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.block.BlockEntityType1_18;
import com.viaversion.viaversion.api.type.types.block.BlockEntityType1_20_2;
import com.viaversion.viaversion.api.type.types.math.ChunkPositionType;
import com.viaversion.viaversion.api.type.types.misc.CompoundTagType;
import com.viaversion.viaversion.api.type.types.math.EulerAngleType;
import com.viaversion.viaversion.api.type.types.block.VarLongBlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13;
import com.viaversion.viaversion.api.type.types.item.ItemType1_13;
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13_2;
import com.viaversion.viaversion.api.type.types.item.ItemType1_13_2;
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.ItemShortArrayType1_8;
import com.viaversion.viaversion.api.type.types.item.ItemType1_13;
import com.viaversion.viaversion.api.type.types.item.ItemType1_13_2;
import com.viaversion.viaversion.api.type.types.item.ItemType1_20_2;
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.OptionalVarIntType;
import com.viaversion.viaversion.api.type.types.misc.PlayerMessageSignatureType;
import com.viaversion.viaversion.api.type.types.math.ChunkPositionType;
import com.viaversion.viaversion.api.type.types.math.EulerAngleType;
import com.viaversion.viaversion.api.type.types.math.GlobalPositionType;
import com.viaversion.viaversion.api.type.types.math.PositionType1_14;
import com.viaversion.viaversion.api.type.types.math.PositionType1_8;
import com.viaversion.viaversion.api.type.types.misc.ProfileKeyType;
import com.viaversion.viaversion.api.type.types.math.QuaternionType;
import com.viaversion.viaversion.api.type.types.misc.TagType;
import com.viaversion.viaversion.api.type.types.block.VarLongBlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
import com.viaversion.viaversion.api.type.types.math.VectorType;
import com.viaversion.viaversion.api.type.types.misc.CompoundTagType;
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.HolderType;
import com.viaversion.viaversion.api.type.types.misc.NamedCompoundTagType;
import com.viaversion.viaversion.api.type.types.misc.PlayerMessageSignatureType;
import com.viaversion.viaversion.api.type.types.misc.ProfileKeyType;
import com.viaversion.viaversion.api.type.types.misc.SoundEventType;
import com.viaversion.viaversion.api.type.types.misc.TagType;
import com.viaversion.viaversion.api.type.types.misc.VillagerDataType;
import com.viaversion.viaversion.util.Unit;
import java.util.UUID;
@ -198,6 +201,8 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<HolderSet> HOLDER_SET = new HolderSetType();
public static final Type<HolderSet> OPTIONAL_HOLDER_SET = new HolderSetType.OptionalHolderSetType();
public static final HolderType<SoundEvent> SOUND_EVENT = new SoundEventType();
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_2 = new ItemType1_13_2();

View File

@ -35,7 +35,7 @@ public class HolderSetType extends Type<HolderSet> {
@Override
public HolderSet read(final ByteBuf buffer) throws Exception {
final int size = Type.VAR_INT.readPrimitive(buffer);
final int size = Type.VAR_INT.readPrimitive(buffer) - 1;
if (size == -1) {
final String tag = Type.STRING.read(buffer);
return new HolderSet(tag);
@ -50,12 +50,12 @@ public class HolderSetType extends Type<HolderSet> {
@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());
if (object.isLeft()) {
Type.VAR_INT.writePrimitive(buffer, 0);
Type.STRING.write(buffer, object.left());
} else {
final int[] values = object.values().right();
Type.VAR_INT.writePrimitive(buffer, values.length);
final int[] values = object.right();
Type.VAR_INT.writePrimitive(buffer, values.length + 1);
for (final int value : values) {
Type.VAR_INT.writePrimitive(buffer, value);
}

View File

@ -0,0 +1,57 @@
/*
* 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.Holder;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public abstract class HolderType<T> extends Type<Holder<T>> {
protected HolderType() {
super(Holder.class);
}
@Override
public Holder<T> read(final ByteBuf buffer) throws Exception {
final int id = Type.VAR_INT.readPrimitive(buffer) - 1; // Normalize id
if (id == -1) {
return new Holder<>(readDirect(buffer));
}
return new Holder<>(id);
}
@Override
public void write(final ByteBuf buffer, final Holder<T> object) throws Exception {
if (object.isLeft()) {
Type.VAR_INT.writePrimitive(buffer, object.id() + 1); // Normalize id
} else {
Type.VAR_INT.writePrimitive(buffer, 0);
writeDirect(buffer, object.right());
}
}
public abstract T readDirect(final ByteBuf buffer) throws Exception;
public abstract void writeDirect(final ByteBuf buffer, final T object) throws Exception;
}

View File

@ -0,0 +1,43 @@
/*
* 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.SoundEvent;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class SoundEventType extends HolderType<SoundEvent> {
@Override
public SoundEvent readDirect(final ByteBuf buffer) throws Exception {
final String resourceLocation = Type.STRING.read(buffer);
final Float fixedRange = Type.OPTIONAL_FLOAT.read(buffer);
return new SoundEvent(resourceLocation, fixedRange);
}
@Override
public void writeDirect(final ByteBuf buffer, final SoundEvent value) throws Exception {
Type.STRING.write(buffer, value.resourceLocation());
Type.OPTIONAL_FLOAT.write(buffer, value.fixedRange());
}
}

View File

@ -23,63 +23,24 @@
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;
public interface Either<X, Y> {
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) {
static <X, Y> Either<X, Y> left(final X left) {
Preconditions.checkNotNull(left);
return new Either<>(left, null);
return new EitherImpl<>(left, null);
}
public static <X, Y> Either<X, Y> right(final Y right) {
static <X, Y> Either<X, Y> right(final Y right) {
Preconditions.checkNotNull(right);
return new Either<>(null, right);
return new EitherImpl<>(null, right);
}
public boolean isLeft() {
return left != null;
}
boolean isLeft();
public boolean isRight() {
return right != null;
}
boolean isRight();
public @Nullable X left() {
return left;
}
X 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;
}
Y right();
}

View File

@ -0,0 +1,79 @@
/*
* 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;
public class EitherImpl<X, Y> implements Either<X, Y> {
private final X left;
private final Y right;
protected EitherImpl(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");
Preconditions.checkArgument(left != null || value != null, "Either.left and Either.right are both null");
}
@Override
public boolean isLeft() {
return left != null;
}
@Override
public boolean isRight() {
return right != null;
}
@Override
public X left() {
return left;
}
@Override
public 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 EitherImpl<?, ?> pair = (EitherImpl<?, ?>) 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;
}
}

View File

@ -43,6 +43,6 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
item.setIdentifier(1);
item.setData((short) 0);
}
return null;
return item;
}
}

View File

@ -23,8 +23,10 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.SoundEvent;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
@ -33,6 +35,7 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.BitSetType;
@ -48,7 +51,6 @@ import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.packets.Invent
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.storage.NonceStorage;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.storage.ReceivedMessagesStorage;
import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
@ -85,35 +87,22 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
entityRewriter.register();
itemRewriter.register();
final SoundRewriter<ClientboundPackets1_19_1> soundRewriter = new SoundRewriter<>(this);
registerClientbound(ClientboundPackets1_19_1.ENTITY_SOUND, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // Sound id
handler(soundRewriter.getSoundHandler());
handler(wrapper -> {
// 0 means a resource location will be written
final int soundId = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, soundId + 1);
});
// Rewrite sounds as holders
final PacketHandler soundHandler = wrapper -> {
int soundId = wrapper.read(Type.VAR_INT);
soundId = MAPPINGS.getSoundMappings().getNewId(soundId);
if (soundId == -1) {
wrapper.cancel();
return;
}
});
registerClientbound(ClientboundPackets1_19_1.SOUND, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // Sound id
handler(soundRewriter.getSoundHandler());
handler(wrapper -> {
// 0 means a resource location will be written
final int soundId = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, soundId + 1);
});
}
});
wrapper.write(Type.SOUND_EVENT, new Holder<>(soundId));
};
registerClientbound(ClientboundPackets1_19_1.ENTITY_SOUND, soundHandler);
registerClientbound(ClientboundPackets1_19_1.SOUND, soundHandler);
registerClientbound(ClientboundPackets1_19_1.NAMED_SOUND, ClientboundPackets1_19_3.SOUND, wrapper -> {
wrapper.write(Type.VAR_INT, 0);
wrapper.passthrough(Type.STRING); // Sound identifier
wrapper.write(Type.OPTIONAL_FLOAT, null); // No fixed range
final String soundIdentifier = wrapper.read(Type.STRING);
wrapper.write(Type.SOUND_EVENT, new Holder<>(new SoundEvent(soundIdentifier, null)));
});
new StatisticsRewriter<>(this).register(ClientboundPackets1_19_1.STATISTICS);

View File

@ -17,6 +17,8 @@
*/
package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.SoundEvent;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
@ -53,20 +55,24 @@ public class SoundRewriter<C extends ClientboundPacketType> {
public PacketHandler soundHolderHandler() {
return wrapper -> {
final int soundId = wrapper.read(Type.VAR_INT);
if (soundId == 0) {
Holder<SoundEvent> soundEventHolder = wrapper.read(Type.SOUND_EVENT);
if (soundEventHolder.isDirect()) {
// Is followed by the resource loation
wrapper.write(Type.VAR_INT, 0);
wrapper.write(Type.SOUND_EVENT, soundEventHolder);
return;
}
final int mappedId = idRewriter.rewrite(soundId - 1); // Normalize sound id
final int mappedId = idRewriter.rewrite(soundEventHolder.id());
if (mappedId == -1) {
wrapper.cancel();
return;
}
wrapper.write(Type.VAR_INT, mappedId + 1);
if (mappedId != soundEventHolder.id()) {
soundEventHolder = new Holder<>(mappedId);
}
wrapper.write(Type.SOUND_EVENT, soundEventHolder);
};
}