Port lexicon pages to Patchouli, improve generator code

This commit is contained in:
Hubry committed 2019-09-24 23:16:29 +02:00
1 parent 6ba1436ac0
commit ab412507c7
104 files changed
+1702 -1064

No files matched your search

@@ -10,21 +10,25 @@
*/
package vazkii.botania.api.lexicon;
import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.IModRecipe;
import vazkii.botania.common.lexicon.page.PageBrew;
import vazkii.botania.common.lexicon.page.PageCraftingRecipe;
import vazkii.botania.common.lexicon.page.PageElvenRecipe;
import vazkii.botania.common.lexicon.page.PageImage;
import vazkii.botania.common.lexicon.page.PageLoreText;
import vazkii.botania.common.lexicon.page.PageManaInfusionRecipe;
import vazkii.botania.common.lexicon.page.PageModRecipe;
import vazkii.botania.common.lexicon.page.PageMultiblock;
import vazkii.botania.common.lexicon.page.PagePetalRecipe;
import vazkii.botania.common.lexicon.page.PageRuneRecipe;
import vazkii.botania.common.lexicon.page.PageTerrasteel;
import vazkii.botania.common.lexicon.page.PageText;
import vazkii.botania.common.lib.LibLexicon;
@@ -34,17 +38,14 @@ import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.reflect.Type;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
@@ -119,62 +120,82 @@ public class LexiconEntry implements Comparable<LexiconEntry> {
}
public void dump() {
File dir = Paths.get(".", "entries", category.getUnlocalizedName().substring(LibLexicon.CATEGORY_PREFIX.length())).toFile();
Map<String, String> multiblocks = ImmutableMap.<String, String>builder()
.put("botania.page.terrasteel4", "botania:terra_plate")
.put("botania.page.manaEnchanting2", "botania:enchanter")
.put("botania.page.aIntro4", "botania:alfheim_portal")
.put("botania.page.gaiaRitual2", "botania:gaia_ritual").build();
File dir = Paths.get(".", "entries", fixCamelCase(category.getUnlocalizedName().substring(LibLexicon.CATEGORY_PREFIX.length()))).toFile();
if(!dir.exists())
dir.mkdirs();
File f = new File(dir, this.unlocalizedName + ".json");
File f = new File(dir, fixCamelCase(this.unlocalizedName) + ".json");
if (f.exists())
throw new RuntimeException("preexisting file " + f.getAbsolutePath());
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Type typ = new TypeToken<Map<String, Object>>() {}.getType();
try (OutputStreamWriter os = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(f)))) {
Map<String, Object> entry = new LinkedHashMap<>();
entry.put("name", this.getUnlocalizedName());
entry.put("category", category.getUnlocalizedName().substring("botania.category.".length()));
entry.put("category", fixCamelCase(category.getUnlocalizedName().substring("botania.category.".length())));
entry.put("icon", getIcon().getItem().getRegistryName().toString());
if (isPriority())
entry.put("priority", true);
List<Object> pages = new ArrayList<>();
for(LexiconPage page : this.pages) {
Map<String, Object> json = new LinkedHashMap<>();
String unlocalizedName = page.getUnlocalizedName();
if (page instanceof PageText) {
json.put("type", "text");
json.put("text", page.getUnlocalizedName());
json.put("type", page instanceof PageLoreText ? "lore_page" : "text");
json.put("text", unlocalizedName);
} else if (page instanceof PageImage) {
json.put("type", "image");
json.put("text", page.getUnlocalizedName());
json.put("text", unlocalizedName);
json.put("images", Collections.singletonList(((PageImage) page).resource.toString()));
} else if (page instanceof PageCraftingRecipe) {
List<IRecipe<?>> recipes = ((PageCraftingRecipe) page).getRecipes();
json.put("type", recipes.size() == 1 ? "crafting" : "crafting_multi");
json.put("text", page.getUnlocalizedName());
if (recipes.size() == 1)
json.put("type", recipes.size() <= 2 ? "crafting" : "crafting_multi");
json.put("text", unlocalizedName);
if (recipes.size() <= 2) {
json.put("recipe", recipes.get(0).getId().toString());
else
json.put("recipes", recipes.stream().map(r -> r.getId().toString()).collect(Collectors.toList()));
if(recipes.size() == 2)
json.put("recipe2", recipes.get(1).getId().toString());
} else
json.put("recipes", recipes.stream().map(r -> r.getId().toString()).collect(Collectors.joining(";")));
} else if (page instanceof PageManaInfusionRecipe) {
json.put("type", "mana_infusion");
json.put("text", page.getUnlocalizedName());
json.put("recipes", ((PageManaInfusionRecipe) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.toList()));
} else if (page instanceof PagePetalRecipe) {
json.put("type", "petal_apothecary");
json.put("text", page.getUnlocalizedName());
json.put("recipes", ((PagePetalRecipe) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.toList()));
} else if (page instanceof PageRuneRecipe) {
json.put("type", "runic_altar");
json.put("text", page.getUnlocalizedName());
json.put("recipes", ((PageRuneRecipe) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.toList()));
json.put("text", unlocalizedName);
json.put("recipes", ((PageManaInfusionRecipe) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.joining(";")));
} else if (page instanceof PageModRecipe) {
json.put("type", page instanceof PagePetalRecipe ? "petal_apothecary" : "runic_altar");
json.put("text", unlocalizedName);
List<String> strings = ((PageModRecipe<? extends IModRecipe>) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.toList());
if(strings.size() == 1) {
json.put("recipe", strings.get(0));
} else {
json.put("recipes", strings);
}
} else if (page instanceof PageElvenRecipe) {
json.put("type", "elven_trade");
json.put("text", page.getUnlocalizedName());
json.put("recipes", ((PageElvenRecipe) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.toList()));
json.put("text", unlocalizedName);
json.put("recipes", ((PageElvenRecipe) page).getRecipes().stream().map(r -> r.getId().toString()).collect(Collectors.joining(";")));
} else if (page instanceof PageBrew) {
json.put("type", "brew");
json.put("text", page.getUnlocalizedName());
json.put("recipe", ((PageBrew) page).recipe.getId());
json.put("text", ((PageBrew) page).text);
json.put("flavor", unlocalizedName);
json.put("recipe", ((PageBrew) page).recipe.getId().toString());
} else if (page instanceof PageMultiblock) {
json.put("type", "multiblock");
json.put("multiblock_id", multiblocks.get(unlocalizedName));
json.put("text", unlocalizedName);
if (unlocalizedName.contains("terrasteel") || unlocalizedName.contains("aIntro")) {
json.put("symmetrical", true);
}
} else if(page instanceof PageTerrasteel) {
json.put("type", "terrasteel");
json.put("text", unlocalizedName);
} else {
json.put("type", "_unknown_" + page.getClass().getSimpleName());
json.put("text", page.getUnlocalizedName());
json.put("type", "_unknown_" + page.getClass().getSimpleName().toLowerCase(Locale.ROOT));
json.put("text", unlocalizedName);
}
pages.add(json);
}
@@ -185,6 +206,17 @@ public class LexiconEntry implements Comparable<LexiconEntry> {
}
}
private static String fixCamelCase(String s) {
if(LibLexicon.CATEGORY_FUNCTIONAL_FLOWERS.equals(s)) {
return "functional_flowers";
} else if(LibLexicon.CATEGORY_GENERATION_FLOWERS.equals(s)) {
return "generating_flowers";
} else if(s.length() == 6 && s.endsWith("Intro")) {
return "intro";
}
return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, s);
}
/**
* Sets what pages you want this entry to have.
*/
@@ -2,6 +2,7 @@ package vazkii.botania.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import java.util.List;
@@ -11,4 +12,5 @@ import java.util.List;
public interface IModRecipe {
List<Ingredient> getInputs();
ItemStack getOutput();
ResourceLocation getId();
}
@@ -59,6 +59,7 @@ public class RecipePetals implements IModRecipe {
return ingredientsMissing.isEmpty();
}
@Override
public ResourceLocation getId() {
return id;
}
@@ -62,6 +62,7 @@ public class RecipeRuneAltar implements IModRecipe {
return ingredientsMissing.isEmpty();
}
@Override
public ResourceLocation getId() {
return id;
}
@@ -0,0 +1,74 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 23 2019, 3:04 PM (GMT)]
*/
package vazkii.botania.client.patchouli;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import vazkii.patchouli.api.IComponentRenderContext;
import vazkii.patchouli.api.PatchouliAPI;
import vazkii.patchouli.client.book.gui.GuiBook;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
public class PatchouliUtils {
/**
* Extracts the tick counter from the current render context, if possible.
* Note: uses Patchouli internals. TODO expose tick counter in the Patchouli API?
*/
public static int getBookTicksElapsed(IComponentRenderContext context) {
return context instanceof GuiBook ? ((GuiBook) context).ticksInBook : 0;
}
/**
* Combines the ingredients, returning the first matching stack of each, then the second stack of each, etc.
* looping back ingredients that run out of matched stacks, until the ingredients reach the length
* of the longest ingredient in the recipe set.
* <p>
* Note: As Patchouli internally converts the list of stacks into an ingredient, which will ignore empty stacks,
* empty ingredients will result in displaying stacks where nothing should be displayed instead.
*
* @param ingredients List of ingredients in the specific slot
* @param longestIngredientSize Longest ingredient in the entire recipe
* @return Serialized Patchouli ingredient string
*/
public static String interweaveIngredients(List<Ingredient> ingredients, int longestIngredientSize) {
if(ingredients.size() == 1) {
return PatchouliAPI.instance.serializeIngredient(ingredients.get(0));
}
ItemStack[] empty = {ItemStack.EMPTY};
List<ItemStack[]> stacks = new ArrayList<>();
for(Ingredient ingredient : ingredients) {
if(ingredient != null && !ingredient.hasNoMatchingItems()) {
stacks.add(ingredient.getMatchingStacks());
} else {
stacks.add(empty);
}
}
StringJoiner joiner = new StringJoiner(",");
for(int i = 0; i < longestIngredientSize; i++) {
for(ItemStack[] stack : stacks) {
joiner.add(PatchouliAPI.instance.serializeItemStack(stack[i % stack.length]));
}
}
return joiner.toString();
}
/**
* Overload of the method above that uses the provided list's longest ingredient size.
*/
public static String interweaveIngredients(List<Ingredient> ingredients) {
return interweaveIngredients(ingredients, ingredients.stream().mapToInt(ingr -> ingr.getMatchingStacks().length).max().orElse(1));
}
}
@@ -0,0 +1,69 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 24 2019, 5:18 PM (GMT)]
*/
package vazkii.botania.client.patchouli.component;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.botania.common.Botania;
import vazkii.patchouli.api.IComponentRenderContext;
import vazkii.patchouli.api.ICustomComponent;
import vazkii.patchouli.api.PatchouliAPI;
import vazkii.patchouli.api.VariableHolder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
// TODO: Remove when we don't need a bypass like that
/**
* A custom Patchouli component that is similiar to the default {@code item} type, but accepts
* air as a valid option in presence of other items.
* It does not support the {@code link_recipe} or the {@code framed} parameters.
* @deprecated For removal when Patchouli does not throw air away.
*/
@Deprecated
public class ItemStackListComponent implements ICustomComponent {
@VariableHolder
public String item;
private transient int x, y;
private transient ItemStack[] stacks;
@Override
public void build(int componentX, int componentY, int pageNum) {
this.x = componentX;
this.y = componentY;
this.stacks = Arrays.stream(splitSerializedStacks(item))
.map(PatchouliAPI.instance::deserializeItemStack).toArray(ItemStack[]::new);
}
@Override
public void render(IComponentRenderContext context, float pticks, int mouseX, int mouseY) {
int index = (PatchouliUtils.getBookTicksElapsed(context) / 20) % stacks.length;
context.renderItemStack(x, y, mouseX, mouseY, stacks[index]);
}
private static final Method splitStacksFromSerializedIngredient = ObfuscationReflectionHelper.findMethod(
vazkii.patchouli.common.util.ItemStackUtil.class, "splitStacksFromSerializedIngredient", String.class);
//TODO stop reflecting into Patchouli
private static String[] splitSerializedStacks(String ingredient) {
String[] strings;
try {
strings = (String[]) splitStacksFromSerializedIngredient.invoke(null, ingredient);
} catch (IllegalAccessException | InvocationTargetException e) {
Botania.LOGGER.error("Failed to access Patchouli internals", e);
return new String[]{"minecraft:air"};
}
return strings;
}
}
@@ -0,0 +1,67 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 08 2019, 10:31 PM (GMT)]
*/
package vazkii.botania.client.patchouli.component;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.resources.I18n;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.botania.common.block.tile.mana.TilePool;
import vazkii.patchouli.api.IComponentRenderContext;
import vazkii.patchouli.api.ICustomComponent;
import vazkii.patchouli.api.VariableHolder;
import java.util.Arrays;
/**
* A custom component that renders a mana bar.
* It only has one custom parameter, {@code mana}, which is a semicolon-separated list of mana values.
* Setting x to {@code -1} will center the component.
*/
public class ManaComponent implements ICustomComponent {
private transient int x, y;
private transient int[] manaValues;
@VariableHolder
public String mana;
@Override
public void build(int componentX, int componentY, int pageNum) {
this.x = componentX != -1 ? componentX : 7;
this.y = componentY;
if(mana.length() > 0) {
this.manaValues = Arrays.stream(mana.split(";")).mapToInt(Integer::valueOf).toArray();
} else {
this.manaValues = new int[]{0};
}
}
@Override
public void render(IComponentRenderContext context, float pticks, int mouseX, int mouseY) {
FontRenderer font = context.getFont();
String manaUsage = I18n.format("botaniamisc.manaUsage");
font.drawString(manaUsage, x + 102 / 2 - font.getStringWidth(manaUsage) / 2, y, 0x66000000);
int ratio = 10;
if(context.isAreaHovered(mouseX, mouseY, x, y - 2, 102, 5 + 20)) {
ratio = 1;
}
HUDHandler.renderManaBar(x, y + 10, 0x0000FF, 0.75F,
manaValues[PatchouliUtils.getBookTicksElapsed(context) % manaValues.length], TilePool.MAX_MANA / ratio);
String ratioString = I18n.format("botaniamisc.ratio", ratio);
font.drawString(ratioString, x + 102 / 2 - font.getStringWidth(ratioString) / 2, y + 15, 0x99000000);
//String stopStr = I18n.format("botaniamisc.shiftToStopSpin"); //TODO we get the vanilla font renderer and Patchouli is tighter than the lexicon
//font.drawString(stopStr, x + 102 / 2 - font.getStringWidth(ratioString) / 2, y + 20, 0x99000000);
}
}
@@ -0,0 +1,31 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 20 2019, 8:49 PM (GMT)]
*/
package vazkii.botania.client.patchouli.component;
import net.minecraft.item.crafting.Ingredient;
import vazkii.patchouli.api.PatchouliAPI;
import vazkii.patchouli.api.VariableHolder;
import java.util.List;
import java.util.stream.Collectors;
/**
* Patchouli custom component that draws a rotating circle of items from a provided list.
*/
public class RotatingItemListComponent extends RotatingItemListComponentBase {
@VariableHolder
public List<String> ingredients;
@Override
protected List<Ingredient> makeIngredients() {
return ingredients.stream().map(PatchouliAPI.instance::deserializeIngredient).collect(Collectors.toList());
}
}
@@ -0,0 +1,75 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 20 2019, 2:59 PM (GMT)]
*/
package vazkii.botania.client.patchouli.component;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.crafting.Ingredient;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.patchouli.api.IComponentRenderContext;
import vazkii.patchouli.api.ICustomComponent;
import java.util.List;
/**
* Base custom Patchouli component that draws a rotating circle of items.
* Size is 80x80. For a centered one, set X to -1.
* For usage with a specified list of items, see {@link RotatingItemListComponent}.
* For usage with a runic altar or petal apothecary recipes, see {@link RotatingRecipeComponent}.
*/
abstract class RotatingItemListComponentBase implements ICustomComponent {
protected transient List<Ingredient> ingredients;
protected transient int x, y;
@Override
public void build(int componentX, int componentY, int pageNum) {
this.x = componentX != -1 ? componentX : 17;
this.y = componentY;
this.ingredients = makeIngredients();
}
protected abstract List<Ingredient> makeIngredients();
@Override
public void render(IComponentRenderContext context, float pticks, int mouseX, int mouseY) {
int degreePerInput = (int) (360F / ingredients.size());
int ticksElapsed = PatchouliUtils.getBookTicksElapsed(context);
float currentDegree = ConfigHandler.CLIENT.lexiconRotatingItems.get()
? Screen.hasShiftDown()
? ticksElapsed
: ticksElapsed + pticks
: 0;
for(Ingredient input : ingredients) {
renderIngredientAtAngle(context, currentDegree, input, mouseX, mouseY);
currentDegree += degreePerInput;
}
}
private void renderIngredientAtAngle(IComponentRenderContext context, float angle, Ingredient ingredient, int mouseX, int mouseY) {
if(ingredient.hasNoMatchingItems())
return;
angle -= 90;
int radius = 32;
double xPos = x + Math.cos(angle * Math.PI / 180D) * radius + 32;
double yPos = y + Math.sin(angle * Math.PI / 180D) * radius + 32;
GlStateManager.pushMatrix(); // This translation makes it not stuttery. It does not affect the tooltip as that is drawn separately later.
GlStateManager.translated(xPos - (int) xPos, yPos - (int) yPos, 0);
context.renderIngredient((int) xPos, (int) yPos, mouseX, mouseY, ingredient);
GlStateManager.popMatrix();
}
}
@@ -0,0 +1,48 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 20 2019, 8:49 PM (GMT)]
*/
package vazkii.botania.client.patchouli.component;
import com.google.gson.annotations.SerializedName;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.IModRecipe;
import vazkii.patchouli.api.VariableHolder;
import java.util.List;
import java.util.Map;
/**
* Patchouli custom component that draws a rotating circle of items from the defined recipe.
*/
public class RotatingRecipeComponent extends RotatingItemListComponentBase {
@VariableHolder
@SerializedName("recipe_name")
public String recipeName;
@VariableHolder
@SerializedName("recipe_type")
public String recipeType;
@Override
protected List<Ingredient> makeIngredients() {
Map<ResourceLocation, ? extends IModRecipe> map;
if("runic_altar".equals(recipeType)) {
map = BotaniaAPI.runeAltarRecipes;
} else if("petal_apothecary".equals(recipeType)) {
map = BotaniaAPI.petalRecipes;
} else {
throw new IllegalArgumentException("Type must be 'runic_altar' or 'petal_apothecary'!");
}
IModRecipe recipe = map.get(new ResourceLocation(recipeName));
return recipe.getInputs();
}
}
@@ -0,0 +1,76 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 24 2019, 2:31 PM (GMT)]
*/
package vazkii.botania.client.patchouli.component;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.item.ItemStack;
import vazkii.patchouli.api.IComponentRenderContext;
import vazkii.patchouli.api.ICustomComponent;
import vazkii.patchouli.api.PatchouliAPI;
import vazkii.patchouli.api.VariableHolder;
/**
* Patchouli custom component that draws provided stacks arranged like the Terrestial Agglomeration Plate multiblock.
* Size is 43 x 31.
* Parameters: corner, center, edge, plate can be provided to override default blocks.
*/
public class TerraPlateComponent implements ICustomComponent {
@VariableHolder
public String corner = "botania:livingrock";
@VariableHolder
public String center = "botania:livingrock";
@VariableHolder
public String edge = "minecraft:lapis_block";
@VariableHolder
public String plate = "botania:terra_plate";
private transient int x, y;
private transient ItemStack cornerBlock, centerBlock, middleBlock, plateBlock;
@Override
public void build(int componentX, int componentY, int pageNum) {
this.x = componentX;
this.y = componentY;
this.cornerBlock = PatchouliAPI.instance.deserializeItemStack(corner);
this.centerBlock = PatchouliAPI.instance.deserializeItemStack(center);
this.middleBlock = PatchouliAPI.instance.deserializeItemStack(edge);
this.plateBlock = PatchouliAPI.instance.deserializeItemStack(plate);
}
@Override
public void render(IComponentRenderContext context, float pticks, int mouseX, int mouseY) {
GlStateManager.pushMatrix();
GlStateManager.translatef(0F, 0F, -10.0f);
context.renderItemStack(x + 13, y + 1, mouseX, mouseY, cornerBlock);
GlStateManager.translatef(0F, 0F, 5F);
context.renderItemStack(x + 20, y + 4, mouseX, mouseY, middleBlock);
context.renderItemStack(x + 7, y + 4, mouseX, mouseY, middleBlock);
GlStateManager.translatef(0F, 0F, 5F);
context.renderItemStack(x + 13, y + 8, mouseX, mouseY, cornerBlock);
context.renderItemStack(x + 27, y + 8, mouseX, mouseY, centerBlock);
context.renderItemStack(x, y + 8, mouseX, mouseY, cornerBlock);
GlStateManager.translatef(0F, 0F, 5F);
context.renderItemStack(x + 7, y + 12, mouseX, mouseY, middleBlock);
context.renderItemStack(x + 20, y + 12, mouseX, mouseY, middleBlock);
GlStateManager.translatef(0F, 0F, 5F);
context.renderItemStack(x + 14, y + 15, mouseX, mouseY, cornerBlock);
GlStateManager.translatef(0F, 0F, 5F);
context.renderItemStack(x + 13, y, mouseX, mouseY, plateBlock);
GlStateManager.translatef(0F, 0F, -10.0f);
GlStateManager.popMatrix();
}
}
@@ -0,0 +1,55 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 22 2019, 7:03 PM (GMT)]
*/
package vazkii.botania.client.patchouli.processor;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.common.item.ModItems;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
public class BrewRecipeProcessor implements IComponentProcessor {
private RecipeBrew recipe;
@Override
public void setup(IVariableProvider<String> variables) {
this.recipe = BotaniaAPI.brewRecipes.get(new ResourceLocation(variables.get("recipe")));
}
@Override
public String process(String key) {
if(recipe == null) {
return null;
} else if(key.equals("heading")) {
return I18n.format("botaniamisc.brewOf", I18n.format(recipe.getBrew().getUnlocalizedName()));
} else if(key.equals("vial")) {
return PatchouliAPI.instance.serializeItemStack(recipe.getOutput(new ItemStack(ModItems.vial)));
} else if(key.equals("flask")) {
return PatchouliAPI.instance.serializeItemStack(recipe.getOutput(new ItemStack(ModItems.flask)));
} else if(key.startsWith("input")) {
int requestedIndex = Integer.parseInt(key.substring(5)) - 1;
int indexOffset = (6 - recipe.getInputs().size()) / 2; //Center the brew ingredients
int index = requestedIndex - indexOffset;
if(index < recipe.getInputs().size() && index >= 0)
return PatchouliAPI.instance.serializeIngredient(recipe.getInputs().get(index));
else
return null;
} else if(key.equals("is_offset")) {
return Boolean.toString(recipe.getInputs().size() % 2 == 0);
}
return null;
}
}
@@ -0,0 +1,93 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 09 2019, 10:20 PM (GMT)]
*/
package vazkii.botania.client.patchouli.processor;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeElvenTrade;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
import java.util.List;
import java.util.stream.Collectors;
public class ElvenTradeProcessor implements IComponentProcessor {
private List<RecipeElvenTrade> recipes;
private int longestIngredientSize, mostInputs, mostOutputs;
@Override
public void setup(IVariableProvider<String> variables) {
ImmutableList.Builder<RecipeElvenTrade> builder = ImmutableList.builder();
for(String s : variables.get("recipes").split(";")) {
RecipeElvenTrade recipeElvenTrade = BotaniaAPI.elvenTradeRecipes.get(new ResourceLocation(s));
if(recipeElvenTrade != null) {
builder.add(recipeElvenTrade);
}
}
recipes = builder.build();
for(RecipeElvenTrade recipe : recipes) {
List<Ingredient> inputs = recipe.getInputs();
for(Ingredient ingredient : inputs) {
int length = ingredient.getMatchingStacks().length;
if(length > longestIngredientSize) {
longestIngredientSize = length;
}
}
if(inputs.size() > mostInputs) {
mostInputs = inputs.size();
}
if(recipe.getOutputs().size() > mostOutputs) {
mostOutputs = recipe.getOutputs().size();
}
}
}
@Override
public String process(String key) {
if(recipes.isEmpty()) {
return null;
}
if(key.equals("heading")) {
return recipes.get(0).getOutputs().get(0).getDisplayName().getString();
} else if(key.startsWith("input")) {
int index = Integer.parseInt(key.substring(5)) - 1;
if(index < mostInputs)
return interweaveIngredients(index);
else
return null;
}
if(key.startsWith("output")) {
int index = Integer.parseInt(key.substring(6)) - 1;
if(index < mostOutputs)
return recipes.stream().map(RecipeElvenTrade::getOutputs)
.map(l -> index < l.size() ? l.get(index) : ItemStack.EMPTY)
.map(PatchouliAPI.instance::serializeItemStack).collect(Collectors.joining(","));
else
return null;
}
return null;
}
private String interweaveIngredients(int inputIndex) {
List<Ingredient> recipes = this.recipes.stream().map(RecipeElvenTrade::getInputs).map(ingredients -> {
if(inputIndex < ingredients.size()) {
return ingredients.get(inputIndex);
} else return Ingredient.EMPTY;
}).collect(Collectors.toList());
return PatchouliUtils.interweaveIngredients(recipes, longestIngredientSize);
}
}
@@ -0,0 +1,72 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 09 2019, 9:34 PM (GMT)]
*/
package vazkii.botania.client.patchouli.processor;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
import java.util.List;
import java.util.stream.Collectors;
public class ManaInfusionProcessor implements IComponentProcessor {
private List<RecipeManaInfusion> recipes;
private boolean hasCustomHeading;
@Override
public void setup(IVariableProvider<String> variables) {
ImmutableList.Builder<RecipeManaInfusion> builder = ImmutableList.builder();
for(String s : variables.get("recipes").split(";")) {
RecipeManaInfusion recipe = BotaniaAPI.manaInfusionRecipes.get(new ResourceLocation(s));
if(recipe != null) {
builder.add(recipe);
}
}
this.recipes = builder.build();
this.hasCustomHeading = variables.has("heading");
}
@Override
public String process(String key) {
if(recipes.isEmpty()) {
return null;
}
switch (key) {
case "heading":
if(!hasCustomHeading)
return recipes.get(0).getOutput().getDisplayName().getString();
return null;
case "input":
return PatchouliUtils.interweaveIngredients(recipes.stream().map(RecipeManaInfusion::getInput).collect(Collectors.toList()));
case "output":
return recipes.stream().map(RecipeManaInfusion::getOutput).map(PatchouliAPI.instance::serializeItemStack).collect(Collectors.joining(","));
case "catalyst":
return recipes.stream().map(RecipeManaInfusion::getCatalyst)
.map(state -> {
if(state == null)
return ItemStack.EMPTY;
return new ItemStack(state.getBlock().asItem());
})
.map(PatchouliAPI.instance::serializeItemStack)
.collect(Collectors.joining(","));
case "mana":
return recipes.stream().mapToInt(RecipeManaInfusion::getManaToConsume).mapToObj(Integer::toString).collect(Collectors.joining(";"));
}
return null;
}
}
@@ -0,0 +1,99 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 24 2019, 6:55 PM (GMT)]
*/
package vazkii.botania.client.patchouli.processor;
import net.minecraft.client.Minecraft;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.crafting.ICraftingRecipe;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.IShapedRecipe;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.botania.common.Botania;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class MultiCraftingProcessor implements IComponentProcessor {
private List<ICraftingRecipe> recipes;
private boolean shapeless = true;
private int longestIngredientSize = 0;
@Override
public void setup(IVariableProvider<String> variables) {
Map<ResourceLocation, IRecipe<CraftingInventory>> recipeMap = Minecraft.getInstance().world.getRecipeManager().getRecipes(IRecipeType.CRAFTING);
String[] names = variables.get("recipes").split(";");
this.recipes = new ArrayList<>();
for(String name : names) {
IRecipe<?> recipe = recipeMap.get(new ResourceLocation(name));
if(recipe != null) {
recipes.add((ICraftingRecipe) recipe);
if(shapeless) {
shapeless = !(recipe instanceof IShapedRecipe);
}
for(Ingredient ingredient : recipe.getIngredients()) {
int size = ingredient.getMatchingStacks().length;
if(longestIngredientSize < size) {
longestIngredientSize = size;
}
}
}
}
}
@Override
public String process(String key) {
if(recipes.isEmpty()) {
return null;
}
if(key.startsWith("input")) {
int index = Integer.parseInt(key.substring(5)) - 1;
int shapedX = index % 3;
int shapedY = index / 3;
List<Ingredient> ingredients = new ArrayList<>();
for(ICraftingRecipe recipe : recipes) {
if(recipe instanceof IShapedRecipe) {
IShapedRecipe shaped = (IShapedRecipe) recipe;
if(shaped.getRecipeWidth() < shapedX + 1) {
ingredients.add(Ingredient.EMPTY);
} else {
if(recipe.getId().getPath().contains("floating")) {
Botania.LOGGER.error("test");
}
int realIndex = index - (shapedY * (3 - shaped.getRecipeWidth()));
NonNullList<Ingredient> list = recipe.getIngredients();
ingredients.add(list.size() > realIndex ? list.get(realIndex) : Ingredient.EMPTY);
}
} else {
NonNullList<Ingredient> list = recipe.getIngredients();
ingredients.add(list.size() > index ? list.get(index) : Ingredient.EMPTY);
}
}
return PatchouliUtils.interweaveIngredients(ingredients, longestIngredientSize);
}
if(key.equals("output")) {
return recipes.stream().map(IRecipe::getRecipeOutput).map(PatchouliAPI.instance::serializeItemStack).collect(Collectors.joining(","));
}
if(key.equals("shapeless")) {
return Boolean.toString(shapeless);
}
return null;
}
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 10 2019, 9:32 PM (GMT)]
*/
package vazkii.botania.client.patchouli.processor;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.IModRecipe;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
public class PetalApothecaryProcessor implements IComponentProcessor {
protected IModRecipe recipe;
@Override
public void setup(IVariableProvider<String> variables) {
this.recipe = BotaniaAPI.petalRecipes.get(new ResourceLocation(variables.get("recipe")));
}
@Override
public String process(String key) {
if(recipe == null) {
return null;
}
switch (key) {
case "recipe":
return recipe.getId().toString();
case "output":
return PatchouliAPI.instance.serializeItemStack(recipe.getOutput());
case "heading":
return recipe.getOutput().getDisplayName().getString();
}
return null;
}
}
@@ -0,0 +1,30 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 10 2019, 9:52 AM (GMT)]
*/
package vazkii.botania.client.patchouli.processor;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.patchouli.api.IVariableProvider;
public class RunicAltarProcessor extends PetalApothecaryProcessor {
@Override
public void setup(IVariableProvider<String> variables) {
this.recipe = BotaniaAPI.runeAltarRecipes.get(new ResourceLocation(variables.get("recipe")));
}
@Override
public String process(String key) {
if(key.equals("mana"))
return String.valueOf(((RecipeRuneAltar) recipe).getManaUsage());
return super.process(key);
}
}
@@ -54,6 +54,8 @@ import vazkii.botania.common.lib.LibLexicon;
import vazkii.botania.common.lib.LibMisc;
import vazkii.botania.common.lib.ResourceLocationHelper;
import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -967,8 +969,8 @@ public final class LexiconData {
laputaShard = new AlfheimLexiconEntry(LibLexicon.TOOL_LAPUTA_SHARD, categoryTools);
laputaShard.setLexiconPages(new PageText("0"), new PageText("2"),
new PageCraftingRecipe("1", inGroup("laputashard_upgrade").negate(), ModItems.laputaShard),
new PageCraftingRecipe("3", inGroup("laputashard_upgrade"), ModItems.laputaShard));
new PageCraftingRecipe("1", inGroup("laputa_shard_upgrade").negate(), ModItems.laputaShard),
new PageCraftingRecipe("3", inGroup("laputa_shard_upgrade"), ModItems.laputaShard));
virus = new AlfheimLexiconEntry(LibLexicon.TOOL_VIRUS, categoryTools);
virus.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModItems.necroVirus),
@@ -1110,8 +1112,8 @@ public final class LexiconData {
flightTiara = new AlfheimLexiconEntry(LibLexicon.ENDER_FLIGHT_TIARA, categoryEnder);
flightTiara.setLexiconPages(new PageText("0"), new PageText("4"), new PageText("5"), new PageText("6"),
new PageCraftingRecipe("1", inGroup("flighttiara_wings").negate(), ModItems.flightTiara), new PageText("2"),
new PageCraftingRecipe("3", inGroup("flighttiara_wings"), ModItems.flightTiara));
new PageCraftingRecipe("1", inGroup("flight_tiara_wings").negate(), ModItems.flightTiara), new PageText("2"),
new PageCraftingRecipe("3", inGroup("flight_tiara_wings"), ModItems.flightTiara));
corporea = new AlfheimLexiconEntry(LibLexicon.ENDER_CORPOREA, categoryEnder);
corporea.setLexiconPages(new PageText("0"), new PageText("1"), new PageText("2"), new PageText("3"),
@@ -1456,10 +1458,15 @@ public final class LexiconData {
}
Botania.LOGGER.info("Reloaded lexicon in {}", stopwatch.stop());
Botania.LOGGER.info("Dumping lexicon entries");
for (LexiconEntry e : BotaniaAPI.getAllEntries()) {
e.dump();
}
File dir = Paths.get(".", "entries").toFile();
if(!dir.exists()) {
Botania.LOGGER.info("Dumping lexicon entries");
for (LexiconEntry e : BotaniaAPI.getAllEntries()) {
e.dump();
}
} else {
Botania.LOGGER.info("Preexisting file {}, aborting lexicon dump", dir.getAbsolutePath());
}
}
private static Predicate<IRecipe<?>> GOG_RECIPE = recipe -> recipe.getId().getPath().contains("garden_of_glass");
@@ -36,7 +36,7 @@ public class PageBrew extends PageRecipe implements ITwoNamedPage {
private static final RecipeBrew DUMMY = new RecipeBrew(new ResourceLocation(LibMisc.MOD_ID, "dummy"), BotaniaAPI.fallbackBrew);
public final RecipeBrew recipe;
private String text;
public String text;
public PageBrew(Brew brew, String unlocalizedName, String bottomText) {
super(bottomText);
@@ -179,7 +179,7 @@ public class PageCraftingRecipe extends PageRecipe {
}
}
if(list.isEmpty()) {
Botania.LOGGER.info("Could not find mana infusion recipes for items {}, using dummy", (Object) this.outputItems);
Botania.LOGGER.info("Could not find crafting recipes for items {}, using dummy for {}", (Object) this.outputItems, this.unlocalizedName);
return DUMMY;
} else {
list.sort((r1, r2) -> {
@@ -189,7 +189,7 @@ public class PageManaInfusionRecipe extends PageRecipe {
}
}
if(list.isEmpty()) {
Botania.LOGGER.warn("Could not find mana infusion recipes for items {}, using dummy", (Object) outputItems);
Botania.LOGGER.warn("Could not find mana infusion recipes for items {}, using dummy for {}", (Object) outputItems, this.unlocalizedName);
return DUMMY;
} else {
list.sort((r1, r2) -> {