Petal recipes to json

This commit is contained in:
Vincent Lee committed 2020-03-30 21:24:07 -05:00
1 parent f8c80d519e
commit 748ef78b3a
55 files changed
+1545 -234

No files matched your search

@@ -8,32 +8,45 @@
*/
package vazkii.botania.api.recipe;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import net.minecraftforge.registries.ForgeRegistryEntry;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.crafting.ModRecipeTypes;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
public class RecipePetals implements IModRecipe {
public class RecipePetals implements IRecipe<RecipeWrapper> {
private final ResourceLocation id;
private final ItemStack output;
private final ImmutableList<Ingredient> inputs;
private final NonNullList<Ingredient> inputs;
public RecipePetals(ResourceLocation id, ItemStack output, Ingredient... inputs) {
this.id = id;
this.output = output;
this.inputs = ImmutableList.copyOf(inputs);
this.inputs = NonNullList.from(null, inputs);
}
public boolean matches(IItemHandler inv) {
@Override
public boolean matches(RecipeWrapper inv, @Nonnull World world) {
List<Ingredient> ingredientsMissing = new ArrayList<>(inputs);
for (int i = 0; i < inv.getSlots(); i++) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack input = inv.getStackInSlot(i);
if (input.isEmpty()) {
break;
@@ -59,36 +72,84 @@ public class RecipePetals implements IModRecipe {
return ingredientsMissing.isEmpty();
}
@Nonnull
@Override
public ItemStack getRecipeOutput() {
return output;
}
@Nonnull
@Override
public NonNullList<Ingredient> getIngredients() {
return inputs;
}
@Nonnull
@Override public ItemStack getIcon() {
return new ItemStack(ModBlocks.defaultAltar);
}
@Nonnull
@Override
public ResourceLocation getId() {
return id;
}
public List<Ingredient> getInputs() {
return inputs;
@Nonnull
@Override
public IRecipeSerializer<?> getSerializer() {
return ModRecipeTypes.PETAL_SERIALIZER;
}
public ItemStack getOutput() {
return output;
@Nonnull
@Override
public IRecipeType<?> getType() {
return ModRecipeTypes.PETAL_TYPE;
}
public void write(PacketBuffer buf) {
buf.writeResourceLocation(id);
buf.writeVarInt(inputs.size());
for (Ingredient input : inputs) {
input.write(buf);
// Ignored IRecipe methods
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return getRecipeOutput();
}
@Override
public boolean canFit(int width, int height) {
return false;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipePetals> {
@Nonnull
@Override
public RecipePetals read(@Nonnull ResourceLocation id, @Nonnull JsonObject json) {
ItemStack output = CraftingHelper.getItemStack(JSONUtils.getJsonObject(json, "output"), true);
JsonArray ingrs = JSONUtils.getJsonArray(json, "ingredients");
List<Ingredient> inputs = new ArrayList<>();
for (JsonElement e : ingrs) {
inputs.add(Ingredient.deserialize(e));
}
return new RecipePetals(id, output, inputs.toArray(new Ingredient[0]));
}
buf.writeItemStack(output, false);
}
public static RecipePetals read(PacketBuffer buf) {
ResourceLocation id = buf.readResourceLocation();
Ingredient[] inputs = new Ingredient[buf.readVarInt()];
for (int i = 0; i < inputs.length; i++) {
inputs[i] = Ingredient.read(buf);
@Override
public RecipePetals read(@Nonnull ResourceLocation id, @Nonnull PacketBuffer buf) {
Ingredient[] inputs = new Ingredient[buf.readVarInt()];
for (int i = 0; i < inputs.length; i++) {
inputs[i] = Ingredient.read(buf);
}
ItemStack output = buf.readItemStack();
return new RecipePetals(id, output, inputs);
}
ItemStack output = buf.readItemStack();
return new RecipePetals(id, output, inputs);
@Override
public void write(@Nonnull PacketBuffer buf, @Nonnull RecipePetals recipe) {
buf.writeVarInt(recipe.getIngredients().size());
for (Ingredient input : recipe.getIngredients()) {
input.write(buf);
}
}
}
}
@@ -123,7 +123,7 @@ public class JEIBotaniaPlugin implements IModPlugin {
public void registerRecipes(@Nonnull IRecipeRegistration registry) {
registry.addRecipes(Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.BREW_TYPE).values(), BreweryRecipeCategory.UID);
registry.addRecipes(Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.PURE_DAISY_TYPE).values(), PureDaisyRecipeCategory.UID);
registry.addRecipes(BotaniaAPI.petalRecipes.values(), PetalApothecaryRecipeCategory.UID);
registry.addRecipes(Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.PETAL_TYPE).values(), PetalApothecaryRecipeCategory.UID);
registry.addRecipes(TileAlfPortal.elvenTradeRecipes(Minecraft.getInstance().world.getRecipeManager()), ElvenTradeRecipeCategory.UID);
registry.addRecipes(BotaniaAPI.runeAltarRecipes.values(), RunicAltarRecipeCategory.UID);
registry.addRecipes(TilePool.manaInfusionRecipes(Minecraft.getInstance().world.getRecipeManager()), ManaPoolRecipeCategory.UID);
@@ -83,11 +83,11 @@ public class PetalApothecaryRecipeCategory implements IRecipeCategory<RecipePeta
@Override
public void setIngredients(RecipePetals recipe, IIngredients iIngredients) {
List<List<ItemStack>> list = new ArrayList<>();
for (Ingredient ingr : recipe.getInputs()) {
for (Ingredient ingr : recipe.getIngredients()) {
list.add(Arrays.asList(ingr.getMatchingStacks()));
}
iIngredients.setInputLists(VanillaTypes.ITEM, list);
iIngredients.setOutput(VanillaTypes.ITEM, recipe.getOutput());
iIngredients.setOutput(VanillaTypes.ITEM, recipe.getRecipeOutput());
}
@Override
@@ -10,12 +10,16 @@ package vazkii.botania.client.patchouli.component;
import com.google.gson.annotations.SerializedName;
import net.minecraft.client.Minecraft;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.IModRecipe;
import vazkii.botania.common.crafting.ModRecipeTypes;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -30,16 +34,15 @@ public class RotatingRecipeComponent extends RotatingItemListComponentBase {
@Override
protected List<Ingredient> makeIngredients() {
Map<ResourceLocation, ? extends IModRecipe> map;
Map<ResourceLocation, ? extends IRecipe<?>> map;
if ("runic_altar".equals(recipeType)) {
map = BotaniaAPI.runeAltarRecipes;
map = Collections.emptyMap(); // BotaniaAPI.runeAltarRecipes;
} else if ("petal_apothecary".equals(recipeType)) {
map = BotaniaAPI.petalRecipes;
map = Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.PETAL_TYPE);
} else {
throw new IllegalArgumentException("Type must be 'runic_altar' or 'petal_apothecary'!");
}
IModRecipe recipe = map.get(new ResourceLocation(recipeName));
return recipe.getInputs();
return map.get(new ResourceLocation(recipeName)).getIngredients();
}
@Override
@@ -8,20 +8,24 @@
*/
package vazkii.botania.client.patchouli.processor;
import net.minecraft.client.Minecraft;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.IModRecipe;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
public class PetalApothecaryProcessor implements IComponentProcessor {
protected IModRecipe recipe;
protected IRecipe<?> recipe;
@Override
public void setup(IVariableProvider<String> variables) {
this.recipe = BotaniaAPI.petalRecipes.get(new ResourceLocation(variables.get("recipe")));
ResourceLocation id = new ResourceLocation(variables.get("recipe"));
this.recipe = Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.PETAL_TYPE).get(id);
}
@Override
@@ -33,9 +37,9 @@ public class PetalApothecaryProcessor implements IComponentProcessor {
case "recipe":
return recipe.getId().toString();
case "output":
return PatchouliAPI.instance.serializeItemStack(recipe.getOutput());
return PatchouliAPI.instance.serializeItemStack(recipe.getRecipeOutput());
case "heading":
return recipe.getOutput().getDisplayName().getString();
return recipe.getRecipeOutput().getDisplayName().getString();
}
return null;
}
@@ -17,7 +17,7 @@ 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")));
this.recipe = null; //BotaniaAPI.runeAltarRecipes.get(new ResourceLocation(variables.get("recipe")));
}
@Override
@@ -39,6 +39,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;
@@ -52,6 +53,7 @@ import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.fx.SparkleParticleData;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.handler.ModSounds;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.lib.LibBlockNames;
import vazkii.botania.common.lib.LibMisc;
@@ -60,6 +62,7 @@ import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
public class TileAltar extends TileSimpleInventory implements IPetalApothecary, ITickableTileEntity {
@@ -144,29 +147,27 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
}
if (SEED_PATTERN.matcher(stack.getTranslationKey()).find()) {
for (RecipePetals recipe : BotaniaAPI.petalRecipes.values()) {
if (recipe.matches(itemHandler)) {
saveLastRecipe();
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, new RecipeWrapper(itemHandler), world);
maybeRecipe.ifPresent(recipe -> {
saveLastRecipe();
for (int i = 0; i < getSizeInventory(); i++) {
itemHandler.setStackInSlot(i, ItemStack.EMPTY);
}
stack.shrink(1);
ItemStack output = recipe.getOutput().copy();
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
outputItem.addTag(ITEM_TAG_APOTHECARY_SPAWNED);
world.addEntity(outputItem);
setFluid(Fluids.EMPTY);
world.updateComparatorOutputLevel(pos, getBlockState().getBlock());
world.addBlockEvent(getPos(), getBlockState().getBlock(), CRAFT_EFFECT_EVENT, 0);
return true;
for (int i = 0; i < getSizeInventory(); i++) {
itemHandler.setStackInSlot(i, ItemStack.EMPTY);
}
}
stack.shrink(1);
ItemStack output = recipe.getRecipeOutput().copy();
ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output);
outputItem.addTag(ITEM_TAG_APOTHECARY_SPAWNED);
world.addEntity(outputItem);
setFluid(Fluids.EMPTY);
world.updateComparatorOutputLevel(pos, getBlockState().getBlock());
world.addBlockEvent(getPos(), getBlockState().getBlock(), CRAFT_EFFECT_EVENT, 0);
});
return maybeRecipe.isPresent();
} else if (!hasFluidCapability && !item.getTags().contains(ITEM_TAG_APOTHECARY_SPAWNED)) {
if (!itemHandler.getStackInSlot(getSizeInventory() - 1).isEmpty()) {
return false;
@@ -387,19 +388,18 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
if (amt > 0) {
float anglePer = 360F / amt;
for (RecipePetals recipe : BotaniaAPI.petalRecipes.values()) {
if (recipe.matches(itemHandler)) {
RenderSystem.color4f(1F, 1F, 1F, 1F);
mc.textureManager.bindTexture(HUDHandler.manaBar);
RenderHelper.drawTexturedModalRect(xc + radius + 9, yc - 8, 0, 8, 22, 15);
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, new RecipeWrapper(itemHandler), world);
maybeRecipe.ifPresent(recipe -> {
RenderSystem.color4f(1F, 1F, 1F, 1F);
mc.textureManager.bindTexture(HUDHandler.manaBar);
RenderHelper.drawTexturedModalRect(xc + radius + 9, yc - 8, 0, 8, 22, 15);
ItemStack stack = recipe.getOutput();
ItemStack stack = recipe.getRecipeOutput();
mc.getItemRenderer().renderItemIntoGUI(stack, xc + radius + 32, yc - 8);
mc.getItemRenderer().renderItemIntoGUI(new ItemStack(Items.WHEAT_SEEDS), xc + radius + 16, yc + 6);
mc.fontRenderer.drawStringWithShadow("+", xc + radius + 14, yc + 10, 0xFFFFFF);
}
}
mc.getItemRenderer().renderItemIntoGUI(stack, xc + radius + 32, yc - 8);
mc.getItemRenderer().renderItemIntoGUI(new ItemStack(Items.WHEAT_SEEDS), xc + radius + 16, yc + 6);
mc.fontRenderer.drawStringWithShadow("+", xc + radius + 14, yc + 10, 0xFFFFFF);
});
for (int i = 0; i < amt; i++) {
double xPos = xc + Math.cos(angle * Math.PI / 180D) * radius - 8;
@@ -1,140 +0,0 @@
/*
* This class is 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
*/
package vazkii.botania.common.crafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.api.recipe.RegisterRecipesEvent;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModSubtiles;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibMisc;
import java.util.Arrays;
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID)
public final class ModPetalRecipes {
@SubscribeEvent
public static void register(RegisterRecipesEvent evt) {
Ingredient white = tagIngr("petals/white");
Ingredient orange = tagIngr("petals/orange");
Ingredient magenta = tagIngr("petals/magenta");
Ingredient lightBlue = tagIngr("petals/light_blue");
Ingredient yellow = tagIngr("petals/yellow");
Ingredient lime = tagIngr("petals/lime");
Ingredient pink = tagIngr("petals/pink");
Ingredient gray = tagIngr("petals/gray");
Ingredient lightGray = tagIngr("petals/light_gray");
Ingredient cyan = tagIngr("petals/cyan");
Ingredient purple = tagIngr("petals/purple");
Ingredient blue = tagIngr("petals/blue");
Ingredient brown = tagIngr("petals/brown");
Ingredient green = tagIngr("petals/green");
Ingredient red = tagIngr("petals/red");
Ingredient black = tagIngr("petals/black");
Ingredient runeWater = tagIngr("runes/water");
Ingredient runeFire = tagIngr("runes/fire");
Ingredient runeEarth = tagIngr("runes/earth");
Ingredient runeAir = tagIngr("runes/air");
Ingredient runeSpring = tagIngr("runes/spring");
Ingredient runeSummer = tagIngr("runes/summer");
Ingredient runeAutumn = tagIngr("runes/autumn");
Ingredient runeWinter = tagIngr("runes/winter");
Ingredient runeMana = tagIngr("runes/mana");
Ingredient runeLust = tagIngr("runes/lust");
Ingredient runeGluttony = tagIngr("runes/gluttony");
Ingredient runeGreed = tagIngr("runes/greed");
Ingredient runeSloth = tagIngr("runes/sloth");
Ingredient runeWrath = tagIngr("runes/wrath");
Ingredient runeEnvy = tagIngr("runes/envy");
Ingredient runePride = tagIngr("runes/pride");
Ingredient redstoneRoot = Ingredient.fromItems(ModItems.redstoneRoot);
Ingredient pixieDust = Ingredient.fromItems(ModItems.pixieDust);
Ingredient gaiaSpirit = Ingredient.fromItems(ModItems.lifeEssence);
evt.apothecary().accept(make(ModSubtiles.pureDaisy, white, white, white, white));
evt.apothecary().accept(make(ModSubtiles.manastar, lightBlue, green, red, cyan));
evt.apothecary().accept(make(ModSubtiles.endoflame, brown, brown, red, lightGray));
evt.apothecary().accept(make(ModSubtiles.hydroangeas, blue, blue, cyan, cyan));
evt.apothecary().accept(make(ModSubtiles.thermalily, red, orange, orange, runeEarth, runeFire));
evt.apothecary().accept(make(ModSubtiles.rosaArcana, pink, pink, purple, purple, lime, runeMana));
evt.apothecary().accept(make(ModSubtiles.munchdew, lime, lime, red, red, green, runeGluttony));
evt.apothecary().accept(make(ModSubtiles.entropinnyum, red, red, gray, gray, white, white, runeWrath, runeFire));
evt.apothecary().accept(make(ModSubtiles.kekimurus, white, white, orange, orange, brown, brown, runeGluttony, pixieDust));
evt.apothecary().accept(make(ModSubtiles.gourmaryllis, lightGray, lightGray, yellow, yellow, red, runeFire, runeSummer));
evt.apothecary().accept(make(ModSubtiles.narslimmus, lime, lime, green, green, black, runeSummer, runeWater));
evt.apothecary().accept(make(ModSubtiles.spectrolus, red, red, green, green, blue, blue, white, white, runeWinter, runeAir, pixieDust));
evt.apothecary().accept(make(ModSubtiles.rafflowsia, purple, purple, green, green, black, runeEarth, runePride, pixieDust));
evt.apothecary().accept(make(ModSubtiles.shulkMeNot, purple, purple, magenta, magenta, lightGray, gaiaSpirit, runeEnvy, runeWrath));
evt.apothecary().accept(make(ModSubtiles.dandelifeon, purple, purple, lime, green, runeWater, runeFire, runeEarth, runeAir, gaiaSpirit));
evt.apothecary().accept(make(ModSubtiles.jadedAmaranthus, purple, lime, green, runeSpring, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.bellethorn, red, red, red, cyan, cyan, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.dreadthorn, black, black, black, cyan, cyan, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.heiseiDream, magenta, magenta, purple, pink, runeWrath, pixieDust));
evt.apothecary().accept(make(ModSubtiles.tigerseye, yellow, brown, orange, lime, runeAutumn));
if (Botania.gardenOfGlassLoaded) {
evt.apothecary().accept(make(ModSubtiles.orechid, gray, gray, yellow, yellow, green, green, red, red));
} else {
evt.apothecary().accept(make(ModSubtiles.orechid, gray, gray, yellow, green, red, runePride, runeGreed, redstoneRoot, pixieDust));
}
evt.apothecary().accept(make(ModSubtiles.orechidIgnem, red, red, white, white, pink, runePride, runeGreed, redstoneRoot, pixieDust));
if (ConfigHandler.COMMON.fallenKanadeEnabled.get()) {
evt.apothecary().accept(make(ModSubtiles.fallenKanade, white, white, yellow, yellow, orange, runeSpring));
}
evt.apothecary().accept(make(ModSubtiles.exoflame, red, red, gray, lightGray, runeFire, runeSummer));
evt.apothecary().accept(make(ModSubtiles.agricarnation, lime, lime, green, yellow, runeSpring, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.hopperhock, gray, gray, lightGray, lightGray, runeAir, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.tangleberrie, cyan, cyan, gray, lightGray, runeAir, runeEarth));
evt.apothecary().accept(make(ModSubtiles.jiyuulia, pink, pink, purple, lightGray, runeWater, runeAir));
evt.apothecary().accept(make(ModSubtiles.rannuncarpus, orange, orange, yellow, runeEarth, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.hyacidus, purple, purple, magenta, magenta, green, runeWater, runeAutumn, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.pollidisiac, red, red, pink, pink, orange, runeLust, runeFire));
evt.apothecary().accept(make(ModSubtiles.clayconia, lightGray, lightGray, gray, cyan, runeEarth));
evt.apothecary().accept(make(ModSubtiles.loonium, green, green, green, green, gray, runeSloth, runeGluttony, runeEnvy, redstoneRoot, pixieDust));
evt.apothecary().accept(make(ModSubtiles.daffomill, white, white, brown, yellow, runeAir, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.vinculotus, black, black, purple, purple, green, runeWater, runeSloth, runeLust, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.spectranthemum, white, white, lightGray, lightGray, cyan, runeEnvy, runeWater, redstoneRoot, pixieDust));
evt.apothecary().accept(make(ModSubtiles.medumone, brown, brown, gray, gray, runeEarth, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.marimorphosis, gray, yellow, green, red, runeEarth, runeFire, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.bubbell, cyan, cyan, lightBlue, lightBlue, blue, blue, runeWater, runeSummer, pixieDust));
evt.apothecary().accept(make(ModSubtiles.solegnolia, brown, brown, red, blue, redstoneRoot));
evt.apothecary().accept(make(ModSubtiles.bergamute, orange, green, green, redstoneRoot));
ItemStack stack = new ItemStack(Items.PLAYER_HEAD);
ItemNBTHelper.setString(stack, "SkullOwner", "Vazkii");
Ingredient[] inputs = new Ingredient[16];
Arrays.fill(inputs, pink);
evt.apothecary().accept(new RecipePetals(prefix("vazkii_head"), stack, inputs));
}
private static Ingredient tagIngr(String tag) {
return Ingredient.fromTag(new ItemTags.Wrapper(new ResourceLocation(LibMisc.MOD_ID, tag)));
}
private static RecipePetals make(IItemProvider item, Ingredient... ingredients) {
return new RecipePetals(item.asItem().getRegistryName(), new ItemStack(item), ingredients);
}
}
@@ -18,10 +18,7 @@ import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.api.recipe.RecipeElvenTrade;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.api.recipe.RecipePureDaisy;
import vazkii.botania.api.recipe.*;
import vazkii.botania.common.lib.LibMisc;
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
@@ -41,6 +38,9 @@ public class ModRecipeTypes {
public static final IRecipeType<RecipeBrew> BREW_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipeBrew> BREW_SERIALIZER = new RecipeBrew.Serializer();
public static final IRecipeType<RecipePetals> PETAL_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipePetals> PETAL_SERIALIZER = new RecipePetals.Serializer();
@SubscribeEvent
public static void register(RegistryEvent.Register<IRecipeSerializer<?>> evt) {
ResourceLocation id = prefix("elven_trade");
@@ -59,6 +59,10 @@ public class ModRecipeTypes {
id = prefix("brew");
Registry.register(Registry.RECIPE_TYPE, id, BREW_TYPE);
evt.getRegistry().register(BREW_SERIALIZER.setRegistryName(id));
id = prefix("petal_apothecary");
Registry.register(Registry.RECIPE_TYPE, id, PETAL_TYPE);
evt.getRegistry().register(PETAL_SERIALIZER.setRegistryName(id));
}
private static class RecipeType<T extends IRecipe<?>> implements IRecipeType<T> {
@@ -21,7 +21,6 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.network.PacketDistributor;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.botania.api.recipe.RegisterRecipesEvent;
@@ -48,21 +47,19 @@ public class SyncHandler {
);
MinecraftForge.EVENT_BUS.post(evt);
BotaniaAPI.petalRecipes = ImmutableMap.copyOf(apothecary);
BotaniaAPI.runeAltarRecipes = ImmutableMap.copyOf(runeAltar);
PacketHandler.HANDLER.send(PacketDistributor.ALL.noArg(), syncPacket());
}
}
private static PacketSyncRecipes syncPacket() {
return new PacketSyncRecipes(BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes);
return new PacketSyncRecipes(BotaniaAPI.runeAltarRecipes);
}
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, value = Dist.CLIENT)
public static class ClientEvents {
@SubscribeEvent
public static void clientLogout(ClientPlayerNetworkEvent.LoggedOutEvent evt) {
BotaniaAPI.petalRecipes = Collections.emptyMap();
BotaniaAPI.runeAltarRecipes = Collections.emptyMap();
}
}
@@ -14,7 +14,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.network.NetworkEvent;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.api.recipe.RecipeRuneAltar;
@@ -24,19 +23,13 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public class PacketSyncRecipes {
private Map<ResourceLocation, RecipePetals> petal;
private Map<ResourceLocation, RecipeRuneAltar> runeAltar;
public PacketSyncRecipes(Map<ResourceLocation, RecipePetals> petal, Map<ResourceLocation, RecipeRuneAltar> runeAltar) {
this.petal = petal;
public PacketSyncRecipes(Map<ResourceLocation, RecipeRuneAltar> runeAltar) {
this.runeAltar = runeAltar;
}
public void encode(PacketBuffer buf) {
buf.writeVarInt(petal.size());
for (RecipePetals recipe : petal.values()) {
recipe.write(buf);
}
buf.writeVarInt(runeAltar.size());
for (RecipeRuneAltar recipe : runeAltar.values()) {
recipe.write(buf);
@@ -44,15 +37,11 @@ public class PacketSyncRecipes {
}
public static PacketSyncRecipes decode(PacketBuffer buf) {
int petalCount = buf.readVarInt();
Map<ResourceLocation, RecipePetals> petal = Stream.generate(() -> RecipePetals.read(buf))
.limit(petalCount)
.collect(Collectors.toMap(RecipePetals::getId, r -> r));
int runeCount = buf.readVarInt();
Map<ResourceLocation, RecipeRuneAltar> rune = Stream.generate(() -> RecipeRuneAltar.read(buf))
.limit(runeCount)
.collect(Collectors.toMap(RecipeRuneAltar::getId, r -> r));
return new PacketSyncRecipes(petal, rune);
return new PacketSyncRecipes(rune);
}
public void handle(Supplier<NetworkEvent.Context> ctx) {
@@ -61,7 +50,6 @@ public class PacketSyncRecipes {
if (Minecraft.getInstance().isSingleplayer()) {
return;
}
BotaniaAPI.petalRecipes = petal;
BotaniaAPI.runeAltarRecipes = runeAltar;
});
}
@@ -74,7 +62,7 @@ public class PacketSyncRecipes {
private int loginIndex;
public Login() {
this(new PacketSyncRecipes(BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes));
this(new PacketSyncRecipes(BotaniaAPI.runeAltarRecipes));
}
public Login(PacketSyncRecipes packet) {
@@ -33,6 +33,7 @@ public class DataGenerators {
evt.getGenerator().addProvider(new ManaInfusionProvider(evt.getGenerator()));
evt.getGenerator().addProvider(new PureDaisyProvider(evt.getGenerator()));
evt.getGenerator().addProvider(new BrewProvider(evt.getGenerator()));
evt.getGenerator().addProvider(new PetalProvider(evt.getGenerator()));
}
}
}
@@ -0,0 +1,193 @@
package vazkii.botania.data.recipes;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.data.RecipeProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModSubtiles;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.function.Consumer;
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
public class PetalProvider extends RecipeProvider {
public PetalProvider(DataGenerator gen) {
super(gen);
}
@Override
public String getName() {
return "Botania petal apothecary recipes";
}
@Override
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
Ingredient white = tagIngr("petals/white");
Ingredient orange = tagIngr("petals/orange");
Ingredient magenta = tagIngr("petals/magenta");
Ingredient lightBlue = tagIngr("petals/light_blue");
Ingredient yellow = tagIngr("petals/yellow");
Ingredient lime = tagIngr("petals/lime");
Ingredient pink = tagIngr("petals/pink");
Ingredient gray = tagIngr("petals/gray");
Ingredient lightGray = tagIngr("petals/light_gray");
Ingredient cyan = tagIngr("petals/cyan");
Ingredient purple = tagIngr("petals/purple");
Ingredient blue = tagIngr("petals/blue");
Ingredient brown = tagIngr("petals/brown");
Ingredient green = tagIngr("petals/green");
Ingredient red = tagIngr("petals/red");
Ingredient black = tagIngr("petals/black");
Ingredient runeWater = tagIngr("runes/water");
Ingredient runeFire = tagIngr("runes/fire");
Ingredient runeEarth = tagIngr("runes/earth");
Ingredient runeAir = tagIngr("runes/air");
Ingredient runeSpring = tagIngr("runes/spring");
Ingredient runeSummer = tagIngr("runes/summer");
Ingredient runeAutumn = tagIngr("runes/autumn");
Ingredient runeWinter = tagIngr("runes/winter");
Ingredient runeMana = tagIngr("runes/mana");
Ingredient runeLust = tagIngr("runes/lust");
Ingredient runeGluttony = tagIngr("runes/gluttony");
Ingredient runeGreed = tagIngr("runes/greed");
Ingredient runeSloth = tagIngr("runes/sloth");
Ingredient runeWrath = tagIngr("runes/wrath");
Ingredient runeEnvy = tagIngr("runes/envy");
Ingredient runePride = tagIngr("runes/pride");
Ingredient redstoneRoot = Ingredient.fromItems(ModItems.redstoneRoot);
Ingredient pixieDust = Ingredient.fromItems(ModItems.pixieDust);
Ingredient gaiaSpirit = Ingredient.fromItems(ModItems.lifeEssence);
consumer.accept(make(ModSubtiles.pureDaisy, white, white, white, white));
consumer.accept(make(ModSubtiles.manastar, lightBlue, green, red, cyan));
consumer.accept(make(ModSubtiles.endoflame, brown, brown, red, lightGray));
consumer.accept(make(ModSubtiles.hydroangeas, blue, blue, cyan, cyan));
consumer.accept(make(ModSubtiles.thermalily, red, orange, orange, runeEarth, runeFire));
consumer.accept(make(ModSubtiles.rosaArcana, pink, pink, purple, purple, lime, runeMana));
consumer.accept(make(ModSubtiles.munchdew, lime, lime, red, red, green, runeGluttony));
consumer.accept(make(ModSubtiles.entropinnyum, red, red, gray, gray, white, white, runeWrath, runeFire));
consumer.accept(make(ModSubtiles.kekimurus, white, white, orange, orange, brown, brown, runeGluttony, pixieDust));
consumer.accept(make(ModSubtiles.gourmaryllis, lightGray, lightGray, yellow, yellow, red, runeFire, runeSummer));
consumer.accept(make(ModSubtiles.narslimmus, lime, lime, green, green, black, runeSummer, runeWater));
consumer.accept(make(ModSubtiles.spectrolus, red, red, green, green, blue, blue, white, white, runeWinter, runeAir, pixieDust));
consumer.accept(make(ModSubtiles.rafflowsia, purple, purple, green, green, black, runeEarth, runePride, pixieDust));
consumer.accept(make(ModSubtiles.shulkMeNot, purple, purple, magenta, magenta, lightGray, gaiaSpirit, runeEnvy, runeWrath));
consumer.accept(make(ModSubtiles.dandelifeon, purple, purple, lime, green, runeWater, runeFire, runeEarth, runeAir, gaiaSpirit));
consumer.accept(make(ModSubtiles.jadedAmaranthus, purple, lime, green, runeSpring, redstoneRoot));
consumer.accept(make(ModSubtiles.bellethorn, red, red, red, cyan, cyan, redstoneRoot));
consumer.accept(make(ModSubtiles.dreadthorn, black, black, black, cyan, cyan, redstoneRoot));
consumer.accept(make(ModSubtiles.heiseiDream, magenta, magenta, purple, pink, runeWrath, pixieDust));
consumer.accept(make(ModSubtiles.tigerseye, yellow, brown, orange, lime, runeAutumn));
consumer.accept(make(ModSubtiles.orechid, gray, gray, yellow, green, red, runePride, runeGreed, redstoneRoot, pixieDust));
// todo 1.15
if (Botania.gardenOfGlassLoaded) {
consumer.accept(make(ModSubtiles.orechid, gray, gray, yellow, yellow, green, green, red, red));
}
consumer.accept(make(ModSubtiles.orechidIgnem, red, red, white, white, pink, runePride, runeGreed, redstoneRoot, pixieDust));
// todo 1.15 config flag
if (ConfigHandler.COMMON.fallenKanadeEnabled.get()) {
consumer.accept(make(ModSubtiles.fallenKanade, white, white, yellow, yellow, orange, runeSpring));
}
consumer.accept(make(ModSubtiles.exoflame, red, red, gray, lightGray, runeFire, runeSummer));
consumer.accept(make(ModSubtiles.agricarnation, lime, lime, green, yellow, runeSpring, redstoneRoot));
consumer.accept(make(ModSubtiles.hopperhock, gray, gray, lightGray, lightGray, runeAir, redstoneRoot));
consumer.accept(make(ModSubtiles.tangleberrie, cyan, cyan, gray, lightGray, runeAir, runeEarth));
consumer.accept(make(ModSubtiles.jiyuulia, pink, pink, purple, lightGray, runeWater, runeAir));
consumer.accept(make(ModSubtiles.rannuncarpus, orange, orange, yellow, runeEarth, redstoneRoot));
consumer.accept(make(ModSubtiles.hyacidus, purple, purple, magenta, magenta, green, runeWater, runeAutumn, redstoneRoot));
consumer.accept(make(ModSubtiles.pollidisiac, red, red, pink, pink, orange, runeLust, runeFire));
consumer.accept(make(ModSubtiles.clayconia, lightGray, lightGray, gray, cyan, runeEarth));
consumer.accept(make(ModSubtiles.loonium, green, green, green, green, gray, runeSloth, runeGluttony, runeEnvy, redstoneRoot, pixieDust));
consumer.accept(make(ModSubtiles.daffomill, white, white, brown, yellow, runeAir, redstoneRoot));
consumer.accept(make(ModSubtiles.vinculotus, black, black, purple, purple, green, runeWater, runeSloth, runeLust, redstoneRoot));
consumer.accept(make(ModSubtiles.spectranthemum, white, white, lightGray, lightGray, cyan, runeEnvy, runeWater, redstoneRoot, pixieDust));
consumer.accept(make(ModSubtiles.medumone, brown, brown, gray, gray, runeEarth, redstoneRoot));
consumer.accept(make(ModSubtiles.marimorphosis, gray, yellow, green, red, runeEarth, runeFire, redstoneRoot));
consumer.accept(make(ModSubtiles.bubbell, cyan, cyan, lightBlue, lightBlue, blue, blue, runeWater, runeSummer, pixieDust));
consumer.accept(make(ModSubtiles.solegnolia, brown, brown, red, blue, redstoneRoot));
consumer.accept(make(ModSubtiles.bergamute, orange, green, green, redstoneRoot));
ItemStack stack = new ItemStack(Items.PLAYER_HEAD);
ItemNBTHelper.setString(stack, "SkullOwner", "Vazkii");
Ingredient[] inputs = new Ingredient[16];
Arrays.fill(inputs, pink);
consumer.accept(new FinishedRecipe(idFor(prefix("vazkii_head")), stack, inputs));
}
private static Ingredient tagIngr(String tag) {
return Ingredient.fromTag(new ItemTags.Wrapper(new ResourceLocation(LibMisc.MOD_ID, tag)));
}
private static FinishedRecipe make(IItemProvider item, Ingredient... ingredients) {
return new FinishedRecipe(idFor(item.asItem().getRegistryName()), new ItemStack(item), ingredients);
}
private static ResourceLocation idFor(ResourceLocation name) {
return new ResourceLocation(name.getNamespace(), "petal/" + name.getPath());
}
private static class FinishedRecipe implements IFinishedRecipe {
private final ResourceLocation id;
private final ItemStack output;
private final Ingredient[] inputs;
private FinishedRecipe(ResourceLocation id, ItemStack output, Ingredient... inputs) {
this.id = id;
this.output = output;
this.inputs = inputs;
}
@Override
public void serialize(JsonObject json) {
json.add("output", ItemNBTHelper.serializeStack(output));
JsonArray ingredients = new JsonArray();
for (Ingredient ingr : inputs) {
ingredients.add(ingr.serialize());
}
json.add("ingredients", ingredients);
}
@Override
public ResourceLocation getID() {
return id;
}
@Override
public IRecipeSerializer<?> getSerializer() {
return ModRecipeTypes.PETAL_SERIALIZER;
}
@Nullable
@Override
public JsonObject getAdvancementJson() {
return null;
}
@Nullable
@Override
public ResourceLocation getAdvancementID() {
return null;
}
}
}