All Downloads are FREE. Search and download functionalities are using the official Maven repository.

personthecat.catlib.util.ValueLookup Maven / Gradle / Ivy

Go to download

Utilities for serialization, commands, noise generation, IO, and some new data types.

The newest version!
package personthecat.catlib.util;

import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import lombok.experimental.UtilityClass;
import net.minecraft.class_2498;
import net.minecraft.class_3614;
import net.minecraft.class_3620;
import java.util.Optional;
import java.util.Set;

import static personthecat.catlib.util.Shorthand.nullable;

/**
 * Used for serialization of non-enum static types.
 * 

* Note that MCP mappings are supported on the Forge platform * for any type that differs between the two platforms. *

*/ @UtilityClass @SuppressWarnings("unused") public class ValueLookup { /** A map of every vanilla material to its name. */ private static final BiMap MATERIAL_MAP = ImmutableBiMap.builder() .put("AIR", class_3614.field_15959) .put("STRUCTURAL_AIR", class_3614.field_15927) .put("PORTAL", class_3614.field_15919) .put("CLOTH_DECORATION", class_3614.field_15957) .put("PLANT", class_3614.field_15935) .put("WATER_PLANT", class_3614.field_15947) .put("REPLACEABLE_PLANT", class_3614.field_15956) .put("REPLACEABLE_FIREPROOF_PLANT", class_3614.field_26708) .put("REPLACEABLE_WATER_PLANT", class_3614.field_15926) .put("WATER", class_3614.field_15920) .put("BUBBLE_COLUMN", class_3614.field_15915) .put("LAVA", class_3614.field_15922) .put("TOP_SNOW", class_3614.field_15948) .put("FIRE", class_3614.field_15943) .put("DECORATION", class_3614.field_15924) .put("WEB", class_3614.field_15913) .put("SCULK", class_3614.field_28242) .put("BUILDABLE_GLASS", class_3614.field_15918) .put("CLAY", class_3614.field_15936) .put("DIRT", class_3614.field_15941) .put("GRASS", class_3614.field_15945) .put("ICE_SOLID", class_3614.field_15928) .put("SAND", class_3614.field_15916) .put("SPONGE", class_3614.field_15917) .put("SHULKER_SHELL", class_3614.field_17008) .put("WOOD", class_3614.field_15932) .put("NETHER_WOOD", class_3614.field_22223) .put("BAMBOO_SAPLING", class_3614.field_15938) .put("BAMBOO", class_3614.field_15946) .put("WOOL", class_3614.field_15931) .put("EXPLOSIVE", class_3614.field_15955) .put("LEAVES", class_3614.field_15923) .put("GLASS", class_3614.field_15942) .put("ICE", class_3614.field_15958) .put("CACTUS", class_3614.field_15925) .put("STONE", class_3614.field_15914) .put("METAL", class_3614.field_15953) .put("SNOW", class_3614.field_15934) .put("HEAVY_METAL", class_3614.field_15949) .put("BARRIER", class_3614.field_15952) .put("PISTON", class_3614.field_15933) .put("MOSS", class_3614.field_15921) .put("VEGETABLE", class_3614.field_15954) .put("EGG", class_3614.field_15930) .put("CAKE", class_3614.field_15937) .put("AMETHYST", class_3614.field_27340) .put("POWDER_SNOW", class_3614.field_27890) .build(); /** A map of every vanilla sound type to its name */ private static final BiMap SOUND_MAP = ImmutableBiMap.builder() .put("WOOD", class_2498.field_11547) .put("GRAVEL", class_2498.field_11529) .put("GRASS", class_2498.field_11535) .put("LILY_PAD", class_2498.field_25183) .put("STONE", class_2498.field_11544) .put("METAL", class_2498.field_11533) .put("GLASS", class_2498.field_11537) .put("WOOL", class_2498.field_11543) .put("SAND", class_2498.field_11526) .put("SNOW", class_2498.field_11548) .put("LADDER", class_2498.field_11532) .put("ANVIL", class_2498.field_11531) .put("SLIME_BLOCK", class_2498.field_11545) .put("HONEY_BLOCK", class_2498.field_21214) .put("WET_GRASS", class_2498.field_11534) .put("CORAL_BLOCK", class_2498.field_11528) .put("BAMBOO", class_2498.field_11542) .put("BAMBOO_SAPLING", class_2498.field_11538) .put("SCAFFOLDING", class_2498.field_16498) .put("SWEET_BERRY_BUSH", class_2498.field_17579) .put("CROP", class_2498.field_17580) .put("HARD_CROP", class_2498.field_18852) .put("VINE", class_2498.field_23083) .put("NETHER_WART", class_2498.field_17581) .put("LANTERN", class_2498.field_17734) .put("STEM", class_2498.field_22152) .put("NYLIUM", class_2498.field_22153) .put("FUNGUS", class_2498.field_22154) .put("ROOTS", class_2498.field_22138) .put("SHROOMLIGHT", class_2498.field_22139) .put("WEEPING_VINES", class_2498.field_22140) .put("TWISTING_VINES", class_2498.field_23082) .put("SOUL_SAND", class_2498.field_22141) .put("SOUL_SOIL", class_2498.field_22142) .put("BASALT", class_2498.field_22143) .put("NETHERRACK", class_2498.field_22145) .put("NETHER_BRICK", class_2498.field_22146) .put("NETHER_SPROUT", class_2498.field_22147) .put("NETHER_ORE", class_2498.field_22148) .put("BONE_BLOCK", class_2498.field_22149) .put("NETHERITE_BLOCK", class_2498.field_22150) .put("ANCIENT_DEBRIS", class_2498.field_22151) .put("LODESTONE", class_2498.field_23265) .put("CHAIN", class_2498.field_24119) .put("NETHER_GOLD_ORE", class_2498.field_24120) .put("GILDED_BLACKSTONE", class_2498.field_24121) .build(); /** A map of every vanilla material color to its name. */ private static final BiMap COLOR_MAP = ImmutableBiMap.builder() .put("NONE", class_3620.field_16008) .put("GRASS", class_3620.field_15999) .put("SAND", class_3620.field_15986) .put("WOOL", class_3620.field_15979) .put("FIRE", class_3620.field_16002) .put("ICE", class_3620.field_16016) .put("METAL", class_3620.field_16005) .put("PLANT", class_3620.field_16004) .put("SNOW", class_3620.field_16022) .put("CLAY", class_3620.field_15976) .put("DIRT", class_3620.field_16000) .put("STONE", class_3620.field_16023) .put("WATER", class_3620.field_16019) .put("WOOD", class_3620.field_15996) .put("QUARTZ", class_3620.field_16025) .put("COLOR_ORANGE", class_3620.field_15987) .put("COLOR_MAGENTA", class_3620.field_15998) .put("COLOR_LIGHT_BLUE", class_3620.field_16024) .put("COLOR_YELLOW", class_3620.field_16010) .put("COLOR_LIGHT_GREEN", class_3620.field_15997) .put("COLOR_PINK", class_3620.field_16030) .put("COLOR_GRAY", class_3620.field_15978) .put("COLOR_LIGHT_GRAY", class_3620.field_15993) .put("COLOR_CYAN", class_3620.field_16026) .put("COLOR_PURPLE", class_3620.field_16014) .put("COLOR_BLUE", class_3620.field_15984) .put("COLOR_BROWN", class_3620.field_15977) .put("COLOR_GREEN", class_3620.field_15995) .put("COLOR_RED", class_3620.field_16020) .put("COLOR_BLACK", class_3620.field_16009) .put("GOLD", class_3620.field_15994) .put("DIAMOND", class_3620.field_15983) .put("LAPIS", class_3620.field_15980) .put("EMERALD", class_3620.field_16001) .put("PODZOL", class_3620.field_16017) .put("NETHER", class_3620.field_16012) .put("TERRACOTTA_WHITE", class_3620.field_16003) .put("TERRACOTTA_ORANGE", class_3620.field_15981) .put("TERRACOTTA_MAGENTA", class_3620.field_15985) .put("TERRACOTTA_LIGHT_BLUE", class_3620.field_15991) .put("TERRACOTTA_YELLOW", class_3620.field_16013) .put("TERRACOTTA_LIGHT_GREEN", class_3620.field_16018) .put("TERRACOTTA_PINK", class_3620.field_15989) .put("TERRACOTTA_GRAY", class_3620.field_16027) .put("TERRACOTTA_LIGHT_GRAY", class_3620.field_15988) .put("TERRACOTTA_CYAN", class_3620.field_15990) .put("TERRACOTTA_PURPLE", class_3620.field_16029) .put("TERRACOTTA_BLUE", class_3620.field_16015) .put("TERRACOTTA_BROWN", class_3620.field_15992) .put("TERRACOTTA_GREEN", class_3620.field_16028) .put("TERRACOTTA_RED", class_3620.field_15982) .put("TERRACOTTA_BLACK", class_3620.field_16007) .put("CRIMSON_NYLIUM", class_3620.field_25702) .put("CRIMSON_STEM", class_3620.field_25703) .put("CRIMSON_HYPHAE", class_3620.field_25704) .put("WARPED_NYLIUM", class_3620.field_25705) .put("WARPED_STEM", class_3620.field_25706) .put("WARPED_HYPHAE", class_3620.field_25707) .put("WARPED_WART_BLOCK", class_3620.field_25708) .build(); /** A regular codec used for serializing material colors in config files. */ public static Codec COLOR_CODEC = Codec.STRING.flatXmap( key -> getColor(key).map(DataResult::success).orElse(DataResult.error("No such color: " + key)), color -> serialize(color).map(DataResult::success).orElse(DataResult.error("Unknown color: " + color)) ); /** A regular codec used for serializing material names in config files. */ public static Codec MATERIAL_CODEC = Codec.STRING.flatXmap( key -> getMaterial(key).map(DataResult::success).orElse(DataResult.error("No such material: " + key)), material -> serialize(material).map(DataResult::success).orElse(DataResult.error("Unknown material: " + material)) ); /** A regular codec used for serializing sound types in config files. */ public static Codec SOUND_CODEC = Codec.STRING.flatXmap( key -> getSoundType(key).map(DataResult::success).orElse(DataResult.error("No such sound type: " + key)), sound -> serialize(sound).map(DataResult::success).orElse(DataResult.error("Unknown sound type: " + sound)) ); /** * Attempts to retrieve a material from the map. * * @param key The name of the material being queried. * @return The corresponding material, or else {@link Optional#empty}. */ public static Optional getMaterial(final String key) { return nullable(MATERIAL_MAP.get(key.toUpperCase())); } /** * Returns every material name in the registry. * * @return All material keys. */ public static Set getMaterialNames() { return MATERIAL_MAP.keySet(); } /** * Returns every material object in the registry. * * @return All known material values. */ public static Set getMaterialValues() { return MATERIAL_MAP.values(); } /** * Converts the input material to a string. * * @param value The actual {@link class_3614} object which may have a name. * @return The name of the material, or else {@link Optional#empty}. */ public static Optional serialize(final class_3614 value) { return nullable(MATERIAL_MAP.inverse().get(value)); } /** * Attempts to retrieve a sound type from the map. * * @param key The name of the sound type being queried. * @return The corresponding {@link class_2498}, or else {@link Optional#empty}. */ public static Optional getSoundType(final String key) { return nullable(SOUND_MAP.get(key.toUpperCase())); } /** * Returns every sound name in the registry. * * @return All sound keys. */ public static Set getSoundNames() { return SOUND_MAP.keySet(); } /** * Returns every sound object in the registry. * * @return All known sound types. */ public static Set getSoundValues() { return SOUND_MAP.values(); } /** * Converts the input sound type to a string. * * @param value The actual {@link class_2498} object which may have a name. * @return The name of the sound, or else {@link Optional#empty}. */ public static Optional serialize(final class_2498 value) { return nullable(SOUND_MAP.inverse().get(value)); } /** * Attempts to retrieve a material color from the map. * * @param key The name of the color being queried. * @return The actual color object, or else {@link Optional#empty}. */ public static Optional getColor(final String key) { return nullable(COLOR_MAP.get(key.toUpperCase())); } /** * Returns every color name in the registry. * * @return All known color keys. */ public static Set getColorNames() { return COLOR_MAP.keySet(); } /** * Returns every color object in the registry. * * @return All known color values. */ public static Set getColorValues() { return COLOR_MAP.values(); } /** * Converts the input color type to a string. * * @param value The actual {@link class_3620} which may have a name. * @return The name of the color, or else {@link Optional#empty}. */ public static Optional serialize(final class_3620 value) { return nullable(COLOR_MAP.inverse().get(value)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy