From 52f8874f81116bd6767c6f9247347c30a3820e51 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 8 Jan 2024 01:42:51 +0100 Subject: Created the EMC system --- src/main/java/lv/enes/mc/eris_alchemy/EMC.java | 568 +++++++++++++++++++++ .../java/lv/enes/mc/eris_alchemy/ErisAlchemy.java | 22 +- src/main/java/lv/enes/mc/eris_alchemy/SubAxe.java | 18 + .../mc/eris_alchemy/mixin/CoralBlockMixin.java | 20 + .../mc/eris_alchemy/mixin/CoralFanBlockMixin.java | 20 + .../eris_alchemy/mixin/CoralPlantBlockMixin.java | 20 + .../eris_alchemy/mixin/CoralWallFanBlockMixin.java | 20 + .../lv/enes/mc/eris_alchemy/mixin/ItemMixin.java | 15 +- .../lv/enes/mc/eris_alchemy/mixin/RecipeMixin.java | 29 ++ .../mixin/SmithingTransformRecipeMixin.java | 28 + .../lv/enes/mc/eris_alchemy/utils/BlockUtils.java | 13 + .../lv/enes/mc/eris_alchemy/utils/CoralUtils.java | 42 ++ .../lv/enes/mc/eris_alchemy/utils/DyeUtils.java | 60 +++ .../lv/enes/mc/eris_alchemy/utils/ItemUtils.java | 13 + .../lv/enes/mc/eris_alchemy/utils/RecipeUtils.java | 23 + .../lv/enes/mc/eris_alchemy/utils/TagUtils.java | 14 + 16 files changed, 905 insertions(+), 20 deletions(-) create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/EMC.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/SubAxe.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralBlockMixin.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralFanBlockMixin.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralPlantBlockMixin.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralWallFanBlockMixin.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/mixin/RecipeMixin.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/mixin/SmithingTransformRecipeMixin.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/utils/BlockUtils.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/utils/CoralUtils.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/utils/DyeUtils.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/utils/RecipeUtils.java create mode 100644 src/main/java/lv/enes/mc/eris_alchemy/utils/TagUtils.java (limited to 'src/main/java') diff --git a/src/main/java/lv/enes/mc/eris_alchemy/EMC.java b/src/main/java/lv/enes/mc/eris_alchemy/EMC.java new file mode 100644 index 0000000..4f2c5e4 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/EMC.java @@ -0,0 +1,568 @@ +package lv.enes.mc.eris_alchemy; + +import jakarta.annotation.Nullable; +import lv.enes.mc.eris_alchemy.utils.CoralUtils; +import lv.enes.mc.eris_alchemy.utils.DyeUtils; +import lv.enes.mc.eris_alchemy.utils.ItemUtils; +import lv.enes.mc.eris_alchemy.utils.RecipeUtils; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.*; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import vazkii.patchouli.common.item.PatchouliItems; + +import java.util.*; +import java.util.stream.Stream; + +public class EMC { + private record SimplifiedRecipe(ItemStack output, List remainder, List inputs) { + public SimplifiedRecipe(ItemLike output, Ingredient... inputs) { + this(new ItemStack(output), List.of(), List.of(inputs)); + } + + public SimplifiedRecipe(ItemLike output, ItemLike... inputs) { + this(new ItemStack(output), List.of(), Arrays.stream(inputs).map(Ingredient::of).toList()); + } + + public SimplifiedRecipe(ItemLike output, ItemStack... inputs) { + this(new ItemStack(output), List.of(), Arrays.stream(inputs).map(Ingredient::of).toList()); + } + + public SimplifiedRecipe(ItemLike output, List remainder, ItemLike... inputs) { + this(new ItemStack(output), remainder, Arrays.stream(inputs).map(Ingredient::of).toList()); + } + + public SimplifiedRecipe(ItemStack output, ItemLike... inputs) { + this(output, List.of(), Arrays.stream(inputs).map(Ingredient::of).toList()); + } + + public SimplifiedRecipe(ItemStack output, ItemStack... inputs) { + this(output, List.of(), Arrays.stream(inputs).map(Ingredient::of).toList()); + } + + public SimplifiedRecipe(Recipe recipe, RegistryAccess registryAccess) { + this( + RecipeUtils.getOutput(recipe, registryAccess), + List.of(), // TODO: + RecipeUtils.getIngredients(recipe).stream().filter(ingredient -> !ingredient.isEmpty()).toList() + ); + } + } + + private static final Map ITEM_COMMON_MAP = new HashMap<>(); + private static final Map, Double> ITEM_TAG_COMMON_MAP = new HashMap<>(); + private static final Map, Double> BLOCK_TAG_COMMON_MAP = new HashMap<>(); + private static final List FAKE_RECIPES = new ArrayList<>(); + + private static final EMC defaultInstance = new EMC(null); + private static final Map instances = Collections.synchronizedMap(new WeakHashMap<>()); + + public static EMC getInstance(Level world) { + if (world == null) { + return defaultInstance; + } + + if (instances.containsKey(world)) { + return instances.get(world); + } + + var instance = new EMC(world); + instances.put(world, instance); + return instance; + } + + private final Map data; + + private EMC(@Nullable Level world) { + data = Collections.synchronizedMap(new HashMap<>(ITEM_COMMON_MAP)); + ITEM_TAG_COMMON_MAP.forEach( + (tag, emcValue) -> BuiltInRegistries.ITEM + .getTagOrEmpty(tag) + .forEach(holder -> data.putIfAbsent(holder.value(), emcValue)) + ); + BLOCK_TAG_COMMON_MAP.forEach( + (tag, emcValue) -> BuiltInRegistries.BLOCK + .getTagOrEmpty(tag) + .forEach(holder -> data.putIfAbsent(holder.value().asItem(), emcValue)) + ); + + ErisAlchemy.LOGGER.info("Getting recipes..."); + var recipes = getRecipes(world); + var configured = new HashSet<>(data.keySet()); + ErisAlchemy.LOGGER.info("Calculating EMC values..."); + BuiltInRegistries.ITEM.forEach(item -> { + configEmc(recipes, configured, item); + if (world != null && !data.containsKey(item)) { + ErisAlchemy.LOGGER.warn("No EMC value for '{}' known", item); + } + }); + } + + public OptionalDouble get(Item item) { + var value = data.get(item); + if (value == null || value <= 0) { + return OptionalDouble.empty(); + } + return OptionalDouble.of(value); + } + + private List getRecipes(@Nullable Level world) { + Stream recipes = Stream.concat( + FAKE_RECIPES.stream(), + SubAxe.getStrippables() + .entrySet() + .stream() + .map(entry -> new SimplifiedRecipe(entry.getValue(), Ingredient.of(entry.getKey()))) + ); + + if (world != null) { + recipes = Stream.concat( + recipes, + world.getRecipeManager() + .getRecipes() + .stream() + .map(recipe -> new SimplifiedRecipe(recipe, world.registryAccess())) + ); + } + + return recipes.toList(); + } + + private OptionalDouble configEmc(List recipes, Set configured, Item item) { + var res = get(item); + if (res.isPresent() || configured.contains(item)) { + return res; + } + + configured.add(item); + + res = recipes.stream() + .filter(recipe -> recipe.output.is(item)) + .map(recipe -> calculateEmcForRecipe(recipes, configured, recipe)) + .filter(OptionalDouble::isPresent) + .mapToDouble(OptionalDouble::getAsDouble) + .average(); + res.ifPresent(emc -> data.put(item, emc)); + if (res.isPresent() && res.getAsDouble() <= 0) { + res = OptionalDouble.empty(); + } + return res; + } + + private OptionalDouble calculateEmcForRecipe(List recipes, Set configured, SimplifiedRecipe recipe) { + try { + if (recipe.inputs.isEmpty()) { + return OptionalDouble.empty(); + } + + var inputEmc = recipe.inputs + .stream() + .map(ingredient -> calculateEmcForIngredient(recipes, configured, ingredient)) + .mapToDouble(OptionalDouble::orElseThrow) + .sum(); + + if (inputEmc <= 0) { + return OptionalDouble.empty(); + } + + var remainderEmc = recipe.remainder + .stream() + .map(remainder -> configEmc(recipes, configured, remainder.getItem())) + .mapToDouble(OptionalDouble::orElseThrow) + .sum(); + + if (remainderEmc > inputEmc) { + ErisAlchemy.LOGGER.warn("Recipe generating {} creates too much EMC out of thin air!", recipe.output); + return OptionalDouble.empty(); + } else if (remainderEmc < 0) { + return OptionalDouble.empty(); + } + + var outputDivisor = (double) recipe.output.getCount(); + + return OptionalDouble.of((inputEmc - remainderEmc) / outputDivisor); + } catch (NoSuchElementException e) { + return OptionalDouble.empty(); + } + } + + private OptionalDouble calculateEmcForIngredient(List recipes, Set configured, Ingredient ingredient) { + return Arrays.stream(ingredient.getItems()) + .map(stack -> configEmc(recipes, configured, stack.getItem()).stream() + .map(x -> x * stack.getCount()) + .findFirst()) + .filter(OptionalDouble::isPresent) + .mapToDouble(OptionalDouble::getAsDouble) + .filter(x -> x > 0) + .average(); + } + + static { + ITEM_COMMON_MAP.putAll(Map.ofEntries( + Map.entry(Items.AIR, -1.0), + Map.entry(Items.AMETHYST_CLUSTER, -1.0), + Map.entry(Items.AMETHYST_SHARD, 1024.0), + Map.entry(Items.ANCIENT_DEBRIS, -1.0), + Map.entry(Items.APPLE, 128.0), + Map.entry(Items.BAMBOO, 2.0), + Map.entry(Items.BARRIER, -1.0), + Map.entry(Items.BEDROCK, -1.0), + Map.entry(Items.BEEF, 64.0), + Map.entry(Items.BEETROOT, 24.0), + Map.entry(Items.BEETROOT_SEEDS, 16.0), + Map.entry(Items.BIG_DRIPLEAF, 1.0), + Map.entry(Items.BLAZE_ROD, 1536.0), + Map.entry(Items.BONE, 96.0), + Map.entry(Items.BROWN_MUSHROOM, 32.0), + Map.entry(Items.BROWN_MUSHROOM_BLOCK, -1.0), + Map.entry(Items.BUDDING_AMETHYST, -1.0), + Map.entry(Items.CACTUS, 8.0), + Map.entry(Items.CARROT, 24.0), + Map.entry(Items.CALCITE, 1.0), + Map.entry(Items.CHAIN_COMMAND_BLOCK, -1.0), + Map.entry(Items.CHICKEN, 64.0), + Map.entry(Items.CHORUS_FLOWER, 32.0), + Map.entry(Items.CHORUS_FRUIT, 32.0), + Map.entry(Items.CHORUS_PLANT, 24.0), + Map.entry(Items.CLAY_BALL, 64.0), + Map.entry(Items.COAL, 128.0), + Map.entry(Items.COBWEB, 12.0), + Map.entry(Items.COBBLESTONE, 1.0), + Map.entry(Items.COBBLED_DEEPSLATE, 1.0), + Map.entry(Items.COCOA_BEANS, 8.0), + Map.entry(Items.COMMAND_BLOCK, -1.0), + Map.entry(Items.COMMAND_BLOCK_MINECART, -1.0), + Map.entry(Items.COPPER_INGOT, 85.0), + Map.entry(Items.CREEPER_HEAD, 34816.0), + Map.entry(Items.CRIMSON_FUNGUS, 24.0), + Map.entry(Items.CRIMSON_ROOTS, 1.0), + Map.entry(Items.CRYING_OBSIDIAN, 64.0), + Map.entry(Items.DEAD_BUSH, 1.0), + Map.entry(Items.DEBUG_STICK, -1.0), + Map.entry(Items.DIAMOND, 8192.0), + Map.entry(Items.DIRT_PATH, 1.0), + Map.entry(Items.DRAGON_BREATH, 34816.0), + Map.entry(Items.DRAGON_EGG, 139264.0), + Map.entry(Items.DRAGON_HEAD, 34816.0), + Map.entry(Items.ECHO_SHARD, 128.0), + Map.entry(Items.EGG, 32.0), + Map.entry(Items.ELYTRA, 8196.0), + Map.entry(Items.EMERALD, 1024.0), + Map.entry(Items.ENCHANTED_BOOK, -1.0), + Map.entry(Items.END_PORTAL_FRAME, -1.0), + Map.entry(Items.END_STONE, 1.0), + Map.entry(Items.ENDER_PEARL, 1024.0), + Map.entry(Items.EXPERIENCE_BOTTLE, -1.0), + Map.entry(Items.FARMLAND, -1.0), + Map.entry(Items.FEATHER, 48.0), + Map.entry(Items.FERN, 1.0), + Map.entry(Items.FIREWORK_STAR, -1.0), + Map.entry(Items.FLINT, 4.0), + Map.entry(Items.FROGSPAWN, -1.0), + Map.entry(Items.GHAST_TEAR, 4096.0), + Map.entry(Items.GLOW_BERRIES, 8.0), + Map.entry(Items.GLOW_LICHEN, 8.0), + Map.entry(Items.GLOWSTONE_DUST, 384.0), + Map.entry(Items.GOAT_HORN, 32.0), + Map.entry(Items.GOLD_INGOT, 2048.0), + Map.entry(Items.GOLD_NUGGET, 2048.0/9), + Map.entry(Items.GRASS, 1.0), + Map.entry(Items.GRAVEL, 4.0), + Map.entry(Items.GUNPOWDER, 192.0), + Map.entry(Items.HANGING_ROOTS, 1.0), + Map.entry(Items.HEART_OF_THE_SEA, 4096.0), + Map.entry(Items.HONEYCOMB, 24.0), + Map.entry(Items.ICE, 1.0), + Map.entry(Items.INFESTED_CHISELED_STONE_BRICKS, -1.0), + Map.entry(Items.INFESTED_COBBLESTONE, -1.0), + Map.entry(Items.INFESTED_CRACKED_STONE_BRICKS, -1.0), + Map.entry(Items.INFESTED_DEEPSLATE, -1.0), + Map.entry(Items.INFESTED_MOSSY_STONE_BRICKS, -1.0), + Map.entry(Items.INFESTED_STONE, -1.0), + Map.entry(Items.INFESTED_STONE_BRICKS, -1.0), + Map.entry(Items.IRON_INGOT, 256.0), + Map.entry(Items.IRON_NUGGET, 256.0/9), + Map.entry(Items.JIGSAW, -1.0), + Map.entry(Items.KELP, 32.0), + Map.entry(Items.KNOWLEDGE_BOOK, -1.0), + Map.entry(Items.LAPIS_LAZULI, 864.0), + Map.entry(Items.LARGE_AMETHYST_BUD, -1.0), + Map.entry(Items.LARGE_FERN, 1.0), + Map.entry(Items.LEATHER, 64.0), + Map.entry(Items.LIGHT, -1.0), + Map.entry(Items.LILY_PAD, 16.0), + Map.entry(Items.LINGERING_POTION, -1.0), + Map.entry(Items.MANGROVE_ROOTS, 1.0), + Map.entry(Items.MEDIUM_AMETHYST_BUD, -1.0), + Map.entry(Items.MELON_SLICE, 144.0), + Map.entry(Items.MUD, 1.0), + Map.entry(Items.MUSHROOM_STEM, -1.0), + Map.entry(Items.MUTTON, 64.0), + Map.entry(Items.NAME_TAG, -1.0), + Map.entry(Items.NAUTILUS_SHELL, 64.0), + Map.entry(Items.NETHER_QUARTZ_ORE, -1.0), + Map.entry(Items.NETHER_SPROUTS, 1.0), + Map.entry(Items.NETHER_STAR, 139264.0), + Map.entry(Items.NETHER_WART, 24.0), + Map.entry(Items.NETHERITE_SCRAP, 16384.0), + Map.entry(Items.OBSIDIAN, 64.0), + Map.entry(Items.PHANTOM_MEMBRANE, 96.0), + Map.entry(Items.PIGLIN_HEAD, 34816.0), + Map.entry(Items.PITCHER_POD, 8.0), + Map.entry(Items.PLAYER_HEAD, 34816.0), + Map.entry(Items.POINTED_DRIPSTONE, 0.25), + Map.entry(Items.PORKCHOP, 64.0), + Map.entry(Items.POTATO, 24.0), + Map.entry(Items.POTION, -1.0), + Map.entry(Items.PRISMARINE_CRYSTALS, 384.0), + Map.entry(Items.PRISMARINE_SHARD, 0.25), + Map.entry(Items.PUMPKIN, 144.0), + Map.entry(Items.QUARTZ, 64.0), + Map.entry(Items.RABBIT, 64.0), + Map.entry(Items.RABBIT_HIDE, 64.0), + Map.entry(Items.RAW_COPPER, -1.0), + Map.entry(Items.RAW_COPPER_BLOCK, -1.0), + Map.entry(Items.RAW_GOLD, -1.0), + Map.entry(Items.RAW_GOLD_BLOCK, -1.0), + Map.entry(Items.RAW_IRON, -1.0), + Map.entry(Items.RAW_IRON_BLOCK, -1.0), + Map.entry(Items.RED_MUSHROOM, 32.0), + Map.entry(Items.RED_MUSHROOM_BLOCK, -1.0), + Map.entry(Items.REDSTONE, 64.0), + Map.entry(Items.REINFORCED_DEEPSLATE, -1.0), + Map.entry(Items.REPEATING_COMMAND_BLOCK, -1.0), + Map.entry(Items.ROTTEN_FLESH, 24.0), + Map.entry(Items.SADDLE, 192.0), + Map.entry(Items.SCULK, 1.0), + Map.entry(Items.SCULK_CATALYST, 16.0), + Map.entry(Items.SCULK_SENSOR, 32.0), + Map.entry(Items.SCULK_SHRIEKER, 16.0), + Map.entry(Items.SCULK_VEIN, 1.0), + Map.entry(Items.SCUTE, 32.0), + Map.entry(Items.SEA_PICKLE, 1.0), + Map.entry(Items.SEAGRASS, 1.0), + Map.entry(Items.SHULKER_SHELL, 256.0), + Map.entry(Items.SKELETON_SKULL, 34816.0), + Map.entry(Items.SLIME_BALL, 24.0), + Map.entry(Items.SMALL_AMETHYST_BUD, -1.0), + Map.entry(Items.SMALL_DRIPLEAF, 1.0), + Map.entry(Items.SNIFFER_EGG, 32.0), + Map.entry(Items.SNOWBALL, 1.0), + Map.entry(Items.SOUL_SAND, 49.0), + Map.entry(Items.SOUL_SOIL, 49.0), + Map.entry(Items.SPAWNER, -1.0), + Map.entry(Items.SPIDER_EYE, 128.0), + Map.entry(Items.SPLASH_POTION, -1.0), + Map.entry(Items.SPONGE, 48.0), + Map.entry(Items.SPORE_BLOSSOM, 1.0), + Map.entry(Items.STICK, 4.0), + Map.entry(Items.STRING, 12.0), + Map.entry(Items.STRUCTURE_BLOCK, -1.0), + Map.entry(Items.STRUCTURE_VOID, -1.0), + Map.entry(Items.SUGAR_CANE, 32.0), + Map.entry(Items.SUSPICIOUS_GRAVEL, 4.0), + Map.entry(Items.SWEET_BERRIES, 8.0), + Map.entry(Items.TALL_GRASS, 1.0), + Map.entry(Items.TIPPED_ARROW, -1.0), + Map.entry(Items.TORCHFLOWER_SEEDS, 8.0), + Map.entry(Items.TOTEM_OF_UNDYING, 4096.0), + Map.entry(Items.TURTLE_EGG, 32.0), + Map.entry(Items.TWISTING_VINES, 8.0), + Map.entry(Items.VINE, 8.0), + Map.entry(Items.WARPED_FUNGUS, 24.0), + Map.entry(Items.WARPED_ROOTS, 1.0), + Map.entry(Items.WARPED_WART_BLOCK, 1.0), + Map.entry(Items.WEEPING_VINES, 8.0), + Map.entry(Items.WET_SPONGE, 48.0), + Map.entry(Items.WHEAT, 24.0), + Map.entry(Items.WHEAT_SEEDS, 16.0), + Map.entry(Items.WITHER_SKELETON_SKULL, 34816.0), + Map.entry(Items.WRITTEN_BOOK, -1.0), + Map.entry(Items.ZOMBIE_HEAD, 34816.0), + + Map.entry(PatchouliItems.BOOK, -1.0) + )); + + SpawnEggItem.eggs().forEach(spawnEgg -> ITEM_COMMON_MAP.put(spawnEgg, -1.0)); + + CoralUtils.streamAllCoralBlocks().forEach(block -> ITEM_COMMON_MAP.put(block.asItem(), 1.0)); + CoralUtils.streamAllDeadCoralBlocks().forEach(block -> ITEM_COMMON_MAP.put(block.asItem(), 1.0)); + CoralUtils.streamAllCorals().forEach(block -> ITEM_COMMON_MAP.put(block.asItem(), 1.0)); + CoralUtils.streamAllDeadCorals().forEach(block -> ITEM_COMMON_MAP.put(block.asItem(), 1.0)); + + BLOCK_TAG_COMMON_MAP.putAll(Map.ofEntries( + Map.entry(BlockTags.BASE_STONE_NETHER, 1.0), + Map.entry(BlockTags.BASE_STONE_OVERWORLD, 1.0), + Map.entry(BlockTags.NYLIUM, 1.0) + )); + + ITEM_TAG_COMMON_MAP.putAll(Map.ofEntries( + Map.entry(ItemTags.COAL_ORES, -1.0), + Map.entry(ItemTags.COPPER_ORES, -1.0), + Map.entry(ItemTags.DIAMOND_ORES, -1.0), + Map.entry(ItemTags.DIRT, 1.0), + Map.entry(ItemTags.MUSIC_DISCS, 4096.0), + Map.entry(ItemTags.EMERALD_ORES, -1.0), + Map.entry(ItemTags.FISHES, 64.0), + Map.entry(ItemTags.FLOWERS, 16.0), + Map.entry(ItemTags.GOLD_ORES, -1.0), + Map.entry(ItemTags.IRON_ORES, -1.0), + Map.entry(ItemTags.LAPIS_ORES, -1.0), + Map.entry(ItemTags.LEAVES, 1.0), + Map.entry(ItemTags.LOGS, 32.0), + Map.entry(ItemTags.REDSTONE_ORES, -1.0), + Map.entry(ItemTags.SAND, 1.0), + Map.entry(ItemTags.SAPLINGS, 32.0), + Map.entry(ItemTags.WOOL, 48.0) + )); + + FAKE_RECIPES.addAll(List.of( + // more oxidised coppers are worth less + new SimplifiedRecipe(new ItemStack(Items.EXPOSED_COPPER, 4), new ItemStack(Items.COPPER_BLOCK, 3)), + new SimplifiedRecipe(new ItemStack(Items.WEATHERED_COPPER, 4), new ItemStack(Items.COPPER_BLOCK, 2)), + new SimplifiedRecipe(new ItemStack(Items.OXIDIZED_COPPER, 4), new ItemStack(Items.COPPER_BLOCK, 1)), + + new SimplifiedRecipe(new ItemStack(Items.WAXED_EXPOSED_COPPER, 4), new ItemStack(Items.WAXED_COPPER_BLOCK, 3)), + new SimplifiedRecipe(new ItemStack(Items.WAXED_WEATHERED_COPPER, 4), new ItemStack(Items.WAXED_COPPER_BLOCK, 2)), + new SimplifiedRecipe(new ItemStack(Items.WAXED_OXIDIZED_COPPER, 4), new ItemStack(Items.WAXED_COPPER_BLOCK, 1)), + + // more damaged anvils are worth less + new SimplifiedRecipe(new ItemStack(Items.CHIPPED_ANVIL, 3), new ItemStack(Items.ANVIL, 2)), + new SimplifiedRecipe(new ItemStack(Items.DAMAGED_ANVIL, 3), new ItemStack(Items.ANVIL, 1)), + + // old oak slabs are the same value as modern ones + new SimplifiedRecipe(Items.PETRIFIED_OAK_SLAB, Items.OAK_SLAB), + + // chainmail armour is worth the same as normal iron armor + new SimplifiedRecipe(Items.CHAINMAIL_HELMET, Items.IRON_HELMET), + new SimplifiedRecipe(Items.CHAINMAIL_CHESTPLATE, Items.IRON_CHESTPLATE), + new SimplifiedRecipe(Items.CHAINMAIL_LEGGINGS, Items.IRON_LEGGINGS), + new SimplifiedRecipe(Items.CHAINMAIL_BOOTS, Items.IRON_BOOTS), + + // enchanted golden apple is worth uhh 16 times the non-enchanted one :3 + new SimplifiedRecipe(Items.ENCHANTED_GOLDEN_APPLE, new ItemStack(Items.GOLDEN_APPLE, 16)), + + // carving a pumpkin with shears + new SimplifiedRecipe(Items.CARVED_PUMPKIN, List.of(new ItemStack(Items.PUMPKIN_SEEDS, 4)), Items.PUMPKIN), + + // gathering honey + new SimplifiedRecipe(Items.HONEY_BOTTLE, Items.HONEYCOMB, Items.GLASS_BOTTLE), + + // smithing template duplicating recipes but -1 templates on both sides + new SimplifiedRecipe(Items.COAST_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.COBBLESTONE)), + new SimplifiedRecipe(Items.DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.SANDSTONE)), + new SimplifiedRecipe(Items.EYE_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.END_STONE)), + new SimplifiedRecipe(Items.HOST_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.TERRACOTTA)), + new SimplifiedRecipe(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.NETHERRACK)), + new SimplifiedRecipe(Items.RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.TERRACOTTA)), + new SimplifiedRecipe(Items.RIB_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.NETHERRACK)), + new SimplifiedRecipe(Items.SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.COBBLESTONE)), + new SimplifiedRecipe(Items.SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.TERRACOTTA)), + new SimplifiedRecipe(Items.SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.COBBLED_DEEPSLATE)), + new SimplifiedRecipe(Items.SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.BLACKSTONE)), + new SimplifiedRecipe(Items.SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.PURPUR_BLOCK)), + new SimplifiedRecipe(Items.TIDE_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.PRISMARINE)), + new SimplifiedRecipe(Items.VEX_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.COBBLESTONE)), + new SimplifiedRecipe(Items.WARD_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.COBBLED_DEEPSLATE)), + new SimplifiedRecipe(Items.WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.TERRACOTTA)), + new SimplifiedRecipe(Items.WILD_ARMOR_TRIM_SMITHING_TEMPLATE, new ItemStack(Items.DIAMOND, 7), new ItemStack(Items.MOSSY_COBBLESTONE)), + + // water bucket = bucket + water, water assumed to be same value as cobblestone + new SimplifiedRecipe(Items.WATER_BUCKET, Items.BUCKET, Items.COBBLESTONE), + + // lava bucket = bucket + lava, lava assumed to be same value as obsidian + new SimplifiedRecipe(Items.LAVA_BUCKET, Items.BUCKET, Items.OBSIDIAN), + + // powder snow bucket = bucket + snow + new SimplifiedRecipe(Items.POWDER_SNOW_BUCKET, Items.BUCKET, Items.SNOW_BLOCK), + + // milk bucket = bucket + milk, milk assumed to be same value as wheat + new SimplifiedRecipe(Items.MILK_BUCKET, Items.BUCKET, Items.WHEAT), + + // [fish] bucket = bucket + [fish] + new SimplifiedRecipe(Items.COD_BUCKET, Items.BUCKET, Items.COD), + new SimplifiedRecipe(Items.PUFFERFISH_BUCKET, Items.BUCKET, Items.PUFFERFISH), + new SimplifiedRecipe(Items.SALMON_BUCKET, Items.BUCKET, Items.SALMON), + new SimplifiedRecipe(Items.TROPICAL_FISH_BUCKET, Items.BUCKET, Items.TROPICAL_FISH), + + // yep + new SimplifiedRecipe(Items.AXOLOTL_BUCKET, Items.TROPICAL_FISH_BUCKET), + new SimplifiedRecipe(Items.TADPOLE_BUCKET, Items.AXOLOTL_BUCKET), + + // dye value is the canon + new SimplifiedRecipe(Items.INK_SAC, Items.BLACK_DYE), + + // disc value is the canon + new SimplifiedRecipe(new ItemStack(Items.DISC_FRAGMENT_5, 9), Items.MUSIC_DISC_5), + + // glowing ink sac is more expensive than an ink sac + new SimplifiedRecipe(Items.GLOW_INK_SAC, new ItemStack(Items.INK_SAC, 4)), + + // activated maps cost the same as unactivated ones + new SimplifiedRecipe(Items.FILLED_MAP, Items.MAP), + + // poisonous potato costs less than a normal one + new SimplifiedRecipe(new ItemStack(Items.POISONOUS_POTATO, 2), Items.POTATO), + + // rabbits foot costs more than rabbit meat + new SimplifiedRecipe(Items.RABBIT_FOOT, new ItemStack(Items.RABBIT, 8)), + + // [X] horse armor == [X] leggings + // wtf, why? see how much leather is used by leather horse armor + new SimplifiedRecipe(Items.IRON_HORSE_ARMOR, Items.IRON_LEGGINGS), + new SimplifiedRecipe(Items.GOLDEN_HORSE_ARMOR, Items.GOLDEN_LEGGINGS), + new SimplifiedRecipe(Items.DIAMOND_HORSE_ARMOR, Items.DIAMOND_LEGGINGS), + + // Trident = 1.5 * iron sword + new SimplifiedRecipe(new ItemStack(Items.TRIDENT, 2), new ItemStack(Items.IRON_SWORD, 3)), + + // an actual recipe but it's special, minecraft:crafting_special_suspiciousstew + new SimplifiedRecipe(Items.SUSPICIOUS_STEW, Items.BOWL, Items.BROWN_MUSHROOM, Items.RED_MUSHROOM, Items.POPPY), + + // obvious + new SimplifiedRecipe(Items.GLOBE_BANNER_PATTERN, Items.CREEPER_BANNER_PATTERN), + new SimplifiedRecipe(Items.PIGLIN_BANNER_PATTERN, Items.CREEPER_BANNER_PATTERN), + + // the vibes fit + new SimplifiedRecipe(Items.BELL, Items.SPYGLASS), + + // light sources, shroomlight has no crafting uses but is brighter + new SimplifiedRecipe(Items.SHROOMLIGHT, Items.GLOWSTONE), + + // bee nest = honeycomb block + new SimplifiedRecipe(Items.BEE_NEST, new ItemStack(Items.HONEYCOMB, 9)), + + // gilded blackstone = blackstone with gold nuggets + new SimplifiedRecipe(Items.GILDED_BLACKSTONE, new ItemStack(Items.BLACKSTONE), new ItemStack(Items.GOLD_NUGGET, 4)), + + // froglight = eaten magma cube + new SimplifiedRecipe(Items.OCHRE_FROGLIGHT, Items.MAGMA_CREAM), + new SimplifiedRecipe(Items.PEARLESCENT_FROGLIGHT, Items.MAGMA_CREAM), + new SimplifiedRecipe(Items.VERDANT_FROGLIGHT, Items.MAGMA_CREAM), + + // UPGRADE[1.20.1]: currently experimental stuff + new SimplifiedRecipe(Items.BUNDLE, new ItemStack(Items.RABBIT_HIDE, 6), new ItemStack(Items.STRING, 2)) + )); + + // pot sherds can be replaced with bricks when making decorated pots + ItemUtils.streamTag(ItemTags.DECORATED_POT_SHERDS).forEach(sherd -> FAKE_RECIPES.add(new SimplifiedRecipe(sherd, Items.BRICK))); + + for (var color : DyeColor.values()) { + ITEM_COMMON_MAP.put(DyeUtils.getDye(color), 8.0); + FAKE_RECIPES.addAll(List.of( + // putting concrete powder in water + new SimplifiedRecipe(DyeUtils.getConcrete(color), DyeUtils.getConcretePowder(color)), + + // an actual recipe but it's special, minecraft:crafting_special_shulkerboxcoloring + new SimplifiedRecipe(DyeUtils.getShulkerBox(color), Items.SHULKER_BOX, DyeUtils.getDye(color)) + )); + } + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java index 724b9c4..a4368fc 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; @@ -18,24 +19,9 @@ public class ErisAlchemy implements ModInitializer { public static final String ID = "eris_alchemy"; public static final Logger LOGGER = LoggerFactory.getLogger(ID); - // Aside from crafting recipe inputs, covalence dusts can be used to repair equipment via shapeless crafting - // Low covalence dust: - // - wooden and stone tools - // - leather armour - // - fishing rods - // - wooden bows - // - turtle shells - // Medium covalence dust: - // - iron, gold, bronze, ruby, sapphire, and green sapphire tools and armour - // - flints & steels - // - shears - // - elytras - // High covalence dust: - // - diamond and netherite tools and armour - // 8 dusts are enough to repair 100% :3 - public static final Item LOW_COVALENCE_DUST = new Item(new QuiltItemSettings()); - public static final Item MEDIUM_COVALENCE_DUST = new Item(new QuiltItemSettings()); - public static final Item HIGH_COVALENCE_DUST = new Item(new QuiltItemSettings()); + public static final Item LOW_COVALENCE_DUST = new Item(new QuiltItemSettings().rarity(Rarity.COMMON)); + public static final Item MEDIUM_COVALENCE_DUST = new Item(new QuiltItemSettings().rarity(Rarity.UNCOMMON)); + public static final Item HIGH_COVALENCE_DUST = new Item(new QuiltItemSettings().rarity(Rarity.RARE)); public static final CreativeModeTab ITEM_GROUP = FabricItemGroup.builder() .icon(() -> new ItemStack(LOW_COVALENCE_DUST)) diff --git a/src/main/java/lv/enes/mc/eris_alchemy/SubAxe.java b/src/main/java/lv/enes/mc/eris_alchemy/SubAxe.java new file mode 100644 index 0000000..045a5a1 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/SubAxe.java @@ -0,0 +1,18 @@ +package lv.enes.mc.eris_alchemy; + +import net.minecraft.world.item.AxeItem; +import net.minecraft.world.item.Tier; +import net.minecraft.world.level.block.Block; + +import java.util.Map; + +/** The only reason this exists is to read STRIPPABLES property from AxeItem :3 */ +public abstract class SubAxe extends AxeItem { + public static Map getStrippables() { + return STRIPPABLES; + } + + private SubAxe(Tier material, float attackDamage, float attackSpeed, Properties settings) { + super(material, attackDamage, attackSpeed, settings); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralBlockMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralBlockMixin.java new file mode 100644 index 0000000..d8024c9 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralBlockMixin.java @@ -0,0 +1,20 @@ +package lv.enes.mc.eris_alchemy.mixin; + +import lv.enes.mc.eris_alchemy.utils.CoralUtils; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralBlock; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CoralBlock.class) +public abstract class CoralBlockMixin implements CoralUtils.CoralSuper { + @Final + @Shadow + private Block deadBlock; + + @Override + public Block lv_enes_mc$getDead() { + return deadBlock; + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralFanBlockMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralFanBlockMixin.java new file mode 100644 index 0000000..86ab8f6 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralFanBlockMixin.java @@ -0,0 +1,20 @@ +package lv.enes.mc.eris_alchemy.mixin; + +import lv.enes.mc.eris_alchemy.utils.CoralUtils; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralFanBlock; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CoralFanBlock.class) +public abstract class CoralFanBlockMixin implements CoralUtils.CoralSuper { + @Final + @Shadow + private Block deadBlock; + + @Override + public Block lv_enes_mc$getDead() { + return deadBlock; + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralPlantBlockMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralPlantBlockMixin.java new file mode 100644 index 0000000..a5614f9 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralPlantBlockMixin.java @@ -0,0 +1,20 @@ +package lv.enes.mc.eris_alchemy.mixin; + +import lv.enes.mc.eris_alchemy.utils.CoralUtils; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralPlantBlock; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CoralPlantBlock.class) +public abstract class CoralPlantBlockMixin implements CoralUtils.CoralSuper { + @Final + @Shadow + private Block deadBlock; + + @Override + public Block lv_enes_mc$getDead() { + return deadBlock; + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralWallFanBlockMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralWallFanBlockMixin.java new file mode 100644 index 0000000..8ffa07e --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/CoralWallFanBlockMixin.java @@ -0,0 +1,20 @@ +package lv.enes.mc.eris_alchemy.mixin; + +import lv.enes.mc.eris_alchemy.utils.CoralUtils; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralWallFanBlock; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CoralWallFanBlock.class) +public abstract class CoralWallFanBlockMixin implements CoralUtils.CoralSuper { + @Final + @Shadow + private Block deadBlock; + + @Override + public Block lv_enes_mc$getDead() { + return deadBlock; + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java index 54a2fd0..aa6270b 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/ItemMixin.java @@ -1,21 +1,32 @@ package lv.enes.mc.eris_alchemy.mixin; +import lv.enes.mc.eris_alchemy.EMC; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.text.DecimalFormat; import java.util.List; @Mixin(Item.class) -public class ItemMixin { +public abstract class ItemMixin { + @Unique + private static final DecimalFormat doubleFormat = new DecimalFormat("0"); + + static { + doubleFormat.setMaximumFractionDigits(1); + } + @Inject(method = "appendHoverText", at = @At("RETURN")) public void onAppendHoverText(ItemStack stack, Level world, List tooltip, TooltipFlag context, CallbackInfo ci) { - tooltip.add(Component.literal("EMC ???")); + var emc = EMC.getInstance(world).get(stack.getItem()); + emc.ifPresent(value -> tooltip.add(Component.literal("EMC %s".formatted(doubleFormat.format(value))))); } } diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/RecipeMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/RecipeMixin.java new file mode 100644 index 0000000..43051e4 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/RecipeMixin.java @@ -0,0 +1,29 @@ +package lv.enes.mc.eris_alchemy.mixin; + +import lv.enes.mc.eris_alchemy.utils.RecipeUtils; +import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.Recipe; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(Recipe.class) +public interface RecipeMixin extends RecipeUtils.RecipeSuper { + @Shadow + NonNullList getIngredients(); + + @Shadow + ItemStack getResultItem(RegistryAccess registryAccess); + + @Override + default NonNullList lv_enes_mc$getIngredients() { + return getIngredients(); + } + + @Override + default ItemStack lv_enes_mc$getOutput(RegistryAccess registryAccess) { + return getResultItem(registryAccess); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/SmithingTransformRecipeMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/SmithingTransformRecipeMixin.java new file mode 100644 index 0000000..bcf49b0 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/SmithingTransformRecipeMixin.java @@ -0,0 +1,28 @@ +package lv.enes.mc.eris_alchemy.mixin; + +import lv.enes.mc.eris_alchemy.utils.RecipeUtils; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.SmithingTransformRecipe; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.List; + +@Mixin(SmithingTransformRecipe.class) +public abstract class SmithingTransformRecipeMixin implements RecipeUtils.RecipeSuper { + @Final + @Shadow + Ingredient template; + @Final + @Shadow + Ingredient base; + @Final + @Shadow + Ingredient addition; + + @Override + public List lv_enes_mc$getIngredients() { + return List.of(template, base, addition); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/BlockUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/BlockUtils.java new file mode 100644 index 0000000..74b6069 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/BlockUtils.java @@ -0,0 +1,13 @@ +package lv.enes.mc.eris_alchemy.utils; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.block.Block; + +import java.util.stream.Stream; + +public class BlockUtils { + public static Stream streamTag(TagKey tag) { + return TagUtils.stream(BuiltInRegistries.BLOCK, tag); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/CoralUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/CoralUtils.java new file mode 100644 index 0000000..c9203c6 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/CoralUtils.java @@ -0,0 +1,42 @@ +package lv.enes.mc.eris_alchemy.utils; + +import net.minecraft.tags.BlockTags; +import net.minecraft.world.level.block.*; + +import java.util.stream.Stream; + +public class CoralUtils { + /** + * @see lv.enes.mc.eris_alchemy.mixin.CoralBlockMixin + * @see lv.enes.mc.eris_alchemy.mixin.CoralFanBlockMixin + * @see lv.enes.mc.eris_alchemy.mixin.CoralPlantBlockMixin + * @see lv.enes.mc.eris_alchemy.mixin.CoralWallFanBlockMixin + */ + public interface CoralSuper { + Block lv_enes_mc$getDead(); + } + + public static Stream streamAllCoralBlocks() { + return BlockUtils.streamTag(BlockTags.CORAL_BLOCKS).map(b -> (CoralBlock)b); + } + + public static Stream streamAllCorals() { + return BlockUtils.streamTag(BlockTags.CORALS).map(b -> (BaseCoralPlantTypeBlock)b); + } + + public static Stream streamAllDeadCoralBlocks() { + return streamAllCoralBlocks().map(CoralUtils::getDeadCoralBlock); + } + + public static Stream streamAllDeadCorals() { + return streamAllCorals().map(CoralUtils::getDeadCoral); + } + + public static Block getDeadCoral(BaseCoralPlantTypeBlock live ) { + return ((CoralSuper)live).lv_enes_mc$getDead(); + } + + public static Block getDeadCoralBlock(CoralBlock live) { + return ((CoralSuper)live).lv_enes_mc$getDead(); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/DyeUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/DyeUtils.java new file mode 100644 index 0000000..83c8e04 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/DyeUtils.java @@ -0,0 +1,60 @@ +package lv.enes.mc.eris_alchemy.utils; + +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.DyeItem; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ConcretePowderBlock; +import net.minecraft.world.level.block.ShulkerBoxBlock; + +public class DyeUtils { + public static Block getConcrete(DyeColor color) { + return switch (color) { + case BLACK -> Blocks.BLACK_CONCRETE; + case BLUE -> Blocks.BLUE_CONCRETE; + case BROWN -> Blocks.BROWN_CONCRETE; + case CYAN -> Blocks.CYAN_CONCRETE; + case GRAY -> Blocks.GRAY_CONCRETE; + case GREEN -> Blocks.GREEN_CONCRETE; + case LIGHT_BLUE -> Blocks.LIGHT_BLUE_CONCRETE; + case LIGHT_GRAY -> Blocks.LIGHT_GRAY_CONCRETE; + case LIME -> Blocks.LIME_CONCRETE; + case MAGENTA -> Blocks.MAGENTA_CONCRETE; + case ORANGE -> Blocks.ORANGE_CONCRETE; + case PINK -> Blocks.PINK_CONCRETE; + case PURPLE -> Blocks.PURPLE_CONCRETE; + case RED -> Blocks.RED_CONCRETE; + case WHITE -> Blocks.WHITE_CONCRETE; + case YELLOW -> Blocks.YELLOW_CONCRETE; + }; + } + + public static ConcretePowderBlock getConcretePowder(DyeColor color) { + return (ConcretePowderBlock)switch (color) { + case BLACK -> Blocks.BLACK_CONCRETE_POWDER; + case BLUE -> Blocks.BLUE_CONCRETE_POWDER; + case BROWN -> Blocks.BROWN_CONCRETE_POWDER; + case CYAN -> Blocks.CYAN_CONCRETE_POWDER; + case GRAY -> Blocks.GRAY_CONCRETE_POWDER; + case GREEN -> Blocks.GREEN_CONCRETE_POWDER; + case LIGHT_BLUE -> Blocks.LIGHT_BLUE_CONCRETE_POWDER; + case LIGHT_GRAY -> Blocks.LIGHT_GRAY_CONCRETE_POWDER; + case LIME -> Blocks.LIME_CONCRETE_POWDER; + case MAGENTA -> Blocks.MAGENTA_CONCRETE_POWDER; + case ORANGE -> Blocks.ORANGE_CONCRETE_POWDER; + case PINK -> Blocks.PINK_CONCRETE_POWDER; + case PURPLE -> Blocks.PURPLE_CONCRETE_POWDER; + case RED -> Blocks.RED_CONCRETE_POWDER; + case WHITE -> Blocks.WHITE_CONCRETE_POWDER; + case YELLOW -> Blocks.YELLOW_CONCRETE_POWDER; + }; + } + + public static DyeItem getDye(DyeColor color) { + return DyeItem.byColor(color); + } + + public static ShulkerBoxBlock getShulkerBox(DyeColor color) { + return (ShulkerBoxBlock)ShulkerBoxBlock.getBlockByColor(color); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java new file mode 100644 index 0000000..2f7c8b2 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java @@ -0,0 +1,13 @@ +package lv.enes.mc.eris_alchemy.utils; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; + +import java.util.stream.Stream; + +public class ItemUtils { + public static Stream streamTag(TagKey tag) { + return TagUtils.stream(BuiltInRegistries.ITEM, tag); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/RecipeUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/RecipeUtils.java new file mode 100644 index 0000000..53ceaab --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/RecipeUtils.java @@ -0,0 +1,23 @@ +package lv.enes.mc.eris_alchemy.utils; + +import net.minecraft.core.RegistryAccess; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.Recipe; + +import java.util.List; + +public class RecipeUtils { + public interface RecipeSuper { + List lv_enes_mc$getIngredients(); + ItemStack lv_enes_mc$getOutput(RegistryAccess registryAccess); + } + + public static List getIngredients(Recipe recipe) { + return ((RecipeSuper)recipe).lv_enes_mc$getIngredients(); + } + + public static ItemStack getOutput(Recipe recipe, RegistryAccess registryAccess) { + return ((RecipeSuper)recipe).lv_enes_mc$getOutput(registryAccess); + } +} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/TagUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/TagUtils.java new file mode 100644 index 0000000..bb923ba --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/TagUtils.java @@ -0,0 +1,14 @@ +package lv.enes.mc.eris_alchemy.utils; + +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.tags.TagKey; + +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class TagUtils { + public static Stream stream(Registry registry, TagKey tag) { + return StreamSupport.stream(registry.getTagOrEmpty(tag).spliterator(), false).map(Holder::value); + } +} -- cgit v1.2.3