3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Move type instances out of its enclosing class

Type constants being hold by its own abstract class has lead to classloading issues in the past, now we're finally free
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-05-11 19:01:31 +02:00
Ursprung ca25e62d2d
Commit 5286efde15
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
236 geänderte Dateien mit 4703 neuen und 4466 gelöschten Zeilen

Datei anzeigen

@ -48,40 +48,41 @@ 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.Unbreakable;
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook; import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.util.Unit; import com.viaversion.viaversion.util.Unit;
public record StructuredDataKey<T>(String identifier, Type<T> type) { public record StructuredDataKey<T>(String identifier, Type<T> type) {
public static final StructuredDataKey<CompoundTag> CUSTOM_DATA = new StructuredDataKey<>("custom_data", Type.COMPOUND_TAG); public static final StructuredDataKey<CompoundTag> CUSTOM_DATA = new StructuredDataKey<>("custom_data", Types.COMPOUND_TAG);
public static final StructuredDataKey<Integer> MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Type.VAR_INT); public static final StructuredDataKey<Integer> MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Types.VAR_INT);
public static final StructuredDataKey<Integer> MAX_DAMAGE = new StructuredDataKey<>("max_damage", Type.VAR_INT); public static final StructuredDataKey<Integer> MAX_DAMAGE = new StructuredDataKey<>("max_damage", Types.VAR_INT);
public static final StructuredDataKey<Integer> DAMAGE = new StructuredDataKey<>("damage", Type.VAR_INT); public static final StructuredDataKey<Integer> DAMAGE = new StructuredDataKey<>("damage", Types.VAR_INT);
public static final StructuredDataKey<Unbreakable> UNBREAKABLE = new StructuredDataKey<>("unbreakable", Unbreakable.TYPE); public static final StructuredDataKey<Unbreakable> UNBREAKABLE = new StructuredDataKey<>("unbreakable", Unbreakable.TYPE);
public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Type.TAG); public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Types.TAG);
public static final StructuredDataKey<Tag> ITEM_NAME = new StructuredDataKey<>("item_name", Type.TAG); public static final StructuredDataKey<Tag> ITEM_NAME = new StructuredDataKey<>("item_name", Types.TAG);
public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", Type.TAG_ARRAY); public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", Types.TAG_ARRAY);
public static final StructuredDataKey<Integer> RARITY = new StructuredDataKey<>("rarity", Type.VAR_INT); public static final StructuredDataKey<Integer> RARITY = new StructuredDataKey<>("rarity", Types.VAR_INT);
public static final StructuredDataKey<Enchantments> ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE); public static final StructuredDataKey<Enchantments> ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE);
public static final StructuredDataKey<AdventureModePredicate> CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE); public static final StructuredDataKey<AdventureModePredicate> CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE);
public static final StructuredDataKey<AdventureModePredicate> CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE); public static final StructuredDataKey<AdventureModePredicate> CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE);
public static final StructuredDataKey<AttributeModifiers> ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers.TYPE); public static final StructuredDataKey<AttributeModifiers> ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers.TYPE);
public static final StructuredDataKey<Integer> CUSTOM_MODEL_DATA = new StructuredDataKey<>("custom_model_data", Type.VAR_INT); public static final StructuredDataKey<Integer> CUSTOM_MODEL_DATA = new StructuredDataKey<>("custom_model_data", Types.VAR_INT);
public static final StructuredDataKey<Unit> HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Type.EMPTY); public static final StructuredDataKey<Unit> HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Types.EMPTY);
public static final StructuredDataKey<Unit> HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Type.EMPTY); public static final StructuredDataKey<Unit> HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Types.EMPTY);
public static final StructuredDataKey<Integer> REPAIR_COST = new StructuredDataKey<>("repair_cost", Type.VAR_INT); public static final StructuredDataKey<Integer> REPAIR_COST = new StructuredDataKey<>("repair_cost", Types.VAR_INT);
public static final StructuredDataKey<Unit> CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Type.EMPTY); 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", Type.BOOLEAN); 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", Type.TAG); // Doesn't actually hold data public static final StructuredDataKey<Tag> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Types.TAG); // Doesn't actually hold data
public static final StructuredDataKey<FoodProperties> FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE); public static final StructuredDataKey<FoodProperties> FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE);
public static final StructuredDataKey<Unit> FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Type.EMPTY); 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<ToolProperties> TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE);
public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE); public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE);
public static final StructuredDataKey<DyedColor> DYED_COLOR = new StructuredDataKey<>("dyed_color", DyedColor.TYPE); public static final StructuredDataKey<DyedColor> DYED_COLOR = new StructuredDataKey<>("dyed_color", DyedColor.TYPE);
public static final StructuredDataKey<Integer> MAP_COLOR = new StructuredDataKey<>("map_color", Type.INT); public static final StructuredDataKey<Integer> MAP_COLOR = new StructuredDataKey<>("map_color", Types.INT);
public static final StructuredDataKey<Integer> MAP_ID = new StructuredDataKey<>("map_id", Type.VAR_INT); public static final StructuredDataKey<Integer> MAP_ID = new StructuredDataKey<>("map_id", Types.VAR_INT);
public static final StructuredDataKey<CompoundTag> MAP_DECORATIONS = new StructuredDataKey<>("map_decorations", Type.COMPOUND_TAG); public static final StructuredDataKey<CompoundTag> MAP_DECORATIONS = new StructuredDataKey<>("map_decorations", Types.COMPOUND_TAG);
public static final StructuredDataKey<Integer> MAP_POST_PROCESSING = new StructuredDataKey<>("map_post_processing", Type.VAR_INT); public static final StructuredDataKey<Integer> MAP_POST_PROCESSING = new StructuredDataKey<>("map_post_processing", Types.VAR_INT);
public static final StructuredDataKey<Item[]> CHARGED_PROJECTILES = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY); public static final StructuredDataKey<Item[]> CHARGED_PROJECTILES = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY);
public static final StructuredDataKey<Item[]> BUNDLE_CONTENTS = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY); public static final StructuredDataKey<Item[]> BUNDLE_CONTENTS = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY);
public static final StructuredDataKey<PotionContents> POTION_CONTENTS = new StructuredDataKey<>("potion_contents", PotionContents.TYPE); public static final StructuredDataKey<PotionContents> POTION_CONTENTS = new StructuredDataKey<>("potion_contents", PotionContents.TYPE);
@ -89,26 +90,26 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
public static final StructuredDataKey<FilterableString[]> WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", FilterableString.ARRAY_TYPE); public static final StructuredDataKey<FilterableString[]> WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", FilterableString.ARRAY_TYPE);
public static final StructuredDataKey<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE); public static final StructuredDataKey<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE);
public static final StructuredDataKey<ArmorTrim> TRIM = new StructuredDataKey<>("trim", ArmorTrim.TYPE); 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> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Types.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> ENTITY_DATA = new StructuredDataKey<>("entity_data", Type.COMPOUND_TAG); public static final StructuredDataKey<CompoundTag> ENTITY_DATA = new StructuredDataKey<>("entity_data", Types.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Type.COMPOUND_TAG); public static final StructuredDataKey<CompoundTag> BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Types.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Type.COMPOUND_TAG); public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Types.COMPOUND_TAG);
public static final StructuredDataKey<Holder<Instrument>> INSTRUMENT = new StructuredDataKey<>("instrument", Instrument.TYPE); public static final StructuredDataKey<Holder<Instrument>> INSTRUMENT = new StructuredDataKey<>("instrument", Instrument.TYPE);
public static final StructuredDataKey<Integer> OMINOUS_BOTTLE_AMPLIFIER = new StructuredDataKey<>("ominous_bottle_amplifier", Type.VAR_INT); public static final StructuredDataKey<Integer> OMINOUS_BOTTLE_AMPLIFIER = new StructuredDataKey<>("ominous_bottle_amplifier", Types.VAR_INT);
public static final StructuredDataKey<Tag> RECIPES = new StructuredDataKey<>("recipes", Type.TAG); public static final StructuredDataKey<Tag> RECIPES = new StructuredDataKey<>("recipes", Types.TAG);
public static final StructuredDataKey<LodestoneTracker> LODESTONE_TRACKER = new StructuredDataKey<>("lodestone_tracker", LodestoneTracker.TYPE); public static final StructuredDataKey<LodestoneTracker> LODESTONE_TRACKER = new StructuredDataKey<>("lodestone_tracker", LodestoneTracker.TYPE);
public static final StructuredDataKey<FireworkExplosion> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE); public static final StructuredDataKey<FireworkExplosion> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE);
public static final StructuredDataKey<Fireworks> FIREWORKS = new StructuredDataKey<>("fireworks", Fireworks.TYPE); public static final StructuredDataKey<Fireworks> FIREWORKS = new StructuredDataKey<>("fireworks", Fireworks.TYPE);
public static final StructuredDataKey<GameProfile> PROFILE = new StructuredDataKey<>("profile", Type.GAME_PROFILE); public static final StructuredDataKey<GameProfile> PROFILE = new StructuredDataKey<>("profile", Types.GAME_PROFILE);
public static final StructuredDataKey<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Type.STRING); public static final StructuredDataKey<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Types.STRING);
public static final StructuredDataKey<BannerPatternLayer[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE); public static final StructuredDataKey<BannerPatternLayer[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE);
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Type.VAR_INT); public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Types.VAR_INT);
public static final StructuredDataKey<PotDecorations> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE); public static final StructuredDataKey<PotDecorations> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE);
public static final StructuredDataKey<Item[]> CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY); public static final StructuredDataKey<Item[]> CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY);
public static final StructuredDataKey<BlockStateProperties> BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE); public static final StructuredDataKey<BlockStateProperties> BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE);
public static final StructuredDataKey<Bee[]> BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE); public static final StructuredDataKey<Bee[]> BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE);
public static final StructuredDataKey<Tag> LOCK = new StructuredDataKey<>("lock", Type.TAG); public static final StructuredDataKey<Tag> LOCK = new StructuredDataKey<>("lock", Types.TAG);
public static final StructuredDataKey<CompoundTag> CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Type.COMPOUND_TAG); public static final StructuredDataKey<CompoundTag> CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Types.COMPOUND_TAG);
@Override @Override
public String toString() { public String toString() {

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.nbt.tag.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.HolderType; import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -35,35 +36,35 @@ public record ArmorTrimMaterial(String assetName, int itemId, float itemModelInd
public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<>() { public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<>() {
@Override @Override
public ArmorTrimMaterial readDirect(final ByteBuf buffer) { public ArmorTrimMaterial readDirect(final ByteBuf buffer) {
final String assetName = Type.STRING.read(buffer); final String assetName = Types.STRING.read(buffer);
final int item = Type.VAR_INT.readPrimitive(buffer); final int item = Types.VAR_INT.readPrimitive(buffer);
final float itemModelIndex = buffer.readFloat(); final float itemModelIndex = buffer.readFloat();
final int overrideArmorMaterialsSize = Type.VAR_INT.readPrimitive(buffer); final int overrideArmorMaterialsSize = Types.VAR_INT.readPrimitive(buffer);
final Int2ObjectMap<String> overrideArmorMaterials = new Int2ObjectOpenHashMap<>(overrideArmorMaterialsSize); final Int2ObjectMap<String> overrideArmorMaterials = new Int2ObjectOpenHashMap<>(overrideArmorMaterialsSize);
for (int i = 0; i < overrideArmorMaterialsSize; i++) { for (int i = 0; i < overrideArmorMaterialsSize; i++) {
final int key = Type.VAR_INT.readPrimitive(buffer); final int key = Types.VAR_INT.readPrimitive(buffer);
final String value = Type.STRING.read(buffer); final String value = Types.STRING.read(buffer);
overrideArmorMaterials.put(key, value); overrideArmorMaterials.put(key, value);
} }
final Tag description = Type.TAG.read(buffer); final Tag description = Types.TAG.read(buffer);
return new ArmorTrimMaterial(assetName, item, itemModelIndex, overrideArmorMaterials, description); return new ArmorTrimMaterial(assetName, item, itemModelIndex, overrideArmorMaterials, description);
} }
@Override @Override
public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) { public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) {
Type.STRING.write(buffer, value.assetName()); Types.STRING.write(buffer, value.assetName());
Type.VAR_INT.writePrimitive(buffer, value.itemId()); Types.VAR_INT.writePrimitive(buffer, value.itemId());
buffer.writeFloat(value.itemModelIndex()); buffer.writeFloat(value.itemModelIndex());
Type.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size()); Types.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size());
for (final Int2ObjectMap.Entry<String> entry : value.overrideArmorMaterials().int2ObjectEntrySet()) { for (final Int2ObjectMap.Entry<String> entry : value.overrideArmorMaterials().int2ObjectEntrySet()) {
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey()); Types.VAR_INT.writePrimitive(buffer, entry.getIntKey());
Type.STRING.write(buffer, entry.getValue()); Types.STRING.write(buffer, entry.getValue());
} }
Type.TAG.write(buffer, value.description()); Types.TAG.write(buffer, value.description());
} }
}; };

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.nbt.tag.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.HolderType; import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -32,18 +33,18 @@ public record ArmorTrimPattern(String assetName, int itemId, Tag description, bo
public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<>() { public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<>() {
@Override @Override
public ArmorTrimPattern readDirect(final ByteBuf buffer) { public ArmorTrimPattern readDirect(final ByteBuf buffer) {
final String assetName = Type.STRING.read(buffer); final String assetName = Types.STRING.read(buffer);
final int itemId = Type.VAR_INT.readPrimitive(buffer); final int itemId = Types.VAR_INT.readPrimitive(buffer);
final Tag description = Type.TAG.read(buffer); final Tag description = Types.TAG.read(buffer);
final boolean decal = buffer.readBoolean(); final boolean decal = buffer.readBoolean();
return new ArmorTrimPattern(assetName, itemId, description, decal); return new ArmorTrimPattern(assetName, itemId, description, decal);
} }
@Override @Override
public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) { public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) {
Type.STRING.write(buffer, value.assetName()); Types.STRING.write(buffer, value.assetName());
Type.VAR_INT.writePrimitive(buffer, value.itemId()); Types.VAR_INT.writePrimitive(buffer, value.itemId());
Type.TAG.write(buffer, value.description()); Types.TAG.write(buffer, value.description());
buffer.writeBoolean(value.decal()); buffer.writeBoolean(value.decal());
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -31,17 +32,17 @@ public record AttributeModifier(int attribute, ModifierData modifier, int slotTy
public static final Type<AttributeModifier> TYPE = new Type<>(AttributeModifier.class) { public static final Type<AttributeModifier> TYPE = new Type<>(AttributeModifier.class) {
@Override @Override
public AttributeModifier read(final ByteBuf buffer) { public AttributeModifier read(final ByteBuf buffer) {
final int attribute = Type.VAR_INT.readPrimitive(buffer); final int attribute = Types.VAR_INT.readPrimitive(buffer);
final ModifierData modifier = ModifierData.TYPE.read(buffer); final ModifierData modifier = ModifierData.TYPE.read(buffer);
final int slot = Type.VAR_INT.readPrimitive(buffer); final int slot = Types.VAR_INT.readPrimitive(buffer);
return new AttributeModifier(attribute, modifier, slot); return new AttributeModifier(attribute, modifier, slot);
} }
@Override @Override
public void write(final ByteBuf buffer, final AttributeModifier value) { public void write(final ByteBuf buffer, final AttributeModifier value) {
Type.VAR_INT.writePrimitive(buffer, value.attribute); Types.VAR_INT.writePrimitive(buffer, value.attribute);
ModifierData.TYPE.write(buffer, value.modifier); ModifierData.TYPE.write(buffer, value.modifier);
Type.VAR_INT.writePrimitive(buffer, value.slotType); Types.VAR_INT.writePrimitive(buffer, value.slotType);
} }
}; };
public static final Type<AttributeModifier[]> ARRAY_TYPE = new ArrayType<>(TYPE); public static final Type<AttributeModifier[]> ARRAY_TYPE = new ArrayType<>(TYPE);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.HolderType; import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -31,15 +32,15 @@ public record BannerPattern(String assetId, String translationKey) {
public static final HolderType<BannerPattern> TYPE = new HolderType<>() { public static final HolderType<BannerPattern> TYPE = new HolderType<>() {
@Override @Override
public BannerPattern readDirect(final ByteBuf buffer) { public BannerPattern readDirect(final ByteBuf buffer) {
final String assetId = Type.STRING.read(buffer); final String assetId = Types.STRING.read(buffer);
final String translationKey = Type.STRING.read(buffer); final String translationKey = Types.STRING.read(buffer);
return new BannerPattern(assetId, translationKey); return new BannerPattern(assetId, translationKey);
} }
@Override @Override
public void writeDirect(final ByteBuf buffer, final BannerPattern value) { public void writeDirect(final ByteBuf buffer, final BannerPattern value) {
Type.STRING.write(buffer, value.assetId); Types.STRING.write(buffer, value.assetId);
Type.STRING.write(buffer, value.translationKey); Types.STRING.write(buffer, value.translationKey);
} }
}; };

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -33,14 +34,14 @@ public record BannerPatternLayer(Holder<BannerPattern> pattern, int dyeColor) {
@Override @Override
public BannerPatternLayer read(final ByteBuf buffer) { public BannerPatternLayer read(final ByteBuf buffer) {
final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer); final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer);
final int color = Type.VAR_INT.readPrimitive(buffer); final int color = Types.VAR_INT.readPrimitive(buffer);
return new BannerPatternLayer(pattern, color); return new BannerPatternLayer(pattern, color);
} }
@Override @Override
public void write(final ByteBuf buffer, final BannerPatternLayer value) { public void write(final ByteBuf buffer, final BannerPatternLayer value) {
BannerPattern.TYPE.write(buffer, value.pattern); BannerPattern.TYPE.write(buffer, value.pattern);
Type.VAR_INT.writePrimitive(buffer, value.dyeColor); Types.VAR_INT.writePrimitive(buffer, value.dyeColor);
} }
}; };
public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE); public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE);

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -32,17 +33,17 @@ public record Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) {
public static final Type<Bee> TYPE = new Type<>(Bee.class) { public static final Type<Bee> TYPE = new Type<>(Bee.class) {
@Override @Override
public Bee read(final ByteBuf buffer) { public Bee read(final ByteBuf buffer) {
final CompoundTag entityData = Type.COMPOUND_TAG.read(buffer); final CompoundTag entityData = Types.COMPOUND_TAG.read(buffer);
final int ticksInHive = Type.VAR_INT.readPrimitive(buffer); final int ticksInHive = Types.VAR_INT.readPrimitive(buffer);
final int minTicksInHive = Type.VAR_INT.readPrimitive(buffer); final int minTicksInHive = Types.VAR_INT.readPrimitive(buffer);
return new Bee(entityData, ticksInHive, minTicksInHive); return new Bee(entityData, ticksInHive, minTicksInHive);
} }
@Override @Override
public void write(final ByteBuf buffer, final Bee value) { public void write(final ByteBuf buffer, final Bee value) {
Type.COMPOUND_TAG.write(buffer, value.entityData); Types.COMPOUND_TAG.write(buffer, value.entityData);
Type.VAR_INT.writePrimitive(buffer, value.ticksInHive); Types.VAR_INT.writePrimitive(buffer, value.ticksInHive);
Type.VAR_INT.writePrimitive(buffer, value.minTicksInHive); Types.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
} }
}; };
public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE); public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE);

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -35,22 +36,22 @@ public record BlockPredicate(@Nullable HolderSet holderSet, StatePropertyMatcher
public static final Type<BlockPredicate> TYPE = new Type<>(BlockPredicate.class) { public static final Type<BlockPredicate> TYPE = new Type<>(BlockPredicate.class) {
@Override @Override
public BlockPredicate read(final ByteBuf buffer) { public BlockPredicate read(final ByteBuf buffer) {
final HolderSet holders = Type.OPTIONAL_HOLDER_SET.read(buffer); final HolderSet holders = Types.OPTIONAL_HOLDER_SET.read(buffer);
final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null; final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null;
final CompoundTag tag = Type.OPTIONAL_COMPOUND_TAG.read(buffer); final CompoundTag tag = Types.OPTIONAL_COMPOUND_TAG.read(buffer);
return new BlockPredicate(holders, propertyMatchers, tag); return new BlockPredicate(holders, propertyMatchers, tag);
} }
@Override @Override
public void write(final ByteBuf buffer, final BlockPredicate value) { public void write(final ByteBuf buffer, final BlockPredicate value) {
Type.OPTIONAL_HOLDER_SET.write(buffer, value.holderSet); Types.OPTIONAL_HOLDER_SET.write(buffer, value.holderSet);
buffer.writeBoolean(value.propertyMatchers != null); buffer.writeBoolean(value.propertyMatchers != null);
if (value.propertyMatchers != null) { if (value.propertyMatchers != null) {
StatePropertyMatcher.ARRAY_TYPE.write(buffer, value.propertyMatchers); StatePropertyMatcher.ARRAY_TYPE.write(buffer, value.propertyMatchers);
} }
Type.OPTIONAL_COMPOUND_TAG.write(buffer, value.tag); Types.OPTIONAL_COMPOUND_TAG.write(buffer, value.tag);
} }
}; };
public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE); public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.Map; import java.util.Map;
@ -32,20 +33,20 @@ public record BlockStateProperties(Map<String, String> properties) {
public static final Type<BlockStateProperties> TYPE = new Type<>(BlockStateProperties.class) { public static final Type<BlockStateProperties> TYPE = new Type<>(BlockStateProperties.class) {
@Override @Override
public BlockStateProperties read(final ByteBuf buffer) { public BlockStateProperties read(final ByteBuf buffer) {
final int size = Type.VAR_INT.readPrimitive(buffer); final int size = Types.VAR_INT.readPrimitive(buffer);
final Map<String, String> properties = new Object2ObjectOpenHashMap<>(size); final Map<String, String> properties = new Object2ObjectOpenHashMap<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
properties.put(Type.STRING.read(buffer), Type.STRING.read(buffer)); properties.put(Types.STRING.read(buffer), Types.STRING.read(buffer));
} }
return new BlockStateProperties(properties); return new BlockStateProperties(properties);
} }
@Override @Override
public void write(final ByteBuf buffer, final BlockStateProperties value) { public void write(final ByteBuf buffer, final BlockStateProperties value) {
Type.VAR_INT.writePrimitive(buffer, value.properties.size()); Types.VAR_INT.writePrimitive(buffer, value.properties.size());
for (final Map.Entry<String, String> entry : value.properties.entrySet()) { for (final Map.Entry<String, String> entry : value.properties.entrySet()) {
Type.STRING.write(buffer, entry.getKey()); Types.STRING.write(buffer, entry.getKey());
Type.STRING.write(buffer, entry.getValue()); Types.STRING.write(buffer, entry.getValue());
} }
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
@ -33,10 +34,10 @@ public record Enchantments(Int2IntMap enchantments, boolean showInTooltip) {
@Override @Override
public Enchantments read(final ByteBuf buffer) { public Enchantments read(final ByteBuf buffer) {
final Int2IntMap enchantments = new Int2IntOpenHashMap(); final Int2IntMap enchantments = new Int2IntOpenHashMap();
final int size = Type.VAR_INT.readPrimitive(buffer); final int size = Types.VAR_INT.readPrimitive(buffer);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final int id = Type.VAR_INT.readPrimitive(buffer); final int id = Types.VAR_INT.readPrimitive(buffer);
final int level = Type.VAR_INT.readPrimitive(buffer); final int level = Types.VAR_INT.readPrimitive(buffer);
enchantments.put(id, level); enchantments.put(id, level);
} }
@ -45,10 +46,10 @@ public record Enchantments(Int2IntMap enchantments, boolean showInTooltip) {
@Override @Override
public void write(final ByteBuf buffer, final Enchantments value) { public void write(final ByteBuf buffer, final Enchantments value) {
Type.VAR_INT.writePrimitive(buffer, value.enchantments.size()); Types.VAR_INT.writePrimitive(buffer, value.enchantments.size());
for (final Int2IntMap.Entry entry : value.enchantments.int2IntEntrySet()) { for (final Int2IntMap.Entry entry : value.enchantments.int2IntEntrySet()) {
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey()); Types.VAR_INT.writePrimitive(buffer, entry.getIntKey());
Type.VAR_INT.writePrimitive(buffer, entry.getIntValue()); Types.VAR_INT.writePrimitive(buffer, entry.getIntValue());
} }
buffer.writeBoolean(value.showInTooltip()); buffer.writeBoolean(value.showInTooltip());
} }

Datei anzeigen

@ -24,12 +24,13 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.nbt.tag.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public final class FilterableComponent extends Filterable<Tag> { public final class FilterableComponent extends Filterable<Tag> {
public static final Type<FilterableComponent> TYPE = new FilterableType<>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) { public static final Type<FilterableComponent> TYPE = new FilterableType<>(Types.TAG, Types.OPTIONAL_TAG, FilterableComponent.class) {
@Override @Override
protected FilterableComponent create(final Tag raw, final Tag filtered) { protected FilterableComponent create(final Tag raw, final Tag filtered) {
return new FilterableComponent(raw, filtered); return new FilterableComponent(raw, filtered);

Datei anzeigen

@ -23,12 +23,13 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public final class FilterableString extends Filterable<String> { public final class FilterableString extends Filterable<String> {
public static final Type<FilterableString> TYPE = new FilterableType<>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) { public static final Type<FilterableString> TYPE = new FilterableType<>(Types.STRING, Types.OPTIONAL_STRING, FilterableString.class) {
@Override @Override
protected FilterableString create(final String raw, final String filtered) { protected FilterableString create(final String raw, final String filtered) {
return new FilterableString(raw, filtered); return new FilterableString(raw, filtered);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -30,9 +31,9 @@ public record FireworkExplosion(int shape, int[] colors, int[] fadeColors, boole
public static final Type<FireworkExplosion> TYPE = new Type<>(FireworkExplosion.class) { public static final Type<FireworkExplosion> TYPE = new Type<>(FireworkExplosion.class) {
@Override @Override
public FireworkExplosion read(final ByteBuf buffer) { public FireworkExplosion read(final ByteBuf buffer) {
final int shape = Type.VAR_INT.readPrimitive(buffer); final int shape = Types.VAR_INT.readPrimitive(buffer);
final int[] colors = Type.INT_ARRAY_PRIMITIVE.read(buffer); final int[] colors = Types.INT_ARRAY_PRIMITIVE.read(buffer);
final int[] fadeColors = Type.INT_ARRAY_PRIMITIVE.read(buffer); final int[] fadeColors = Types.INT_ARRAY_PRIMITIVE.read(buffer);
final boolean hasTrail = buffer.readBoolean(); final boolean hasTrail = buffer.readBoolean();
final boolean hasTwinkle = buffer.readBoolean(); final boolean hasTwinkle = buffer.readBoolean();
return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle); return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle);
@ -40,9 +41,9 @@ public record FireworkExplosion(int shape, int[] colors, int[] fadeColors, boole
@Override @Override
public void write(final ByteBuf buffer, final FireworkExplosion value) { public void write(final ByteBuf buffer, final FireworkExplosion value) {
Type.VAR_INT.writePrimitive(buffer, value.shape); Types.VAR_INT.writePrimitive(buffer, value.shape);
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.colors); Types.INT_ARRAY_PRIMITIVE.write(buffer, value.colors);
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors); Types.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors);
buffer.writeBoolean(value.hasTrail); buffer.writeBoolean(value.hasTrail);
buffer.writeBoolean(value.hasTwinkle); buffer.writeBoolean(value.hasTwinkle);
} }

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public record Fireworks(int flightDuration, FireworkExplosion[] explosions) { public record Fireworks(int flightDuration, FireworkExplosion[] explosions) {
@ -30,14 +31,14 @@ public record Fireworks(int flightDuration, FireworkExplosion[] explosions) {
public static final Type<Fireworks> TYPE = new Type<>(Fireworks.class) { public static final Type<Fireworks> TYPE = new Type<>(Fireworks.class) {
@Override @Override
public Fireworks read(final ByteBuf buffer) { public Fireworks read(final ByteBuf buffer) {
final int flightDuration = Type.VAR_INT.readPrimitive(buffer); final int flightDuration = Types.VAR_INT.readPrimitive(buffer);
final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer); final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer);
return new Fireworks(flightDuration, explosions); return new Fireworks(flightDuration, explosions);
} }
@Override @Override
public void write(final ByteBuf buffer, final Fireworks value) { public void write(final ByteBuf buffer, final Fireworks value) {
Type.VAR_INT.writePrimitive(buffer, value.flightDuration); Types.VAR_INT.writePrimitive(buffer, value.flightDuration);
FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions); FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions);
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds, public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds,
@ -31,7 +32,7 @@ public record FoodProperties(int nutrition, float saturationModifier, boolean ca
public static final Type<FoodProperties> TYPE = new Type<>(FoodProperties.class) { public static final Type<FoodProperties> TYPE = new Type<>(FoodProperties.class) {
@Override @Override
public FoodProperties read(final ByteBuf buffer) { public FoodProperties read(final ByteBuf buffer) {
final int nutrition = Type.VAR_INT.readPrimitive(buffer); final int nutrition = Types.VAR_INT.readPrimitive(buffer);
final float saturationModifier = buffer.readFloat(); final float saturationModifier = buffer.readFloat();
final boolean canAlwaysEat = buffer.readBoolean(); final boolean canAlwaysEat = buffer.readBoolean();
final float eatSeconds = buffer.readFloat(); final float eatSeconds = buffer.readFloat();
@ -41,7 +42,7 @@ public record FoodProperties(int nutrition, float saturationModifier, boolean ca
@Override @Override
public void write(final ByteBuf buffer, final FoodProperties value) { public void write(final ByteBuf buffer, final FoodProperties value) {
Type.VAR_INT.writePrimitive(buffer, value.nutrition); Types.VAR_INT.writePrimitive(buffer, value.nutrition);
buffer.writeFloat(value.saturationModifier); buffer.writeFloat(value.saturationModifier);
buffer.writeBoolean(value.canAlwaysEat); buffer.writeBoolean(value.canAlwaysEat);
buffer.writeFloat(value.eatSeconds); buffer.writeFloat(value.eatSeconds);

Datei anzeigen

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

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.GlobalPosition; import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -32,14 +33,14 @@ public record LodestoneTracker(@Nullable GlobalPosition position, boolean tracke
public static final Type<LodestoneTracker> TYPE = new Type<>(LodestoneTracker.class) { public static final Type<LodestoneTracker> TYPE = new Type<>(LodestoneTracker.class) {
@Override @Override
public LodestoneTracker read(final ByteBuf buffer) { public LodestoneTracker read(final ByteBuf buffer) {
final GlobalPosition position = Type.OPTIONAL_GLOBAL_POSITION.read(buffer); final GlobalPosition position = Types.OPTIONAL_GLOBAL_POSITION.read(buffer);
final boolean tracked = buffer.readBoolean(); final boolean tracked = buffer.readBoolean();
return new LodestoneTracker(position, tracked); return new LodestoneTracker(position, tracked);
} }
@Override @Override
public void write(final ByteBuf buffer, final LodestoneTracker value) { public void write(final ByteBuf buffer, final LodestoneTracker value) {
Type.OPTIONAL_GLOBAL_POSITION.write(buffer, value.position); Types.OPTIONAL_GLOBAL_POSITION.write(buffer, value.position);
buffer.writeBoolean(value.tracked); buffer.writeBoolean(value.tracked);
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public record MapDecoration(String type, double x, double z, float rotation) { public record MapDecoration(String type, double x, double z, float rotation) {
@ -30,16 +31,16 @@ public record MapDecoration(String type, double x, double z, float rotation) {
public static final Type<MapDecoration> TYPE = new Type<>(MapDecoration.class) { public static final Type<MapDecoration> TYPE = new Type<>(MapDecoration.class) {
@Override @Override
public MapDecoration read(final ByteBuf buffer) { public MapDecoration read(final ByteBuf buffer) {
final String type = Type.STRING.read(buffer); final String type = Types.STRING.read(buffer);
final double x = Type.DOUBLE.readPrimitive(buffer); final double x = Types.DOUBLE.readPrimitive(buffer);
final double z = Type.DOUBLE.readPrimitive(buffer); final double z = Types.DOUBLE.readPrimitive(buffer);
final float rotation = Type.FLOAT.readPrimitive(buffer); final float rotation = Types.FLOAT.readPrimitive(buffer);
return new MapDecoration(type, x, z, rotation); return new MapDecoration(type, x, z, rotation);
} }
@Override @Override
public void write(final ByteBuf buffer, final MapDecoration value) { public void write(final ByteBuf buffer, final MapDecoration value) {
Type.STRING.write(buffer, value.type); Types.STRING.write(buffer, value.type);
buffer.writeDouble(value.x); buffer.writeDouble(value.x);
buffer.writeDouble(value.z); buffer.writeDouble(value.z);
buffer.writeFloat(value.rotation); buffer.writeFloat(value.rotation);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
@ -34,9 +35,9 @@ public record MapDecorations(Map<String, MapDecoration> decorations) {
@Override @Override
public MapDecorations read(final ByteBuf buffer) { public MapDecorations read(final ByteBuf buffer) {
final Object2ObjectMap<String, MapDecoration> decorations = new Object2ObjectOpenHashMap<>(); final Object2ObjectMap<String, MapDecoration> decorations = new Object2ObjectOpenHashMap<>();
final int size = Type.VAR_INT.readPrimitive(buffer); final int size = Types.VAR_INT.readPrimitive(buffer);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final String id = Type.STRING.read(buffer); final String id = Types.STRING.read(buffer);
final MapDecoration decoration = MapDecoration.TYPE.read(buffer); final MapDecoration decoration = MapDecoration.TYPE.read(buffer);
decorations.put(id, decoration); decorations.put(id, decoration);
} }
@ -45,9 +46,9 @@ public record MapDecorations(Map<String, MapDecoration> decorations) {
@Override @Override
public void write(final ByteBuf buffer, final MapDecorations value) { public void write(final ByteBuf buffer, final MapDecorations value) {
Type.VAR_INT.writePrimitive(buffer, value.decorations.size()); Types.VAR_INT.writePrimitive(buffer, value.decorations.size());
for (final Map.Entry<String, MapDecoration> entry : value.decorations.entrySet()) { for (final Map.Entry<String, MapDecoration> entry : value.decorations.entrySet()) {
Type.STRING.write(buffer, entry.getKey()); Types.STRING.write(buffer, entry.getKey());
MapDecoration.TYPE.write(buffer, entry.getValue()); MapDecoration.TYPE.write(buffer, entry.getValue());
} }
} }

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
@ -31,19 +32,19 @@ public record ModifierData(UUID uuid, String name, double amount, int operation)
public static final Type<ModifierData> TYPE = new Type<>(ModifierData.class) { public static final Type<ModifierData> TYPE = new Type<>(ModifierData.class) {
@Override @Override
public ModifierData read(final ByteBuf buffer) { public ModifierData read(final ByteBuf buffer) {
final UUID uuid = Type.UUID.read(buffer); final UUID uuid = Types.UUID.read(buffer);
final String name = Type.STRING.read(buffer); final String name = Types.STRING.read(buffer);
final double amount = buffer.readDouble(); final double amount = buffer.readDouble();
final int operation = Type.VAR_INT.readPrimitive(buffer); final int operation = Types.VAR_INT.readPrimitive(buffer);
return new ModifierData(uuid, name, amount, operation); return new ModifierData(uuid, name, amount, operation);
} }
@Override @Override
public void write(final ByteBuf buffer, final ModifierData value) { public void write(final ByteBuf buffer, final ModifierData value) {
Type.UUID.write(buffer, value.uuid); Types.UUID.write(buffer, value.uuid);
Type.STRING.write(buffer, value.name); Types.STRING.write(buffer, value.name);
buffer.writeDouble(value.amount); buffer.writeDouble(value.amount);
Type.VAR_INT.writePrimitive(buffer, value.operation); Types.VAR_INT.writePrimitive(buffer, value.operation);
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public final class PotDecorations { public final class PotDecorations {
@ -30,12 +31,12 @@ public final class PotDecorations {
public static final Type<PotDecorations> TYPE = new Type<>(PotDecorations.class) { public static final Type<PotDecorations> TYPE = new Type<>(PotDecorations.class) {
@Override @Override
public PotDecorations read(final ByteBuf buffer) { public PotDecorations read(final ByteBuf buffer) {
return new PotDecorations(Type.VAR_INT_ARRAY_PRIMITIVE.read(buffer)); return new PotDecorations(Types.VAR_INT_ARRAY_PRIMITIVE.read(buffer));
} }
@Override @Override
public void write(final ByteBuf buffer, final PotDecorations value) { public void write(final ByteBuf buffer, final PotDecorations value) {
Type.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds()); Types.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds());
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -31,7 +32,7 @@ public record PotionContents(@Nullable Integer potion, @Nullable Integer customC
public static final Type<PotionContents> TYPE = new Type<>(PotionContents.class) { public static final Type<PotionContents> TYPE = new Type<>(PotionContents.class) {
@Override @Override
public PotionContents read(final ByteBuf buffer) { public PotionContents read(final ByteBuf buffer) {
final Integer potion = buffer.readBoolean() ? Type.VAR_INT.readPrimitive(buffer) : null; final Integer potion = buffer.readBoolean() ? Types.VAR_INT.readPrimitive(buffer) : null;
final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null; final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null;
final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer); final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer);
return new PotionContents(potion, customColor, customEffects); return new PotionContents(potion, customColor, customEffects);
@ -41,7 +42,7 @@ public record PotionContents(@Nullable Integer potion, @Nullable Integer customC
public void write(final ByteBuf buffer, final PotionContents value) { public void write(final ByteBuf buffer, final PotionContents value) {
buffer.writeBoolean(value.potion != null); buffer.writeBoolean(value.potion != null);
if (value.potion != null) { if (value.potion != null) {
Type.VAR_INT.writePrimitive(buffer, value.potion); Types.VAR_INT.writePrimitive(buffer, value.potion);
} }
buffer.writeBoolean(value.customColor != null); buffer.writeBoolean(value.customColor != null);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -31,14 +32,14 @@ public record PotionEffect(int effect, PotionEffectData effectData) {
public static final Type<PotionEffect> TYPE = new Type<>(PotionEffect.class) { public static final Type<PotionEffect> TYPE = new Type<>(PotionEffect.class) {
@Override @Override
public PotionEffect read(final ByteBuf buffer) { public PotionEffect read(final ByteBuf buffer) {
final int effect = Type.VAR_INT.readPrimitive(buffer); final int effect = Types.VAR_INT.readPrimitive(buffer);
final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer); final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer);
return new PotionEffect(effect, effectData); return new PotionEffect(effect, effectData);
} }
@Override @Override
public void write(final ByteBuf buffer, final PotionEffect value) { public void write(final ByteBuf buffer, final PotionEffect value) {
Type.VAR_INT.writePrimitive(buffer, value.effect); Types.VAR_INT.writePrimitive(buffer, value.effect);
PotionEffectData.TYPE.write(buffer, value.effectData); PotionEffectData.TYPE.write(buffer, value.effectData);
} }
}; };

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -33,8 +34,8 @@ public record PotionEffectData(int amplifier, int duration, boolean ambient, boo
public static final Type<PotionEffectData> TYPE = new Type<>(PotionEffectData.class) { public static final Type<PotionEffectData> TYPE = new Type<>(PotionEffectData.class) {
@Override @Override
public PotionEffectData read(final ByteBuf buffer) { public PotionEffectData read(final ByteBuf buffer) {
final int amplifier = Type.VAR_INT.readPrimitive(buffer); final int amplifier = Types.VAR_INT.readPrimitive(buffer);
final int duration = Type.VAR_INT.readPrimitive(buffer); final int duration = Types.VAR_INT.readPrimitive(buffer);
final boolean ambient = buffer.readBoolean(); final boolean ambient = buffer.readBoolean();
final boolean showParticles = buffer.readBoolean(); final boolean showParticles = buffer.readBoolean();
final boolean showIcon = buffer.readBoolean(); final boolean showIcon = buffer.readBoolean();
@ -44,8 +45,8 @@ public record PotionEffectData(int amplifier, int duration, boolean ambient, boo
@Override @Override
public void write(final ByteBuf buffer, final PotionEffectData value) { public void write(final ByteBuf buffer, final PotionEffectData value) {
Type.VAR_INT.writePrimitive(buffer, value.amplifier); Types.VAR_INT.writePrimitive(buffer, value.amplifier);
Type.VAR_INT.writePrimitive(buffer, value.duration); Types.VAR_INT.writePrimitive(buffer, value.duration);
buffer.writeBoolean(value.ambient); buffer.writeBoolean(value.ambient);
buffer.writeBoolean(value.showParticles); buffer.writeBoolean(value.showParticles);
buffer.writeBoolean(value.showIcon); buffer.writeBoolean(value.showIcon);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import com.viaversion.viaversion.util.Either; import com.viaversion.viaversion.util.Either;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -34,27 +35,27 @@ public record StatePropertyMatcher(String name, Either<String, RangedMatcher> ma
public static final Type<StatePropertyMatcher> TYPE = new Type<>(StatePropertyMatcher.class) { public static final Type<StatePropertyMatcher> TYPE = new Type<>(StatePropertyMatcher.class) {
@Override @Override
public StatePropertyMatcher read(final ByteBuf buffer) { public StatePropertyMatcher read(final ByteBuf buffer) {
final String name = Type.STRING.read(buffer); final String name = Types.STRING.read(buffer);
if (buffer.readBoolean()) { if (buffer.readBoolean()) {
final String value = Type.STRING.read(buffer); final String value = Types.STRING.read(buffer);
return new StatePropertyMatcher(name, Either.left(value)); return new StatePropertyMatcher(name, Either.left(value));
} else { } else {
final String minValue = Type.OPTIONAL_STRING.read(buffer); final String minValue = Types.OPTIONAL_STRING.read(buffer);
final String maxValue = Type.OPTIONAL_STRING.read(buffer); final String maxValue = Types.OPTIONAL_STRING.read(buffer);
return new StatePropertyMatcher(name, Either.right(new RangedMatcher(minValue, maxValue))); return new StatePropertyMatcher(name, Either.right(new RangedMatcher(minValue, maxValue)));
} }
} }
@Override @Override
public void write(final ByteBuf buffer, final StatePropertyMatcher value) { public void write(final ByteBuf buffer, final StatePropertyMatcher value) {
Type.STRING.write(buffer, value.name); Types.STRING.write(buffer, value.name);
if (value.matcher.isLeft()) { if (value.matcher.isLeft()) {
buffer.writeBoolean(true); buffer.writeBoolean(true);
Type.STRING.write(buffer, value.matcher.left()); Types.STRING.write(buffer, value.matcher.left());
} else { } else {
buffer.writeBoolean(false); buffer.writeBoolean(false);
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().minValue()); Types.OPTIONAL_STRING.write(buffer, value.matcher.right().minValue());
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().maxValue()); Types.OPTIONAL_STRING.write(buffer, value.matcher.right().maxValue());
} }
} }
}; };

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -31,15 +32,15 @@ public record SuspiciousStewEffect(int mobEffect, int duration) {
public static final Type<SuspiciousStewEffect> TYPE = new Type<>(SuspiciousStewEffect.class) { public static final Type<SuspiciousStewEffect> TYPE = new Type<>(SuspiciousStewEffect.class) {
@Override @Override
public SuspiciousStewEffect read(final ByteBuf buffer) { public SuspiciousStewEffect read(final ByteBuf buffer) {
final int effect = Type.VAR_INT.readPrimitive(buffer); final int effect = Types.VAR_INT.readPrimitive(buffer);
final int duration = Type.VAR_INT.readPrimitive(buffer); final int duration = Types.VAR_INT.readPrimitive(buffer);
return new SuspiciousStewEffect(effect, duration); return new SuspiciousStewEffect(effect, duration);
} }
@Override @Override
public void write(final ByteBuf buffer, final SuspiciousStewEffect value) { public void write(final ByteBuf buffer, final SuspiciousStewEffect value) {
Type.VAR_INT.writePrimitive(buffer, value.mobEffect); Types.VAR_INT.writePrimitive(buffer, value.mobEffect);
Type.VAR_INT.writePrimitive(buffer, value.duration); Types.VAR_INT.writePrimitive(buffer, value.duration);
} }
}; };
public static final Type<SuspiciousStewEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE); public static final Type<SuspiciousStewEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int damagePerBlock) { public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int damagePerBlock) {
@ -32,7 +33,7 @@ public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int dam
public ToolProperties read(final ByteBuf buffer) { public ToolProperties read(final ByteBuf buffer) {
final ToolRule[] rules = ToolRule.ARRAY_TYPE.read(buffer); final ToolRule[] rules = ToolRule.ARRAY_TYPE.read(buffer);
final float defaultMiningSpeed = buffer.readFloat(); final float defaultMiningSpeed = buffer.readFloat();
final int damagePerBlock = Type.VAR_INT.readPrimitive(buffer); final int damagePerBlock = Types.VAR_INT.readPrimitive(buffer);
return new ToolProperties(rules, defaultMiningSpeed, damagePerBlock); return new ToolProperties(rules, defaultMiningSpeed, damagePerBlock);
} }
@ -40,7 +41,7 @@ public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int dam
public void write(final ByteBuf buffer, final ToolProperties value) { public void write(final ByteBuf buffer, final ToolProperties value) {
ToolRule.ARRAY_TYPE.write(buffer, value.rules()); ToolRule.ARRAY_TYPE.write(buffer, value.rules());
buffer.writeFloat(value.defaultMiningSpeed()); buffer.writeFloat(value.defaultMiningSpeed());
Type.VAR_INT.writePrimitive(buffer, value.damagePerBlock()); Types.VAR_INT.writePrimitive(buffer, value.damagePerBlock());
} }
}; };

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -33,17 +34,17 @@ public record ToolRule(HolderSet blocks, @Nullable Float speed, @Nullable Boolea
public static final Type<ToolRule> TYPE = new Type<>(ToolRule.class) { public static final Type<ToolRule> TYPE = new Type<>(ToolRule.class) {
@Override @Override
public ToolRule read(final ByteBuf buffer) { public ToolRule read(final ByteBuf buffer) {
final HolderSet blocks = Type.HOLDER_SET.read(buffer); final HolderSet blocks = Types.HOLDER_SET.read(buffer);
final Float speed = Type.OPTIONAL_FLOAT.read(buffer); final Float speed = Types.OPTIONAL_FLOAT.read(buffer);
final Boolean correctForDrops = Type.OPTIONAL_BOOLEAN.read(buffer); final Boolean correctForDrops = Types.OPTIONAL_BOOLEAN.read(buffer);
return new ToolRule(blocks, speed, correctForDrops); return new ToolRule(blocks, speed, correctForDrops);
} }
@Override @Override
public void write(final ByteBuf buffer, final ToolRule value) { public void write(final ByteBuf buffer, final ToolRule value) {
Type.HOLDER_SET.write(buffer, value.blocks); Types.HOLDER_SET.write(buffer, value.blocks);
Type.OPTIONAL_FLOAT.write(buffer, value.speed); Types.OPTIONAL_FLOAT.write(buffer, value.speed);
Type.OPTIONAL_BOOLEAN.write(buffer, value.correctForDrops); Types.OPTIONAL_BOOLEAN.write(buffer, value.correctForDrops);
} }
}; };
public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE); public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE);

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item.data; package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public record WrittenBook(FilterableString title, String author, int generation, FilterableComponent[] pages, public record WrittenBook(FilterableString title, String author, int generation, FilterableComponent[] pages,
@ -32,8 +33,8 @@ public record WrittenBook(FilterableString title, String author, int generation,
@Override @Override
public WrittenBook read(final ByteBuf buffer) { public WrittenBook read(final ByteBuf buffer) {
final FilterableString title = FilterableString.TYPE.read(buffer); final FilterableString title = FilterableString.TYPE.read(buffer);
final String author = Type.STRING.read(buffer); final String author = Types.STRING.read(buffer);
final int generation = Type.VAR_INT.readPrimitive(buffer); final int generation = Types.VAR_INT.readPrimitive(buffer);
final FilterableComponent[] pages = FilterableComponent.ARRAY_TYPE.read(buffer); final FilterableComponent[] pages = FilterableComponent.ARRAY_TYPE.read(buffer);
final boolean resolved = buffer.readBoolean(); final boolean resolved = buffer.readBoolean();
return new WrittenBook(title, author, generation, pages, resolved); return new WrittenBook(title, author, generation, pages, resolved);
@ -42,8 +43,8 @@ public record WrittenBook(FilterableString title, String author, int generation,
@Override @Override
public void write(final ByteBuf buffer, final WrittenBook value) { public void write(final ByteBuf buffer, final WrittenBook value) {
FilterableString.TYPE.write(buffer, value.title); FilterableString.TYPE.write(buffer, value.title);
Type.STRING.write(buffer, value.author); Types.STRING.write(buffer, value.author);
Type.VAR_INT.writePrimitive(buffer, value.generation); Types.VAR_INT.writePrimitive(buffer, value.generation);
FilterableComponent.ARRAY_TYPE.write(buffer, value.pages); FilterableComponent.ARRAY_TYPE.write(buffer, value.pages);
buffer.writeBoolean(value.resolved); buffer.writeBoolean(value.resolved);
} }

Datei anzeigen

@ -24,28 +24,27 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
public enum MetaType1_12 implements MetaType { public enum MetaType1_12 implements MetaType {
Byte(0, Type.BYTE), BYTE(Types.BYTE),
VarInt(1, Type.VAR_INT), VAR_INT(Types.VAR_INT),
Float(2, Type.FLOAT), FLOAT(Types.FLOAT),
String(3, Type.STRING), STRING(Types.STRING),
Chat(4, Type.COMPONENT), COMPONENT(Types.COMPONENT),
Slot(5, Type.ITEM1_8), ITEM(Types.ITEM1_8),
Boolean(6, Type.BOOLEAN), BOOLEAN(Types.BOOLEAN),
Vector3F(7, Type.ROTATION), ROTATIONS(Types.ROTATIONS),
Position(8, Type.POSITION1_8), BLOCK_POSITION(Types.BLOCK_POSITION1_8),
OptPosition(9, Type.OPTIONAL_POSITION1_8), OPTIONAL_BLOCK_POSITION(Types.OPTIONAL_POSITION1_8),
Direction(10, Type.VAR_INT), DIRECTION(Types.VAR_INT),
OptUUID(11, Type.OPTIONAL_UUID), OPTIONAL_UUID(Types.OPTIONAL_UUID),
BlockID(12, Type.VAR_INT), OPTIONAL_BLOCK_STATE(Types.VAR_INT),
NBTTag(13, Type.NAMED_COMPOUND_TAG); COMPOUND_TAG(Types.NAMED_COMPOUND_TAG);
private final int typeID; private final Type<?> type;
private final Type type;
MetaType1_12(int typeID, Type type) { MetaType1_12(Type<?> type) {
this.typeID = typeID;
this.type = type; this.type = type;
} }
@ -55,7 +54,7 @@ public enum MetaType1_12 implements MetaType {
@Override @Override
public int typeId() { public int typeId() {
return typeID; return ordinal();
} }
@Override @Override

Datei anzeigen

@ -24,22 +24,21 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
public enum MetaType1_8 implements MetaType { public enum MetaType1_8 implements MetaType {
Byte(0, Type.BYTE), BYTE(Types.BYTE),
Short(1, Type.SHORT), SHORT(Types.SHORT),
Int(2, Type.INT), INT(Types.INT),
Float(3, Type.FLOAT), FLOAT(Types.FLOAT),
String(4, Type.STRING), STRING(Types.STRING),
Slot(5, Type.ITEM1_8), ITEM(Types.ITEM1_8),
Position(6, Type.VECTOR), BLOCK_POSITION(Types.VECTOR),
Rotation(7, Type.ROTATION); ROTATIONS(Types.ROTATIONS);
private final int typeID; private final Type<?> type;
private final Type type;
MetaType1_8(int typeID, Type type) { MetaType1_8(Type<?> type) {
this.typeID = typeID;
this.type = type; this.type = type;
} }
@ -49,7 +48,7 @@ public enum MetaType1_8 implements MetaType {
@Override @Override
public int typeId() { public int typeId() {
return typeID; return ordinal();
} }
@Override @Override

Datei anzeigen

@ -24,27 +24,26 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
public enum MetaType1_9 implements MetaType { public enum MetaType1_9 implements MetaType {
Byte(0, Type.BYTE), BYTE(Types.BYTE),
VarInt(1, Type.VAR_INT), VAR_INT(Types.VAR_INT),
Float(2, Type.FLOAT), FLOAT(Types.FLOAT),
String(3, Type.STRING), STRING(Types.STRING),
Chat(4, Type.COMPONENT), COMPONENT(Types.COMPONENT),
Slot(5, Type.ITEM1_8), ITEM(Types.ITEM1_8),
Boolean(6, Type.BOOLEAN), BOOLEAN(Types.BOOLEAN),
Vector3F(7, Type.ROTATION), ROTATIONS(Types.ROTATIONS),
Position(8, Type.POSITION1_8), BLOCK_POSITION(Types.BLOCK_POSITION1_8),
OptPosition(9, Type.OPTIONAL_POSITION1_8), OPTIONAL_BLOCK_POSITION(Types.OPTIONAL_POSITION1_8),
Direction(10, Type.VAR_INT), DIRECTION(Types.VAR_INT),
OptUUID(11, Type.OPTIONAL_UUID), OPTIONAL_UUID(Types.OPTIONAL_UUID),
BlockID(12, Type.VAR_INT); OPTIONAL_BLOCK_STATE(Types.VAR_INT);
private final int typeID; private final Type<?> type;
private final Type type;
MetaType1_9(int typeID, Type type) { MetaType1_9(Type<?> type) {
this.typeID = typeID;
this.type = type; this.type = type;
} }
@ -54,7 +53,7 @@ public enum MetaType1_9 implements MetaType {
@Override @Override
public int typeId() { public int typeId() {
return typeID; return ordinal();
} }
@Override @Override

Datei anzeigen

@ -24,25 +24,26 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_13 extends AbstractMetaTypes { public final class MetaTypes1_13 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType floatType = add(2, Type.FLOAT); public final MetaType floatType = add(2, Types.FLOAT);
public final MetaType stringType = add(3, Type.STRING); public final MetaType stringType = add(3, Types.STRING);
public final MetaType componentType = add(4, Type.COMPONENT); public final MetaType componentType = add(4, Types.COMPONENT);
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(5, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(6, Type.ITEM1_13); public final MetaType itemType = add(6, Types.ITEM1_13);
public final MetaType booleanType = add(7, Type.BOOLEAN); public final MetaType booleanType = add(7, Types.BOOLEAN);
public final MetaType rotationType = add(8, Type.ROTATION); public final MetaType rotationsType = add(8, Types.ROTATIONS);
public final MetaType positionType = add(9, Type.POSITION1_8); public final MetaType blockPositionType = add(9, Types.BLOCK_POSITION1_8);
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION1_8); public final MetaType optionalBlockPositionType = add(10, Types.OPTIONAL_POSITION1_8);
public final MetaType directionType = add(11, Type.VAR_INT); public final MetaType directionType = add(11, Types.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(12, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT); public final MetaType optionalBlockStateType = add(13, Types.VAR_INT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG); public final MetaType compoundTagType = add(14, Types.NAMED_COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public MetaTypes1_13(final ParticleType particleType) { public MetaTypes1_13(final ParticleType particleType) {

Datei anzeigen

@ -24,25 +24,26 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_13_2 extends AbstractMetaTypes { public final class MetaTypes1_13_2 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType floatType = add(2, Type.FLOAT); public final MetaType floatType = add(2, Types.FLOAT);
public final MetaType stringType = add(3, Type.STRING); public final MetaType stringType = add(3, Types.STRING);
public final MetaType componentType = add(4, Type.COMPONENT); public final MetaType componentType = add(4, Types.COMPONENT);
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(5, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(6, Type.ITEM1_13_2); public final MetaType itemType = add(6, Types.ITEM1_13_2);
public final MetaType booleanType = add(7, Type.BOOLEAN); public final MetaType booleanType = add(7, Types.BOOLEAN);
public final MetaType rotationType = add(8, Type.ROTATION); public final MetaType rotationsType = add(8, Types.ROTATIONS);
public final MetaType positionType = add(9, Type.POSITION1_8); public final MetaType blockPositionType = add(9, Types.BLOCK_POSITION1_8);
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION1_8); public final MetaType optionalBlockPositionType = add(10, Types.OPTIONAL_POSITION1_8);
public final MetaType directionType = add(11, Type.VAR_INT); public final MetaType directionType = add(11, Types.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(12, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT); public final MetaType optionalBlockStateType = add(13, Types.VAR_INT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG); public final MetaType compoundTagType = add(14, Types.NAMED_COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public MetaTypes1_13_2(final ParticleType particleType) { public MetaTypes1_13_2(final ParticleType particleType) {

Datei anzeigen

@ -24,29 +24,30 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_14 extends AbstractMetaTypes { public final class MetaTypes1_14 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType floatType = add(2, Type.FLOAT); public final MetaType floatType = add(2, Types.FLOAT);
public final MetaType stringType = add(3, Type.STRING); public final MetaType stringType = add(3, Types.STRING);
public final MetaType componentType = add(4, Type.COMPONENT); public final MetaType componentType = add(4, Types.COMPONENT);
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(5, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(6, Type.ITEM1_13_2); public final MetaType itemType = add(6, Types.ITEM1_13_2);
public final MetaType booleanType = add(7, Type.BOOLEAN); public final MetaType booleanType = add(7, Types.BOOLEAN);
public final MetaType rotationType = add(8, Type.ROTATION); public final MetaType rotationsType = add(8, Types.ROTATIONS);
public final MetaType positionType = add(9, Type.POSITION1_14); public final MetaType blockPositionType = add(9, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(10, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(11, Type.VAR_INT); public final MetaType directionType = add(11, Types.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(12, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT); public final MetaType optionalBlockStateType = add(13, Types.VAR_INT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG); public final MetaType compoundTagType = add(14, Types.NAMED_COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(16, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(17, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(18, Type.VAR_INT); public final MetaType poseType = add(18, Types.VAR_INT);
public MetaTypes1_14(final ParticleType particleType) { public MetaTypes1_14(final ParticleType particleType) {
super(19); super(19);

Datei anzeigen

@ -24,33 +24,34 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_19 extends AbstractMetaTypes { public final class MetaTypes1_19 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType floatType = add(2, Type.FLOAT); public final MetaType floatType = add(2, Types.FLOAT);
public final MetaType stringType = add(3, Type.STRING); public final MetaType stringType = add(3, Types.STRING);
public final MetaType componentType = add(4, Type.COMPONENT); public final MetaType componentType = add(4, Types.COMPONENT);
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(5, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(6, Type.ITEM1_13_2); public final MetaType itemType = add(6, Types.ITEM1_13_2);
public final MetaType booleanType = add(7, Type.BOOLEAN); public final MetaType booleanType = add(7, Types.BOOLEAN);
public final MetaType rotationType = add(8, Type.ROTATION); public final MetaType rotationsType = add(8, Types.ROTATIONS);
public final MetaType positionType = add(9, Type.POSITION1_14); public final MetaType blockPositionType = add(9, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(10, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(11, Type.VAR_INT); public final MetaType directionType = add(11, Types.VAR_INT);
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(12, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(13, Type.VAR_INT); public final MetaType optionalBlockStateType = add(13, Types.VAR_INT);
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG); public final MetaType compoundTagType = add(14, Types.NAMED_COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(16, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(17, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(18, Type.VAR_INT); public final MetaType poseType = add(18, Types.VAR_INT);
public final MetaType catVariantType = add(19, Type.VAR_INT); public final MetaType catVariantType = add(19, Types.VAR_INT);
public final MetaType frogVariantType = add(20, Type.VAR_INT); public final MetaType frogVariantType = add(20, Types.VAR_INT);
public final MetaType optionalGlobalPosition = add(21, Type.OPTIONAL_GLOBAL_POSITION); public final MetaType optionalGlobalPosition = add(21, Types.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(22, Type.VAR_INT); public final MetaType paintingVariantType = add(22, Types.VAR_INT);
public MetaTypes1_19(final ParticleType particleType) { public MetaTypes1_19(final ParticleType particleType) {
super(23); super(23);

Datei anzeigen

@ -24,34 +24,35 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_19_3 extends AbstractMetaTypes { public final class MetaTypes1_19_3 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType longType = add(2, Type.VAR_LONG); public final MetaType longType = add(2, Types.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT); public final MetaType floatType = add(3, Types.FLOAT);
public final MetaType stringType = add(4, Type.STRING); public final MetaType stringType = add(4, Types.STRING);
public final MetaType componentType = add(5, Type.COMPONENT); public final MetaType componentType = add(5, Types.COMPONENT);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(6, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(7, Type.ITEM1_13_2); public final MetaType itemType = add(7, Types.ITEM1_13_2);
public final MetaType booleanType = add(8, Type.BOOLEAN); public final MetaType booleanType = add(8, Types.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION); public final MetaType rotationsType = add(9, Types.ROTATIONS);
public final MetaType positionType = add(10, Type.POSITION1_14); public final MetaType blockPositionType = add(10, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(11, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(12, Type.VAR_INT); public final MetaType directionType = add(12, Types.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(13, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT); public final MetaType optionalBlockStateType = add(14, Types.VAR_INT);
public final MetaType nbtType = add(15, Type.NAMED_COMPOUND_TAG); public final MetaType compoundTagType = add(15, Types.NAMED_COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType villagerDatatType = add(17, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(17, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(18, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(18, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(19, Type.VAR_INT); public final MetaType poseType = add(19, Types.VAR_INT);
public final MetaType catVariantType = add(20, Type.VAR_INT); public final MetaType catVariantType = add(20, Types.VAR_INT);
public final MetaType frogVariantType = add(21, Type.VAR_INT); public final MetaType frogVariantType = add(21, Types.VAR_INT);
public final MetaType optionalGlobalPosition = add(22, Type.OPTIONAL_GLOBAL_POSITION); public final MetaType optionalGlobalPosition = add(22, Types.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(23, Type.VAR_INT); public final MetaType paintingVariantType = add(23, Types.VAR_INT);
public MetaTypes1_19_3(final ParticleType particleType) { public MetaTypes1_19_3(final ParticleType particleType) {
super(24); super(24);

Datei anzeigen

@ -24,38 +24,39 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_19_4 extends AbstractMetaTypes { public final class MetaTypes1_19_4 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType longType = add(2, Type.VAR_LONG); public final MetaType longType = add(2, Types.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT); public final MetaType floatType = add(3, Types.FLOAT);
public final MetaType stringType = add(4, Type.STRING); public final MetaType stringType = add(4, Types.STRING);
public final MetaType componentType = add(5, Type.COMPONENT); public final MetaType componentType = add(5, Types.COMPONENT);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(6, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(7, Type.ITEM1_13_2); public final MetaType itemType = add(7, Types.ITEM1_13_2);
public final MetaType booleanType = add(8, Type.BOOLEAN); public final MetaType booleanType = add(8, Types.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION); public final MetaType rotationsType = add(9, Types.ROTATIONS);
public final MetaType positionType = add(10, Type.POSITION1_14); public final MetaType blockPositionType = add(10, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(11, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(12, Type.VAR_INT); public final MetaType directionType = add(12, Types.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(13, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT); public final MetaType blockStateType = add(14, Types.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT); public final MetaType optionalBlockStateType = add(15, Types.VAR_INT);
public final MetaType nbtType = add(16, Type.NAMED_COMPOUND_TAG); public final MetaType compoundTagType = add(16, Types.NAMED_COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(18, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(19, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(20, Type.VAR_INT); public final MetaType poseType = add(20, Types.VAR_INT);
public final MetaType catVariantType = add(21, Type.VAR_INT); public final MetaType catVariantType = add(21, Types.VAR_INT);
public final MetaType frogVariantType = add(22, Type.VAR_INT); public final MetaType frogVariantType = add(22, Types.VAR_INT);
public final MetaType optionalGlobalPosition = add(23, Type.OPTIONAL_GLOBAL_POSITION); public final MetaType optionalGlobalPosition = add(23, Types.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(24, Type.VAR_INT); public final MetaType paintingVariantType = add(24, Types.VAR_INT);
public final MetaType snifferState = add(25, Type.VAR_INT); public final MetaType snifferState = add(25, Types.VAR_INT);
public final MetaType vectorType = add(26, Type.VECTOR3F); public final MetaType vector3FType = add(26, Types.VECTOR3F);
public final MetaType quaternionType = add(27, Type.QUATERNION); public final MetaType quaternionType = add(27, Types.QUATERNION);
public MetaTypes1_19_4(final ParticleType particleType) { public MetaTypes1_19_4(final ParticleType particleType) {
super(28); super(28);

Datei anzeigen

@ -24,38 +24,39 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_20_2 extends AbstractMetaTypes { public final class MetaTypes1_20_2 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType longType = add(2, Type.VAR_LONG); public final MetaType longType = add(2, Types.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT); public final MetaType floatType = add(3, Types.FLOAT);
public final MetaType stringType = add(4, Type.STRING); public final MetaType stringType = add(4, Types.STRING);
public final MetaType componentType = add(5, Type.COMPONENT); public final MetaType componentType = add(5, Types.COMPONENT);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPONENT); public final MetaType optionalComponentType = add(6, Types.OPTIONAL_COMPONENT);
public final MetaType itemType = add(7, Type.ITEM1_20_2); public final MetaType itemType = add(7, Types.ITEM1_20_2);
public final MetaType booleanType = add(8, Type.BOOLEAN); public final MetaType booleanType = add(8, Types.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION); public final MetaType rotationsType = add(9, Types.ROTATIONS);
public final MetaType positionType = add(10, Type.POSITION1_14); public final MetaType blockPositionType = add(10, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(11, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(12, Type.VAR_INT); public final MetaType directionType = add(12, Types.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(13, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT); public final MetaType blockStateType = add(14, Types.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT); public final MetaType optionalBlockStateType = add(15, Types.VAR_INT);
public final MetaType nbtType = add(16, Type.COMPOUND_TAG); public final MetaType compoundTagType = add(16, Types.COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(18, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(19, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(20, Type.VAR_INT); public final MetaType poseType = add(20, Types.VAR_INT);
public final MetaType catVariantType = add(21, Type.VAR_INT); public final MetaType catVariantType = add(21, Types.VAR_INT);
public final MetaType frogVariantType = add(22, Type.VAR_INT); public final MetaType frogVariantType = add(22, Types.VAR_INT);
public final MetaType optionalGlobalPosition = add(23, Type.OPTIONAL_GLOBAL_POSITION); public final MetaType optionalGlobalPosition = add(23, Types.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(24, Type.VAR_INT); public final MetaType paintingVariantType = add(24, Types.VAR_INT);
public final MetaType snifferState = add(25, Type.VAR_INT); public final MetaType snifferState = add(25, Types.VAR_INT);
public final MetaType vectorType = add(26, Type.VECTOR3F); public final MetaType vector3FType = add(26, Types.VECTOR3F);
public final MetaType quaternionType = add(27, Type.QUATERNION); public final MetaType quaternionType = add(27, Types.QUATERNION);
public MetaTypes1_20_2(final ParticleType particleType) { public MetaTypes1_20_2(final ParticleType particleType) {
super(28); super(28);

Datei anzeigen

@ -24,38 +24,39 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
public final class MetaTypes1_20_3 extends AbstractMetaTypes { public final class MetaTypes1_20_3 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType longType = add(2, Type.VAR_LONG); public final MetaType longType = add(2, Types.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT); public final MetaType floatType = add(3, Types.FLOAT);
public final MetaType stringType = add(4, Type.STRING); public final MetaType stringType = add(4, Types.STRING);
public final MetaType componentType = add(5, Type.TAG); public final MetaType componentType = add(5, Types.TAG);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG); public final MetaType optionalComponentType = add(6, Types.OPTIONAL_TAG);
public final MetaType itemType = add(7, Type.ITEM1_20_2); public final MetaType itemType = add(7, Types.ITEM1_20_2);
public final MetaType booleanType = add(8, Type.BOOLEAN); public final MetaType booleanType = add(8, Types.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION); public final MetaType rotationsType = add(9, Types.ROTATIONS);
public final MetaType positionType = add(10, Type.POSITION1_14); public final MetaType blockPositionType = add(10, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(11, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(12, Type.VAR_INT); public final MetaType directionType = add(12, Types.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(13, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT); public final MetaType blockStateType = add(14, Types.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT); public final MetaType optionalBlockStateType = add(15, Types.VAR_INT);
public final MetaType nbtType = add(16, Type.COMPOUND_TAG); public final MetaType compoundTagType = add(16, Types.COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(18, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(19, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(20, Type.VAR_INT); public final MetaType poseType = add(20, Types.VAR_INT);
public final MetaType catVariantType = add(21, Type.VAR_INT); public final MetaType catVariantType = add(21, Types.VAR_INT);
public final MetaType frogVariantType = add(22, Type.VAR_INT); public final MetaType frogVariantType = add(22, Types.VAR_INT);
public final MetaType optionalGlobalPosition = add(23, Type.OPTIONAL_GLOBAL_POSITION); public final MetaType optionalGlobalPosition = add(23, Types.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(24, Type.VAR_INT); public final MetaType paintingVariantType = add(24, Types.VAR_INT);
public final MetaType snifferState = add(25, Type.VAR_INT); public final MetaType snifferState = add(25, Types.VAR_INT);
public final MetaType vectorType = add(26, Type.VECTOR3F); public final MetaType vector3FType = add(26, Types.VECTOR3F);
public final MetaType quaternionType = add(27, Type.QUATERNION); public final MetaType quaternionType = add(27, Types.QUATERNION);
public MetaTypes1_20_3(final ParticleType particleType) { public MetaTypes1_20_3(final ParticleType particleType) {
super(28); super(28);

Datei anzeigen

@ -25,43 +25,44 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type; 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.ArrayType;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
public final class MetaTypes1_20_5 extends AbstractMetaTypes { public final class MetaTypes1_20_5 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE); public final MetaType byteType = add(0, Types.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT); public final MetaType varIntType = add(1, Types.VAR_INT);
public final MetaType longType = add(2, Type.VAR_LONG); public final MetaType longType = add(2, Types.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT); public final MetaType floatType = add(3, Types.FLOAT);
public final MetaType stringType = add(4, Type.STRING); public final MetaType stringType = add(4, Types.STRING);
public final MetaType componentType = add(5, Type.TAG); public final MetaType componentType = add(5, Types.TAG);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG); public final MetaType optionalComponentType = add(6, Types.OPTIONAL_TAG);
public final MetaType itemType = add(7, Types1_20_5.ITEM); public final MetaType itemType = add(7, Types1_20_5.ITEM);
public final MetaType booleanType = add(8, Type.BOOLEAN); public final MetaType booleanType = add(8, Types.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION); public final MetaType rotationsType = add(9, Types.ROTATIONS);
public final MetaType positionType = add(10, Type.POSITION1_14); public final MetaType blockPositionType = add(10, Types.BLOCK_POSITION1_14);
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14); public final MetaType optionalBlockPositionType = add(11, Types.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(12, Type.VAR_INT); public final MetaType directionType = add(12, Types.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID); public final MetaType optionalUUIDType = add(13, Types.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT); public final MetaType blockStateType = add(14, Types.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT); public final MetaType optionalBlockStateType = add(15, Types.VAR_INT);
public final MetaType nbtType = add(16, Type.COMPOUND_TAG); public final MetaType compoundTagType = add(16, Types.COMPOUND_TAG);
public final MetaType particleType; public final MetaType particleType;
public final MetaType particlesType; public final MetaType particlesType;
public final MetaType villagerDatatType = add(19, Type.VILLAGER_DATA); public final MetaType villagerDatatType = add(19, Types.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(20, Type.OPTIONAL_VAR_INT); public final MetaType optionalVarIntType = add(20, Types.OPTIONAL_VAR_INT);
public final MetaType poseType = add(21, Type.VAR_INT); public final MetaType poseType = add(21, Types.VAR_INT);
public final MetaType catVariantType = add(22, Type.VAR_INT); public final MetaType catVariantType = add(22, Types.VAR_INT);
public final MetaType wolfVariantType = add(23, Type.VAR_INT); public final MetaType wolfVariantType = add(23, Types.VAR_INT);
public final MetaType frogVariantType = add(24, Type.VAR_INT); public final MetaType frogVariantType = add(24, Types.VAR_INT);
public final MetaType optionalGlobalPosition = add(25, Type.OPTIONAL_GLOBAL_POSITION); public final MetaType optionalGlobalPosition = add(25, Types.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(26, Type.VAR_INT); public final MetaType paintingVariantType = add(26, Types.VAR_INT);
public final MetaType snifferState = add(27, Type.VAR_INT); public final MetaType snifferState = add(27, Types.VAR_INT);
public final MetaType armadilloState = add(28, Type.VAR_INT); public final MetaType armadilloState = add(28, Types.VAR_INT);
public final MetaType vectorType = add(29, Type.VECTOR3F); public final MetaType vector3FType = add(29, Types.VECTOR3F);
public final MetaType quaternionType = add(30, Type.QUATERNION); public final MetaType quaternionType = add(30, Types.QUATERNION);
public MetaTypes1_20_5(final ParticleType particleType, final ArrayType<Particle> particlesType) { public MetaTypes1_20_5(final ParticleType particleType, final ArrayType<Particle> particlesType) {
super(31); super(31);

Datei anzeigen

@ -22,196 +22,14 @@
*/ */
package com.viaversion.viaversion.api.type; package com.viaversion.viaversion.api.type;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.EulerAngle;
import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
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;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.BooleanType;
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.UnsignedByteType;
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
import com.viaversion.viaversion.api.type.types.VarIntType;
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.block.VarLongBlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13;
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13_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.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.math.QuaternionType;
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;
/** /**
* Type for buffer reading and writing. * Type for buffer reading and writing.
* *
* @param <T> read/written type * @param <T> read/written type
* @see Types
*/ */
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> { public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<Unit> EMPTY = new EmptyType();
public static final ByteType BYTE = new ByteType();
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
public static final Type<byte[]> BYTE_ARRAY_PRIMITIVE = new ByteArrayType();
public static final Type<byte[]> OPTIONAL_BYTE_ARRAY_PRIMITIVE = new ByteArrayType.OptionalByteArrayType();
public static final Type<byte[]> SHORT_BYTE_ARRAY = new ShortByteArrayType();
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
public static final Type<int[]> INT_ARRAY_PRIMITIVE = new IntArrayType();
public static final ShortType SHORT = new ShortType();
public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType();
public static final IntType INT = new IntType();
public static final FloatType FLOAT = new FloatType();
public static final FloatType.OptionalFloatType OPTIONAL_FLOAT = new FloatType.OptionalFloatType();
public static final DoubleType DOUBLE = new DoubleType();
public static final LongType LONG = new LongType();
public static final Type<long[]> LONG_ARRAY_PRIMITIVE = new LongArrayType();
public static final BooleanType BOOLEAN = new BooleanType();
public static final BooleanType.OptionalBooleanType OPTIONAL_BOOLEAN = new BooleanType.OptionalBooleanType();
/* Other Types */
public static final Type<JsonElement> COMPONENT = new ComponentType();
public static final Type<JsonElement> OPTIONAL_COMPONENT = new ComponentType.OptionalComponentType();
public static final Type<String> STRING = new StringType();
public static final Type<String> OPTIONAL_STRING = new StringType.OptionalStringType();
public static final Type<String[]> STRING_ARRAY = new ArrayType<>(Type.STRING);
public static final Type<UUID> UUID = new UUIDType();
public static final Type<UUID> OPTIONAL_UUID = new UUIDType.OptionalUUIDType();
public static final Type<UUID[]> UUID_ARRAY = new ArrayType<>(Type.UUID);
public static final VarIntType VAR_INT = new VarIntType();
public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType();
public static final Type<int[]> VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType();
public static final VarLongType VAR_LONG = new VarLongType();
/* MC Types */
public static final Type<Position> POSITION1_8 = new PositionType1_8();
public static final Type<Position> OPTIONAL_POSITION1_8 = new PositionType1_8.OptionalPositionType();
public static final Type<Position> POSITION1_14 = new PositionType1_14();
public static final Type<Position> OPTIONAL_POSITION_1_14 = new PositionType1_14.OptionalPosition1_14Type();
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
public static final Type<Vector> VECTOR = new VectorType();
public static final Type<Vector3f> VECTOR3F = new Vector3fType();
public static final Type<Quaternion> QUATERNION = new QuaternionType();
public static final Type<CompoundTag> NAMED_COMPOUND_TAG = new NamedCompoundTagType();
public static final Type<CompoundTag> OPTIONAL_NAMED_COMPOUND_TAG = new NamedCompoundTagType.OptionalNamedCompoundTagType();
public static final Type<CompoundTag[]> NAMED_COMPOUND_TAG_ARRAY = new ArrayType<>(Type.NAMED_COMPOUND_TAG);
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = new CompoundTagType.OptionalCompoundTagType();
public static final Type<Tag> TAG = new TagType();
public static final Type<Tag[]> TAG_ARRAY = new ArrayType<>(TAG);
public static final Type<Tag> OPTIONAL_TAG = new TagType.OptionalTagType();
public static final Type<GlobalPosition> GLOBAL_POSITION = new GlobalPositionType();
public static final Type<GlobalPosition> OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType();
public static final Type<ChunkPosition> CHUNK_POSITION = new ChunkPositionType();
public static final Type<BlockEntity> BLOCK_ENTITY1_18 = new BlockEntityType1_18();
public static final Type<BlockEntity> BLOCK_ENTITY1_20_2 = new BlockEntityType1_20_2();
public static final Type<BlockChangeRecord> BLOCK_CHANGE_RECORD = new BlockChangeRecordType();
public static final Type<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD);
public static final Type<BlockChangeRecord> VAR_LONG_BLOCK_CHANGE_RECORD = new VarLongBlockChangeRecordType();
public static final Type<BlockChangeRecord[]> VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.VAR_LONG_BLOCK_CHANGE_RECORD);
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
public static final Type<GameProfile> GAME_PROFILE = new GameProfileType();
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
public static final Type<ProfileKey> OPTIONAL_PROFILE_KEY = new ProfileKeyType.OptionalProfileKeyType();
public static final Type<PlayerMessageSignature> PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType();
public static final Type<PlayerMessageSignature> OPTIONAL_PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType.OptionalPlayerMessageSignatureType();
public static final Type<PlayerMessageSignature[]> PLAYER_MESSAGE_SIGNATURE_ARRAY = new ArrayType<>(PLAYER_MESSAGE_SIGNATURE);
public static final BitSetType PROFILE_ACTIONS_ENUM = new BitSetType(6);
public static final ByteArrayType SIGNATURE_BYTES = new ByteArrayType(256);
public static final BitSetType ACKNOWLEDGED_BIT_SET = new BitSetType(20);
public static final ByteArrayType.OptionalByteArrayType OPTIONAL_SIGNATURE_BYTES = new ByteArrayType.OptionalByteArrayType(256);
public static final Type<RegistryEntry> REGISTRY_ENTRY = new RegistryEntryType();
public static final Type<RegistryEntry[]> REGISTRY_ENTRY_ARRAY = new ArrayType<>(REGISTRY_ENTRY);
public static final Type<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();
public static final Type<Item> ITEM1_20_2 = new ItemType1_20_2();
public static final Type<Item[]> ITEM1_8_SHORT_ARRAY = new ItemShortArrayType1_8();
public static final Type<Item[]> ITEM1_13_SHORT_ARRAY = new ItemShortArrayType1_13();
public static final Type<Item[]> ITEM1_13_2_SHORT_ARRAY = new ItemShortArrayType1_13_2();
public static final Type<Item[]> ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13);
public static final Type<Item[]> ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2);
public static final Type<Item[]> ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2);
/* Actual Class */ /* Actual Class */
private final Class<? super T> outputClass; private final Class<? super T> outputClass;
private final String typeName; private final String typeName;

Datei anzeigen

@ -0,0 +1,215 @@
/*
* 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;
import com.google.gson.JsonElement;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.EulerAngle;
import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
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;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.BooleanType;
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.UnsignedByteType;
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
import com.viaversion.viaversion.api.type.types.VarIntType;
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.block.VarLongBlockChangeRecordType;
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13;
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13_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.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.math.QuaternionType;
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.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.util.Unit;
import java.util.UUID;
/**
* Holds the mostly stable {@link Type} instances.
* Others may be held separately or object classes themselves, e.g. {@link Types1_20_5} or {@link Enchantments}
*/
public final class Types {
public static final Type<Unit> EMPTY = new EmptyType();
public static final ByteType BYTE = new ByteType();
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
public static final Type<byte[]> BYTE_ARRAY_PRIMITIVE = new ByteArrayType();
public static final Type<byte[]> OPTIONAL_BYTE_ARRAY_PRIMITIVE = new ByteArrayType.OptionalByteArrayType();
public static final Type<byte[]> SHORT_BYTE_ARRAY = new ShortByteArrayType();
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
public static final Type<int[]> INT_ARRAY_PRIMITIVE = new IntArrayType();
public static final ShortType SHORT = new ShortType();
public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType();
public static final IntType INT = new IntType();
public static final FloatType FLOAT = new FloatType();
public static final FloatType.OptionalFloatType OPTIONAL_FLOAT = new FloatType.OptionalFloatType();
public static final DoubleType DOUBLE = new DoubleType();
public static final LongType LONG = new LongType();
public static final Type<long[]> LONG_ARRAY_PRIMITIVE = new LongArrayType();
public static final BooleanType BOOLEAN = new BooleanType();
public static final BooleanType.OptionalBooleanType OPTIONAL_BOOLEAN = new BooleanType.OptionalBooleanType();
/* Other Types */
public static final Type<JsonElement> COMPONENT = new ComponentType();
public static final Type<JsonElement> OPTIONAL_COMPONENT = new ComponentType.OptionalComponentType();
public static final Type<String> STRING = new StringType();
public static final Type<String> OPTIONAL_STRING = new StringType.OptionalStringType();
public static final Type<String[]> STRING_ARRAY = new ArrayType<>(Types.STRING);
public static final Type<UUID> UUID = new UUIDType();
public static final Type<UUID> OPTIONAL_UUID = new UUIDType.OptionalUUIDType();
public static final Type<UUID[]> UUID_ARRAY = new ArrayType<>(Types.UUID);
public static final VarIntType VAR_INT = new VarIntType();
public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType();
public static final Type<int[]> VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType();
public static final VarLongType VAR_LONG = new VarLongType();
/* MC Types */
public static final Type<Position> BLOCK_POSITION1_8 = new PositionType1_8();
public static final Type<Position> OPTIONAL_POSITION1_8 = new PositionType1_8.OptionalPositionType();
public static final Type<Position> BLOCK_POSITION1_14 = new PositionType1_14();
public static final Type<Position> OPTIONAL_POSITION_1_14 = new PositionType1_14.OptionalPosition1_14Type();
public static final Type<EulerAngle> ROTATIONS = new EulerAngleType();
public static final Type<Vector> VECTOR = new VectorType();
public static final Type<Vector3f> VECTOR3F = new Vector3fType();
public static final Type<Quaternion> QUATERNION = new QuaternionType();
public static final Type<CompoundTag> NAMED_COMPOUND_TAG = new NamedCompoundTagType();
public static final Type<CompoundTag> OPTIONAL_NAMED_COMPOUND_TAG = new NamedCompoundTagType.OptionalNamedCompoundTagType();
public static final Type<CompoundTag[]> NAMED_COMPOUND_TAG_ARRAY = new ArrayType<>(Types.NAMED_COMPOUND_TAG);
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = new CompoundTagType.OptionalCompoundTagType();
public static final Type<Tag> TAG = new TagType();
public static final Type<Tag[]> TAG_ARRAY = new ArrayType<>(TAG);
public static final Type<Tag> OPTIONAL_TAG = new TagType.OptionalTagType();
public static final Type<GlobalPosition> GLOBAL_POSITION = new GlobalPositionType();
public static final Type<GlobalPosition> OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType();
public static final Type<ChunkPosition> CHUNK_POSITION = new ChunkPositionType();
public static final Type<BlockEntity> BLOCK_ENTITY1_18 = new BlockEntityType1_18();
public static final Type<BlockEntity> BLOCK_ENTITY1_20_2 = new BlockEntityType1_20_2();
public static final Type<BlockChangeRecord> BLOCK_CHANGE = new BlockChangeRecordType();
public static final Type<BlockChangeRecord[]> BLOCK_CHANGE_ARRAY = new ArrayType<>(Types.BLOCK_CHANGE);
public static final Type<BlockChangeRecord> VAR_LONG_BLOCK_CHANGE = new VarLongBlockChangeRecordType();
public static final Type<BlockChangeRecord[]> VAR_LONG_BLOCK_CHANGE_ARRAY = new ArrayType<>(Types.VAR_LONG_BLOCK_CHANGE);
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
public static final Type<GameProfile> GAME_PROFILE = new GameProfileType();
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
public static final Type<ProfileKey> OPTIONAL_PROFILE_KEY = new ProfileKeyType.OptionalProfileKeyType();
public static final Type<PlayerMessageSignature> PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType();
public static final Type<PlayerMessageSignature> OPTIONAL_PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType.OptionalPlayerMessageSignatureType();
public static final Type<PlayerMessageSignature[]> PLAYER_MESSAGE_SIGNATURE_ARRAY = new ArrayType<>(PLAYER_MESSAGE_SIGNATURE);
public static final BitSetType PROFILE_ACTIONS_ENUM = new BitSetType(6);
public static final ByteArrayType SIGNATURE_BYTES = new ByteArrayType(256);
public static final BitSetType ACKNOWLEDGED_BIT_SET = new BitSetType(20);
public static final ByteArrayType.OptionalByteArrayType OPTIONAL_SIGNATURE_BYTES = new ByteArrayType.OptionalByteArrayType(256);
public static final Type<RegistryEntry> REGISTRY_ENTRY = new RegistryEntryType();
public static final Type<RegistryEntry[]> REGISTRY_ENTRY_ARRAY = new ArrayType<>(REGISTRY_ENTRY);
public static final Type<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();
public static final Type<Item> ITEM1_20_2 = new ItemType1_20_2();
public static final Type<Item[]> ITEM1_8_SHORT_ARRAY = new ItemShortArrayType1_8();
public static final Type<Item[]> ITEM1_13_SHORT_ARRAY = new ItemShortArrayType1_13();
public static final Type<Item[]> ITEM1_13_2_SHORT_ARRAY = new ItemShortArrayType1_13_2();
public static final Type<Item[]> ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13);
public static final Type<Item[]> ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2);
public static final Type<Item[]> ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2);
}

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type.types; package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -41,7 +42,7 @@ public class ArrayType<T> extends Type<T[]> {
@Override @Override
public T[] read(ByteBuf buffer) { public T[] read(ByteBuf buffer) {
int amount = Type.VAR_INT.readPrimitive(buffer); int amount = Types.VAR_INT.readPrimitive(buffer);
T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount); T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
@ -52,7 +53,7 @@ public class ArrayType<T> extends Type<T[]> {
@Override @Override
public void write(ByteBuf buffer, T[] object) { public void write(ByteBuf buffer, T[] object) {
Type.VAR_INT.writePrimitive(buffer, object.length); Types.VAR_INT.writePrimitive(buffer, object.length);
for (T o : object) { for (T o : object) {
elementType.write(buffer, o); elementType.write(buffer, o);
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.TypeConverter; import com.viaversion.viaversion.api.type.TypeConverter;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class BooleanType extends Type<Boolean> implements TypeConverter<Boolean> { public class BooleanType extends Type<Boolean> implements TypeConverter<Boolean> {
@ -55,7 +56,7 @@ public class BooleanType extends Type<Boolean> implements TypeConverter<Boolean>
public static final class OptionalBooleanType extends OptionalType<Boolean> { public static final class OptionalBooleanType extends OptionalType<Boolean> {
public OptionalBooleanType() { public OptionalBooleanType() {
super(Type.BOOLEAN); super(Types.BOOLEAN);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ByteArrayType extends Type<byte[]> { public class ByteArrayType extends Type<byte[]> {
@ -46,14 +47,14 @@ public class ByteArrayType extends Type<byte[]> {
if (this.length != -1) { if (this.length != -1) {
Preconditions.checkArgument(length == object.length, "Length does not match expected length"); Preconditions.checkArgument(length == object.length, "Length does not match expected length");
} else { } else {
Type.VAR_INT.writePrimitive(buffer, object.length); Types.VAR_INT.writePrimitive(buffer, object.length);
} }
buffer.writeBytes(object); buffer.writeBytes(object);
} }
@Override @Override
public byte[] read(final ByteBuf buffer) { public byte[] read(final ByteBuf buffer) {
final int length = this.length == -1 ? Type.VAR_INT.readPrimitive(buffer) : this.length; final int length = this.length == -1 ? Types.VAR_INT.readPrimitive(buffer) : this.length;
Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes"); Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes");
final byte[] array = new byte[length]; final byte[] array = new byte[length];
buffer.readBytes(array); buffer.readBytes(array);
@ -63,7 +64,7 @@ public class ByteArrayType extends Type<byte[]> {
public static final class OptionalByteArrayType extends OptionalType<byte[]> { public static final class OptionalByteArrayType extends OptionalType<byte[]> {
public OptionalByteArrayType() { public OptionalByteArrayType() {
super(Type.BYTE_ARRAY_PRIMITIVE); super(Types.BYTE_ARRAY_PRIMITIVE);
} }
public OptionalByteArrayType(final int length) { public OptionalByteArrayType(final int length) {

Datei anzeigen

@ -28,6 +28,7 @@ import com.google.gson.JsonSyntaxException;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ComponentType extends Type<JsonElement> { public class ComponentType extends Type<JsonElement> {
@ -56,7 +57,7 @@ public class ComponentType extends Type<JsonElement> {
public static final class OptionalComponentType extends OptionalType<JsonElement> { public static final class OptionalComponentType extends OptionalType<JsonElement> {
public OptionalComponentType() { public OptionalComponentType() {
super(Type.COMPONENT); super(Types.COMPONENT);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.TypeConverter; import com.viaversion.viaversion.api.type.TypeConverter;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class FloatType extends Type<Float> implements TypeConverter<Float> { public class FloatType extends Type<Float> implements TypeConverter<Float> {
@ -72,7 +73,7 @@ public class FloatType extends Type<Float> implements TypeConverter<Float> {
public static final class OptionalFloatType extends OptionalType<Float> { public static final class OptionalFloatType extends OptionalType<Float> {
public OptionalFloatType() { public OptionalFloatType() {
super(Type.FLOAT); super(Types.FLOAT);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class IntArrayType extends Type<int[]> { public class IntArrayType extends Type<int[]> {
@ -46,7 +47,7 @@ public class IntArrayType extends Type<int[]> {
if (this.length != -1) { if (this.length != -1) {
Preconditions.checkArgument(length == object.length, "Length does not match expected length"); Preconditions.checkArgument(length == object.length, "Length does not match expected length");
} else { } else {
Type.VAR_INT.writePrimitive(buffer, object.length); Types.VAR_INT.writePrimitive(buffer, object.length);
} }
for (final int i : object) { for (final int i : object) {
buffer.writeInt(i); buffer.writeInt(i);
@ -55,7 +56,7 @@ public class IntArrayType extends Type<int[]> {
@Override @Override
public int[] read(final ByteBuf buffer) { public int[] read(final ByteBuf buffer) {
final int length = this.length == -1 ? Type.VAR_INT.readPrimitive(buffer) : this.length; final int length = this.length == -1 ? Types.VAR_INT.readPrimitive(buffer) : this.length;
Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes"); Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes");
final int[] array = new int[length]; final int[] array = new int[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type.types; package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class LongArrayType extends Type<long[]> { public class LongArrayType extends Type<long[]> {
@ -33,7 +34,7 @@ public class LongArrayType extends Type<long[]> {
@Override @Override
public long[] read(ByteBuf buffer) { public long[] read(ByteBuf buffer) {
int length = Type.VAR_INT.readPrimitive(buffer); int length = Types.VAR_INT.readPrimitive(buffer);
long[] array = new long[length]; long[] array = new long[length];
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
array[i] = buffer.readLong(); array[i] = buffer.readLong();
@ -43,7 +44,7 @@ public class LongArrayType extends Type<long[]> {
@Override @Override
public void write(ByteBuf buffer, long[] object) { public void write(ByteBuf buffer, long[] object) {
Type.VAR_INT.writePrimitive(buffer, object.length); Types.VAR_INT.writePrimitive(buffer, object.length);
for (long l : object) { for (long l : object) {
buffer.writeLong(l); buffer.writeLong(l);
} }

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.type.types; package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class OptionalVarIntType extends Type<Integer> { public class OptionalVarIntType extends Type<Integer> {
@ -33,16 +34,16 @@ public class OptionalVarIntType extends Type<Integer> {
@Override @Override
public Integer read(final ByteBuf buffer) { public Integer read(final ByteBuf buffer) {
final int value = Type.VAR_INT.readPrimitive(buffer); final int value = Types.VAR_INT.readPrimitive(buffer);
return value == 0 ? null : value - 1; return value == 0 ? null : value - 1;
} }
@Override @Override
public void write(final ByteBuf buffer, final Integer object) { public void write(final ByteBuf buffer, final Integer object) {
if (object == null) { if (object == null) {
Type.VAR_INT.writePrimitive(buffer, 0); Types.VAR_INT.writePrimitive(buffer, 0);
} else { } else {
Type.VAR_INT.writePrimitive(buffer, object + 1); Types.VAR_INT.writePrimitive(buffer, object + 1);
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class RegistryEntryType extends Type<RegistryEntry> { public class RegistryEntryType extends Type<RegistryEntry> {
@ -34,12 +35,12 @@ public class RegistryEntryType extends Type<RegistryEntry> {
@Override @Override
public RegistryEntry read(final ByteBuf buffer) { public RegistryEntry read(final ByteBuf buffer) {
return new RegistryEntry(Type.STRING.read(buffer), Type.OPTIONAL_TAG.read(buffer)); return new RegistryEntry(Types.STRING.read(buffer), Types.OPTIONAL_TAG.read(buffer));
} }
@Override @Override
public void write(final ByteBuf buffer, final RegistryEntry entry) { public void write(final ByteBuf buffer, final RegistryEntry entry) {
Type.STRING.write(buffer, entry.key()); Types.STRING.write(buffer, entry.key());
Type.OPTIONAL_TAG.write(buffer, entry.tag()); Types.OPTIONAL_TAG.write(buffer, entry.tag());
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -45,7 +46,7 @@ public class StringType extends Type<String> {
@Override @Override
public String read(ByteBuf buffer) { public String read(ByteBuf buffer) {
int len = Type.VAR_INT.readPrimitive(buffer); int len = Types.VAR_INT.readPrimitive(buffer);
Preconditions.checkArgument(len <= maxLength * MAX_CHAR_UTF_8_LENGTH, Preconditions.checkArgument(len <= maxLength * MAX_CHAR_UTF_8_LENGTH,
"Cannot receive string longer than Short.MAX_VALUE * " + MAX_CHAR_UTF_8_LENGTH + " bytes (got %s bytes)", len); "Cannot receive string longer than Short.MAX_VALUE * " + MAX_CHAR_UTF_8_LENGTH + " bytes (got %s bytes)", len);
@ -66,14 +67,14 @@ public class StringType extends Type<String> {
} }
byte[] b = object.getBytes(StandardCharsets.UTF_8); byte[] b = object.getBytes(StandardCharsets.UTF_8);
Type.VAR_INT.writePrimitive(buffer, b.length); Types.VAR_INT.writePrimitive(buffer, b.length);
buffer.writeBytes(b); buffer.writeBytes(b);
} }
public static final class OptionalStringType extends OptionalType<String> { public static final class OptionalStringType extends OptionalType<String> {
public OptionalStringType() { public OptionalStringType() {
super(Type.STRING); super(Types.STRING);
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
@ -47,7 +48,7 @@ public class UUIDType extends Type<UUID> {
public static final class OptionalUUIDType extends OptionalType<UUID> { public static final class OptionalUUIDType extends OptionalType<UUID> {
public OptionalUUIDType() { public OptionalUUIDType() {
super(Type.UUID); super(Types.UUID);
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class VarIntArrayType extends Type<int[]> { public class VarIntArrayType extends Type<int[]> {
@ -33,20 +34,20 @@ public class VarIntArrayType extends Type<int[]> {
@Override @Override
public int[] read(ByteBuf buffer) { public int[] read(ByteBuf buffer) {
int length = Type.VAR_INT.readPrimitive(buffer); int length = Types.VAR_INT.readPrimitive(buffer);
Preconditions.checkArgument(buffer.isReadable(length)); // Sanity check, at least 1 byte will be used for each varint Preconditions.checkArgument(buffer.isReadable(length)); // Sanity check, at least 1 byte will be used for each varint
int[] array = new int[length]; int[] array = new int[length];
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
array[i] = Type.VAR_INT.readPrimitive(buffer); array[i] = Types.VAR_INT.readPrimitive(buffer);
} }
return array; return array;
} }
@Override @Override
public void write(ByteBuf buffer, int[] object) { public void write(ByteBuf buffer, int[] object) {
Type.VAR_INT.writePrimitive(buffer, object.length); Types.VAR_INT.writePrimitive(buffer, object.length);
for (int i : object) { for (int i : object) {
Type.VAR_INT.writePrimitive(buffer, i); Types.VAR_INT.writePrimitive(buffer, i);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.block;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class BlockChangeRecordType extends Type<BlockChangeRecord> { public class BlockChangeRecordType extends Type<BlockChangeRecord> {
@ -35,14 +36,14 @@ public class BlockChangeRecordType extends Type<BlockChangeRecord> {
@Override @Override
public BlockChangeRecord read(ByteBuf buffer) { public BlockChangeRecord read(ByteBuf buffer) {
short position = Type.SHORT.readPrimitive(buffer); short position = Types.SHORT.readPrimitive(buffer);
int blockId = Type.VAR_INT.readPrimitive(buffer); int blockId = Types.VAR_INT.readPrimitive(buffer);
return new BlockChangeRecord1_8(position >> 12 & 0xF, position & 0xFF, position >> 8 & 0xF, blockId); return new BlockChangeRecord1_8(position >> 12 & 0xF, position & 0xFF, position >> 8 & 0xF, blockId);
} }
@Override @Override
public void write(ByteBuf buffer, BlockChangeRecord object) { public void write(ByteBuf buffer, BlockChangeRecord object) {
Type.SHORT.writePrimitive(buffer, (short) (object.getSectionX() << 12 | object.getSectionZ() << 8 | object.getY())); Types.SHORT.writePrimitive(buffer, (short) (object.getSectionX() << 12 | object.getSectionZ() << 8 | object.getY()));
Type.VAR_INT.writePrimitive(buffer, object.getBlockId()); Types.VAR_INT.writePrimitive(buffer, object.getBlockId());
} }
} }

Datei anzeigen

@ -26,6 +26,7 @@ import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class BlockEntityType1_18 extends Type<BlockEntity> { public class BlockEntityType1_18 extends Type<BlockEntity> {
@ -38,8 +39,8 @@ public class BlockEntityType1_18 extends Type<BlockEntity> {
public BlockEntity read(final ByteBuf buffer) { public BlockEntity read(final ByteBuf buffer) {
final byte xz = buffer.readByte(); final byte xz = buffer.readByte();
final short y = buffer.readShort(); final short y = buffer.readShort();
final int typeId = Type.VAR_INT.readPrimitive(buffer); final int typeId = Types.VAR_INT.readPrimitive(buffer);
final CompoundTag tag = Type.NAMED_COMPOUND_TAG.read(buffer); final CompoundTag tag = Types.NAMED_COMPOUND_TAG.read(buffer);
return new BlockEntityImpl(xz, y, typeId, tag); return new BlockEntityImpl(xz, y, typeId, tag);
} }
@ -47,7 +48,7 @@ public class BlockEntityType1_18 extends Type<BlockEntity> {
public void write(final ByteBuf buffer, final BlockEntity entity) { public void write(final ByteBuf buffer, final BlockEntity entity) {
buffer.writeByte(entity.packedXZ()); buffer.writeByte(entity.packedXZ());
buffer.writeShort(entity.y()); buffer.writeShort(entity.y());
Type.VAR_INT.writePrimitive(buffer, entity.typeId()); Types.VAR_INT.writePrimitive(buffer, entity.typeId());
Type.NAMED_COMPOUND_TAG.write(buffer, entity.tag()); Types.NAMED_COMPOUND_TAG.write(buffer, entity.tag());
} }
} }

Datei anzeigen

@ -26,6 +26,7 @@ import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class BlockEntityType1_20_2 extends Type<BlockEntity> { public class BlockEntityType1_20_2 extends Type<BlockEntity> {
@ -38,8 +39,8 @@ public class BlockEntityType1_20_2 extends Type<BlockEntity> {
public BlockEntity read(final ByteBuf buffer) { public BlockEntity read(final ByteBuf buffer) {
final byte xz = buffer.readByte(); final byte xz = buffer.readByte();
final short y = buffer.readShort(); final short y = buffer.readShort();
final int typeId = Type.VAR_INT.readPrimitive(buffer); final int typeId = Types.VAR_INT.readPrimitive(buffer);
final CompoundTag tag = Type.COMPOUND_TAG.read(buffer); final CompoundTag tag = Types.COMPOUND_TAG.read(buffer);
return new BlockEntityImpl(xz, y, typeId, tag); return new BlockEntityImpl(xz, y, typeId, tag);
} }
@ -47,7 +48,7 @@ public class BlockEntityType1_20_2 extends Type<BlockEntity> {
public void write(final ByteBuf buffer, final BlockEntity entity) { public void write(final ByteBuf buffer, final BlockEntity entity) {
buffer.writeByte(entity.packedXZ()); buffer.writeByte(entity.packedXZ());
buffer.writeShort(entity.y()); buffer.writeShort(entity.y());
Type.VAR_INT.writePrimitive(buffer, entity.typeId()); Types.VAR_INT.writePrimitive(buffer, entity.typeId());
Type.COMPOUND_TAG.write(buffer, entity.tag()); Types.COMPOUND_TAG.write(buffer, entity.tag());
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.block;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_16_2; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_16_2;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class VarLongBlockChangeRecordType extends Type<BlockChangeRecord> { public class VarLongBlockChangeRecordType extends Type<BlockChangeRecord> {
@ -35,7 +36,7 @@ public class VarLongBlockChangeRecordType extends Type<BlockChangeRecord> {
@Override @Override
public BlockChangeRecord read(ByteBuf buffer) { public BlockChangeRecord read(ByteBuf buffer) {
long data = Type.VAR_LONG.readPrimitive(buffer); long data = Types.VAR_LONG.readPrimitive(buffer);
short position = (short) (data & 0xFFFL); short position = (short) (data & 0xFFFL);
return new BlockChangeRecord1_16_2(position >>> 8 & 0xF, position & 0xF, position >>> 4 & 0xF, (int) (data >>> 12)); return new BlockChangeRecord1_16_2(position >>> 8 & 0xF, position & 0xF, position >>> 4 & 0xF, (int) (data >>> 12));
} }
@ -43,6 +44,6 @@ public class VarLongBlockChangeRecordType extends Type<BlockChangeRecord> {
@Override @Override
public void write(ByteBuf buffer, BlockChangeRecord object) { public void write(ByteBuf buffer, BlockChangeRecord object) {
short position = (short) (object.getSectionX() << 8 | object.getSectionZ() << 4 | object.getSectionY()); short position = (short) (object.getSectionX() << 8 | object.getSectionZ() << 4 | object.getSectionY());
Type.VAR_LONG.writePrimitive(buffer, (long) object.getBlockId() << 12 | position); Types.VAR_LONG.writePrimitive(buffer, (long) object.getBlockId() << 12 | position);
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.chunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class BulkChunkType1_8 extends Type<Chunk[]> { public class BulkChunkType1_8 extends Type<Chunk[]> {
@ -42,7 +43,7 @@ public class BulkChunkType1_8 extends Type<Chunk[]> {
@Override @Override
public Chunk[] read(ByteBuf input) { public Chunk[] read(ByteBuf input) {
final boolean skyLight = input.readBoolean(); final boolean skyLight = input.readBoolean();
final int count = Type.VAR_INT.readPrimitive(input); final int count = Types.VAR_INT.readPrimitive(input);
final Chunk[] chunks = new Chunk[count]; final Chunk[] chunks = new Chunk[count];
final ChunkBulkSection[] chunkInfo = new ChunkBulkSection[count]; final ChunkBulkSection[] chunkInfo = new ChunkBulkSection[count];
@ -73,7 +74,7 @@ public class BulkChunkType1_8 extends Type<Chunk[]> {
} }
} }
output.writeBoolean(skyLight); output.writeBoolean(skyLight);
Type.VAR_INT.writePrimitive(output, chunks.length); Types.VAR_INT.writePrimitive(output, chunks.length);
// Write metadata // Write metadata
for (Chunk chunk : chunks) { for (Chunk chunk : chunks) {

Datei anzeigen

@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.util.CompactArrayUtil; import com.viaversion.viaversion.util.CompactArrayUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -50,18 +51,18 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
// Read palette // Read palette
ChunkSection chunkSection; ChunkSection chunkSection;
if (bitsPerBlock != GLOBAL_PALETTE) { if (bitsPerBlock != GLOBAL_PALETTE) {
int paletteLength = Type.VAR_INT.readPrimitive(buffer); int paletteLength = Types.VAR_INT.readPrimitive(buffer);
chunkSection = new ChunkSectionImpl(true, paletteLength); chunkSection = new ChunkSectionImpl(true, paletteLength);
DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS);
for (int i = 0; i < paletteLength; i++) { for (int i = 0; i < paletteLength; i++) {
blockPalette.addId(Type.VAR_INT.readPrimitive(buffer)); blockPalette.addId(Types.VAR_INT.readPrimitive(buffer));
} }
} else { } else {
chunkSection = new ChunkSectionImpl(true); chunkSection = new ChunkSectionImpl(true);
} }
// Read blocks // Read blocks
long[] blockData = Type.LONG_ARRAY_PRIMITIVE.read(buffer); long[] blockData = Types.LONG_ARRAY_PRIMITIVE.read(buffer);
if (blockData.length > 0) { if (blockData.length > 0) {
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0); int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
if (blockData.length == expectedLength) { if (blockData.length == expectedLength) {
@ -90,14 +91,14 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
// Write palette // Write palette
if (bitsPerBlock != GLOBAL_PALETTE) { if (bitsPerBlock != GLOBAL_PALETTE) {
Type.VAR_INT.writePrimitive(buffer, blockPalette.size()); Types.VAR_INT.writePrimitive(buffer, blockPalette.size());
for (int i = 0; i < blockPalette.size(); i++) { for (int i = 0; i < blockPalette.size(); i++) {
Type.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i)); Types.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i));
} }
} }
long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE, long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE,
bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt); bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt);
Type.LONG_ARRAY_PRIMITIVE.write(buffer, data); Types.LONG_ARRAY_PRIMITIVE.write(buffer, data);
} }
} }

Datei anzeigen

@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.util.CompactArrayUtil; import com.viaversion.viaversion.util.CompactArrayUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -50,18 +51,18 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
// Read palette // Read palette
ChunkSection chunkSection; ChunkSection chunkSection;
if (bitsPerBlock != GLOBAL_PALETTE) { if (bitsPerBlock != GLOBAL_PALETTE) {
int paletteLength = Type.VAR_INT.readPrimitive(buffer); int paletteLength = Types.VAR_INT.readPrimitive(buffer);
chunkSection = new ChunkSectionImpl(false, paletteLength); chunkSection = new ChunkSectionImpl(false, paletteLength);
DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS);
for (int i = 0; i < paletteLength; i++) { for (int i = 0; i < paletteLength; i++) {
blockPalette.addId(Type.VAR_INT.readPrimitive(buffer)); blockPalette.addId(Types.VAR_INT.readPrimitive(buffer));
} }
} else { } else {
chunkSection = new ChunkSectionImpl(false); chunkSection = new ChunkSectionImpl(false);
} }
// Read blocks // Read blocks
long[] blockData = Type.LONG_ARRAY_PRIMITIVE.read(buffer); long[] blockData = Types.LONG_ARRAY_PRIMITIVE.read(buffer);
if (blockData.length > 0) { if (blockData.length > 0) {
char valuesPerLong = (char) (64 / bitsPerBlock); char valuesPerLong = (char) (64 / bitsPerBlock);
int expectedLength = (ChunkSection.SIZE + valuesPerLong - 1) / valuesPerLong; int expectedLength = (ChunkSection.SIZE + valuesPerLong - 1) / valuesPerLong;
@ -91,14 +92,14 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
// Write palette // Write palette
if (bitsPerBlock != GLOBAL_PALETTE) { if (bitsPerBlock != GLOBAL_PALETTE) {
Type.VAR_INT.writePrimitive(buffer, blockPalette.size()); Types.VAR_INT.writePrimitive(buffer, blockPalette.size());
for (int i = 0; i < blockPalette.size(); i++) { for (int i = 0; i < blockPalette.size(); i++) {
Type.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i)); Types.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i));
} }
} }
long[] data = CompactArrayUtil.createCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, long[] data = CompactArrayUtil.createCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE,
bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt); bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt);
Type.LONG_ARRAY_PRIMITIVE.write(buffer, data); Types.LONG_ARRAY_PRIMITIVE.write(buffer, data);
} }
} }

Datei anzeigen

@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.util.CompactArrayUtil; import com.viaversion.viaversion.util.CompactArrayUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -49,19 +50,19 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
} }
// Read palette // Read palette
int paletteLength = Type.VAR_INT.readPrimitive(buffer); int paletteLength = Types.VAR_INT.readPrimitive(buffer);
ChunkSection chunkSection = bitsPerBlock != GLOBAL_PALETTE ? new ChunkSectionImpl(true, paletteLength) : new ChunkSectionImpl(true); ChunkSection chunkSection = bitsPerBlock != GLOBAL_PALETTE ? new ChunkSectionImpl(true, paletteLength) : new ChunkSectionImpl(true);
DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS);
for (int i = 0; i < paletteLength; i++) { for (int i = 0; i < paletteLength; i++) {
if (bitsPerBlock != GLOBAL_PALETTE) { if (bitsPerBlock != GLOBAL_PALETTE) {
blockPalette.addId(Type.VAR_INT.readPrimitive(buffer)); blockPalette.addId(Types.VAR_INT.readPrimitive(buffer));
} else { } else {
Type.VAR_INT.readPrimitive(buffer); Types.VAR_INT.readPrimitive(buffer);
} }
} }
// Read blocks // Read blocks
long[] blockData = Type.LONG_ARRAY_PRIMITIVE.read(buffer); long[] blockData = Types.LONG_ARRAY_PRIMITIVE.read(buffer);
if (blockData.length > 0) { if (blockData.length > 0) {
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0); int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
if (blockData.length == expectedLength) { if (blockData.length == expectedLength) {
@ -89,16 +90,16 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
// Write palette // Write palette
if (bitsPerBlock != GLOBAL_PALETTE) { if (bitsPerBlock != GLOBAL_PALETTE) {
Type.VAR_INT.writePrimitive(buffer, blockPalette.size()); Types.VAR_INT.writePrimitive(buffer, blockPalette.size());
for (int i = 0; i < blockPalette.size(); i++) { for (int i = 0; i < blockPalette.size(); i++) {
Type.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i)); Types.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i));
} }
} else { } else {
Type.VAR_INT.writePrimitive(buffer, 0); Types.VAR_INT.writePrimitive(buffer, 0);
} }
long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE, long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE,
bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt); bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt);
Type.LONG_ARRAY_PRIMITIVE.write(buffer, data); Types.LONG_ARRAY_PRIMITIVE.write(buffer, data);
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -57,8 +58,8 @@ public class ChunkType1_13 extends Type<Chunk> {
int chunkZ = input.readInt(); int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean(); boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
// Read sections // Read sections
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
@ -84,7 +85,7 @@ public class ChunkType1_13 extends Type<Chunk> {
} }
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
} }
@ -94,7 +95,7 @@ public class ChunkType1_13 extends Type<Chunk> {
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try { try {
@ -109,7 +110,7 @@ public class ChunkType1_13 extends Type<Chunk> {
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); Types.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
@ -123,6 +124,6 @@ public class ChunkType1_13 extends Type<Chunk> {
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,9 +49,9 @@ public class ChunkType1_14 extends Type<Chunk> {
int chunkZ = input.readInt(); int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean(); boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input); CompoundTag heightMap = Types.NAMED_COMPOUND_TAG.read(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
// Read sections // Read sections
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
@ -70,7 +71,7 @@ public class ChunkType1_14 extends Type<Chunk> {
} }
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
} }
@ -80,8 +81,8 @@ public class ChunkType1_14 extends Type<Chunk> {
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap()); Types.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try { try {
@ -93,7 +94,7 @@ public class ChunkType1_14 extends Type<Chunk> {
Types1_13.CHUNK_SECTION.write(buf, section); Types1_13.CHUNK_SECTION.write(buf, section);
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); // 256 * 4 Types.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); // 256 * 4
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
@ -107,6 +108,6 @@ public class ChunkType1_14 extends Type<Chunk> {
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,8 +49,8 @@ public class ChunkType1_15 extends Type<Chunk> {
int chunkZ = input.readInt(); int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean(); boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input); CompoundTag heightMap = Types.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = fullChunk ? new int[1024] : null; int[] biomeData = fullChunk ? new int[1024] : null;
if (fullChunk) { if (fullChunk) {
@ -58,7 +59,7 @@ public class ChunkType1_15 extends Type<Chunk> {
} }
} }
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
// Read sections // Read sections
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
@ -71,7 +72,7 @@ public class ChunkType1_15 extends Type<Chunk> {
sections[i] = section; sections[i] = section;
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
} }
@ -81,8 +82,8 @@ public class ChunkType1_15 extends Type<Chunk> {
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap()); Types.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {
@ -101,13 +102,13 @@ public class ChunkType1_15 extends Type<Chunk> {
Types1_13.CHUNK_SECTION.write(buf, section); Types1_13.CHUNK_SECTION.write(buf, section);
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes()); Types.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.api.type.types.version.Types1_16;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -49,8 +50,8 @@ public class ChunkType1_16 extends Type<Chunk> {
boolean fullChunk = input.readBoolean(); boolean fullChunk = input.readBoolean();
boolean ignoreOldLightData = input.readBoolean(); boolean ignoreOldLightData = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input); CompoundTag heightMap = Types.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = fullChunk ? new int[1024] : null; int[] biomeData = fullChunk ? new int[1024] : null;
if (fullChunk) { if (fullChunk) {
@ -59,7 +60,7 @@ public class ChunkType1_16 extends Type<Chunk> {
} }
} }
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
// Read sections // Read sections
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
@ -72,7 +73,7 @@ public class ChunkType1_16 extends Type<Chunk> {
sections[i] = section; sections[i] = section;
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, fullChunk, ignoreOldLightData, primaryBitmask, sections, biomeData, heightMap, nbtData); return new BaseChunk(chunkX, chunkZ, fullChunk, ignoreOldLightData, primaryBitmask, sections, biomeData, heightMap, nbtData);
} }
@ -83,8 +84,8 @@ public class ChunkType1_16 extends Type<Chunk> {
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
output.writeBoolean(chunk.isIgnoreOldLightData()); output.writeBoolean(chunk.isIgnoreOldLightData());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap()); Types.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {
@ -103,13 +104,13 @@ public class ChunkType1_16 extends Type<Chunk> {
Types1_16.CHUNK_SECTION.write(buf, section); Types1_16.CHUNK_SECTION.write(buf, section);
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes()); Types.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.api.type.types.version.Types1_16;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,15 +49,15 @@ public class ChunkType1_16_2 extends Type<Chunk> {
int chunkZ = input.readInt(); int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean(); boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input); CompoundTag heightMap = Types.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = null; int[] biomeData = null;
if (fullChunk) { if (fullChunk) {
biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input); biomeData = Types.VAR_INT_ARRAY_PRIMITIVE.read(input);
} }
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
// Read sections // Read sections
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
@ -69,7 +70,7 @@ public class ChunkType1_16_2 extends Type<Chunk> {
sections[i] = section; sections[i] = section;
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
} }
@ -79,12 +80,12 @@ public class ChunkType1_16_2 extends Type<Chunk> {
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap()); Types.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {
Type.VAR_INT_ARRAY_PRIMITIVE.write(output, chunk.getBiomeData()); Types.VAR_INT_ARRAY_PRIMITIVE.write(output, chunk.getBiomeData());
} }
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
@ -97,13 +98,13 @@ public class ChunkType1_16_2 extends Type<Chunk> {
Types1_16.CHUNK_SECTION.write(buf, section); Types1_16.CHUNK_SECTION.write(buf, section);
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes()); Types.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.api.type.types.version.Types1_16;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -51,12 +52,12 @@ public final class ChunkType1_17 extends Type<Chunk> {
int chunkX = input.readInt(); int chunkX = input.readInt();
int chunkZ = input.readInt(); int chunkZ = input.readInt();
BitSet sectionsMask = BitSet.valueOf(Type.LONG_ARRAY_PRIMITIVE.read(input)); BitSet sectionsMask = BitSet.valueOf(Types.LONG_ARRAY_PRIMITIVE.read(input));
CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(input); CompoundTag heightMap = Types.NAMED_COMPOUND_TAG.read(input);
int[] biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input); int[] biomeData = Types.VAR_INT_ARRAY_PRIMITIVE.read(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
// Read sections // Read sections
ChunkSection[] sections = new ChunkSection[ySectionCount]; ChunkSection[] sections = new ChunkSection[ySectionCount];
@ -69,7 +70,7 @@ public final class ChunkType1_17 extends Type<Chunk> {
sections[i] = section; sections[i] = section;
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, true, false, sectionsMask, sections, biomeData, heightMap, nbtData); return new BaseChunk(chunkX, chunkZ, true, false, sectionsMask, sections, biomeData, heightMap, nbtData);
} }
@ -78,11 +79,11 @@ public final class ChunkType1_17 extends Type<Chunk> {
output.writeInt(chunk.getX()); output.writeInt(chunk.getX());
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
Type.LONG_ARRAY_PRIMITIVE.write(output, chunk.getChunkMask().toLongArray()); Types.LONG_ARRAY_PRIMITIVE.write(output, chunk.getChunkMask().toLongArray());
Type.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap()); Types.NAMED_COMPOUND_TAG.write(output, chunk.getHeightMap());
// Write biome data // Write biome data
Type.VAR_INT_ARRAY_PRIMITIVE.write(output, chunk.getBiomeData()); Types.VAR_INT_ARRAY_PRIMITIVE.write(output, chunk.getBiomeData());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try { try {
@ -94,13 +95,13 @@ public final class ChunkType1_17 extends Type<Chunk> {
Types1_16.CHUNK_SECTION.write(buf, section); Types1_16.CHUNK_SECTION.write(buf, section);
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes()); Types.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18; import com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -48,10 +49,10 @@ public final class ChunkType1_18 extends Type<Chunk> {
public Chunk read(final ByteBuf buffer) { public Chunk read(final ByteBuf buffer) {
final int chunkX = buffer.readInt(); final int chunkX = buffer.readInt();
final int chunkZ = buffer.readInt(); final int chunkZ = buffer.readInt();
final CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(buffer); final CompoundTag heightMap = Types.NAMED_COMPOUND_TAG.read(buffer);
// Read sections // Read sections
final ByteBuf sectionsBuf = buffer.readBytes(Type.VAR_INT.readPrimitive(buffer)); final ByteBuf sectionsBuf = buffer.readBytes(Types.VAR_INT.readPrimitive(buffer));
final ChunkSection[] sections = new ChunkSection[ySectionCount]; final ChunkSection[] sections = new ChunkSection[ySectionCount];
try { try {
for (int i = 0; i < ySectionCount; i++) { for (int i = 0; i < ySectionCount; i++) {
@ -61,10 +62,10 @@ public final class ChunkType1_18 extends Type<Chunk> {
sectionsBuf.release(); sectionsBuf.release();
} }
final int blockEntitiesLength = Type.VAR_INT.readPrimitive(buffer); final int blockEntitiesLength = Types.VAR_INT.readPrimitive(buffer);
final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength); final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength);
for (int i = 0; i < blockEntitiesLength; i++) { for (int i = 0; i < blockEntitiesLength; i++) {
blockEntities.add(Type.BLOCK_ENTITY1_18.read(buffer)); blockEntities.add(Types.BLOCK_ENTITY1_18.read(buffer));
} }
return new Chunk1_18(chunkX, chunkZ, sections, heightMap, blockEntities); return new Chunk1_18(chunkX, chunkZ, sections, heightMap, blockEntities);
@ -75,7 +76,7 @@ public final class ChunkType1_18 extends Type<Chunk> {
buffer.writeInt(chunk.getX()); buffer.writeInt(chunk.getX());
buffer.writeInt(chunk.getZ()); buffer.writeInt(chunk.getZ());
Type.NAMED_COMPOUND_TAG.write(buffer, chunk.getHeightMap()); Types.NAMED_COMPOUND_TAG.write(buffer, chunk.getHeightMap());
final ByteBuf sectionBuffer = buffer.alloc().buffer(); final ByteBuf sectionBuffer = buffer.alloc().buffer();
try { try {
@ -83,15 +84,15 @@ public final class ChunkType1_18 extends Type<Chunk> {
sectionType.write(sectionBuffer, section); sectionType.write(sectionBuffer, section);
} }
sectionBuffer.readerIndex(0); sectionBuffer.readerIndex(0);
Type.VAR_INT.writePrimitive(buffer, sectionBuffer.readableBytes()); Types.VAR_INT.writePrimitive(buffer, sectionBuffer.readableBytes());
buffer.writeBytes(sectionBuffer); buffer.writeBytes(sectionBuffer);
} finally { } finally {
sectionBuffer.release(); // release buffer sectionBuffer.release(); // release buffer
} }
Type.VAR_INT.writePrimitive(buffer, chunk.blockEntities().size()); Types.VAR_INT.writePrimitive(buffer, chunk.blockEntities().size());
for (final BlockEntity blockEntity : chunk.blockEntities()) { for (final BlockEntity blockEntity : chunk.blockEntities()) {
Type.BLOCK_ENTITY1_18.write(buffer, blockEntity); Types.BLOCK_ENTITY1_18.write(buffer, blockEntity);
} }
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18; import com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -48,10 +49,10 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
public Chunk read(final ByteBuf buffer) { public Chunk read(final ByteBuf buffer) {
final int chunkX = buffer.readInt(); final int chunkX = buffer.readInt();
final int chunkZ = buffer.readInt(); final int chunkZ = buffer.readInt();
final CompoundTag heightMap = Type.COMPOUND_TAG.read(buffer); final CompoundTag heightMap = Types.COMPOUND_TAG.read(buffer);
// Read sections // Read sections
final ByteBuf sectionsBuf = buffer.readBytes(Type.VAR_INT.readPrimitive(buffer)); final ByteBuf sectionsBuf = buffer.readBytes(Types.VAR_INT.readPrimitive(buffer));
final ChunkSection[] sections = new ChunkSection[ySectionCount]; final ChunkSection[] sections = new ChunkSection[ySectionCount];
try { try {
for (int i = 0; i < ySectionCount; i++) { for (int i = 0; i < ySectionCount; i++) {
@ -61,10 +62,10 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
sectionsBuf.release(); sectionsBuf.release();
} }
final int blockEntitiesLength = Type.VAR_INT.readPrimitive(buffer); final int blockEntitiesLength = Types.VAR_INT.readPrimitive(buffer);
final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength); final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength);
for (int i = 0; i < blockEntitiesLength; i++) { for (int i = 0; i < blockEntitiesLength; i++) {
blockEntities.add(Type.BLOCK_ENTITY1_20_2.read(buffer)); blockEntities.add(Types.BLOCK_ENTITY1_20_2.read(buffer));
} }
return new Chunk1_18(chunkX, chunkZ, sections, heightMap, blockEntities); return new Chunk1_18(chunkX, chunkZ, sections, heightMap, blockEntities);
@ -75,7 +76,7 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
buffer.writeInt(chunk.getX()); buffer.writeInt(chunk.getX());
buffer.writeInt(chunk.getZ()); buffer.writeInt(chunk.getZ());
Type.COMPOUND_TAG.write(buffer, chunk.getHeightMap()); Types.COMPOUND_TAG.write(buffer, chunk.getHeightMap());
final ByteBuf sectionBuffer = buffer.alloc().buffer(); final ByteBuf sectionBuffer = buffer.alloc().buffer();
try { try {
@ -83,15 +84,15 @@ public final class ChunkType1_20_2 extends Type<Chunk> {
sectionType.write(sectionBuffer, section); sectionType.write(sectionBuffer, section);
} }
sectionBuffer.readerIndex(0); sectionBuffer.readerIndex(0);
Type.VAR_INT.writePrimitive(buffer, sectionBuffer.readableBytes()); Types.VAR_INT.writePrimitive(buffer, sectionBuffer.readableBytes());
buffer.writeBytes(sectionBuffer); buffer.writeBytes(sectionBuffer);
} finally { } finally {
sectionBuffer.release(); // release buffer sectionBuffer.release(); // release buffer
} }
Type.VAR_INT.writePrimitive(buffer, chunk.blockEntities().size()); Types.VAR_INT.writePrimitive(buffer, chunk.blockEntities().size());
for (final BlockEntity blockEntity : chunk.blockEntities()) { for (final BlockEntity blockEntity : chunk.blockEntities()) {
Type.BLOCK_ENTITY1_20_2.write(buffer, blockEntity); Types.BLOCK_ENTITY1_20_2.write(buffer, blockEntity);
} }
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_8; import com.viaversion.viaversion.api.type.types.version.Types1_8;
import com.viaversion.viaversion.util.ChunkUtil; import com.viaversion.viaversion.util.ChunkUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -57,7 +58,7 @@ public class ChunkType1_8 extends Type<Chunk> {
final int chunkZ = input.readInt(); final int chunkZ = input.readInt();
final boolean fullChunk = input.readBoolean(); final boolean fullChunk = input.readBoolean();
final int bitmask = input.readUnsignedShort(); final int bitmask = input.readUnsignedShort();
final int dataLength = Type.VAR_INT.readPrimitive(input); final int dataLength = Types.VAR_INT.readPrimitive(input);
final byte[] data = new byte[dataLength]; final byte[] data = new byte[dataLength];
input.readBytes(data); input.readBytes(data);
@ -81,7 +82,7 @@ public class ChunkType1_8 extends Type<Chunk> {
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
output.writeShort(chunk.getBitmask()); output.writeShort(chunk.getBitmask());
final byte[] data = serialize(chunk); final byte[] data = serialize(chunk);
Type.VAR_INT.writePrimitive(output, data.length); Types.VAR_INT.writePrimitive(output, data.length);
output.writeBytes(data); output.writeBytes(data);
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.util.ChunkUtil; import com.viaversion.viaversion.util.ChunkUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -57,8 +58,8 @@ public class ChunkType1_9_1 extends Type<Chunk> {
int chunkZ = input.readInt(); int chunkZ = input.readInt();
boolean groundUp = input.readBoolean(); boolean groundUp = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
int[] biomeData = groundUp ? new int[256] : null; int[] biomeData = groundUp ? new int[256] : null;
@ -101,7 +102,7 @@ public class ChunkType1_9_1 extends Type<Chunk> {
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try { try {
@ -116,7 +117,7 @@ public class ChunkType1_9_1 extends Type<Chunk> {
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0)); Types.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.util.ChunkUtil; import com.viaversion.viaversion.util.ChunkUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -59,8 +60,8 @@ public class ChunkType1_9_3 extends Type<Chunk> {
int chunkZ = input.readInt(); int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean(); boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input); int primaryBitmask = Types.VAR_INT.readPrimitive(input);
ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); ByteBuf data = input.readSlice(Types.VAR_INT.readPrimitive(input));
ChunkSection[] sections = new ChunkSection[16]; ChunkSection[] sections = new ChunkSection[16];
int[] biomeData = fullChunk ? new int[256] : null; int[] biomeData = fullChunk ? new int[256] : null;
@ -87,7 +88,7 @@ public class ChunkType1_9_3 extends Type<Chunk> {
return ChunkUtil.createEmptyChunk(chunkX, chunkZ); return ChunkUtil.createEmptyChunk(chunkX, chunkZ);
} }
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NAMED_COMPOUND_TAG_ARRAY.read(input))); List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Types.NAMED_COMPOUND_TAG_ARRAY.read(input)));
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
} }
@ -97,7 +98,7 @@ public class ChunkType1_9_3 extends Type<Chunk> {
output.writeInt(chunk.getZ()); output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Types.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try { try {
@ -111,7 +112,7 @@ public class ChunkType1_9_3 extends Type<Chunk> {
section.getLight().writeSkyLight(buf); section.getLight().writeSkyLight(buf);
} }
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0)); Types.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally { } finally {
buf.release(); // release buffer buf.release(); // release buffer
@ -125,6 +126,6 @@ public class ChunkType1_9_3 extends Type<Chunk> {
} }
// Write Block Entities // Write Block Entities
Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); Types.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
} }
} }

Datei anzeigen

@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl; import com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.util.CompactArrayUtil; import com.viaversion.viaversion.util.CompactArrayUtil;
import com.viaversion.viaversion.util.MathUtil; import com.viaversion.viaversion.util.MathUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -47,8 +48,8 @@ public final class PaletteType1_18 extends Type<DataPalette> {
if (bitsPerValue == 0) { if (bitsPerValue == 0) {
// Single value storage // Single value storage
palette = new DataPaletteImpl(type.size(), 1); palette = new DataPaletteImpl(type.size(), 1);
palette.addId(Type.VAR_INT.readPrimitive(buffer)); palette.addId(Types.VAR_INT.readPrimitive(buffer));
Type.LONG_ARRAY_PRIMITIVE.read(buffer); // Just eat it if not empty - thanks, Hypixel Types.LONG_ARRAY_PRIMITIVE.read(buffer); // Just eat it if not empty - thanks, Hypixel
return palette; return palette;
} }
@ -60,17 +61,17 @@ public final class PaletteType1_18 extends Type<DataPalette> {
// Read palette // Read palette
if (bitsPerValue != globalPaletteBits) { if (bitsPerValue != globalPaletteBits) {
final int paletteLength = Type.VAR_INT.readPrimitive(buffer); final int paletteLength = Types.VAR_INT.readPrimitive(buffer);
palette = new DataPaletteImpl(type.size(), paletteLength); palette = new DataPaletteImpl(type.size(), paletteLength);
for (int i = 0; i < paletteLength; i++) { for (int i = 0; i < paletteLength; i++) {
palette.addId(Type.VAR_INT.readPrimitive(buffer)); palette.addId(Types.VAR_INT.readPrimitive(buffer));
} }
} else { } else {
palette = new DataPaletteImpl(type.size()); palette = new DataPaletteImpl(type.size());
} }
// Read values // Read values
final long[] values = Type.LONG_ARRAY_PRIMITIVE.read(buffer); final long[] values = Types.LONG_ARRAY_PRIMITIVE.read(buffer);
if (values.length > 0) { if (values.length > 0) {
final int valuesPerLong = (char) (64 / bitsPerValue); final int valuesPerLong = (char) (64 / bitsPerValue);
final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong; final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong;
@ -88,8 +89,8 @@ public final class PaletteType1_18 extends Type<DataPalette> {
if (size == 1) { if (size == 1) {
// Single value palette // Single value palette
buffer.writeByte(0); // 0 bit storage buffer.writeByte(0); // 0 bit storage
Type.VAR_INT.writePrimitive(buffer, palette.idByIndex(0)); Types.VAR_INT.writePrimitive(buffer, palette.idByIndex(0));
Type.VAR_INT.writePrimitive(buffer, 0); // Empty values length Types.VAR_INT.writePrimitive(buffer, 0); // Empty values length
return; return;
} }
@ -104,12 +105,12 @@ public final class PaletteType1_18 extends Type<DataPalette> {
if (bitsPerValue != globalPaletteBits) { if (bitsPerValue != globalPaletteBits) {
// Write palette // Write palette
Type.VAR_INT.writePrimitive(buffer, size); Types.VAR_INT.writePrimitive(buffer, size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Type.VAR_INT.writePrimitive(buffer, palette.idByIndex(i)); Types.VAR_INT.writePrimitive(buffer, palette.idByIndex(i));
} }
} }
Type.LONG_ARRAY_PRIMITIVE.write(buffer, CompactArrayUtil.createCompactArrayWithPadding(bitsPerValue, type.size(), bitsPerValue == globalPaletteBits ? palette::idAt : palette::paletteIndexAt)); Types.LONG_ARRAY_PRIMITIVE.write(buffer, CompactArrayUtil.createCompactArrayWithPadding(bitsPerValue, type.size(), bitsPerValue == globalPaletteBits ? palette::idAt : palette::paletteIndexAt));
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.StructuredItem; import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
// Very similar to normal items (and just results in an item), except it allows non-positive amounts and has id/amount swapped because ??? // Very similar to normal items (and just results in an item), except it allows non-positive amounts and has id/amount swapped because ???
@ -43,16 +44,16 @@ public final class ItemCostType1_20_5 extends Type<Item> {
@Override @Override
public Item read(final ByteBuf buffer) { public Item read(final ByteBuf buffer) {
final int id = Type.VAR_INT.readPrimitive(buffer); final int id = Types.VAR_INT.readPrimitive(buffer);
final int amount = Type.VAR_INT.readPrimitive(buffer); final int amount = Types.VAR_INT.readPrimitive(buffer);
final StructuredData<?>[] dataArray = dataArrayType.read(buffer); final StructuredData<?>[] dataArray = dataArrayType.read(buffer);
return new StructuredItem(id, amount, new StructuredDataContainer(dataArray)); return new StructuredItem(id, amount, new StructuredDataContainer(dataArray));
} }
@Override @Override
public void write(final ByteBuf buffer, final Item object) { public void write(final ByteBuf buffer, final Item object) {
Type.VAR_INT.writePrimitive(buffer, object.identifier()); Types.VAR_INT.writePrimitive(buffer, object.identifier());
Type.VAR_INT.writePrimitive(buffer, object.amount()); Types.VAR_INT.writePrimitive(buffer, object.amount());
dataArrayType.write(buffer, object.structuredData().data().values().toArray(EMPTY_DATA_ARRAY)); dataArrayType.write(buffer, object.structuredData().data().values().toArray(EMPTY_DATA_ARRAY));
} }

Datei anzeigen

@ -24,25 +24,26 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_13 extends BaseItemArrayType { public class ItemShortArrayType1_13 extends BaseItemArrayType {
@Override @Override
public Item[] read(ByteBuf buffer) { public Item[] read(ByteBuf buffer) {
int amount = Type.SHORT.readPrimitive(buffer); int amount = Types.SHORT.readPrimitive(buffer);
Item[] array = new Item[amount]; Item[] array = new Item[amount];
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
array[i] = Type.ITEM1_13.read(buffer); array[i] = Types.ITEM1_13.read(buffer);
} }
return array; return array;
} }
@Override @Override
public void write(ByteBuf buffer, Item[] object) { public void write(ByteBuf buffer, Item[] object) {
Type.SHORT.writePrimitive(buffer, (short) object.length); Types.SHORT.writePrimitive(buffer, (short) object.length);
for (Item o : object) { for (Item o : object) {
Type.ITEM1_13.write(buffer, o); Types.ITEM1_13.write(buffer, o);
} }
} }
} }

Datei anzeigen

@ -24,25 +24,26 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_13_2 extends BaseItemArrayType { public class ItemShortArrayType1_13_2 extends BaseItemArrayType {
@Override @Override
public Item[] read(ByteBuf buffer) { public Item[] read(ByteBuf buffer) {
int amount = Type.SHORT.readPrimitive(buffer); int amount = Types.SHORT.readPrimitive(buffer);
Item[] array = new Item[amount]; Item[] array = new Item[amount];
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
array[i] = Type.ITEM1_13_2.read(buffer); array[i] = Types.ITEM1_13_2.read(buffer);
} }
return array; return array;
} }
@Override @Override
public void write(ByteBuf buffer, Item[] object) { public void write(ByteBuf buffer, Item[] object) {
Type.SHORT.writePrimitive(buffer, (short) object.length); Types.SHORT.writePrimitive(buffer, (short) object.length);
for (Item o : object) { for (Item o : object) {
Type.ITEM1_13_2.write(buffer, o); Types.ITEM1_13_2.write(buffer, o);
} }
} }
} }

Datei anzeigen

@ -24,25 +24,26 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_8 extends BaseItemArrayType { public class ItemShortArrayType1_8 extends BaseItemArrayType {
@Override @Override
public Item[] read(ByteBuf buffer) { public Item[] read(ByteBuf buffer) {
int amount = Type.SHORT.readPrimitive(buffer); int amount = Types.SHORT.readPrimitive(buffer);
Item[] array = new Item[amount]; Item[] array = new Item[amount];
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
array[i] = Type.ITEM1_8.read(buffer); array[i] = Types.ITEM1_8.read(buffer);
} }
return array; return array;
} }
@Override @Override
public void write(ByteBuf buffer, Item[] object) { public void write(ByteBuf buffer, Item[] object) {
Type.SHORT.writePrimitive(buffer, (short) object.length); Types.SHORT.writePrimitive(buffer, (short) object.length);
for (Item o : object) { for (Item o : object) {
Type.ITEM1_8.write(buffer, o); Types.ITEM1_8.write(buffer, o);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -42,7 +43,7 @@ public class ItemType1_13 extends Type<Item> {
Item item = new DataItem(); Item item = new DataItem();
item.setIdentifier(id); item.setIdentifier(id);
item.setAmount(buffer.readByte()); item.setAmount(buffer.readByte());
item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer)); item.setTag(Types.NAMED_COMPOUND_TAG.read(buffer));
return item; return item;
} }
} }
@ -54,7 +55,7 @@ public class ItemType1_13 extends Type<Item> {
} else { } else {
buffer.writeShort(object.identifier()); buffer.writeShort(object.identifier());
buffer.writeByte(object.amount()); buffer.writeByte(object.amount());
Type.NAMED_COMPOUND_TAG.write(buffer, object.tag()); Types.NAMED_COMPOUND_TAG.write(buffer, object.tag());
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -40,9 +41,9 @@ public class ItemType1_13_2 extends Type<Item> {
return null; return null;
} else { } else {
Item item = new DataItem(); Item item = new DataItem();
item.setIdentifier(Type.VAR_INT.readPrimitive(buffer)); item.setIdentifier(Types.VAR_INT.readPrimitive(buffer));
item.setAmount(buffer.readByte()); item.setAmount(buffer.readByte());
item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer)); item.setTag(Types.NAMED_COMPOUND_TAG.read(buffer));
return item; return item;
} }
} }
@ -53,9 +54,9 @@ public class ItemType1_13_2 extends Type<Item> {
buffer.writeBoolean(false); buffer.writeBoolean(false);
} else { } else {
buffer.writeBoolean(true); buffer.writeBoolean(true);
Type.VAR_INT.writePrimitive(buffer, object.identifier()); Types.VAR_INT.writePrimitive(buffer, object.identifier());
buffer.writeByte(object.amount()); buffer.writeByte(object.amount());
Type.NAMED_COMPOUND_TAG.write(buffer, object.tag()); Types.NAMED_COMPOUND_TAG.write(buffer, object.tag());
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -41,9 +42,9 @@ public class ItemType1_20_2 extends Type<Item> {
} }
final Item item = new DataItem(); final Item item = new DataItem();
item.setIdentifier(Type.VAR_INT.readPrimitive(buffer)); item.setIdentifier(Types.VAR_INT.readPrimitive(buffer));
item.setAmount(buffer.readByte()); item.setAmount(buffer.readByte());
item.setTag(Type.COMPOUND_TAG.read(buffer)); item.setTag(Types.COMPOUND_TAG.read(buffer));
return item; return item;
} }
@ -53,9 +54,9 @@ public class ItemType1_20_2 extends Type<Item> {
buffer.writeBoolean(false); buffer.writeBoolean(false);
} else { } else {
buffer.writeBoolean(true); buffer.writeBoolean(true);
Type.VAR_INT.writePrimitive(buffer, object.identifier()); Types.VAR_INT.writePrimitive(buffer, object.identifier());
buffer.writeByte(object.amount()); buffer.writeByte(object.amount());
Type.COMPOUND_TAG.write(buffer, object.tag()); Types.COMPOUND_TAG.write(buffer, object.tag());
} }
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.StructuredItem; import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import java.util.Map; import java.util.Map;
@ -45,19 +46,19 @@ public class ItemType1_20_5 extends Type<Item> {
@Override @Override
public @Nullable Item read(final ByteBuf buffer) { public @Nullable Item read(final ByteBuf buffer) {
final int amount = Type.VAR_INT.readPrimitive(buffer); final int amount = Types.VAR_INT.readPrimitive(buffer);
if (amount <= 0) { if (amount <= 0) {
return null; return null;
} }
final int id = Type.VAR_INT.readPrimitive(buffer); final int id = Types.VAR_INT.readPrimitive(buffer);
final Map<StructuredDataKey<?>, StructuredData<?>> data = readData(buffer); final Map<StructuredDataKey<?>, StructuredData<?>> data = readData(buffer);
return new StructuredItem(id, amount, new StructuredDataContainer(data)); return new StructuredItem(id, amount, new StructuredDataContainer(data));
} }
private Map<StructuredDataKey<?>, StructuredData<?>> readData(final ByteBuf buffer) { private Map<StructuredDataKey<?>, StructuredData<?>> readData(final ByteBuf buffer) {
final int valuesSize = Type.VAR_INT.readPrimitive(buffer); final int valuesSize = Types.VAR_INT.readPrimitive(buffer);
final int markersSize = Type.VAR_INT.readPrimitive(buffer); final int markersSize = Types.VAR_INT.readPrimitive(buffer);
if (valuesSize == 0 && markersSize == 0) { if (valuesSize == 0 && markersSize == 0) {
return new Reference2ObjectOpenHashMap<>(); return new Reference2ObjectOpenHashMap<>();
} }
@ -71,7 +72,7 @@ public class ItemType1_20_5 extends Type<Item> {
} }
for (int i = 0; i < markersSize; i++) { for (int i = 0; i < markersSize; i++) {
final int id = Type.VAR_INT.readPrimitive(buffer); final int id = Types.VAR_INT.readPrimitive(buffer);
final StructuredDataKey<?> key = dataType.key(id); final StructuredDataKey<?> key = dataType.key(id);
Preconditions.checkNotNull(key, "No data component serializer found for empty id %s", id); Preconditions.checkNotNull(key, "No data component serializer found for empty id %s", id);
map.put(key, StructuredData.empty(key, id)); map.put(key, StructuredData.empty(key, id));
@ -82,12 +83,12 @@ public class ItemType1_20_5 extends Type<Item> {
@Override @Override
public void write(final ByteBuf buffer, @Nullable final Item object) { public void write(final ByteBuf buffer, @Nullable final Item object) {
if (object == null) { if (object == null) {
Type.VAR_INT.writePrimitive(buffer, 0); Types.VAR_INT.writePrimitive(buffer, 0);
return; return;
} }
Type.VAR_INT.writePrimitive(buffer, object.amount()); Types.VAR_INT.writePrimitive(buffer, object.amount());
Type.VAR_INT.writePrimitive(buffer, object.identifier()); Types.VAR_INT.writePrimitive(buffer, object.identifier());
final Map<StructuredDataKey<?>, StructuredData<?>> data = object.structuredData().data(); final Map<StructuredDataKey<?>, StructuredData<?>> data = object.structuredData().data();
int valuesSize = 0; int valuesSize = 0;
@ -100,8 +101,8 @@ public class ItemType1_20_5 extends Type<Item> {
} }
} }
Type.VAR_INT.writePrimitive(buffer, valuesSize); Types.VAR_INT.writePrimitive(buffer, valuesSize);
Type.VAR_INT.writePrimitive(buffer, markersSize); Types.VAR_INT.writePrimitive(buffer, markersSize);
for (final StructuredData<?> value : data.values()) { for (final StructuredData<?> value : data.values()) {
if (value.isPresent()) { if (value.isPresent()) {
@ -110,7 +111,7 @@ public class ItemType1_20_5 extends Type<Item> {
} }
for (final StructuredData<?> value : data.values()) { for (final StructuredData<?> value : data.values()) {
if (value.isEmpty()) { if (value.isEmpty()) {
Type.VAR_INT.writePrimitive(buffer, value.id()); Types.VAR_INT.writePrimitive(buffer, value.id());
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -44,7 +45,7 @@ public class ItemType1_8 extends Type<Item> {
item.setIdentifier(id); item.setIdentifier(id);
item.setAmount(buffer.readByte()); item.setAmount(buffer.readByte());
item.setData(buffer.readShort()); item.setData(buffer.readShort());
item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer)); item.setTag(Types.NAMED_COMPOUND_TAG.read(buffer));
return item; return item;
} }
} }
@ -57,7 +58,7 @@ public class ItemType1_8 extends Type<Item> {
buffer.writeShort(object.identifier()); buffer.writeShort(object.identifier());
buffer.writeByte(object.amount()); buffer.writeByte(object.amount());
buffer.writeShort(object.data()); buffer.writeShort(object.data());
Type.NAMED_COMPOUND_TAG.write(buffer, object.tag()); Types.NAMED_COMPOUND_TAG.write(buffer, object.tag());
} }
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -41,14 +42,14 @@ public class StructuredDataType extends Type<StructuredData<?>> {
@Override @Override
public void write(final ByteBuf buffer, final StructuredData<?> object) { public void write(final ByteBuf buffer, final StructuredData<?> object) {
Type.VAR_INT.writePrimitive(buffer, object.id()); Types.VAR_INT.writePrimitive(buffer, object.id());
object.write(buffer); object.write(buffer);
} }
@Override @Override
public StructuredData<?> read(final ByteBuf buffer) { public StructuredData<?> read(final ByteBuf buffer) {
Preconditions.checkNotNull(types, "StructuredDataType has not been initialized"); Preconditions.checkNotNull(types, "StructuredDataType has not been initialized");
final int id = Type.VAR_INT.readPrimitive(buffer); final int id = Types.VAR_INT.readPrimitive(buffer);
final StructuredDataKey<?> key = this.types[id]; final StructuredDataKey<?> key = this.types[id];
if (key == null) { if (key == null) {
throw new IllegalArgumentException("No data component serializer found for id " + id); throw new IllegalArgumentException("No data component serializer found for id " + id);

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.math;
import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition; import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ChunkPositionType extends Type<ChunkPosition> { public class ChunkPositionType extends Type<ChunkPosition> {
@ -34,12 +35,12 @@ public class ChunkPositionType extends Type<ChunkPosition> {
@Override @Override
public ChunkPosition read(ByteBuf buffer) { public ChunkPosition read(ByteBuf buffer) {
final long chunkKey = Type.LONG.readPrimitive(buffer); final long chunkKey = Types.LONG.readPrimitive(buffer);
return new ChunkPosition(chunkKey); return new ChunkPosition(chunkKey);
} }
@Override @Override
public void write(ByteBuf buffer, ChunkPosition chunkPosition) { public void write(ByteBuf buffer, ChunkPosition chunkPosition) {
Type.LONG.writePrimitive(buffer, chunkPosition.chunkKey()); Types.LONG.writePrimitive(buffer, chunkPosition.chunkKey());
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.math;
import com.viaversion.viaversion.api.minecraft.EulerAngle; import com.viaversion.viaversion.api.minecraft.EulerAngle;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class EulerAngleType extends Type<EulerAngle> { public class EulerAngleType extends Type<EulerAngle> {
@ -33,17 +34,17 @@ public class EulerAngleType extends Type<EulerAngle> {
@Override @Override
public EulerAngle read(ByteBuf buffer) { public EulerAngle read(ByteBuf buffer) {
float x = Type.FLOAT.readPrimitive(buffer); float x = Types.FLOAT.readPrimitive(buffer);
float y = Type.FLOAT.readPrimitive(buffer); float y = Types.FLOAT.readPrimitive(buffer);
float z = Type.FLOAT.readPrimitive(buffer); float z = Types.FLOAT.readPrimitive(buffer);
return new EulerAngle(x, y, z); return new EulerAngle(x, y, z);
} }
@Override @Override
public void write(ByteBuf buffer, EulerAngle object) { public void write(ByteBuf buffer, EulerAngle object) {
Type.FLOAT.writePrimitive(buffer, object.x()); Types.FLOAT.writePrimitive(buffer, object.x());
Type.FLOAT.writePrimitive(buffer, object.y()); Types.FLOAT.writePrimitive(buffer, object.y());
Type.FLOAT.writePrimitive(buffer, object.z()); Types.FLOAT.writePrimitive(buffer, object.z());
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.math;
import com.viaversion.viaversion.api.minecraft.GlobalPosition; import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class GlobalPositionType extends Type<GlobalPosition> { public class GlobalPositionType extends Type<GlobalPosition> {
@ -35,20 +36,20 @@ public class GlobalPositionType extends Type<GlobalPosition> {
@Override @Override
public GlobalPosition read(ByteBuf buffer) { public GlobalPosition read(ByteBuf buffer) {
final String dimension = Type.STRING.read(buffer); final String dimension = Types.STRING.read(buffer);
return Type.POSITION1_14.read(buffer).withDimension(dimension); return Types.BLOCK_POSITION1_14.read(buffer).withDimension(dimension);
} }
@Override @Override
public void write(ByteBuf buffer, GlobalPosition object) { public void write(ByteBuf buffer, GlobalPosition object) {
Type.STRING.write(buffer, object.dimension()); Types.STRING.write(buffer, object.dimension());
Type.POSITION1_14.write(buffer, object); Types.BLOCK_POSITION1_14.write(buffer, object);
} }
public static final class OptionalGlobalPositionType extends OptionalType<GlobalPosition> { public static final class OptionalGlobalPositionType extends OptionalType<GlobalPosition> {
public OptionalGlobalPositionType() { public OptionalGlobalPositionType() {
super(Type.GLOBAL_POSITION); super(Types.GLOBAL_POSITION);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.math;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class PositionType1_14 extends Type<Position> { public class PositionType1_14 extends Type<Position> {
@ -53,7 +54,7 @@ public class PositionType1_14 extends Type<Position> {
public static final class OptionalPosition1_14Type extends OptionalType<Position> { public static final class OptionalPosition1_14Type extends OptionalType<Position> {
public OptionalPosition1_14Type() { public OptionalPosition1_14Type() {
super(Type.POSITION1_14); super(Types.BLOCK_POSITION1_14);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.math;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class PositionType1_8 extends Type<Position> { public class PositionType1_8 extends Type<Position> {
@ -51,7 +52,7 @@ public class PositionType1_8 extends Type<Position> {
public static final class OptionalPositionType extends OptionalType<Position> { public static final class OptionalPositionType extends OptionalType<Position> {
public OptionalPositionType() { public OptionalPositionType() {
super(Type.POSITION1_8); super(Types.BLOCK_POSITION1_8);
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.math;
import com.viaversion.viaversion.api.minecraft.Vector; import com.viaversion.viaversion.api.minecraft.Vector;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class VectorType extends Type<Vector> { public class VectorType extends Type<Vector> {
@ -33,17 +34,17 @@ public class VectorType extends Type<Vector> {
@Override @Override
public Vector read(ByteBuf buffer) { public Vector read(ByteBuf buffer) {
int x = Type.INT.read(buffer); int x = Types.INT.read(buffer);
int y = Type.INT.read(buffer); int y = Types.INT.read(buffer);
int z = Type.INT.read(buffer); int z = Types.INT.read(buffer);
return new Vector(x, y, z); return new Vector(x, y, z);
} }
@Override @Override
public void write(ByteBuf buffer, Vector object) { public void write(ByteBuf buffer, Vector object) {
Type.INT.write(buffer, object.blockX()); Types.INT.write(buffer, object.blockX());
Type.INT.write(buffer, object.blockY()); Types.INT.write(buffer, object.blockY());
Type.INT.write(buffer, object.blockZ()); Types.INT.write(buffer, object.blockZ());
} }
} }

Datei anzeigen

@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.type.types.metadata;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public abstract class ModernMetaType extends MetaTypeTemplate { public abstract class ModernMetaType extends MetaTypeTemplate {
@ -34,7 +34,7 @@ public abstract class ModernMetaType extends MetaTypeTemplate {
public Metadata read(final ByteBuf buffer) { public Metadata read(final ByteBuf buffer) {
final short index = buffer.readUnsignedByte(); final short index = buffer.readUnsignedByte();
if (index == END) return null; // End of metadata if (index == END) return null; // End of metadata
final MetaType type = this.getType(Type.VAR_INT.readPrimitive(buffer)); final MetaType type = this.getType(Types.VAR_INT.readPrimitive(buffer));
return new Metadata(index, type, type.type().read(buffer)); return new Metadata(index, type, type.type().read(buffer));
} }
@ -47,7 +47,7 @@ public abstract class ModernMetaType extends MetaTypeTemplate {
} else { } else {
buffer.writeByte(object.id()); buffer.writeByte(object.id());
final MetaType type = object.metaType(); final MetaType type = object.metaType();
Type.VAR_INT.writePrimitive(buffer, type.typeId()); Types.VAR_INT.writePrimitive(buffer, type.typeId());
type.type().write(buffer, object.getValue()); type.type().write(buffer, object.getValue());
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException; import java.io.IOException;
@ -62,7 +63,7 @@ public class CompoundTagType extends Type<CompoundTag> {
public static final class OptionalCompoundTagType extends OptionalType<CompoundTag> { public static final class OptionalCompoundTagType extends OptionalType<CompoundTag> {
public OptionalCompoundTagType() { public OptionalCompoundTagType() {
super(Type.COMPOUND_TAG); super(Types.COMPOUND_TAG);
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.viaversion.api.minecraft.GameProfile; import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public final class GameProfileType extends Type<GameProfile> { public final class GameProfileType extends Type<GameProfile> {
@ -34,14 +35,14 @@ public final class GameProfileType extends Type<GameProfile> {
@Override @Override
public GameProfile read(final ByteBuf buffer) { public GameProfile read(final ByteBuf buffer) {
final String name = Type.OPTIONAL_STRING.read(buffer); final String name = Types.OPTIONAL_STRING.read(buffer);
final java.util.UUID id = Type.OPTIONAL_UUID.read(buffer); final java.util.UUID id = Types.OPTIONAL_UUID.read(buffer);
final int propertyCount = Type.VAR_INT.readPrimitive(buffer); final int propertyCount = Types.VAR_INT.readPrimitive(buffer);
final GameProfile.Property[] properties = new GameProfile.Property[propertyCount]; final GameProfile.Property[] properties = new GameProfile.Property[propertyCount];
for (int i = 0; i < propertyCount; i++) { for (int i = 0; i < propertyCount; i++) {
final String propertyName = Type.STRING.read(buffer); final String propertyName = Types.STRING.read(buffer);
final String propertyValue = Type.STRING.read(buffer); final String propertyValue = Types.STRING.read(buffer);
final String propertySignature = Type.OPTIONAL_STRING.read(buffer); final String propertySignature = Types.OPTIONAL_STRING.read(buffer);
properties[i] = new GameProfile.Property(propertyName, propertyValue, propertySignature); properties[i] = new GameProfile.Property(propertyName, propertyValue, propertySignature);
} }
return new GameProfile(name, id, properties); return new GameProfile(name, id, properties);
@ -49,13 +50,13 @@ public final class GameProfileType extends Type<GameProfile> {
@Override @Override
public void write(final ByteBuf buffer, final GameProfile value) { public void write(final ByteBuf buffer, final GameProfile value) {
Type.OPTIONAL_STRING.write(buffer, value.name()); Types.OPTIONAL_STRING.write(buffer, value.name());
Type.OPTIONAL_UUID.write(buffer, value.id()); Types.OPTIONAL_UUID.write(buffer, value.id());
Type.VAR_INT.writePrimitive(buffer, value.properties().length); Types.VAR_INT.writePrimitive(buffer, value.properties().length);
for (final GameProfile.Property property : value.properties()) { for (final GameProfile.Property property : value.properties()) {
Type.STRING.write(buffer, property.name()); Types.STRING.write(buffer, property.name());
Type.STRING.write(buffer, property.value()); Types.STRING.write(buffer, property.value());
Type.OPTIONAL_STRING.write(buffer, property.signature()); Types.OPTIONAL_STRING.write(buffer, property.signature());
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class HolderSetType extends Type<HolderSet> { public class HolderSetType extends Type<HolderSet> {
@ -35,15 +36,15 @@ public class HolderSetType extends Type<HolderSet> {
@Override @Override
public HolderSet read(final ByteBuf buffer) { public HolderSet read(final ByteBuf buffer) {
final int size = Type.VAR_INT.readPrimitive(buffer) - 1; final int size = Types.VAR_INT.readPrimitive(buffer) - 1;
if (size == -1) { if (size == -1) {
final String tag = Type.STRING.read(buffer); final String tag = Types.STRING.read(buffer);
return HolderSet.of(tag); return HolderSet.of(tag);
} }
final int[] values = new int[size]; final int[] values = new int[size];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
values[i] = Type.VAR_INT.readPrimitive(buffer); values[i] = Types.VAR_INT.readPrimitive(buffer);
} }
return HolderSet.of(values); return HolderSet.of(values);
} }
@ -51,13 +52,13 @@ public class HolderSetType extends Type<HolderSet> {
@Override @Override
public void write(final ByteBuf buffer, final HolderSet object) { public void write(final ByteBuf buffer, final HolderSet object) {
if (object.hasTagKey()) { if (object.hasTagKey()) {
Type.VAR_INT.writePrimitive(buffer, 0); Types.VAR_INT.writePrimitive(buffer, 0);
Type.STRING.write(buffer, object.tagKey()); Types.STRING.write(buffer, object.tagKey());
} else { } else {
final int[] values = object.ids(); final int[] values = object.ids();
Type.VAR_INT.writePrimitive(buffer, values.length + 1); Types.VAR_INT.writePrimitive(buffer, values.length + 1);
for (final int value : values) { for (final int value : values) {
Type.VAR_INT.writePrimitive(buffer, value); Types.VAR_INT.writePrimitive(buffer, value);
} }
} }
} }
@ -65,7 +66,7 @@ public class HolderSetType extends Type<HolderSet> {
public static final class OptionalHolderSetType extends OptionalType<HolderSet> { public static final class OptionalHolderSetType extends OptionalType<HolderSet> {
public OptionalHolderSetType() { public OptionalHolderSetType() {
super(Type.HOLDER_SET); super(Types.HOLDER_SET);
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public abstract class HolderType<T> extends Type<Holder<T>> { public abstract class HolderType<T> extends Type<Holder<T>> {
@ -34,7 +35,7 @@ public abstract class HolderType<T> extends Type<Holder<T>> {
@Override @Override
public Holder<T> read(final ByteBuf buffer) { public Holder<T> read(final ByteBuf buffer) {
final int id = Type.VAR_INT.readPrimitive(buffer) - 1; // Normalize id final int id = Types.VAR_INT.readPrimitive(buffer) - 1; // Normalize id
if (id == -1) { if (id == -1) {
return Holder.of(readDirect(buffer)); return Holder.of(readDirect(buffer));
} }
@ -44,9 +45,9 @@ public abstract class HolderType<T> extends Type<Holder<T>> {
@Override @Override
public void write(final ByteBuf buffer, final Holder<T> object) { public void write(final ByteBuf buffer, final Holder<T> object) {
if (object.hasId()) { if (object.hasId()) {
Type.VAR_INT.writePrimitive(buffer, object.id() + 1); // Normalize id Types.VAR_INT.writePrimitive(buffer, object.id() + 1); // Normalize id
} else { } else {
Type.VAR_INT.writePrimitive(buffer, 0); Types.VAR_INT.writePrimitive(buffer, 0);
writeDirect(buffer, object.value()); writeDirect(buffer, object.value());
} }
} }

Datei anzeigen

@ -27,6 +27,7 @@ import com.viaversion.nbt.tag.Tag;
import com.viaversion.nbt.limiter.TagLimiter; import com.viaversion.nbt.limiter.TagLimiter;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.ByteBufOutputStream;
@ -94,7 +95,7 @@ public class NamedCompoundTagType extends Type<CompoundTag> {
public static final class OptionalNamedCompoundTagType extends OptionalType<CompoundTag> { public static final class OptionalNamedCompoundTagType extends OptionalType<CompoundTag> {
public OptionalNamedCompoundTagType() { public OptionalNamedCompoundTagType() {
super(Type.NAMED_COMPOUND_TAG); super(Types.NAMED_COMPOUND_TAG);
} }
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -40,7 +41,7 @@ public class ParticleType extends DynamicType<Particle> {
@Override @Override
public void write(final ByteBuf buffer, final Particle object) { public void write(final ByteBuf buffer, final Particle object) {
Type.VAR_INT.writePrimitive(buffer, object.id()); Types.VAR_INT.writePrimitive(buffer, object.id());
for (final Particle.ParticleData<?> data : object.getArguments()) { for (final Particle.ParticleData<?> data : object.getArguments()) {
data.write(buffer); data.write(buffer);
} }
@ -48,7 +49,7 @@ public class ParticleType extends DynamicType<Particle> {
@Override @Override
public Particle read(final ByteBuf buffer) { public Particle read(final ByteBuf buffer) {
final int type = Type.VAR_INT.readPrimitive(buffer); final int type = Types.VAR_INT.readPrimitive(buffer);
final Particle particle = new Particle(type); final Particle particle = new Particle(type);
readData(buffer, particle); readData(buffer, particle);
return particle; return particle;
@ -66,77 +67,77 @@ public class ParticleType extends DynamicType<Particle> {
public static final class Readers { public static final class Readers {
public static final DataReader<Particle> BLOCK = (buf, particle) -> { public static final DataReader<Particle> BLOCK = (buf, particle) -> {
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Flat Block particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Flat Block
}; };
public static final DataReader<Particle> ITEM1_13 = itemHandler(Type.ITEM1_13); public static final DataReader<Particle> ITEM1_13 = itemHandler(Types.ITEM1_13);
public static final DataReader<Particle> ITEM1_13_2 = itemHandler(Type.ITEM1_13_2); public static final DataReader<Particle> ITEM1_13_2 = itemHandler(Types.ITEM1_13_2);
public static final DataReader<Particle> ITEM1_20_2 = itemHandler(Type.ITEM1_20_2); public static final DataReader<Particle> ITEM1_20_2 = itemHandler(Types.ITEM1_20_2);
public static final DataReader<Particle> ITEM1_20_5 = itemHandler(Types1_20_5.ITEM); public static final DataReader<Particle> ITEM1_20_5 = itemHandler(Types1_20_5.ITEM);
public static final DataReader<Particle> DUST = (buf, particle) -> { public static final DataReader<Particle> DUST = (buf, particle) -> {
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Red 0-1
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Green 0-1
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Blue 0-1
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Scale 0.01-4 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Scale 0.01-4
}; };
public static final DataReader<Particle> DUST_TRANSITION = (buf, particle) -> { public static final DataReader<Particle> DUST_TRANSITION = (buf, particle) -> {
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Red 0-1
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Green 0-1
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1 particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Blue 0-1
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Scale 0.01-4 (moved to the end as of 24w03a / 1.20.5) particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Scale 0.01-4 (moved to the end as of 24w03a / 1.20.5)
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Red
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Green
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Blue
}; };
public static final DataReader<Particle> VIBRATION = (buf, particle) -> { public static final DataReader<Particle> VIBRATION = (buf, particle) -> {
particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // From block pos particle.add(Types.BLOCK_POSITION1_14, Types.BLOCK_POSITION1_14.read(buf)); // From block pos
String resourceLocation = Type.STRING.read(buf); String resourceLocation = Types.STRING.read(buf);
particle.add(Type.STRING, resourceLocation); particle.add(Types.STRING, resourceLocation);
resourceLocation = Key.stripMinecraftNamespace(resourceLocation); resourceLocation = Key.stripMinecraftNamespace(resourceLocation);
if (resourceLocation.equals("block")) { if (resourceLocation.equals("block")) {
particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // Target block pos particle.add(Types.BLOCK_POSITION1_14, Types.BLOCK_POSITION1_14.read(buf)); // Target block pos
} else if (resourceLocation.equals("entity")) { } else if (resourceLocation.equals("entity")) {
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Target entity particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Target entity
} else { } else {
Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + resourceLocation); Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + resourceLocation);
} }
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Arrival in ticks
}; };
public static final DataReader<Particle> VIBRATION1_19 = (buf, particle) -> { public static final DataReader<Particle> VIBRATION1_19 = (buf, particle) -> {
String resourceLocation = Type.STRING.read(buf); String resourceLocation = Types.STRING.read(buf);
particle.add(Type.STRING, resourceLocation); particle.add(Types.STRING, resourceLocation);
resourceLocation = Key.stripMinecraftNamespace(resourceLocation); resourceLocation = Key.stripMinecraftNamespace(resourceLocation);
if (resourceLocation.equals("block")) { if (resourceLocation.equals("block")) {
particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // Target block pos particle.add(Types.BLOCK_POSITION1_14, Types.BLOCK_POSITION1_14.read(buf)); // Target block pos
} else if (resourceLocation.equals("entity")) { } else if (resourceLocation.equals("entity")) {
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Target entity particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Target entity
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Y offset particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Y offset
} else { } else {
Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + resourceLocation); Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + resourceLocation);
} }
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Arrival in ticks
}; };
public static final DataReader<Particle> VIBRATION1_20_3 = (buf, particle) -> { public static final DataReader<Particle> VIBRATION1_20_3 = (buf, particle) -> {
final int sourceTypeId = Type.VAR_INT.readPrimitive(buf); final int sourceTypeId = Types.VAR_INT.readPrimitive(buf);
particle.add(Type.VAR_INT, sourceTypeId); particle.add(Types.VAR_INT, sourceTypeId);
if (sourceTypeId == 0) { // Block if (sourceTypeId == 0) { // Block
particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // Target block pos particle.add(Types.BLOCK_POSITION1_14, Types.BLOCK_POSITION1_14.read(buf)); // Target block pos
} else if (sourceTypeId == 1) { // Entity } else if (sourceTypeId == 1) { // Entity
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Target entity particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Target entity
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Y offset particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Y offset
} else { } else {
Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + sourceTypeId); Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + sourceTypeId);
} }
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Arrival in ticks
}; };
public static final DataReader<Particle> SCULK_CHARGE = (buf, particle) -> { public static final DataReader<Particle> SCULK_CHARGE = (buf, particle) -> {
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Roll particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Roll
}; };
public static final DataReader<Particle> SHRIEK = (buf, particle) -> { public static final DataReader<Particle> SHRIEK = (buf, particle) -> {
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Delay particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Delay
}; };
public static final DataReader<Particle> COLOR = (buf, particle) -> particle.add(Type.INT, buf.readInt()); public static final DataReader<Particle> COLOR = (buf, particle) -> particle.add(Types.INT, buf.readInt());
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class PlayerMessageSignatureType extends Type<PlayerMessageSignature> { public class PlayerMessageSignatureType extends Type<PlayerMessageSignature> {
@ -35,19 +36,19 @@ public class PlayerMessageSignatureType extends Type<PlayerMessageSignature> {
@Override @Override
public PlayerMessageSignature read(final ByteBuf buffer) { public PlayerMessageSignature read(final ByteBuf buffer) {
return new PlayerMessageSignature(Type.UUID.read(buffer), Type.BYTE_ARRAY_PRIMITIVE.read(buffer)); return new PlayerMessageSignature(Types.UUID.read(buffer), Types.BYTE_ARRAY_PRIMITIVE.read(buffer));
} }
@Override @Override
public void write(final ByteBuf buffer, final PlayerMessageSignature value) { public void write(final ByteBuf buffer, final PlayerMessageSignature value) {
Type.UUID.write(buffer, value.uuid()); Types.UUID.write(buffer, value.uuid());
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, value.signatureBytes()); Types.BYTE_ARRAY_PRIMITIVE.write(buffer, value.signatureBytes());
} }
public static final class OptionalPlayerMessageSignatureType extends OptionalType<PlayerMessageSignature> { public static final class OptionalPlayerMessageSignatureType extends OptionalType<PlayerMessageSignature> {
public OptionalPlayerMessageSignatureType() { public OptionalPlayerMessageSignatureType() {
super(Type.PLAYER_MESSAGE_SIGNATURE); super(Types.PLAYER_MESSAGE_SIGNATURE);
} }
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.viaversion.api.minecraft.ProfileKey; import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ProfileKeyType extends Type<ProfileKey> { public class ProfileKeyType extends Type<ProfileKey> {
@ -35,20 +36,20 @@ public class ProfileKeyType extends Type<ProfileKey> {
@Override @Override
public ProfileKey read(final ByteBuf buffer) { public ProfileKey read(final ByteBuf buffer) {
return new ProfileKey(buffer.readLong(), Type.BYTE_ARRAY_PRIMITIVE.read(buffer), Type.BYTE_ARRAY_PRIMITIVE.read(buffer)); return new ProfileKey(buffer.readLong(), Types.BYTE_ARRAY_PRIMITIVE.read(buffer), Types.BYTE_ARRAY_PRIMITIVE.read(buffer));
} }
@Override @Override
public void write(final ByteBuf buffer, final ProfileKey object) { public void write(final ByteBuf buffer, final ProfileKey object) {
buffer.writeLong(object.expiresAt()); buffer.writeLong(object.expiresAt());
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, object.publicKey()); Types.BYTE_ARRAY_PRIMITIVE.write(buffer, object.publicKey());
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, object.keySignature()); Types.BYTE_ARRAY_PRIMITIVE.write(buffer, object.keySignature());
} }
public static final class OptionalProfileKeyType extends OptionalType<ProfileKey> { public static final class OptionalProfileKeyType extends OptionalType<ProfileKey> {
public OptionalProfileKeyType() { public OptionalProfileKeyType() {
super(Type.PROFILE_KEY); super(Types.PROFILE_KEY);
} }
} }
} }

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen