From 0c474664806cce70a5c1ce5069d314de9262daa7 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 26 Nov 2023 13:04:11 -0600 Subject: [PATCH] generate site data, fix patchouli typo --- LATEST_CHANGES.MD | 1 + .../command/GenerateSiteData.java | 154 ++++++++++++------ .../en_us/entries/misc/schools.json | 6 +- 3 files changed, 106 insertions(+), 55 deletions(-) diff --git a/LATEST_CHANGES.MD b/LATEST_CHANGES.MD index 78ffba51f..e072c012c 100644 --- a/LATEST_CHANGES.MD +++ b/LATEST_CHANGES.MD @@ -28,6 +28,7 @@ - Undead are weak to Holy magic and resistant to Blood magic - Fire mobs are resistant to Fire magic - Water mobs are weak to Lightning magic + - Added Scroll Bar to Scroll Forge ### Changes - Spell Balance diff --git a/src/main/java/io/redspace/ironsspellbooks/command/GenerateSiteData.java b/src/main/java/io/redspace/ironsspellbooks/command/GenerateSiteData.java index c808e4bf8..57006ffed 100644 --- a/src/main/java/io/redspace/ironsspellbooks/command/GenerateSiteData.java +++ b/src/main/java/io/redspace/ironsspellbooks/command/GenerateSiteData.java @@ -5,9 +5,12 @@ import io.redspace.ironsspellbooks.IronsSpellbooks; import io.redspace.ironsspellbooks.api.registry.SpellRegistry; import io.redspace.ironsspellbooks.capabilities.spellbook.SpellBookData; +import io.redspace.ironsspellbooks.item.InkItem; import io.redspace.ironsspellbooks.item.SpellBook; import io.redspace.ironsspellbooks.item.UniqueSpellBook; import io.redspace.ironsspellbooks.api.item.weapons.ExtendedSwordItem; +import io.redspace.ironsspellbooks.item.UpgradeOrbItem; +import io.redspace.ironsspellbooks.item.consumables.SimpleElixir; import io.redspace.ironsspellbooks.item.curios.CurioBaseItem; import io.redspace.ironsspellbooks.registries.ItemRegistry; import net.minecraft.commands.CommandSourceStack; @@ -19,7 +22,9 @@ import net.minecraft.world.item.crafting.*; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.registries.ForgeRegistries; +import org.jetbrains.annotations.NotNull; +import javax.annotation.Nullable; import java.io.BufferedWriter; import java.io.FileWriter; import java.util.*; @@ -114,75 +119,54 @@ private static void generateRecipeData(CommandSourceStack source) { itemsTracked.add(ItemRegistry.WIMPY_SPELL_BOOK.get()); itemsTracked.add(ItemRegistry.LEGENDARY_SPELL_BOOK.get()); itemsTracked.add(Items.POISONOUS_POTATO); - - source.getLevel().getRecipeManager().getRecipes() - .stream() - .filter(r -> r.getId().getNamespace().equals("irons_spellbooks") && !r.getId().toString().contains("poisonous_potato")) - .sorted(Comparator.comparing(x -> x.getId().toString())) - .forEach(recipe -> { - //IronsSpellbooks.LOGGER.debug("recipe: {}, {}, {}", recipe.getId(), recipe.getClass(), recipe.getType()); - //IronsSpellbooks.LOGGER.debug("recipe: resultItem: {}", ForgeRegistries.ITEMS.getKey(recipe.getResultItem().getItem())); - - var resultItemResourceLocation = ForgeRegistries.ITEMS.getKey(recipe.getResultItem().getItem()); - var recipeData = new ArrayList(10); - recipeData.add(new RecipeData( - resultItemResourceLocation.toString(), - recipe.getResultItem().getItem().getName(ItemStack.EMPTY).getString(), - String.format("/img/items/%s.png", resultItemResourceLocation.getPath()), - recipe.getResultItem().getItem()) - ); - - itemsTracked.add(recipe.getResultItem().getItem()); - - if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) { - recipe.getIngredients().forEach(ingredient -> { - handleIngeredient(ingredient, recipeData, recipe); - }); - } else if (recipe instanceof UpgradeRecipe upgradeRecipe) { - handleIngeredient(upgradeRecipe.base, recipeData, recipe); - handleIngeredient(upgradeRecipe.addition, recipeData, recipe); - } - - var name = getRecipeDataAtIndex(recipeData, 0).name; - var tooltip = getTooltip(source.getPlayer(), recipe.getResultItem()); - - if (getRecipeDataAtIndex(recipeData, 0).item instanceof SpellBook || getRecipeDataAtIndex(recipeData, 0).item instanceof ExtendedSwordItem) { - appendToBuilder(spellbookBuilder, recipe, recipeData, "", tooltip); - } else if (armorTypes.stream().anyMatch(item -> name.contains(item))) { - var words = name.split(" "); - var group = Arrays.stream(words).limit(words.length - 1).collect(Collectors.joining(" ")); - appendToBuilder(armorBuilder, recipe, recipeData, group, tooltip); - } else if (recipe.getResultItem().getItem() instanceof BlockItem) { - appendToBuilder(blockBuilder, recipe, recipeData, "", tooltip); - } else { - appendToBuilder(itemBuilder, recipe, recipeData, "", tooltip); - } - }); - + handleAffinityRingEntry(curioBuilder, itemsTracked, source); ForgeRegistries.ITEMS.getValues() .stream() - .sorted(Comparator.comparing(Item::getDescriptionId)) + //.sorted(Comparator.comparing(Item::getDescriptionId)) .forEach(item -> { var itemResource = ForgeRegistries.ITEMS.getKey(item); var tooltip = getTooltip(source.getPlayer(), new ItemStack(item)); if (itemResource.getNamespace().equals("irons_spellbooks") && !itemsTracked.contains(item) && !ITEM_BLACKLIST.resolve().get().contains(item)) { - //Non craftable items + var recipe = getRecipeFor(source, item); var name = item.getName(ItemStack.EMPTY).getString(); if (item.getDescriptionId().contains("patchouli") || item.getDescriptionId().contains("spawn_egg") || item.getDescriptionId().equals("item.irons_spellbooks.scroll")) { //Skip } else if (item instanceof ArmorItem) { - appendToBuilder2(armorBuilder, name, itemResource, tooltip); + if (recipe != null) { + var words = name.split(" "); + var group = Arrays.stream(words).limit(words.length - 1).collect(Collectors.joining(" ")); + appendToBuilder(armorBuilder, recipe, getRecipeData(recipe), group, tooltip); + } else { + appendToBuilder2(armorBuilder, name, itemResource, tooltip); + } } else if (item instanceof CurioBaseItem) { - appendToBuilder2(curioBuilder, name, itemResource, tooltip); + if (recipe != null) { + appendToBuilder(curioBuilder, recipe, getRecipeData(recipe), "", tooltip); + } else { + appendToBuilder2(curioBuilder, name, itemResource, tooltip); + } } else if (item instanceof UniqueSpellBook) { + //should never have recipe appendToBuilder2(spellbookBuilder, name, itemResource, getSpells(new ItemStack(item))); } else if (item instanceof SpellBook || item instanceof ExtendedSwordItem) { - appendToBuilder2(spellbookBuilder, name, itemResource, tooltip); + if (recipe != null) { + appendToBuilder(spellbookBuilder, recipe, getRecipeData(recipe), "", tooltip); + } else { + appendToBuilder2(spellbookBuilder, name, itemResource, tooltip); + } } else if (item instanceof BlockItem) { - appendToBuilder2(blockBuilder, name, itemResource, tooltip); + if (recipe != null) { + appendToBuilder(blockBuilder, recipe, getRecipeData(recipe), "", tooltip); + } else { + appendToBuilder2(blockBuilder, name, itemResource, tooltip); + } } else { - appendToBuilder2(itemBuilder, name, itemResource, tooltip); + if (recipe != null) { + appendToBuilder(itemBuilder, recipe, getRecipeData(recipe), handleGenericItemGrouping(item), tooltip); + } else { + appendToBuilder3(itemBuilder, name, itemResource, handleGenericItemGrouping(item), tooltip); + } } itemsTracked.add(item); @@ -213,6 +197,61 @@ private static void generateRecipeData(CommandSourceStack source) { } } + private static void handleAffinityRingEntry(StringBuilder curioBuilder, Set itemsTracked, CommandSourceStack source) { + var item = ItemRegistry.AFFINITY_RING.get(); + itemsTracked.add(item); + var itemResource = ForgeRegistries.ITEMS.getKey(item); + var name = item.getName(ItemStack.EMPTY).getString(); + appendToBuilder2(curioBuilder, name, itemResource, + "Affinity Rings are randomly generated as loot, and will boost the level of a select spell by one. This effect can stack." + ); + + } + + private static String handleGenericItemGrouping(Item item) { + if (item instanceof InkItem) { + return "Ink"; + } else if (item.getDescriptionId().contains("rune")) { + return "Runes"; + } else if (item instanceof UpgradeOrbItem) { + return "Upgrade Orbs"; + } else if (item instanceof SimpleElixir) { + return "Elixirs"; + } else { + return "All"; + } + } + + @NotNull + private static ArrayList getRecipeData(Recipe recipe) { + var resultItemResourceLocation = ForgeRegistries.ITEMS.getKey(recipe.getResultItem().getItem()); + var recipeData = new ArrayList(10); + recipeData.add(new RecipeData( + resultItemResourceLocation.toString(), + recipe.getResultItem().getItem().getName(ItemStack.EMPTY).getString(), + String.format("/img/items/%s.png", resultItemResourceLocation.getPath()), + recipe.getResultItem().getItem()) + ); + if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) { + recipe.getIngredients().forEach(ingredient -> { + handleIngeredient(ingredient, recipeData, recipe); + }); + } else if (recipe instanceof UpgradeRecipe upgradeRecipe) { + handleIngeredient(upgradeRecipe.base, recipeData, recipe); + handleIngeredient(upgradeRecipe.addition, recipeData, recipe); + } + return recipeData; + } + + private static @Nullable Recipe getRecipeFor(CommandSourceStack sourceStack, Item item) { + for (Recipe recipe : sourceStack.getRecipeManager().getRecipes()) { + if (recipe.getResultItem().is(item)) { + return recipe; + } + } + return null; + } + private static String postProcess(StringBuilder sb) { return sb.toString() .replace("netherite_spell_book.png", "netherite_spell_book.gif") @@ -303,6 +342,17 @@ private static void appendToBuilder2(StringBuilder sb, String name, ResourceLoca )); } + private static void appendToBuilder3(StringBuilder sb, String name, ResourceLocation itemResource, String group, String tooltip) { + sb.append(String.format(RECIPE_DATA_TEMPLATE, + itemResource.toString(), + name, + String.format("/img/items/%s.png", itemResource.getPath()), + group, + "none", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", tooltip + )); + } + private static void handleIngeredient(Ingredient ingredient, ArrayList recipeData, Recipe recipe) { Arrays.stream(ingredient.getItems()) .findFirst() diff --git a/src/main/resources/data/irons_spellbooks/patchouli_books/iss_guide_book/en_us/entries/misc/schools.json b/src/main/resources/data/irons_spellbooks/patchouli_books/iss_guide_book/en_us/entries/misc/schools.json index 6802bd935..5942c38f8 100644 --- a/src/main/resources/data/irons_spellbooks/patchouli_books/iss_guide_book/en_us/entries/misc/schools.json +++ b/src/main/resources/data/irons_spellbooks/patchouli_books/iss_guide_book/en_us/entries/misc/schools.json @@ -8,7 +8,7 @@ { "type": "patchouli:text", "title": "Overview", - "text": "Each magical spell belong to a school of magic. Each school encapsulates a theme, both visually and functionally, and each have an Focus: a representative item used as a crafting ingredient. Furthermore, each school can be empowered by specific school related gear, allowing you to become a powerful master of a single school, or mix and match to become a jack of all trades." + "text": "Each magical spell belong to a school of magic. Each school encapsulates a theme, both visually and functionally, and each have a Focus: a representative item used as a crafting ingredient. Furthermore, each school can be empowered by specific school related gear, allowing you to become a powerful master of a single school, or mix and match to become a jack of all trades." }, { "type": "patchouli:spotlight", @@ -32,7 +32,7 @@ "type": "patchouli:spotlight", "item": "irons_spellbooks:divine_pearl", "title": "Holy", - "text": "The Holy school, with the Divine Pearl as its Focus, is centered around support, healing, and buffing characters." + "text": "The Holy school, with the Divine Pearl as its Focus, is centered around support, healing, and buffing allies." }, { "type": "patchouli:spotlight", @@ -62,7 +62,7 @@ "type": "patchouli:spotlight", "item": "irons_spellbooks:eldritch_manuscript", "title": "Eldritch", - "text": "The Eldritch school is not like the others. It is an ancient and powerful way of magic, one that has all but been forgotten; you will be unable to craft or cast them. However, shreds of ancient Eldritch manuscripts can still be found scattered throughout the world, and may even be pieced back together with the help of an echo shard." + "text": "The Eldritch school is not like the others. It is an ancient and powerful way of magic, one that has all but been forgotten; you will be unable to immediately craft or cast Eldritch spells. However, shreds of ancient Eldritch manuscripts can still be found scattered throughout the world, and may even be pieced back together with the help of an echo shard." }, { "type": "patchouli:spotlight",