From e0951a851ce54d0797784a7af8a52f4dbba3a852 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Mon, 30 Mar 2020 21:55:28 -0500 Subject: [PATCH] Rune recipes to json --- .../data/botania/recipes/rune/air.json | 25 +++ .../data/botania/recipes/rune/autumn.json | 27 ++++ .../data/botania/recipes/rune/earth.json | 30 ++++ .../data/botania/recipes/rune/envy.json | 21 +++ .../data/botania/recipes/rune/fire.json | 25 +++ .../data/botania/recipes/rune/gluttony.json | 21 +++ .../data/botania/recipes/rune/greed.json | 21 +++ .../data/botania/recipes/rune/head.json | 24 +++ .../data/botania/recipes/rune/lust.json | 21 +++ .../data/botania/recipes/rune/mana.json | 27 ++++ .../data/botania/recipes/rune/pride.json | 21 +++ .../data/botania/recipes/rune/sloth.json | 21 +++ .../data/botania/recipes/rune/spring.json | 27 ++++ .../data/botania/recipes/rune/summer.json | 27 ++++ .../data/botania/recipes/rune/water.json | 25 +++ .../data/botania/recipes/rune/winter.json | 27 ++++ .../data/botania/recipes/rune/wrath.json | 21 +++ .../java/vazkii/botania/api/BotaniaAPI.java | 6 - .../vazkii/botania/api/recipe/IModRecipe.java | 24 --- .../botania/api/recipe/RecipeRuneAltar.java | 118 +++++++++++--- .../integration/jei/JEIBotaniaPlugin.java | 2 +- .../runicaltar/RunicAltarRecipeCategory.java | 4 +- .../component/RotatingRecipeComponent.java | 2 - .../processor/PetalApothecaryProcessor.java | 2 - .../java/vazkii/botania/common/Botania.java | 3 - .../common/block/tile/TileRuneAltar.java | 74 ++++----- .../common/crafting/ModRecipeTypes.java | 10 ++ .../common/crafting/ModRuneRecipes.java | 82 ---------- .../botania/common/crafting/SyncHandler.java | 67 -------- .../common/crafting/recipe/HeadRecipe.java | 58 ++++++- .../botania/common/network/PacketAck.java | 36 ----- .../botania/common/network/PacketHandler.java | 15 +- .../common/network/PacketSyncRecipes.java | 95 ----------- .../vazkii/botania/data/DataGenerators.java | 1 + .../botania/data/recipes/RuneProvider.java | 150 ++++++++++++++++++ 35 files changed, 755 insertions(+), 405 deletions(-) create mode 100644 src/generated/resources/data/botania/recipes/rune/air.json create mode 100644 src/generated/resources/data/botania/recipes/rune/autumn.json create mode 100644 src/generated/resources/data/botania/recipes/rune/earth.json create mode 100644 src/generated/resources/data/botania/recipes/rune/envy.json create mode 100644 src/generated/resources/data/botania/recipes/rune/fire.json create mode 100644 src/generated/resources/data/botania/recipes/rune/gluttony.json create mode 100644 src/generated/resources/data/botania/recipes/rune/greed.json create mode 100644 src/generated/resources/data/botania/recipes/rune/head.json create mode 100644 src/generated/resources/data/botania/recipes/rune/lust.json create mode 100644 src/generated/resources/data/botania/recipes/rune/mana.json create mode 100644 src/generated/resources/data/botania/recipes/rune/pride.json create mode 100644 src/generated/resources/data/botania/recipes/rune/sloth.json create mode 100644 src/generated/resources/data/botania/recipes/rune/spring.json create mode 100644 src/generated/resources/data/botania/recipes/rune/summer.json create mode 100644 src/generated/resources/data/botania/recipes/rune/water.json create mode 100644 src/generated/resources/data/botania/recipes/rune/winter.json create mode 100644 src/generated/resources/data/botania/recipes/rune/wrath.json delete mode 100644 src/main/java/vazkii/botania/api/recipe/IModRecipe.java delete mode 100644 src/main/java/vazkii/botania/common/crafting/ModRuneRecipes.java delete mode 100644 src/main/java/vazkii/botania/common/crafting/SyncHandler.java delete mode 100644 src/main/java/vazkii/botania/common/network/PacketAck.java delete mode 100644 src/main/java/vazkii/botania/common/network/PacketSyncRecipes.java create mode 100644 src/main/java/vazkii/botania/data/recipes/RuneProvider.java diff --git a/src/generated/resources/data/botania/recipes/rune/air.json b/src/generated/resources/data/botania/recipes/rune/air.json new file mode 100644 index 000000000..d16d96a1c --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/air.json @@ -0,0 +1,25 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_air", + "count": 2 + }, + "mana": 5200, + "ingredients": [ + { + "tag": "forge:dusts/mana" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "tag": "minecraft:carpets" + }, + { + "item": "minecraft:feather" + }, + { + "item": "minecraft:string" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/autumn.json b/src/generated/resources/data/botania/recipes/rune/autumn.json new file mode 100644 index 000000000..66b2d4ad9 --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/autumn.json @@ -0,0 +1,27 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_autumn" + }, + "mana": 8000, + "ingredients": [ + { + "tag": "botania:runes/fire" + }, + { + "tag": "botania:runes/air" + }, + { + "tag": "minecraft:leaves" + }, + { + "tag": "minecraft:leaves" + }, + { + "tag": "minecraft:leaves" + }, + { + "item": "minecraft:spider_eye" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/earth.json b/src/generated/resources/data/botania/recipes/rune/earth.json new file mode 100644 index 000000000..74e32141f --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/earth.json @@ -0,0 +1,30 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_earth", + "count": 2 + }, + "mana": 5200, + "ingredients": [ + { + "tag": "forge:dusts/mana" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "tag": "forge:stone" + }, + { + "tag": "forge:storage_blocks/coal" + }, + [ + { + "item": "minecraft:brown_mushroom" + }, + { + "item": "minecraft:red_mushroom" + } + ] + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/envy.json b/src/generated/resources/data/botania/recipes/rune/envy.json new file mode 100644 index 000000000..54694bacb --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/envy.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_envy" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/winter" + }, + { + "tag": "botania:runes/water" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/fire.json b/src/generated/resources/data/botania/recipes/rune/fire.json new file mode 100644 index 000000000..9721b2545 --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/fire.json @@ -0,0 +1,25 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_fire", + "count": 2 + }, + "mana": 5200, + "ingredients": [ + { + "tag": "forge:dusts/mana" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "item": "minecraft:nether_brick" + }, + { + "item": "minecraft:gunpowder" + }, + { + "item": "minecraft:nether_wart" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/gluttony.json b/src/generated/resources/data/botania/recipes/rune/gluttony.json new file mode 100644 index 000000000..515d8417c --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/gluttony.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_gluttony" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/winter" + }, + { + "tag": "botania:runes/fire" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/greed.json b/src/generated/resources/data/botania/recipes/rune/greed.json new file mode 100644 index 000000000..81ad783af --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/greed.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_greed" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/spring" + }, + { + "tag": "botania:runes/water" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/head.json b/src/generated/resources/data/botania/recipes/rune/head.json new file mode 100644 index 000000000..53140071a --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/head.json @@ -0,0 +1,24 @@ +{ + "type": "botania:runic_altar_head", + "output": { + "item": "minecraft:player_head" + }, + "mana": 22500, + "ingredients": [ + { + "item": "minecraft:skeleton_skull" + }, + { + "item": "botania:pixie_dust" + }, + { + "item": "minecraft:prismarine_crystals" + }, + { + "item": "minecraft:name_tag" + }, + { + "item": "minecraft:golden_apple" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/lust.json b/src/generated/resources/data/botania/recipes/rune/lust.json new file mode 100644 index 000000000..2a990919f --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/lust.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_lust" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/summer" + }, + { + "tag": "botania:runes/air" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/mana.json b/src/generated/resources/data/botania/recipes/rune/mana.json new file mode 100644 index 000000000..2c934fedd --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/mana.json @@ -0,0 +1,27 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_mana" + }, + "mana": 8000, + "ingredients": [ + { + "tag": "forge:ingots/manasteel" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "item": "botania:mana_pearl" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/pride.json b/src/generated/resources/data/botania/recipes/rune/pride.json new file mode 100644 index 000000000..6993cb913 --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/pride.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_pride" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/summer" + }, + { + "tag": "botania:runes/fire" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/sloth.json b/src/generated/resources/data/botania/recipes/rune/sloth.json new file mode 100644 index 000000000..c586dd815 --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/sloth.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_sloth" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/autumn" + }, + { + "tag": "botania:runes/air" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/spring.json b/src/generated/resources/data/botania/recipes/rune/spring.json new file mode 100644 index 000000000..81d3c4298 --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/spring.json @@ -0,0 +1,27 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_spring" + }, + "mana": 8000, + "ingredients": [ + { + "tag": "botania:runes/water" + }, + { + "tag": "botania:runes/fire" + }, + { + "tag": "minecraft:saplings" + }, + { + "tag": "minecraft:saplings" + }, + { + "tag": "minecraft:saplings" + }, + { + "item": "minecraft:wheat" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/summer.json b/src/generated/resources/data/botania/recipes/rune/summer.json new file mode 100644 index 000000000..7ec2a6edb --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/summer.json @@ -0,0 +1,27 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_summer" + }, + "mana": 8000, + "ingredients": [ + { + "tag": "botania:runes/earth" + }, + { + "tag": "botania:runes/air" + }, + { + "tag": "minecraft:sand" + }, + { + "tag": "minecraft:sand" + }, + { + "item": "minecraft:slime_ball" + }, + { + "item": "minecraft:melon_slice" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/water.json b/src/generated/resources/data/botania/recipes/rune/water.json new file mode 100644 index 000000000..e21a2a317 --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/water.json @@ -0,0 +1,25 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_water", + "count": 2 + }, + "mana": 5200, + "ingredients": [ + { + "tag": "forge:dusts/mana" + }, + { + "tag": "forge:ingots/manasteel" + }, + { + "item": "minecraft:bone_meal" + }, + { + "item": "minecraft:sugar_cane" + }, + { + "item": "minecraft:fishing_rod" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/winter.json b/src/generated/resources/data/botania/recipes/rune/winter.json new file mode 100644 index 000000000..5489d73fe --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/winter.json @@ -0,0 +1,27 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_winter" + }, + "mana": 8000, + "ingredients": [ + { + "tag": "botania:runes/water" + }, + { + "tag": "botania:runes/earth" + }, + { + "item": "minecraft:snow" + }, + { + "item": "minecraft:snow_block" + }, + { + "tag": "minecraft:wool" + }, + { + "item": "minecraft:cake" + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/botania/recipes/rune/wrath.json b/src/generated/resources/data/botania/recipes/rune/wrath.json new file mode 100644 index 000000000..b3161335b --- /dev/null +++ b/src/generated/resources/data/botania/recipes/rune/wrath.json @@ -0,0 +1,21 @@ +{ + "type": "botania:runic_altar", + "output": { + "item": "botania:rune_wrath" + }, + "mana": 12000, + "ingredients": [ + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "forge:gems/mana_diamond" + }, + { + "tag": "botania:runes/winter" + }, + { + "tag": "botania:runes/earth" + } + ] +} \ No newline at end of file diff --git a/src/main/java/vazkii/botania/api/BotaniaAPI.java b/src/main/java/vazkii/botania/api/BotaniaAPI.java index 10ccebc21..747364b30 100644 --- a/src/main/java/vazkii/botania/api/BotaniaAPI.java +++ b/src/main/java/vazkii/botania/api/BotaniaAPI.java @@ -57,12 +57,6 @@ public final class BotaniaAPI { // TODO 1.15 MOVE THIS public static IForgeRegistry brewRegistry; - /* - * These maps are not meant to be mutated! - */ - public static Map petalRecipes = Collections.emptyMap(); - public static Map runeAltarRecipes = Collections.emptyMap(); - public static Map oreWeights = Collections.emptyMap(); public static Map oreWeightsNether = Collections.emptyMap(); diff --git a/src/main/java/vazkii/botania/api/recipe/IModRecipe.java b/src/main/java/vazkii/botania/api/recipe/IModRecipe.java deleted file mode 100644 index 776dc47ca..000000000 --- a/src/main/java/vazkii/botania/api/recipe/IModRecipe.java +++ /dev/null @@ -1,24 +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.api.recipe; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.ResourceLocation; - -import java.util.List; - -/** - * Implementation detail, you shouldn't need to use this. - */ -public interface IModRecipe { - List getInputs(); - ItemStack getOutput(); - ResourceLocation getId(); -} diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java b/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java index b05cdf419..ad00304e9 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java @@ -11,19 +11,34 @@ package vazkii.botania.api.recipe; import com.google.common.base.Preconditions; 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.minecraft.world.World; +import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.items.IItemHandler; +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 RecipeRuneAltar implements IModRecipe { +public class RecipeRuneAltar implements IRecipe { private final ResourceLocation id; private final ItemStack output; - private final ImmutableList inputs; + private final NonNullList inputs; private final int mana; public RecipeRuneAltar(ResourceLocation id, ItemStack output, int mana, Ingredient... inputs) { @@ -31,14 +46,15 @@ public class RecipeRuneAltar implements IModRecipe { Preconditions.checkArgument(mana <= 100000); this.id = id; this.output = output; - this.inputs = ImmutableList.copyOf(inputs); + this.inputs = NonNullList.from(null, inputs); this.mana = mana; } - public boolean matches(IItemHandler inv) { + @Override + public boolean matches(RecipeWrapper inv, @Nonnull World world) { List 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; @@ -64,42 +80,92 @@ public class RecipeRuneAltar implements IModRecipe { return ingredientsMissing.isEmpty(); } + @Nonnull + @Override + public ItemStack getRecipeOutput() { + return output; + } + + @Nonnull + @Override + public NonNullList getIngredients() { + return inputs; + } + + @Nonnull + @Override + public ItemStack getIcon() { + return new ItemStack(ModBlocks.runeAltar); + } + + @Nonnull @Override public ResourceLocation getId() { return id; } - public List getInputs() { - return inputs; + @Nonnull + @Override + public IRecipeSerializer getSerializer() { + return ModRecipeTypes.RUNE_SERIALIZER; } - public ItemStack getOutput() { - return output; + @Nonnull + @Override + public IRecipeType getType() { + return ModRecipeTypes.RUNE_TYPE; } public int getManaUsage() { return mana; } - - public void write(PacketBuffer buf) { - buf.writeResourceLocation(id); - buf.writeVarInt(inputs.size()); - for (Ingredient input : inputs) { - input.write(buf); - } - buf.writeItemStack(output, false); - buf.writeVarInt(mana); + + // Ignored IRecipe methods + @Nonnull + @Override + public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) { + return getRecipeOutput(); } - public static RecipeRuneAltar 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 boolean canFit(int width, int height) { + return false; + } + + public static class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { + @Nonnull + @Override + public RecipeRuneAltar read(@Nonnull ResourceLocation id, @Nonnull JsonObject json) { + ItemStack output = CraftingHelper.getItemStack(JSONUtils.getJsonObject(json, "output"), true); + int mana = JSONUtils.getInt(json, "mana"); + JsonArray ingrs = JSONUtils.getJsonArray(json, "ingredients"); + List inputs = new ArrayList<>(); + for (JsonElement e : ingrs) { + inputs.add(Ingredient.deserialize(e)); + } + return new RecipeRuneAltar(id, output, mana, inputs.toArray(new Ingredient[0])); + } + + @Override + public RecipeRuneAltar 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(); + int mana = buf.readVarInt(); + return new RecipeRuneAltar(id, output, mana, inputs); + } + + @Override + public void write(@Nonnull PacketBuffer buf, @Nonnull RecipeRuneAltar recipe) { + buf.writeVarInt(recipe.getIngredients().size()); + for (Ingredient input : recipe.getIngredients()) { + input.write(buf); + } + buf.writeItemStack(recipe.getRecipeOutput(), false); + buf.writeVarInt(recipe.getManaUsage()); } - ItemStack output = buf.readItemStack(); - int mana = buf.readVarInt(); - return new RecipeRuneAltar(id, output, mana, inputs); } } diff --git a/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java b/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java index 0bfa6007f..ec5d7158f 100644 --- a/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java +++ b/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java @@ -125,7 +125,7 @@ public class JEIBotaniaPlugin implements IModPlugin { registry.addRecipes(Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.PURE_DAISY_TYPE).values(), PureDaisyRecipeCategory.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(Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.RUNE_TYPE).values(), RunicAltarRecipeCategory.UID); registry.addRecipes(TilePool.manaInfusionRecipes(Minecraft.getInstance().world.getRecipeManager()), ManaPoolRecipeCategory.UID); registry.addRecipes( diff --git a/src/main/java/vazkii/botania/client/integration/jei/runicaltar/RunicAltarRecipeCategory.java b/src/main/java/vazkii/botania/client/integration/jei/runicaltar/RunicAltarRecipeCategory.java index 38c2b0d3c..a17a4b6d4 100644 --- a/src/main/java/vazkii/botania/client/integration/jei/runicaltar/RunicAltarRecipeCategory.java +++ b/src/main/java/vazkii/botania/client/integration/jei/runicaltar/RunicAltarRecipeCategory.java @@ -84,11 +84,11 @@ public class RunicAltarRecipeCategory implements IRecipeCategory> 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 diff --git a/src/main/java/vazkii/botania/client/patchouli/component/RotatingRecipeComponent.java b/src/main/java/vazkii/botania/client/patchouli/component/RotatingRecipeComponent.java index 4b1011e57..2c5cea819 100644 --- a/src/main/java/vazkii/botania/client/patchouli/component/RotatingRecipeComponent.java +++ b/src/main/java/vazkii/botania/client/patchouli/component/RotatingRecipeComponent.java @@ -15,8 +15,6 @@ 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; diff --git a/src/main/java/vazkii/botania/client/patchouli/processor/PetalApothecaryProcessor.java b/src/main/java/vazkii/botania/client/patchouli/processor/PetalApothecaryProcessor.java index 1d4786791..4f61ff4c5 100644 --- a/src/main/java/vazkii/botania/client/patchouli/processor/PetalApothecaryProcessor.java +++ b/src/main/java/vazkii/botania/client/patchouli/processor/PetalApothecaryProcessor.java @@ -12,8 +12,6 @@ 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; diff --git a/src/main/java/vazkii/botania/common/Botania.java b/src/main/java/vazkii/botania/common/Botania.java index 8bd24c0d5..e96dd7bfd 100644 --- a/src/main/java/vazkii/botania/common/Botania.java +++ b/src/main/java/vazkii/botania/common/Botania.java @@ -52,7 +52,6 @@ import vazkii.botania.common.block.tile.TileAlfPortal; import vazkii.botania.common.block.tile.TileEnchanter; import vazkii.botania.common.block.tile.TileTerraPlate; import vazkii.botania.common.block.tile.corporea.TileCorporeaIndex; -import vazkii.botania.common.brew.ModBrews; import vazkii.botania.common.capability.NoopCapStorage; import vazkii.botania.common.capability.NoopExoflameHeatable; import vazkii.botania.common.core.command.CommandSkyblockSpread; @@ -69,7 +68,6 @@ import vazkii.botania.common.core.loot.TrueGuardianKiller; import vazkii.botania.common.core.proxy.IProxy; import vazkii.botania.common.core.proxy.ServerProxy; import vazkii.botania.common.crafting.FluxfieldCondition; -import vazkii.botania.common.crafting.SyncHandler; import vazkii.botania.common.lib.LibMisc; import vazkii.botania.common.network.PacketHandler; import vazkii.botania.common.world.ModFeatures; @@ -252,7 +250,6 @@ public class Botania { + " \"Do not Override\". Whoever had the brilliant idea of overriding it needs to go" + " back to elementary school and learn to read. (Expected classname: " + expect + ", Actual classname: " + clname + ")"); } - event.getServer().getResourceManager().addReloadListener(new SyncHandler.ReloadListener()); } private void serverStarting(FMLServerStartingEvent event) { diff --git a/src/main/java/vazkii/botania/common/block/tile/TileRuneAltar.java b/src/main/java/vazkii/botania/common/block/tile/TileRuneAltar.java index 121e1c1c2..849700e7d 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileRuneAltar.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileRuneAltar.java @@ -23,6 +23,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; +import net.minecraftforge.items.wrapper.RecipeWrapper; import net.minecraftforge.registries.ObjectHolder; import org.lwjgl.opengl.GL11; @@ -39,6 +40,7 @@ import vazkii.botania.common.Botania; import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.core.handler.ModSounds; import vazkii.botania.common.core.helper.Vector3; +import vazkii.botania.common.crafting.ModRecipeTypes; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.material.ItemRune; import vazkii.botania.common.lib.LibBlockNames; @@ -49,6 +51,7 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver, ITickableTileEntity { @ObjectHolder(LibMisc.MOD_ID + ":" + LibBlockNames.RUNE_ALTAR) public static TileEntityType TYPE; @@ -206,11 +209,10 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver, if (currentRecipe != null) { this.manaToGet = currentRecipe.getManaUsage(); } else { - for (RecipeRuneAltar recipe : BotaniaAPI.runeAltarRecipes.values()) { - if (recipe.matches(itemHandler)) { - this.manaToGet = recipe.getManaUsage(); - break getMana; - } + Optional maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world); + if (maybeRecipe.isPresent()) { + this.manaToGet = maybeRecipe.get().getManaUsage(); + break getMana; } this.manaToGet = 0; } @@ -243,13 +245,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver, } public boolean hasValidRecipe() { - for (RecipeRuneAltar recipe : BotaniaAPI.runeAltarRecipes.values()) { - if (recipe.matches(itemHandler)) { - return true; - } - } - - return false; + return world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world).isPresent(); } public void onWanded(PlayerEntity player, ItemStack wand) { @@ -262,15 +258,13 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver, if (currentRecipe != null) { recipe = currentRecipe; } else { - for (RecipeRuneAltar recipe_ : BotaniaAPI.runeAltarRecipes.values()) { - if (recipe_.matches(itemHandler)) { - recipe = recipe_; - break; - } + Optional maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world); + if (maybeRecipe.isPresent()) { + recipe = maybeRecipe.get(); } } - if (manaToGet > 0 && mana >= manaToGet) { + if (recipe != null && manaToGet > 0 && mana >= manaToGet) { List items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(pos, pos.add(1, 1, 1))); ItemEntity livingrock = null; for (ItemEntity item : items) { @@ -283,7 +277,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver, if (livingrock != null) { int mana = recipe.getManaUsage(); recieveMana(-mana); - ItemStack output = recipe.getOutput().copy(); + ItemStack output = recipe.getRecipeOutput().copy(); ItemEntity outputItem = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output); world.addEntity(outputItem); currentRecipe = null; @@ -391,32 +385,30 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver, if (amt > 0) { float anglePer = 360F / amt; - for (RecipeRuneAltar recipe : BotaniaAPI.runeAltarRecipes.values()) { - if (recipe.matches(itemHandler)) { - RenderSystem.enableBlend(); - RenderSystem.enableRescaleNormal(); - RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, new RecipeWrapper(itemHandler), world).ifPresent(recipe -> { + RenderSystem.enableBlend(); + RenderSystem.enableRescaleNormal(); + RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - float progress = (float) mana / (float) manaToGet; + float progress = (float) mana / (float) manaToGet; - mc.textureManager.bindTexture(HUDHandler.manaBar); - RenderSystem.color4f(1F, 1F, 1F, 1F); - RenderHelper.drawTexturedModalRect(xc + radius + 9, yc - 8, progress == 1F ? 0 : 22, 8, 22, 15); + mc.textureManager.bindTexture(HUDHandler.manaBar); + RenderSystem.color4f(1F, 1F, 1F, 1F); + RenderHelper.drawTexturedModalRect(xc + radius + 9, yc - 8, progress == 1F ? 0 : 22, 8, 22, 15); - if (progress == 1F) { - mc.getItemRenderer().renderItemIntoGUI(new ItemStack(ModBlocks.livingrock), xc + radius + 16, yc + 8); - RenderSystem.translatef(0F, 0F, 100F); - mc.getItemRenderer().renderItemIntoGUI(new ItemStack(ModItems.twigWand), xc + radius + 24, yc + 8); - RenderSystem.translatef(0F, 0F, -100F); - } - - RenderHelper.renderProgressPie(xc + radius + 32, yc - 8, progress, recipe.getOutput()); - - if (progress == 1F) { - mc.fontRenderer.drawStringWithShadow("+", xc + radius + 14, yc + 12, 0xFFFFFF); - } + if (progress == 1F) { + mc.getItemRenderer().renderItemIntoGUI(new ItemStack(ModBlocks.livingrock), xc + radius + 16, yc + 8); + RenderSystem.translatef(0F, 0F, 100F); + mc.getItemRenderer().renderItemIntoGUI(new ItemStack(ModItems.twigWand), xc + radius + 24, yc + 8); + RenderSystem.translatef(0F, 0F, -100F); } - } + + RenderHelper.renderProgressPie(xc + radius + 32, yc - 8, progress, recipe.getRecipeOutput()); + + if (progress == 1F) { + mc.fontRenderer.drawStringWithShadow("+", xc + radius + 14, yc + 12, 0xFFFFFF); + } + }); for (int i = 0; i < amt; i++) { double xPos = xc + Math.cos(angle * Math.PI / 180D) * radius - 8; diff --git a/src/main/java/vazkii/botania/common/crafting/ModRecipeTypes.java b/src/main/java/vazkii/botania/common/crafting/ModRecipeTypes.java index 35daafe20..775322114 100644 --- a/src/main/java/vazkii/botania/common/crafting/ModRecipeTypes.java +++ b/src/main/java/vazkii/botania/common/crafting/ModRecipeTypes.java @@ -19,6 +19,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import vazkii.botania.api.recipe.*; +import vazkii.botania.common.crafting.recipe.HeadRecipe; import vazkii.botania.common.lib.LibMisc; import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; @@ -41,6 +42,10 @@ public class ModRecipeTypes { public static final IRecipeType PETAL_TYPE = new RecipeType<>(); public static final IRecipeSerializer PETAL_SERIALIZER = new RecipePetals.Serializer(); + public static final IRecipeType RUNE_TYPE = new RecipeType<>(); + public static final IRecipeSerializer RUNE_SERIALIZER = new RecipeRuneAltar.Serializer(); + public static final IRecipeSerializer RUNE_HEAD_SERIALIZER = new HeadRecipe.Serializer(); + @SubscribeEvent public static void register(RegistryEvent.Register> evt) { ResourceLocation id = prefix("elven_trade"); @@ -63,6 +68,11 @@ public class ModRecipeTypes { id = prefix("petal_apothecary"); Registry.register(Registry.RECIPE_TYPE, id, PETAL_TYPE); evt.getRegistry().register(PETAL_SERIALIZER.setRegistryName(id)); + + id = prefix("runic_altar"); + Registry.register(Registry.RECIPE_TYPE, id, RUNE_TYPE); + evt.getRegistry().register(RUNE_SERIALIZER.setRegistryName(id)); + evt.getRegistry().register(RUNE_HEAD_SERIALIZER.setRegistryName(prefix("runic_altar_head"))); } private static class RecipeType> implements IRecipeType { diff --git a/src/main/java/vazkii/botania/common/crafting/ModRuneRecipes.java b/src/main/java/vazkii/botania/common/crafting/ModRuneRecipes.java deleted file mode 100644 index 0378c73b2..000000000 --- a/src/main/java/vazkii/botania/common/crafting/ModRuneRecipes.java +++ /dev/null @@ -1,82 +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.block.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.tags.ItemTags; -import net.minecraftforge.common.Tags; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -import vazkii.botania.api.recipe.RecipeRuneAltar; -import vazkii.botania.api.recipe.RegisterRecipesEvent; -import vazkii.botania.common.crafting.recipe.HeadRecipe; -import vazkii.botania.common.item.ModItems; -import vazkii.botania.common.lib.LibMisc; -import vazkii.botania.common.lib.ModTags; - -import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; - -@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID) -public final class ModRuneRecipes { - - // todo 1.13 re-tagify these once the community settles down on some names - @SubscribeEvent - public static void register(RegisterRecipesEvent evt) { - final int costTier1 = 5200; - final int costTier2 = 8000; - final int costTier3 = 12000; - - Ingredient manaSteel = Ingredient.fromTag(ModTags.Items.INGOTS_MANASTEEL); - Ingredient manaDiamond = Ingredient.fromTag(ModTags.Items.GEMS_MANA_DIAMOND); - Ingredient manaPowder = Ingredient.fromTag(ModTags.Items.DUSTS_MANA); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("water"), new ItemStack(ModItems.runeWater, 2), costTier1, manaPowder, manaSteel, Ingredient.fromItems(Items.BONE_MEAL), Ingredient.fromItems(Blocks.SUGAR_CANE), Ingredient.fromItems(Items.FISHING_ROD))); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("fire"), new ItemStack(ModItems.runeFire, 2), costTier1, manaPowder, manaSteel, Ingredient.fromItems(Items.NETHER_BRICK), Ingredient.fromItems(Items.GUNPOWDER), Ingredient.fromItems(Items.NETHER_WART))); - - Ingredient stone = Ingredient.fromTag(Tags.Items.STONE); - Ingredient coalBlock = Ingredient.fromTag(Tags.Items.STORAGE_BLOCKS_COAL); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("earth"), new ItemStack(ModItems.runeEarth, 2), costTier1, manaPowder, manaSteel, stone, coalBlock, Ingredient.fromItems(Blocks.BROWN_MUSHROOM, Blocks.RED_MUSHROOM))); - - evt.runeAltar().accept(new RecipeRuneAltar(prefix("air"), new ItemStack(ModItems.runeAir, 2), costTier1, manaPowder, manaSteel, Ingredient.fromTag(ItemTags.CARPETS), Ingredient.fromItems(Items.FEATHER), Ingredient.fromItems(Items.STRING))); - - Ingredient fire = Ingredient.fromTag(ModTags.Items.RUNES_FIRE); - Ingredient water = Ingredient.fromTag(ModTags.Items.RUNES_WATER); - Ingredient earth = Ingredient.fromTag(ModTags.Items.RUNES_EARTH); - Ingredient air = Ingredient.fromTag(ModTags.Items.RUNES_AIR); - - Ingredient sapling = Ingredient.fromTag(ItemTags.SAPLINGS); - Ingredient leaves = Ingredient.fromTag(ItemTags.LEAVES); - Ingredient sand = Ingredient.fromTag(ItemTags.SAND); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("spring"), new ItemStack(ModItems.runeSpring), costTier2, water, fire, sapling, sapling, sapling, Ingredient.fromItems(Items.WHEAT))); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("summer"), new ItemStack(ModItems.runeSummer), costTier2, earth, air, sand, sand, Ingredient.fromItems(Items.SLIME_BALL), Ingredient.fromItems(Items.MELON_SLICE))); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("autumn"), new ItemStack(ModItems.runeAutumn), costTier2, fire, air, leaves, leaves, leaves, Ingredient.fromItems(Items.SPIDER_EYE))); - - evt.runeAltar().accept(new RecipeRuneAltar(prefix("winter"), new ItemStack(ModItems.runeWinter), costTier2, water, earth, Ingredient.fromItems(Blocks.SNOW), Ingredient.fromItems(Blocks.SNOW_BLOCK), Ingredient.fromTag(ItemTags.WOOL), Ingredient.fromItems(Blocks.CAKE))); - - Ingredient spring = Ingredient.fromTag(ModTags.Items.RUNES_SPRING); - Ingredient summer = Ingredient.fromTag(ModTags.Items.RUNES_SUMMER); - Ingredient autumn = Ingredient.fromTag(ModTags.Items.RUNES_AUTUMN); - Ingredient winter = Ingredient.fromTag(ModTags.Items.RUNES_WINTER); - - evt.runeAltar().accept(new RecipeRuneAltar(prefix("mana"), new ItemStack(ModItems.runeMana), costTier2, manaSteel, manaSteel, manaSteel, manaSteel, manaSteel, Ingredient.fromItems(ModItems.manaPearl))); - - evt.runeAltar().accept(new RecipeRuneAltar(prefix("lust"), new ItemStack(ModItems.runeLust), costTier3, manaDiamond, manaDiamond, summer, air)); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("gluttony"), new ItemStack(ModItems.runeGluttony), costTier3, manaDiamond, manaDiamond, winter, fire)); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("greed"), new ItemStack(ModItems.runeGreed), costTier3, manaDiamond, manaDiamond, spring, water)); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("sloth"), new ItemStack(ModItems.runeSloth), costTier3, manaDiamond, manaDiamond, autumn, air)); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("wrath"), new ItemStack(ModItems.runeWrath), costTier3, manaDiamond, manaDiamond, winter, earth)); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("envy"), new ItemStack(ModItems.runeEnvy), costTier3, manaDiamond, manaDiamond, winter, water)); - evt.runeAltar().accept(new RecipeRuneAltar(prefix("pride"), new ItemStack(ModItems.runePride), costTier3, manaDiamond, manaDiamond, summer, fire)); - - evt.runeAltar().accept(new HeadRecipe(prefix("head"), new ItemStack(Items.PLAYER_HEAD), 22500, Ingredient.fromItems(Items.SKELETON_SKULL), Ingredient.fromItems(ModItems.pixieDust), Ingredient.fromItems(Items.PRISMARINE_CRYSTALS), Ingredient.fromItems(Items.NAME_TAG), Ingredient.fromItems(Items.GOLDEN_APPLE))); - } -} diff --git a/src/main/java/vazkii/botania/common/crafting/SyncHandler.java b/src/main/java/vazkii/botania/common/crafting/SyncHandler.java deleted file mode 100644 index 2eee9c74c..000000000 --- a/src/main/java/vazkii/botania/common/crafting/SyncHandler.java +++ /dev/null @@ -1,67 +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 com.google.common.collect.ImmutableMap; - -import net.minecraft.resources.IResourceManager; -import net.minecraft.resources.IResourceManagerReloadListener; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.ClientPlayerNetworkEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.network.PacketDistributor; - -import vazkii.botania.api.BotaniaAPI; -import vazkii.botania.api.recipe.RecipePetals; -import vazkii.botania.api.recipe.RecipeRuneAltar; -import vazkii.botania.api.recipe.RegisterRecipesEvent; -import vazkii.botania.common.lib.LibMisc; -import vazkii.botania.common.network.PacketHandler; -import vazkii.botania.common.network.PacketSyncRecipes; - -import javax.annotation.Nullable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class SyncHandler { - public static class ReloadListener implements IResourceManagerReloadListener { - @Override - public void onResourceManagerReload(@Nullable IResourceManager manager) { - Map apothecary = new HashMap<>(); - Map runeAltar = new HashMap<>(); - - RegisterRecipesEvent evt = new RegisterRecipesEvent( - r -> apothecary.put(r.getId(), r), - r -> runeAltar.put(r.getId(), r) - ); - MinecraftForge.EVENT_BUS.post(evt); - - BotaniaAPI.runeAltarRecipes = ImmutableMap.copyOf(runeAltar); - PacketHandler.HANDLER.send(PacketDistributor.ALL.noArg(), syncPacket()); - } - } - - private static PacketSyncRecipes syncPacket() { - 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.runeAltarRecipes = Collections.emptyMap(); - } - } - -} diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/HeadRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/HeadRecipe.java index a43f1ecc8..3ee1591b8 100644 --- a/src/main/java/vazkii/botania/common/crafting/recipe/HeadRecipe.java +++ b/src/main/java/vazkii/botania/common/crafting/recipe/HeadRecipe.java @@ -8,15 +8,31 @@ */ package vazkii.botania.common.crafting.recipe; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; 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.network.PacketBuffer; +import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.World; +import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.RecipeWrapper; +import net.minecraftforge.registries.ForgeRegistryEntry; import vazkii.botania.api.recipe.RecipeRuneAltar; import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.crafting.ModRecipeTypes; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; public class HeadRecipe extends RecipeRuneAltar { @@ -27,11 +43,11 @@ public class HeadRecipe extends RecipeRuneAltar { } @Override - public boolean matches(IItemHandler inv) { - boolean matches = super.matches(inv); + public boolean matches(RecipeWrapper inv, @Nonnull World world) { + boolean matches = super.matches(inv, world); if (matches) { - for (int i = 0; i < inv.getSlots(); i++) { + for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); if (stack.isEmpty()) { break; @@ -50,8 +66,9 @@ public class HeadRecipe extends RecipeRuneAltar { return matches; } + @Nonnull @Override - public ItemStack getOutput() { + public ItemStack getRecipeOutput() { ItemStack stack = new ItemStack(Items.PLAYER_HEAD); if (!name.isEmpty()) { ItemNBTHelper.setString(stack, "SkullOwner", name); @@ -59,4 +76,37 @@ public class HeadRecipe extends RecipeRuneAltar { return stack; } + public static class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { + + // todo 1.15 reduce this duplication with RecipeRuneAltar, probably by introducing an abstract superclass + @Nonnull + @Override + public HeadRecipe read(@Nonnull ResourceLocation id, @Nonnull JsonObject json) { + ItemStack output = CraftingHelper.getItemStack(JSONUtils.getJsonObject(json, "output"), true); + int mana = JSONUtils.getInt(json, "mana"); + JsonArray ingrs = JSONUtils.getJsonArray(json, "ingredients"); + List inputs = new ArrayList<>(); + for (JsonElement e : ingrs) { + inputs.add(Ingredient.deserialize(e)); + } + return new HeadRecipe(id, output, mana, inputs.toArray(new Ingredient[0])); + } + + @Override + public HeadRecipe 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(); + int mana = buf.readVarInt(); + return new HeadRecipe(id, output, mana, inputs); + } + + @Override + public void write(@Nonnull PacketBuffer buf, @Nonnull HeadRecipe recipe) { + ModRecipeTypes.RUNE_SERIALIZER.write(buf, recipe); + } + } + } diff --git a/src/main/java/vazkii/botania/common/network/PacketAck.java b/src/main/java/vazkii/botania/common/network/PacketAck.java deleted file mode 100644 index 7b12d9cdd..000000000 --- a/src/main/java/vazkii/botania/common/network/PacketAck.java +++ /dev/null @@ -1,36 +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.network; - -import net.minecraft.network.PacketBuffer; -import net.minecraftforge.fml.network.NetworkEvent; - -import java.util.function.Supplier; - -public class PacketAck implements ILoginPacket { - private int loginIndex; - - public static PacketAck decode(PacketBuffer buf) { - return new PacketAck(); - } - - @Override - public void setLoginIndex(int index) { - this.loginIndex = index; - } - - @Override - public int getLoginIndex() { - return loginIndex; - } - - public void handle(Supplier ctx) { - ctx.get().setPacketHandled(true); - } -} diff --git a/src/main/java/vazkii/botania/common/network/PacketHandler.java b/src/main/java/vazkii/botania/common/network/PacketHandler.java index 254e498fe..326d04814 100644 --- a/src/main/java/vazkii/botania/common/network/PacketHandler.java +++ b/src/main/java/vazkii/botania/common/network/PacketHandler.java @@ -24,7 +24,7 @@ import net.minecraftforge.fml.network.simple.SimpleChannel; import vazkii.botania.common.lib.LibMisc; public final class PacketHandler { - private static final String PROTOCOL = "3"; + private static final String PROTOCOL = "4"; public static final SimpleChannel HANDLER = NetworkRegistry.newSimpleChannel( new ResourceLocation(LibMisc.MOD_ID, "chan"), () -> PROTOCOL, @@ -39,20 +39,7 @@ public final class PacketHandler { HANDLER.registerMessage(id++, PacketDodge.class, PacketDodge::encode, PacketDodge::decode, PacketDodge::handle); HANDLER.registerMessage(id++, PacketJump.class, PacketJump::encode, PacketJump::decode, PacketJump::handle); HANDLER.registerMessage(id++, PacketItemAge.class, PacketItemAge::encode, PacketItemAge::decode, PacketItemAge::handle); - HANDLER.registerMessage(id++, PacketSyncRecipes.class, PacketSyncRecipes::encode, PacketSyncRecipes::decode, PacketSyncRecipes::handle); HANDLER.registerMessage(id++, PacketIndexKeybindRequest.class, PacketIndexKeybindRequest::encode, PacketIndexKeybindRequest::decode, PacketIndexKeybindRequest::handle); - - HANDLER.messageBuilder(PacketSyncRecipes.Login.class, id++) - .loginIndex(ILoginPacket::getLoginIndex, ILoginPacket::setLoginIndex) - .encoder(PacketSyncRecipes.Login::encode).decoder(PacketSyncRecipes.Login::decode) - .consumer(FMLHandshakeHandler.biConsumerFor((hh, msg, ctx) -> msg.handle(ctx))) - .markAsLoginPacket().add(); - - HANDLER.messageBuilder(PacketAck.class, id++) - .loginIndex(ILoginPacket::getLoginIndex, ILoginPacket::setLoginIndex) - .encoder((packet, buf) -> {}).decoder(PacketAck::decode) - .consumer(FMLHandshakeHandler.indexFirst((hh, msg, ctx) -> msg.handle(ctx))) - .add(); } /** diff --git a/src/main/java/vazkii/botania/common/network/PacketSyncRecipes.java b/src/main/java/vazkii/botania/common/network/PacketSyncRecipes.java deleted file mode 100644 index a38738171..000000000 --- a/src/main/java/vazkii/botania/common/network/PacketSyncRecipes.java +++ /dev/null @@ -1,95 +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.network; - -import net.minecraft.client.Minecraft; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.network.NetworkEvent; - -import vazkii.botania.api.BotaniaAPI; -import vazkii.botania.api.recipe.RecipePetals; -import vazkii.botania.api.recipe.RecipeRuneAltar; - -import java.util.Map; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class PacketSyncRecipes { - private Map runeAltar; - - public PacketSyncRecipes(Map runeAltar) { - this.runeAltar = runeAltar; - } - - public void encode(PacketBuffer buf) { - buf.writeVarInt(runeAltar.size()); - for (RecipeRuneAltar recipe : runeAltar.values()) { - recipe.write(buf); - } - } - - public static PacketSyncRecipes decode(PacketBuffer buf) { - int runeCount = buf.readVarInt(); - Map rune = Stream.generate(() -> RecipeRuneAltar.read(buf)) - .limit(runeCount) - .collect(Collectors.toMap(RecipeRuneAltar::getId, r -> r)); - return new PacketSyncRecipes(rune); - } - - public void handle(Supplier ctx) { - if (ctx.get().getDirection().getReceptionSide().isClient()) { - ctx.get().enqueueWork(() -> { - if (Minecraft.getInstance().isSingleplayer()) { - return; - } - BotaniaAPI.runeAltarRecipes = runeAltar; - }); - } - ctx.get().setPacketHandled(true); - } - - // The login packet wraps the proper one because directly extending it will cause a freeze on the handshake. - public static class Login implements ILoginPacket { - private final PacketSyncRecipes wrapped; - private int loginIndex; - - public Login() { - this(new PacketSyncRecipes(BotaniaAPI.runeAltarRecipes)); - } - - public Login(PacketSyncRecipes packet) { - this.wrapped = packet; - } - - public static Login decode(PacketBuffer buf) { - return new Login(PacketSyncRecipes.decode(buf)); - } - - public void encode(PacketBuffer buf) { - wrapped.encode(buf); - } - - public void handle(Supplier ctx) { - wrapped.handle(ctx); - PacketHandler.HANDLER.reply(new PacketAck(), ctx.get()); - } - - @Override - public void setLoginIndex(int index) { - this.loginIndex = index; - } - - @Override - public int getLoginIndex() { - return loginIndex; - } - } -} diff --git a/src/main/java/vazkii/botania/data/DataGenerators.java b/src/main/java/vazkii/botania/data/DataGenerators.java index 3dfa47de1..9e8cfb446 100644 --- a/src/main/java/vazkii/botania/data/DataGenerators.java +++ b/src/main/java/vazkii/botania/data/DataGenerators.java @@ -34,6 +34,7 @@ public class DataGenerators { evt.getGenerator().addProvider(new PureDaisyProvider(evt.getGenerator())); evt.getGenerator().addProvider(new BrewProvider(evt.getGenerator())); evt.getGenerator().addProvider(new PetalProvider(evt.getGenerator())); + evt.getGenerator().addProvider(new RuneProvider(evt.getGenerator())); } } } diff --git a/src/main/java/vazkii/botania/data/recipes/RuneProvider.java b/src/main/java/vazkii/botania/data/recipes/RuneProvider.java new file mode 100644 index 000000000..3c996271d --- /dev/null +++ b/src/main/java/vazkii/botania/data/recipes/RuneProvider.java @@ -0,0 +1,150 @@ +package vazkii.botania.data.recipes; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import net.minecraft.block.Blocks; +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.ResourceLocation; +import net.minecraftforge.common.Tags; +import vazkii.botania.api.recipe.RecipeRuneAltar; +import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.crafting.ModRecipeTypes; +import vazkii.botania.common.crafting.recipe.HeadRecipe; +import vazkii.botania.common.item.ModItems; +import vazkii.botania.common.lib.ModTags; + +import javax.annotation.Nullable; +import java.util.function.Consumer; + +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; + +public class RuneProvider extends RecipeProvider { + public RuneProvider(DataGenerator gen) { + super(gen); + } + + @Override + public String getName() { + return "Botania runic altar recipes"; + } + + @Override + protected void registerRecipes(Consumer consumer) { + // todo 1.13 re-tagify these once the community settles down on some names + final int costTier1 = 5200; + final int costTier2 = 8000; + final int costTier3 = 12000; + + Ingredient manaSteel = Ingredient.fromTag(ModTags.Items.INGOTS_MANASTEEL); + Ingredient manaDiamond = Ingredient.fromTag(ModTags.Items.GEMS_MANA_DIAMOND); + Ingredient manaPowder = Ingredient.fromTag(ModTags.Items.DUSTS_MANA); + consumer.accept(new FinishedRecipe(idFor("water"), new ItemStack(ModItems.runeWater, 2), costTier1, manaPowder, manaSteel, Ingredient.fromItems(Items.BONE_MEAL), Ingredient.fromItems(Blocks.SUGAR_CANE), Ingredient.fromItems(Items.FISHING_ROD))); + consumer.accept(new FinishedRecipe(idFor("fire"), new ItemStack(ModItems.runeFire, 2), costTier1, manaPowder, manaSteel, Ingredient.fromItems(Items.NETHER_BRICK), Ingredient.fromItems(Items.GUNPOWDER), Ingredient.fromItems(Items.NETHER_WART))); + + Ingredient stone = Ingredient.fromTag(Tags.Items.STONE); + Ingredient coalBlock = Ingredient.fromTag(Tags.Items.STORAGE_BLOCKS_COAL); + consumer.accept(new FinishedRecipe(idFor("earth"), new ItemStack(ModItems.runeEarth, 2), costTier1, manaPowder, manaSteel, stone, coalBlock, Ingredient.fromItems(Blocks.BROWN_MUSHROOM, Blocks.RED_MUSHROOM))); + + consumer.accept(new FinishedRecipe(idFor("air"), new ItemStack(ModItems.runeAir, 2), costTier1, manaPowder, manaSteel, Ingredient.fromTag(ItemTags.CARPETS), Ingredient.fromItems(Items.FEATHER), Ingredient.fromItems(Items.STRING))); + + Ingredient fire = Ingredient.fromTag(ModTags.Items.RUNES_FIRE); + Ingredient water = Ingredient.fromTag(ModTags.Items.RUNES_WATER); + Ingredient earth = Ingredient.fromTag(ModTags.Items.RUNES_EARTH); + Ingredient air = Ingredient.fromTag(ModTags.Items.RUNES_AIR); + + Ingredient sapling = Ingredient.fromTag(ItemTags.SAPLINGS); + Ingredient leaves = Ingredient.fromTag(ItemTags.LEAVES); + Ingredient sand = Ingredient.fromTag(ItemTags.SAND); + consumer.accept(new FinishedRecipe(idFor("spring"), new ItemStack(ModItems.runeSpring), costTier2, water, fire, sapling, sapling, sapling, Ingredient.fromItems(Items.WHEAT))); + consumer.accept(new FinishedRecipe(idFor("summer"), new ItemStack(ModItems.runeSummer), costTier2, earth, air, sand, sand, Ingredient.fromItems(Items.SLIME_BALL), Ingredient.fromItems(Items.MELON_SLICE))); + consumer.accept(new FinishedRecipe(idFor("autumn"), new ItemStack(ModItems.runeAutumn), costTier2, fire, air, leaves, leaves, leaves, Ingredient.fromItems(Items.SPIDER_EYE))); + + consumer.accept(new FinishedRecipe(idFor("winter"), new ItemStack(ModItems.runeWinter), costTier2, water, earth, Ingredient.fromItems(Blocks.SNOW), Ingredient.fromItems(Blocks.SNOW_BLOCK), Ingredient.fromTag(ItemTags.WOOL), Ingredient.fromItems(Blocks.CAKE))); + + Ingredient spring = Ingredient.fromTag(ModTags.Items.RUNES_SPRING); + Ingredient summer = Ingredient.fromTag(ModTags.Items.RUNES_SUMMER); + Ingredient autumn = Ingredient.fromTag(ModTags.Items.RUNES_AUTUMN); + Ingredient winter = Ingredient.fromTag(ModTags.Items.RUNES_WINTER); + + consumer.accept(new FinishedRecipe(idFor("mana"), new ItemStack(ModItems.runeMana), costTier2, manaSteel, manaSteel, manaSteel, manaSteel, manaSteel, Ingredient.fromItems(ModItems.manaPearl))); + + consumer.accept(new FinishedRecipe(idFor("lust"), new ItemStack(ModItems.runeLust), costTier3, manaDiamond, manaDiamond, summer, air)); + consumer.accept(new FinishedRecipe(idFor("gluttony"), new ItemStack(ModItems.runeGluttony), costTier3, manaDiamond, manaDiamond, winter, fire)); + consumer.accept(new FinishedRecipe(idFor("greed"), new ItemStack(ModItems.runeGreed), costTier3, manaDiamond, manaDiamond, spring, water)); + consumer.accept(new FinishedRecipe(idFor("sloth"), new ItemStack(ModItems.runeSloth), costTier3, manaDiamond, manaDiamond, autumn, air)); + consumer.accept(new FinishedRecipe(idFor("wrath"), new ItemStack(ModItems.runeWrath), costTier3, manaDiamond, manaDiamond, winter, earth)); + consumer.accept(new FinishedRecipe(idFor("envy"), new ItemStack(ModItems.runeEnvy), costTier3, manaDiamond, manaDiamond, winter, water)); + consumer.accept(new FinishedRecipe(idFor("pride"), new ItemStack(ModItems.runePride), costTier3, manaDiamond, manaDiamond, summer, fire)); + + consumer.accept(new FinishedHeadRecipe(idFor("head"), new ItemStack(Items.PLAYER_HEAD), 22500, Ingredient.fromItems(Items.SKELETON_SKULL), Ingredient.fromItems(ModItems.pixieDust), Ingredient.fromItems(Items.PRISMARINE_CRYSTALS), Ingredient.fromItems(Items.NAME_TAG), Ingredient.fromItems(Items.GOLDEN_APPLE))); + } + + private static ResourceLocation idFor(String s) { + return prefix("rune/" + s); + } + + private static class FinishedRecipe implements IFinishedRecipe { + private final ResourceLocation id; + private final ItemStack output; + private final int mana; + private final Ingredient[] inputs; + + private FinishedRecipe(ResourceLocation id, ItemStack output, int mana, Ingredient... inputs) { + this.id = id; + this.output = output; + this.mana = mana; + 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.addProperty("mana", mana); + json.add("ingredients", ingredients); + } + + @Override + public ResourceLocation getID() { + return id; + } + + @Override + public IRecipeSerializer getSerializer() { + return ModRecipeTypes.RUNE_SERIALIZER; + } + + @Nullable + @Override + public JsonObject getAdvancementJson() { + return null; + } + + @Nullable + @Override + public ResourceLocation getAdvancementID() { + return null; + } + } + + private static class FinishedHeadRecipe extends FinishedRecipe { + private FinishedHeadRecipe(ResourceLocation id, ItemStack output, int mana, Ingredient... inputs) { + super(id, output, mana, inputs); + } + + @Override + public IRecipeSerializer getSerializer() { + return ModRecipeTypes.RUNE_HEAD_SERIALIZER; + } + } +}