mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 12:19:46 +00:00
Brew recipes to json
This commit is contained in:
1 parent
12129ea470
commit
604e0f5d99
33 files changed
+599
-135
No files matched your search
@@ -62,7 +62,6 @@ public final class BotaniaAPI {
|
||||
*/
|
||||
public static Map<ResourceLocation, RecipePetals> petalRecipes = Collections.emptyMap();
|
||||
public static Map<ResourceLocation, RecipeRuneAltar> runeAltarRecipes = Collections.emptyMap();
|
||||
public static Map<ResourceLocation, RecipeBrew> brewRecipes = Collections.emptyMap();
|
||||
|
||||
public static Map<ResourceLocation, Integer> oreWeights = Collections.emptyMap();
|
||||
public static Map<ResourceLocation, Integer> oreWeightsNether = Collections.emptyMap();
|
||||
|
||||
@@ -10,36 +10,53 @@ 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 com.google.gson.JsonParseException;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
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.items.IItemHandler;
|
||||
|
||||
import net.minecraftforge.items.wrapper.RecipeWrapper;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.brew.Brew;
|
||||
import vazkii.botania.api.brew.IBrewContainer;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class RecipeBrew {
|
||||
public class RecipeBrew implements IRecipe<RecipeWrapper> {
|
||||
private final ResourceLocation id;
|
||||
private final Brew brew;
|
||||
private final ImmutableList<Ingredient> inputs;
|
||||
private final NonNullList<Ingredient> inputs;
|
||||
|
||||
public RecipeBrew(ResourceLocation id, Brew brew, Ingredient... inputs) {
|
||||
this.id = id;
|
||||
this.brew = brew;
|
||||
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> inputsMissing = new ArrayList<>(inputs);
|
||||
|
||||
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;
|
||||
@@ -69,12 +86,40 @@ public class RecipeBrew {
|
||||
return inputsMissing.isEmpty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getIcon() {
|
||||
return new ItemStack(ModBlocks.brewery);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<Ingredient> getInputs() {
|
||||
return new ArrayList<>(inputs);
|
||||
@Nonnull
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeTypes.BREW_SERIALIZER;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return ModRecipeTypes.BREW_TYPE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public Brew getBrew() {
|
||||
@@ -106,23 +151,54 @@ public class RecipeBrew {
|
||||
&& inputs.equals(((RecipeBrew) o).inputs);
|
||||
}
|
||||
|
||||
public void write(PacketBuffer buf) {
|
||||
buf.writeResourceLocation(id);
|
||||
buf.writeResourceLocation(brew.getRegistryName());
|
||||
buf.writeVarInt(inputs.size());
|
||||
for (Ingredient input : inputs) {
|
||||
input.write(buf);
|
||||
}
|
||||
// Ignored IRecipe methods
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static RecipeBrew read(PacketBuffer buf) {
|
||||
ResourceLocation id = buf.readResourceLocation();
|
||||
Brew brew = BotaniaAPI.brewRegistry.getValue(buf.readResourceLocation());
|
||||
Ingredient[] inputs = new Ingredient[buf.readVarInt()];
|
||||
for (int i = 0; i < inputs.length; i++) {
|
||||
inputs[i] = Ingredient.read(buf);
|
||||
}
|
||||
return new RecipeBrew(id, brew, inputs);
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeBrew> {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeBrew read(@Nonnull ResourceLocation id, @Nonnull JsonObject json) {
|
||||
String brewStr = JSONUtils.getString(json, "brew");
|
||||
ResourceLocation brewId = ResourceLocation.tryCreate(brewStr);
|
||||
if (brewId == null || !BotaniaAPI.brewRegistry.containsKey(brewId)) {
|
||||
throw new JsonParseException("Unknown brew " + brewStr);
|
||||
}
|
||||
Brew brew = BotaniaAPI.brewRegistry.getValue(brewId);
|
||||
|
||||
JsonArray ingrs = JSONUtils.getJsonArray(json, "ingredients");
|
||||
List<Ingredient> inputs = new ArrayList<>();
|
||||
for (JsonElement e : ingrs) {
|
||||
inputs.add(Ingredient.deserialize(e));
|
||||
}
|
||||
return new RecipeBrew(id, brew, inputs.toArray(new Ingredient[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeBrew read(@Nonnull ResourceLocation id, @Nonnull PacketBuffer buf) {
|
||||
Brew brew = buf.readRegistryIdUnsafe(BotaniaAPI.brewRegistry);
|
||||
Ingredient[] inputs = new Ingredient[buf.readVarInt()];
|
||||
for (int i = 0; i < inputs.length; i++) {
|
||||
inputs[i] = Ingredient.read(buf);
|
||||
}
|
||||
return new RecipeBrew(id, brew, inputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@Nonnull PacketBuffer buf, @Nonnull RecipeBrew recipe) {
|
||||
buf.writeResourceLocation(recipe.getBrew().getRegistryName());
|
||||
buf.writeVarInt(recipe.getIngredients().size());
|
||||
for (Ingredient input : recipe.getIngredients()) {
|
||||
input.write(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,20 +20,14 @@ import java.util.function.Consumer;
|
||||
* handlers as stateless as possible.
|
||||
*/
|
||||
public class RegisterRecipesEvent extends Event {
|
||||
private final Consumer<RecipeBrew> brew;
|
||||
private final Consumer<RecipePetals> apothecary;
|
||||
private final Consumer<RecipeRuneAltar> runeAltar;
|
||||
|
||||
public RegisterRecipesEvent(Consumer<RecipeBrew> brew, Consumer<RecipePetals> apothecary, Consumer<RecipeRuneAltar> runeAltar) {
|
||||
this.brew = brew;
|
||||
public RegisterRecipesEvent(Consumer<RecipePetals> apothecary, Consumer<RecipeRuneAltar> runeAltar) {
|
||||
this.apothecary = apothecary;
|
||||
this.runeAltar = runeAltar;
|
||||
}
|
||||
|
||||
public Consumer<RecipeBrew> brew() {
|
||||
return brew;
|
||||
}
|
||||
|
||||
public Consumer<RecipePetals> apothecary() {
|
||||
return apothecary;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class JEIBotaniaPlugin implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void registerRecipes(@Nonnull IRecipeRegistration registry) {
|
||||
registry.addRecipes(BotaniaAPI.brewRecipes.values(), BreweryRecipeCategory.UID);
|
||||
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(TileAlfPortal.elvenTradeRecipes(Minecraft.getInstance().world.getRecipeManager()), ElvenTradeRecipeCategory.UID);
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ public class BreweryRecipeCategory implements IRecipeCategory<RecipeBrew> {
|
||||
}
|
||||
inputBuilder.add(containers.build());
|
||||
|
||||
for (Ingredient i : recipe.getInputs()) {
|
||||
for (Ingredient i : recipe.getIngredients()) {
|
||||
inputBuilder.add(Arrays.asList(i.getMatchingStacks()));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
*/
|
||||
package vazkii.botania.client.patchouli.processor;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.patchouli.api.IComponentProcessor;
|
||||
import vazkii.patchouli.api.IVariableProvider;
|
||||
@@ -24,7 +27,11 @@ public class BrewRecipeProcessor implements IComponentProcessor {
|
||||
|
||||
@Override
|
||||
public void setup(IVariableProvider<String> variables) {
|
||||
this.recipe = BotaniaAPI.brewRecipes.get(new ResourceLocation(variables.get("recipe")));
|
||||
ResourceLocation id = new ResourceLocation(variables.get("recipe"));
|
||||
IRecipe<?> recipe = Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.BREW_TYPE).get(id);
|
||||
if (recipe instanceof RecipeBrew) {
|
||||
this.recipe = (RecipeBrew) recipe;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,16 +46,16 @@ public class BrewRecipeProcessor implements IComponentProcessor {
|
||||
return PatchouliAPI.instance.serializeItemStack(recipe.getOutput(new ItemStack(ModItems.flask)));
|
||||
} else if (key.startsWith("input")) {
|
||||
int requestedIndex = Integer.parseInt(key.substring(5)) - 1;
|
||||
int indexOffset = (6 - recipe.getInputs().size()) / 2; //Center the brew ingredients
|
||||
int indexOffset = (6 - recipe.getIngredients().size()) / 2; //Center the brew ingredients
|
||||
int index = requestedIndex - indexOffset;
|
||||
|
||||
if (index < recipe.getInputs().size() && index >= 0) {
|
||||
return PatchouliAPI.instance.serializeIngredient(recipe.getInputs().get(index));
|
||||
if (index < recipe.getIngredients().size() && index >= 0) {
|
||||
return PatchouliAPI.instance.serializeIngredient(recipe.getIngredients().get(index));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (key.equals("is_offset")) {
|
||||
return Boolean.toString(recipe.getInputs().size() % 2 == 0);
|
||||
return Boolean.toString(recipe.getIngredients().size() % 2 == 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraftforge.items.wrapper.RecipeWrapper;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
@@ -32,6 +34,7 @@ import vazkii.botania.client.fx.SparkleParticleData;
|
||||
import vazkii.botania.client.fx.WispParticleData;
|
||||
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;
|
||||
|
||||
@@ -39,6 +42,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TileBrewery extends TileSimpleInventory implements IManaReceiver, ITickableTileEntity {
|
||||
|
||||
@@ -82,26 +86,24 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
|
||||
if (did) {
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
|
||||
for (RecipeBrew recipe : BotaniaAPI.brewRecipes.values()) {
|
||||
if (recipe.matches(itemHandler) && !recipe.getOutput(itemHandler.getStackInSlot(0)).isEmpty()) {
|
||||
this.recipe = recipe;
|
||||
world.setBlockState(pos, ModBlocks.brewery.getDefaultState().with(BotaniaStateProps.POWERED, true));
|
||||
}
|
||||
}
|
||||
findRecipe();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void findRecipe() {
|
||||
Optional<RecipeBrew> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, new RecipeWrapper(itemHandler), world);
|
||||
maybeRecipe.ifPresent(recipeBrew -> {
|
||||
this.recipe = recipeBrew;
|
||||
world.setBlockState(pos, ModBlocks.brewery.getDefaultState().with(BotaniaStateProps.POWERED, true));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (mana > 0 && recipe == null) {
|
||||
for (RecipeBrew recipe : BotaniaAPI.brewRecipes.values()) {
|
||||
if (recipe.matches(itemHandler)) {
|
||||
this.recipe = recipe;
|
||||
world.setBlockState(pos, ModBlocks.brewery.getDefaultState().with(BotaniaStateProps.POWERED, true));
|
||||
}
|
||||
}
|
||||
findRecipe();
|
||||
|
||||
if (recipe == null) {
|
||||
mana = 0;
|
||||
@@ -122,7 +124,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
|
||||
}
|
||||
|
||||
if (recipe != null) {
|
||||
if (!recipe.matches(itemHandler)) {
|
||||
if (!recipe.matches(new RecipeWrapper(itemHandler), world)) {
|
||||
recipe = null;
|
||||
world.setBlockState(pos, ModBlocks.brewery.getDefaultState());
|
||||
}
|
||||
|
||||
@@ -1,65 +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.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RegisterRecipesEvent;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.brew.ModBrews;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID)
|
||||
public class ModBrewRecipes {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegisterRecipesEvent evt) {
|
||||
evt.brew().accept(new RecipeBrew(prefix("speed"), ModBrews.speed, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SUGAR), Ingredient.fromItems(Items.REDSTONE)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("strength"), ModBrews.strength, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.BLAZE_POWDER), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("haste"), ModBrews.haste, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SUGAR), Ingredient.fromItems(Items.GOLD_NUGGET)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("healing"), ModBrews.healing, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GLISTERING_MELON_SLICE), Ingredient.fromItems(Items.POTATO)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("jump_boost"), ModBrews.jumpBoost, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.FEATHER), Ingredient.fromItems(Items.CARROT)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("regeneration"), ModBrews.regen, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GHAST_TEAR), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("weak_regeneration"), ModBrews.regenWeak, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GHAST_TEAR), Ingredient.fromItems(Items.REDSTONE)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("resistance"), ModBrews.resistance, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.IRON_INGOT), Ingredient.fromItems(Items.LEATHER)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("fire_resistance"), ModBrews.fireResistance, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.MAGMA_CREAM), Ingredient.fromItems(Blocks.NETHERRACK)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("water_breathing"), ModBrews.waterBreathing, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.PRISMARINE_CRYSTALS), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("invisibility"), ModBrews.invisibility, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SNOWBALL), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("night_vision"), ModBrews.nightVision, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SPIDER_EYE), Ingredient.fromItems(Items.GOLDEN_CARROT)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("absorption"), ModBrews.absorption, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GOLDEN_APPLE), Ingredient.fromItems(Items.POTATO)));
|
||||
|
||||
evt.brew().accept(new RecipeBrew(prefix("overload"), ModBrews.overload, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.BLAZE_POWDER), Ingredient.fromItems(Items.SUGAR), Ingredient.fromItems(Items.GLOWSTONE_DUST), Ingredient.fromItems(ModItems.manaSteel), Ingredient.fromItems(Items.SPIDER_EYE)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("soul_cross"), ModBrews.soulCross, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Blocks.SOUL_SAND), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.APPLE), Ingredient.fromItems(Items.BONE)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("feather_feet"), ModBrews.featherfeet, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.FEATHER), Ingredient.fromItems(Items.LEATHER), Ingredient.fromTag(ItemTags.WOOL)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("emptiness"), ModBrews.emptiness, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GUNPOWDER), Ingredient.fromItems(Items.ROTTEN_FLESH), Ingredient.fromItems(Items.BONE), Ingredient.fromItems(Items.STRING), Ingredient.fromItems(Items.ENDER_PEARL)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("bloodthirst"), ModBrews.bloodthirst, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.FERMENTED_SPIDER_EYE), Ingredient.fromItems(Items.LAPIS_LAZULI), Ingredient.fromItems(Items.FIRE_CHARGE), Ingredient.fromItems(Items.IRON_INGOT)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("allure"), ModBrews.allure, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.COD), Ingredient.fromItems(Items.QUARTZ), Ingredient.fromItems(Items.GOLDEN_CARROT)));
|
||||
evt.brew().accept(new RecipeBrew(prefix("clear"), ModBrews.clear, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.QUARTZ), Ingredient.fromItems(Items.EMERALD), Ingredient.fromItems(Items.MELON_SLICE)));
|
||||
|
||||
if (Botania.thaumcraftLoaded) {
|
||||
Item salisMundus = ForgeRegistries.ITEMS.getValue(new ResourceLocation("thaumcraft", "salis_mundus"));
|
||||
Item bathSalts = ForgeRegistries.ITEMS.getValue(new ResourceLocation("thaumcraft", "bath_salts"));
|
||||
Item amber = ForgeRegistries.ITEMS.getValue(new ResourceLocation("thaumcraft", "amber"));
|
||||
|
||||
evt.brew().accept(new RecipeBrew(prefix("warp_ward"), ModBrews.warpWard, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(salisMundus), Ingredient.fromItems(bathSalts), Ingredient.fromItems(amber)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +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;
|
||||
@@ -37,6 +38,9 @@ public class ModRecipeTypes {
|
||||
public static final IRecipeType<RecipePureDaisy> PURE_DAISY_TYPE = new RecipeType<>();
|
||||
public static final IRecipeSerializer<RecipePureDaisy> PURE_DAISY_SERIALIZER = new RecipePureDaisy.Serializer();
|
||||
|
||||
public static final IRecipeType<RecipeBrew> BREW_TYPE = new RecipeType<>();
|
||||
public static final IRecipeSerializer<RecipeBrew> BREW_SERIALIZER = new RecipeBrew.Serializer();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<IRecipeSerializer<?>> evt) {
|
||||
ResourceLocation id = prefix("elven_trade");
|
||||
@@ -51,6 +55,10 @@ public class ModRecipeTypes {
|
||||
id = prefix("pure_daisy");
|
||||
Registry.register(Registry.RECIPE_TYPE, id, PURE_DAISY_TYPE);
|
||||
evt.getRegistry().register(PURE_DAISY_SERIALIZER.setRegistryName(id));
|
||||
|
||||
id = prefix("brew");
|
||||
Registry.register(Registry.RECIPE_TYPE, id, BREW_TYPE);
|
||||
evt.getRegistry().register(BREW_SERIALIZER.setRegistryName(id));
|
||||
}
|
||||
|
||||
private static class RecipeType<T extends IRecipe<?>> implements IRecipeType<T> {
|
||||
|
||||
@@ -39,18 +39,15 @@ public class SyncHandler {
|
||||
public static class ReloadListener implements IResourceManagerReloadListener {
|
||||
@Override
|
||||
public void onResourceManagerReload(@Nullable IResourceManager manager) {
|
||||
Map<ResourceLocation, RecipeBrew> brew = new HashMap<>();
|
||||
Map<ResourceLocation, RecipePetals> apothecary = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeRuneAltar> runeAltar = new HashMap<>();
|
||||
|
||||
RegisterRecipesEvent evt = new RegisterRecipesEvent(
|
||||
r -> brew.put(r.getId(), r),
|
||||
r -> apothecary.put(r.getId(), r),
|
||||
r -> apothecary.put(r.getId(), r),
|
||||
r -> runeAltar.put(r.getId(), r)
|
||||
);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
BotaniaAPI.brewRecipes = ImmutableMap.copyOf(brew);
|
||||
BotaniaAPI.petalRecipes = ImmutableMap.copyOf(apothecary);
|
||||
BotaniaAPI.runeAltarRecipes = ImmutableMap.copyOf(runeAltar);
|
||||
PacketHandler.HANDLER.send(PacketDistributor.ALL.noArg(), syncPacket());
|
||||
@@ -58,14 +55,13 @@ public class SyncHandler {
|
||||
}
|
||||
|
||||
private static PacketSyncRecipes syncPacket() {
|
||||
return new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes);
|
||||
return new PacketSyncRecipes(BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, value = Dist.CLIENT)
|
||||
public static class ClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void clientLogout(ClientPlayerNetworkEvent.LoggedOutEvent evt) {
|
||||
BotaniaAPI.brewRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.petalRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.runeAltarRecipes = Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -24,21 +24,15 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PacketSyncRecipes {
|
||||
private Map<ResourceLocation, RecipeBrew> brew;
|
||||
private Map<ResourceLocation, RecipePetals> petal;
|
||||
private Map<ResourceLocation, RecipeRuneAltar> runeAltar;
|
||||
|
||||
public PacketSyncRecipes(Map<ResourceLocation, RecipeBrew> brew, Map<ResourceLocation, RecipePetals> petal, Map<ResourceLocation, RecipeRuneAltar> runeAltar) {
|
||||
this.brew = brew;
|
||||
public PacketSyncRecipes(Map<ResourceLocation, RecipePetals> petal, Map<ResourceLocation, RecipeRuneAltar> runeAltar) {
|
||||
this.petal = petal;
|
||||
this.runeAltar = runeAltar;
|
||||
}
|
||||
|
||||
public void encode(PacketBuffer buf) {
|
||||
buf.writeVarInt(brew.size());
|
||||
for (RecipeBrew recipe : brew.values()) {
|
||||
recipe.write(buf);
|
||||
}
|
||||
buf.writeVarInt(petal.size());
|
||||
for (RecipePetals recipe : petal.values()) {
|
||||
recipe.write(buf);
|
||||
@@ -50,10 +44,6 @@ public class PacketSyncRecipes {
|
||||
}
|
||||
|
||||
public static PacketSyncRecipes decode(PacketBuffer buf) {
|
||||
int brewCount = buf.readVarInt();
|
||||
Map<ResourceLocation, RecipeBrew> brew = Stream.generate(() -> RecipeBrew.read(buf))
|
||||
.limit(brewCount)
|
||||
.collect(Collectors.toMap(RecipeBrew::getId, r -> r));
|
||||
int petalCount = buf.readVarInt();
|
||||
Map<ResourceLocation, RecipePetals> petal = Stream.generate(() -> RecipePetals.read(buf))
|
||||
.limit(petalCount)
|
||||
@@ -62,7 +52,7 @@ public class PacketSyncRecipes {
|
||||
Map<ResourceLocation, RecipeRuneAltar> rune = Stream.generate(() -> RecipeRuneAltar.read(buf))
|
||||
.limit(runeCount)
|
||||
.collect(Collectors.toMap(RecipeRuneAltar::getId, r -> r));
|
||||
return new PacketSyncRecipes(brew, petal, rune);
|
||||
return new PacketSyncRecipes(petal, rune);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
@@ -71,7 +61,6 @@ public class PacketSyncRecipes {
|
||||
if (Minecraft.getInstance().isSingleplayer()) {
|
||||
return;
|
||||
}
|
||||
BotaniaAPI.brewRecipes = brew;
|
||||
BotaniaAPI.petalRecipes = petal;
|
||||
BotaniaAPI.runeAltarRecipes = runeAltar;
|
||||
});
|
||||
@@ -85,7 +74,7 @@ public class PacketSyncRecipes {
|
||||
private int loginIndex;
|
||||
|
||||
public Login() {
|
||||
this(new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes));
|
||||
this(new PacketSyncRecipes(BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes));
|
||||
}
|
||||
|
||||
public Login(PacketSyncRecipes packet) {
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package vazkii.botania.data;
|
||||
|
||||
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.Item;
|
||||
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.registries.ForgeRegistries;
|
||||
import vazkii.botania.api.brew.Brew;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.brew.ModBrews;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
public class BrewProvider extends RecipeProvider {
|
||||
public BrewProvider(DataGenerator gen) {
|
||||
super(gen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Botania Brew recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
consumer.accept(new FinishedRecipe(idFor("speed"), ModBrews.speed, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SUGAR), Ingredient.fromItems(Items.REDSTONE)));
|
||||
consumer.accept(new FinishedRecipe(idFor("strength"), ModBrews.strength, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.BLAZE_POWDER), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
consumer.accept(new FinishedRecipe(idFor("haste"), ModBrews.haste, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SUGAR), Ingredient.fromItems(Items.GOLD_NUGGET)));
|
||||
consumer.accept(new FinishedRecipe(idFor("healing"), ModBrews.healing, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GLISTERING_MELON_SLICE), Ingredient.fromItems(Items.POTATO)));
|
||||
consumer.accept(new FinishedRecipe(idFor("jump_boost"), ModBrews.jumpBoost, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.FEATHER), Ingredient.fromItems(Items.CARROT)));
|
||||
consumer.accept(new FinishedRecipe(idFor("regeneration"), ModBrews.regen, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GHAST_TEAR), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
consumer.accept(new FinishedRecipe(idFor("weak_regeneration"), ModBrews.regenWeak, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GHAST_TEAR), Ingredient.fromItems(Items.REDSTONE)));
|
||||
consumer.accept(new FinishedRecipe(idFor("resistance"), ModBrews.resistance, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.IRON_INGOT), Ingredient.fromItems(Items.LEATHER)));
|
||||
consumer.accept(new FinishedRecipe(idFor("fire_resistance"), ModBrews.fireResistance, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.MAGMA_CREAM), Ingredient.fromItems(Blocks.NETHERRACK)));
|
||||
consumer.accept(new FinishedRecipe(idFor("water_breathing"), ModBrews.waterBreathing, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.PRISMARINE_CRYSTALS), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
consumer.accept(new FinishedRecipe(idFor("invisibility"), ModBrews.invisibility, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SNOWBALL), Ingredient.fromItems(Items.GLOWSTONE_DUST)));
|
||||
consumer.accept(new FinishedRecipe(idFor("night_vision"), ModBrews.nightVision, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.SPIDER_EYE), Ingredient.fromItems(Items.GOLDEN_CARROT)));
|
||||
consumer.accept(new FinishedRecipe(idFor("absorption"), ModBrews.absorption, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GOLDEN_APPLE), Ingredient.fromItems(Items.POTATO)));
|
||||
|
||||
consumer.accept(new FinishedRecipe(idFor("overload"), ModBrews.overload, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.BLAZE_POWDER), Ingredient.fromItems(Items.SUGAR), Ingredient.fromItems(Items.GLOWSTONE_DUST), Ingredient.fromItems(ModItems.manaSteel), Ingredient.fromItems(Items.SPIDER_EYE)));
|
||||
consumer.accept(new FinishedRecipe(idFor("soul_cross"), ModBrews.soulCross, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Blocks.SOUL_SAND), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.APPLE), Ingredient.fromItems(Items.BONE)));
|
||||
consumer.accept(new FinishedRecipe(idFor("feather_feet"), ModBrews.featherfeet, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.FEATHER), Ingredient.fromItems(Items.LEATHER), Ingredient.fromTag(ItemTags.WOOL)));
|
||||
consumer.accept(new FinishedRecipe(idFor("emptiness"), ModBrews.emptiness, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.GUNPOWDER), Ingredient.fromItems(Items.ROTTEN_FLESH), Ingredient.fromItems(Items.BONE), Ingredient.fromItems(Items.STRING), Ingredient.fromItems(Items.ENDER_PEARL)));
|
||||
consumer.accept(new FinishedRecipe(idFor("bloodthirst"), ModBrews.bloodthirst, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.FERMENTED_SPIDER_EYE), Ingredient.fromItems(Items.LAPIS_LAZULI), Ingredient.fromItems(Items.FIRE_CHARGE), Ingredient.fromItems(Items.IRON_INGOT)));
|
||||
consumer.accept(new FinishedRecipe(idFor("allure"), ModBrews.allure, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.COD), Ingredient.fromItems(Items.QUARTZ), Ingredient.fromItems(Items.GOLDEN_CARROT)));
|
||||
consumer.accept(new FinishedRecipe(idFor("clear"), ModBrews.clear, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(Items.QUARTZ), Ingredient.fromItems(Items.EMERALD), Ingredient.fromItems(Items.MELON_SLICE)));
|
||||
|
||||
// todo 1.15 conditional recipe or remove
|
||||
if (Botania.thaumcraftLoaded) {
|
||||
Item salisMundus = ForgeRegistries.ITEMS.getValue(new ResourceLocation("thaumcraft", "salis_mundus"));
|
||||
Item bathSalts = ForgeRegistries.ITEMS.getValue(new ResourceLocation("thaumcraft", "bath_salts"));
|
||||
Item amber = ForgeRegistries.ITEMS.getValue(new ResourceLocation("thaumcraft", "amber"));
|
||||
|
||||
consumer.accept(new FinishedRecipe(idFor("warp_ward"), ModBrews.warpWard, Ingredient.fromItems(Items.NETHER_WART), Ingredient.fromItems(salisMundus), Ingredient.fromItems(bathSalts), Ingredient.fromItems(amber)));
|
||||
}
|
||||
}
|
||||
|
||||
private static ResourceLocation idFor(String s) {
|
||||
return prefix("brew/" + s);
|
||||
}
|
||||
|
||||
private static class FinishedRecipe implements IFinishedRecipe {
|
||||
private final ResourceLocation id;
|
||||
private final Brew brew;
|
||||
private final Ingredient[] inputs;
|
||||
|
||||
private FinishedRecipe(ResourceLocation id, Brew brew, Ingredient... inputs) {
|
||||
this.id = id;
|
||||
this.brew = brew;
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonObject json) {
|
||||
json.addProperty("brew", brew.getRegistryName().toString());
|
||||
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.BREW_SERIALIZER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject getAdvancementJson() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementID() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class DataGenerators {
|
||||
evt.getGenerator().addProvider(new ElvenTradeProvider(evt.getGenerator()));
|
||||
evt.getGenerator().addProvider(new ManaInfusionProvider(evt.getGenerator()));
|
||||
evt.getGenerator().addProvider(new PureDaisyProvider(evt.getGenerator()));
|
||||
evt.getGenerator().addProvider(new BrewProvider(evt.getGenerator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user