interface-ify recipe classes

This commit is contained in:
Vincent Lee committed 2020-04-05 14:05:09 -05:00
1 parent 44079ea64d
commit d47348209a
44 files changed
+648 -536

No files matched your search

@@ -37,6 +37,8 @@ import java.util.Map;
import java.util.function.Function;
public interface BotaniaAPI {
String MODID = "botania";
LazyValue<BotaniaAPI> INSTANCE = new LazyValue<>(() -> {
try {
return (BotaniaAPI) Class.forName("vazkii.botania.common.impl.BotaniaAPIImpl").newInstance();
@@ -0,0 +1,45 @@
package vazkii.botania.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.brew.Brew;
import javax.annotation.Nonnull;
public interface IBrewRecipe extends IRecipe<RecipeWrapper> {
ResourceLocation TYPE_ID = new ResourceLocation(BotaniaAPI.MODID, "brew");
Brew getBrew();
int getManaUsage();
ItemStack getOutput(ItemStack container);
@Nonnull
@Override
default IRecipeType<?> getType() {
return Registry.RECIPE_TYPE.getValue(TYPE_ID).get();
}
@Nonnull
@Override
default ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
@Nonnull
@Override
default ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return ItemStack.EMPTY;
}
@Override
default boolean canFit(int width, int height) {
return false;
}
}
@@ -6,7 +6,7 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.common.crafting;
package vazkii.botania.api.recipe;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -16,21 +16,18 @@ import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.api.BotaniaAPI;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Optional;
public abstract class AbstractElvenTradeRecipe implements IRecipe<IInventory> {
private final ResourceLocation id;
protected AbstractElvenTradeRecipe(ResourceLocation id) {
this.id = id;
}
public interface IElvenTradeRecipe extends IRecipe<IInventory> {
ResourceLocation TYPE_ID = new ResourceLocation(BotaniaAPI.MODID, "elven_trade");
/**
* Attempts to match the recipe
@@ -39,65 +36,56 @@ public abstract class AbstractElvenTradeRecipe implements IRecipe<IInventory> {
* @return {@link Optional#empty()} if recipe doesn't match, Optional with a set of items used by recipe
* otherwise
*/
public abstract Optional<List<ItemStack>> match(List<ItemStack> stacks);
Optional<List<ItemStack>> match(List<ItemStack> stacks);
/**
* If the recipe does not contain the item, it will be destroyed upon entering the portal.
*/
public abstract boolean containsItem(ItemStack stack);
boolean containsItem(ItemStack stack);
/**
* @return Preview of the inputs
*/
@Nonnull
@Override
public abstract NonNullList<Ingredient> getIngredients();
NonNullList<Ingredient> getIngredients();
/**
* @return Preview of the outputs
*/
public abstract List<ItemStack> getOutputs();
List<ItemStack> getOutputs();
/**
* Actually evaluate the recipe
*/
public abstract List<ItemStack> getOutputs(List<ItemStack> inputs);
List<ItemStack> getOutputs(List<ItemStack> inputs);
@Nonnull
@Override
public ItemStack getIcon() {
return new ItemStack(ModBlocks.alfPortal);
}
@Override
public final ResourceLocation getId() {
return id;
}
@Override
public final IRecipeType<?> getType() {
return ModRecipeTypes.ELVEN_TRADE_TYPE;
default IRecipeType<?> getType() {
return Registry.RECIPE_TYPE.getValue(TYPE_ID).get();
}
// Ignored IRecipe boilerplate
@Override
public boolean matches(IInventory inv, World world) {
default boolean matches(@Nonnull IInventory inv, @Nonnull World world) {
return false;
}
@Nonnull
@Override
public ItemStack getCraftingResult(IInventory inv) {
default ItemStack getCraftingResult(@Nonnull IInventory inv) {
return ItemStack.EMPTY;
}
@Override
public boolean canFit(int width, int height) {
default boolean canFit(int width, int height) {
return false;
}
@Override
public ItemStack getRecipeOutput() {
default ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
}
@@ -0,0 +1,49 @@
package vazkii.botania.api.recipe;
import net.minecraft.block.BlockState;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public interface IManaInfusionRecipe extends IRecipe<IInventory> {
ResourceLocation TYPE_ID = new ResourceLocation(BotaniaAPI.MODID, "mana_infusion");
boolean matches(ItemStack stack);
@Nullable
BlockState getCatalyst();
int getManaToConsume();
@Nonnull
@Override
default IRecipeType<?> getType() {
return Registry.RECIPE_TYPE.getValue(TYPE_ID).get();
}
// Ignored IRecipe stuff
@Nonnull
@Override
default ItemStack getCraftingResult(@Nonnull IInventory inv) {
return ItemStack.EMPTY;
}
@Override
default boolean matches(@Nonnull IInventory inv, @Nonnull World world) {
return false;
}
@Override
default boolean canFit(int width, int height) {
return false;
}
}
@@ -0,0 +1,25 @@
package vazkii.botania.api.recipe;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import vazkii.botania.api.BotaniaAPI;
import javax.annotation.Nonnull;
public interface IPetalRecipe extends IRecipe<RecipeWrapper> {
ResourceLocation TYPE_ID = new ResourceLocation(BotaniaAPI.MODID, "petal_apothecary");
@Nonnull
@Override
default IRecipeType<?> getType() {
return Registry.RECIPE_TYPE.getValue(TYPE_ID).get();
}
@Override
default boolean canFit(int width, int height) {
return false;
}
}
@@ -0,0 +1,60 @@
package vazkii.botania.api.recipe;
import net.minecraft.block.BlockState;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
public interface IPureDaisyRecipe extends IRecipe<IInventory> {
static ResourceLocation TYPE_ID = new ResourceLocation(BotaniaAPI.MODID, "pure_daisy");
/**
* This gets called every tick, please be careful with your checks.
*/
boolean matches(World world, BlockPos pos, TileEntitySpecialFlower pureDaisy, BlockState state);
/**
* Returns true if the block was placed (and if the Pure Daisy should do particles and stuffs).
* Should only place the block if !world.isRemote, but should return true if it would've placed
* it otherwise. You may return false to cancel the normal particles and do your own.
*/
boolean set(World world, BlockPos pos, TileEntitySpecialFlower pureDaisy);
StateIngredient getInput();
BlockState getOutputState();
int getTime();
@Override
default IRecipeType<?> getType() {
return Registry.RECIPE_TYPE.getValue(TYPE_ID).get();
}
@Override
default boolean matches(IInventory p_77569_1_, World p_77569_2_) {
return false;
}
@Override
default ItemStack getCraftingResult(IInventory p_77572_1_) {
return ItemStack.EMPTY;
}
@Override
default boolean canFit(int p_194133_1_, int p_194133_2_) {
return false;
}
@Override
default ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
}
@@ -0,0 +1,27 @@
package vazkii.botania.api.recipe;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import vazkii.botania.api.BotaniaAPI;
import javax.annotation.Nonnull;
public interface IRuneAltarRecipe extends IRecipe<RecipeWrapper> {
ResourceLocation TYPE_ID = new ResourceLocation(BotaniaAPI.MODID, "runic_altar");
int getManaUsage();
@Nonnull
@Override
default IRecipeType<?> getType() {
return Registry.RECIPE_TYPE.getValue(TYPE_ID).get();
}
@Override
default boolean canFit(int width, int height) {
return false;
}
}
@@ -9,205 +9,19 @@
package vazkii.botania.api.recipe;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.JsonOps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.NBTDynamicOps;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.Tag;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public abstract class StateIngredient implements Predicate<BlockState> {
public interface StateIngredient extends Predicate<BlockState> {
public static StateIngredient of(Block block) {
return new OfBlock(block);
}
JsonObject serialize();
public static StateIngredient of(BlockState state) {
return new OfState(state);
}
void write(PacketBuffer buffer);
public static StateIngredient of(Tag<Block> tag) {
return new OfTag(tag);
}
List<BlockState> getDisplayed();
public static StateIngredient of(ResourceLocation id) {
return new OfTag(id);
}
public static StateIngredient deserialize(JsonObject object) {
switch (JSONUtils.getString(object, "type")) {
case "tag":
return new OfTag(new BlockTags.Wrapper(new ResourceLocation(JSONUtils.getString(object, "tag"))));
case "block":
return new OfBlock(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(JSONUtils.getString(object, "block"))));
case "state":
return new OfState(readBlockState(object));
default:
throw new JsonParseException("Unknown type!");
}
}
public static StateIngredient read(PacketBuffer buffer) {
switch (buffer.readVarInt()) {
case 0:
return new OfTag(buffer.readResourceLocation());
case 1:
return new OfBlock(buffer.readRegistryIdUnsafe(ForgeRegistries.BLOCKS));
case 2:
return new OfState(Block.getStateById(buffer.readVarInt()));
default:
throw new IllegalArgumentException("Unknown input discriminator!");
}
}
/**
* Writes data about the block state to the provided json object.
*/
public static JsonObject serializeBlockState(BlockState state) {
CompoundNBT nbt = NBTUtil.writeBlockState(state);
ItemNBTHelper.renameTag(nbt, "Name", "name");
ItemNBTHelper.renameTag(nbt, "Properties", "properties");
Dynamic<INBT> dyn = new Dynamic<>(NBTDynamicOps.INSTANCE, nbt);
return dyn.convert(JsonOps.INSTANCE).getValue().getAsJsonObject();
}
/**
* Reads the block state from the provided json object.
*/
public static BlockState readBlockState(JsonObject object) {
CompoundNBT nbt = (CompoundNBT) new Dynamic<>(JsonOps.INSTANCE, object).convert(NBTDynamicOps.INSTANCE).getValue();
ItemNBTHelper.renameTag(nbt, "name", "Name");
ItemNBTHelper.renameTag(nbt, "properties", "Properties");
String name = nbt.getString("Name");
ResourceLocation id = ResourceLocation.tryCreate(name);
if (id == null || !ForgeRegistries.BLOCKS.containsKey(id)) {
throw new IllegalArgumentException("Invalid or unknown block ID: " + name);
}
return NBTUtil.readBlockState(nbt);
}
public abstract JsonObject serialize();
public abstract void write(PacketBuffer buffer);
public abstract List<BlockState> getDisplayed();
private static class OfBlock extends StateIngredient {
private final net.minecraft.block.Block block;
private OfBlock(net.minecraft.block.Block block) {
this.block = block;
}
@Override
public boolean test(BlockState blockState) {
return block == blockState.getBlock();
}
@Override
public JsonObject serialize() {
JsonObject object = new JsonObject();
object.addProperty("type", "block");
object.addProperty("block", block.getRegistryName().toString());
return object;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeVarInt(1);
buffer.writeRegistryIdUnsafe(ForgeRegistries.BLOCKS, block);
}
@Override
public List<BlockState> getDisplayed() {
return Collections.singletonList(block.getDefaultState());
}
}
private static class OfState extends StateIngredient {
private final BlockState state;
private OfState(BlockState state) {
this.state = state;
}
@Override
public boolean test(BlockState blockState) {
return false;
}
@Override
public JsonObject serialize() {
JsonObject object = serializeBlockState(state);
object.addProperty("type", "state");
return object;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeVarInt(2);
buffer.writeVarInt(Block.getStateId(state));
}
@Override
public List<BlockState> getDisplayed() {
return Collections.singletonList(state);
}
}
private static class OfTag extends StateIngredient {
private final Tag<Block> tag;
public OfTag(Tag<Block> tag) {
this.tag = tag;
}
public OfTag(ResourceLocation id) {
this(new BlockTags.Wrapper(id));
}
@Override
public boolean test(BlockState state) {
return tag.contains(state.getBlock());
}
@Override
public JsonObject serialize() {
JsonObject object = new JsonObject();
object.addProperty("type", "tag");
object.addProperty("tag", tag.getId().toString());
return object;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeVarInt(0);
buffer.writeResourceLocation(tag.getId());
}
@Override
public List<BlockState> getDisplayed() {
return tag.getAllElements().stream().map(Block::getDefaultState).collect(Collectors.toList());
}
}
}
@@ -44,7 +44,7 @@ import vazkii.botania.api.mana.ICreativeManaProvider;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.api.recipe.IManaInfusionRecipe;
import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.lib.LibResources;
@@ -278,7 +278,7 @@ public final class HUDHandler {
IProfiler profiler = mc.getProfiler();
profiler.startSection("poolRecipe");
RecipeManaInfusion recipe = tile.getMatchingRecipe(stack, tile.getWorld().getBlockState(tile.getPos().down()));
IManaInfusionRecipe recipe = tile.getMatchingRecipe(stack, tile.getWorld().getBlockState(tile.getPos().down()));
if (recipe != null) {
int x = mc.getWindow().getScaledWidth() / 2 - 11;
int y = mc.getWindow().getScaledHeight() / 2 + 10;
@@ -55,7 +55,7 @@ import vazkii.botania.common.block.ModSubtiles;
import vazkii.botania.common.block.tile.TileAlfPortal;
import vazkii.botania.common.block.tile.mana.TilePool;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.crafting.AbstractElvenTradeRecipe;
import vazkii.botania.api.recipe.IElvenTradeRecipe;
import vazkii.botania.common.crafting.LexiconElvenTradeRecipe;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.crafting.recipe.AncientWillRecipe;
@@ -192,7 +192,7 @@ public class JEIBotaniaPlugin implements IModPlugin {
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
IRecipeManager recipeRegistry = jeiRuntime.getRecipeManager();
// Hide the return recipes (iron ingot/diamond/ender pearl returns, not lexicon)
for (AbstractElvenTradeRecipe recipe : TileAlfPortal.elvenTradeRecipes(Minecraft.getInstance().world.getRecipeManager())) {
for (IElvenTradeRecipe recipe : TileAlfPortal.elvenTradeRecipes(Minecraft.getInstance().world.getRecipeManager())) {
if (recipe instanceof LexiconElvenTradeRecipe) {
continue;
}
@@ -24,7 +24,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.api.recipe.IBrewRecipe;
import vazkii.botania.client.integration.jei.JEIBotaniaPlugin;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.item.ModItems;
@@ -36,7 +36,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class BreweryRecipeCategory implements IRecipeCategory<RecipeBrew> {
public class BreweryRecipeCategory implements IRecipeCategory<IBrewRecipe> {
public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "brewery");
private final IDrawableStatic background;
@@ -58,8 +58,8 @@ public class BreweryRecipeCategory implements IRecipeCategory<RecipeBrew> {
@Nonnull
@Override
public Class<? extends RecipeBrew> getRecipeClass() {
return RecipeBrew.class;
public Class<? extends IBrewRecipe> getRecipeClass() {
return IBrewRecipe.class;
}
@Nonnull
@@ -81,7 +81,7 @@ public class BreweryRecipeCategory implements IRecipeCategory<RecipeBrew> {
}
@Override
public void setIngredients(RecipeBrew recipe, IIngredients iIngredients) {
public void setIngredients(IBrewRecipe recipe, IIngredients iIngredients) {
ImmutableList.Builder<List<ItemStack>> inputBuilder = ImmutableList.builder();
ImmutableList.Builder<ItemStack> outputBuilder = ImmutableList.builder();
ImmutableList.Builder<ItemStack> containers = ImmutableList.builder();
@@ -106,7 +106,7 @@ public class BreweryRecipeCategory implements IRecipeCategory<RecipeBrew> {
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull RecipeBrew recipe, @Nonnull IIngredients ingredients) {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IBrewRecipe recipe, @Nonnull IIngredients ingredients) {
List<List<ItemStack>> inputs = ingredients.getInputs(VanillaTypes.ITEM);
List<List<ItemStack>> outputs = ingredients.getOutputs(VanillaTypes.ITEM);
@@ -35,7 +35,7 @@ import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.handler.MiscellaneousIcons;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.crafting.AbstractElvenTradeRecipe;
import vazkii.botania.api.recipe.IElvenTradeRecipe;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nonnull;
@@ -43,7 +43,7 @@ import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
public class ElvenTradeRecipeCategory implements IRecipeCategory<AbstractElvenTradeRecipe> {
public class ElvenTradeRecipeCategory implements IRecipeCategory<IElvenTradeRecipe> {
public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "elven_trade");
private final String localizedName;
@@ -66,8 +66,8 @@ public class ElvenTradeRecipeCategory implements IRecipeCategory<AbstractElvenTr
@Nonnull
@Override
public Class<? extends AbstractElvenTradeRecipe> getRecipeClass() {
return AbstractElvenTradeRecipe.class;
public Class<? extends IElvenTradeRecipe> getRecipeClass() {
return IElvenTradeRecipe.class;
}
@Nonnull
@@ -89,7 +89,7 @@ public class ElvenTradeRecipeCategory implements IRecipeCategory<AbstractElvenTr
}
@Override
public void setIngredients(AbstractElvenTradeRecipe recipe, IIngredients iIngredients) {
public void setIngredients(IElvenTradeRecipe recipe, IIngredients iIngredients) {
ImmutableList.Builder<List<ItemStack>> builder = ImmutableList.builder();
for (Ingredient i : recipe.getIngredients()) {
builder.add(Arrays.asList(i.getMatchingStacks()));
@@ -99,7 +99,7 @@ public class ElvenTradeRecipeCategory implements IRecipeCategory<AbstractElvenTr
}
@Override
public void draw(AbstractElvenTradeRecipe recipe, double mouseX, double mouseY) {
public void draw(IElvenTradeRecipe recipe, double mouseX, double mouseY) {
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend();
overlay.draw(0, 4);
@@ -123,7 +123,7 @@ public class ElvenTradeRecipeCategory implements IRecipeCategory<AbstractElvenTr
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull AbstractElvenTradeRecipe recipe, @Nonnull IIngredients ingredients) {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IElvenTradeRecipe recipe, @Nonnull IIngredients ingredients) {
int index = 0, posX = 42;
for (List<ItemStack> o : ingredients.getInputs(VanillaTypes.ITEM)) {
recipeLayout.getItemStacks().init(index, true, posX, 0);
@@ -24,7 +24,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.api.recipe.IManaInfusionRecipe;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.integration.jei.JEIBotaniaPlugin;
import vazkii.botania.common.block.ModBlocks;
@@ -37,7 +37,7 @@ import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
public class ManaPoolRecipeCategory implements IRecipeCategory<RecipeManaInfusion> {
public class ManaPoolRecipeCategory implements IRecipeCategory<IManaInfusionRecipe> {
public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "mana_pool");
private final IDrawable background;
@@ -63,8 +63,8 @@ public class ManaPoolRecipeCategory implements IRecipeCategory<RecipeManaInfusio
@Nonnull
@Override
public Class<? extends RecipeManaInfusion> getRecipeClass() {
return RecipeManaInfusion.class;
public Class<? extends IManaInfusionRecipe> getRecipeClass() {
return IManaInfusionRecipe.class;
}
@Nonnull
@@ -86,10 +86,10 @@ public class ManaPoolRecipeCategory implements IRecipeCategory<RecipeManaInfusio
}
@Override
public void setIngredients(RecipeManaInfusion recipe, IIngredients iIngredients) {
public void setIngredients(IManaInfusionRecipe recipe, IIngredients iIngredients) {
ImmutableList.Builder<List<ItemStack>> builder = ImmutableList.builder();
builder.add(Arrays.asList(recipe.getInput().getMatchingStacks()));
builder.add(Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks()));
if (recipe.getCatalyst() != null) {
Block block = recipe.getCatalyst().getBlock();
@@ -103,7 +103,7 @@ public class ManaPoolRecipeCategory implements IRecipeCategory<RecipeManaInfusio
}
@Override
public void draw(RecipeManaInfusion recipe, double mouseX, double mouseY) {
public void draw(IManaInfusionRecipe recipe, double mouseX, double mouseY) {
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend();
overlay.draw(48, 0);
@@ -113,7 +113,7 @@ public class ManaPoolRecipeCategory implements IRecipeCategory<RecipeManaInfusio
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull RecipeManaInfusion recipe, @Nonnull IIngredients ingredients) {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IManaInfusionRecipe recipe, @Nonnull IIngredients ingredients) {
int index = 0;
recipeLayout.getItemStacks().init(index, true, 40, 12);
@@ -23,7 +23,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.api.recipe.IPetalRecipe;
import vazkii.botania.client.integration.jei.JEIBotaniaPlugin;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.lib.LibMisc;
@@ -35,7 +35,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PetalApothecaryRecipeCategory implements IRecipeCategory<RecipePetals> {
public class PetalApothecaryRecipeCategory implements IRecipeCategory<IPetalRecipe> {
public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "petals");
private final IDrawableStatic background;
@@ -59,8 +59,8 @@ public class PetalApothecaryRecipeCategory implements IRecipeCategory<RecipePeta
@Nonnull
@Override
public Class<? extends RecipePetals> getRecipeClass() {
return RecipePetals.class;
public Class<? extends IPetalRecipe> getRecipeClass() {
return IPetalRecipe.class;
}
@Nonnull
@@ -82,7 +82,7 @@ public class PetalApothecaryRecipeCategory implements IRecipeCategory<RecipePeta
}
@Override
public void setIngredients(RecipePetals recipe, IIngredients iIngredients) {
public void setIngredients(IPetalRecipe recipe, IIngredients iIngredients) {
List<List<ItemStack>> list = new ArrayList<>();
for (Ingredient ingr : recipe.getIngredients()) {
list.add(Arrays.asList(ingr.getMatchingStacks()));
@@ -92,7 +92,7 @@ public class PetalApothecaryRecipeCategory implements IRecipeCategory<RecipePeta
}
@Override
public void draw(RecipePetals recipe, double mouseX, double mouseY) {
public void draw(IPetalRecipe recipe, double mouseX, double mouseY) {
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend();
overlay.draw();
@@ -101,7 +101,7 @@ public class PetalApothecaryRecipeCategory implements IRecipeCategory<RecipePeta
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull RecipePetals recipe, @Nonnull IIngredients ingredients) {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IPetalRecipe recipe, @Nonnull IIngredients ingredients) {
recipeLayout.getItemStacks().init(0, true, 64, 52);
recipeLayout.getItemStacks().set(0, new ItemStack(ModBlocks.defaultAltar));
@@ -27,11 +27,10 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tags.Tag;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import vazkii.botania.api.recipe.RecipePureDaisy;
import vazkii.botania.api.recipe.IPureDaisyRecipe;
import vazkii.botania.api.recipe.StateIngredient;
import vazkii.botania.client.integration.jei.JEIBotaniaPlugin;
import vazkii.botania.common.block.ModSubtiles;
@@ -43,7 +42,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy> {
public class PureDaisyRecipeCategory implements IRecipeCategory<IPureDaisyRecipe> {
public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "pure_daisy");
private final IDrawable background;
@@ -67,8 +66,8 @@ public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy>
@Nonnull
@Override
public Class<? extends RecipePureDaisy> getRecipeClass() {
return RecipePureDaisy.class;
public Class<? extends IPureDaisyRecipe> getRecipeClass() {
return IPureDaisyRecipe.class;
}
@Nonnull
@@ -90,7 +89,7 @@ public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy>
}
@Override
public void setIngredients(RecipePureDaisy recipe, IIngredients iIngredients) {
public void setIngredients(IPureDaisyRecipe recipe, IIngredients iIngredients) {
StateIngredient input = recipe.getInput();
if (input.getDisplayed().size() > 1) {
iIngredients.setInputLists(VanillaTypes.ITEM, Collections.singletonList(input.getDisplayed().stream()
@@ -122,7 +121,7 @@ public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy>
}
@Override
public void draw(RecipePureDaisy recipe, double mouseX, double mouseY) {
public void draw(IPureDaisyRecipe recipe, double mouseX, double mouseY) {
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend();
overlay.draw(48, 0);
@@ -131,7 +130,7 @@ public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy>
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull RecipePureDaisy recipe, @Nonnull IIngredients ingredients) {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IPureDaisyRecipe recipe, @Nonnull IIngredients ingredients) {
boolean inputFluid = !ingredients.getInputs(VanillaTypes.FLUID).isEmpty();
boolean outputFluid = !ingredients.getOutputs(VanillaTypes.FLUID).isEmpty();
@@ -22,7 +22,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.botania.api.recipe.IRuneAltarRecipe;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.integration.jei.JEIBotaniaPlugin;
import vazkii.botania.common.block.ModBlocks;
@@ -36,7 +36,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class RunicAltarRecipeCategory implements IRecipeCategory<RecipeRuneAltar> {
public class RunicAltarRecipeCategory implements IRecipeCategory<IRuneAltarRecipe> {
public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "runic_altar");
private final IDrawable background;
@@ -60,8 +60,8 @@ public class RunicAltarRecipeCategory implements IRecipeCategory<RecipeRuneAltar
@Nonnull
@Override
public Class<? extends RecipeRuneAltar> getRecipeClass() {
return RecipeRuneAltar.class;
public Class<? extends IRuneAltarRecipe> getRecipeClass() {
return IRuneAltarRecipe.class;
}
@Nonnull
@@ -83,7 +83,7 @@ public class RunicAltarRecipeCategory implements IRecipeCategory<RecipeRuneAltar
}
@Override
public void setIngredients(RecipeRuneAltar recipe, IIngredients iIngredients) {
public void setIngredients(IRuneAltarRecipe recipe, IIngredients iIngredients) {
List<List<ItemStack>> list = new ArrayList<>();
for (Ingredient ingr : recipe.getIngredients()) {
list.add(Arrays.asList(ingr.getMatchingStacks()));
@@ -93,7 +93,7 @@ public class RunicAltarRecipeCategory implements IRecipeCategory<RecipeRuneAltar
}
@Override
public void draw(RecipeRuneAltar recipe, double mouseX, double mouseY) {
public void draw(IRuneAltarRecipe recipe, double mouseX, double mouseY) {
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend();
overlay.draw();
@@ -103,7 +103,7 @@ public class RunicAltarRecipeCategory implements IRecipeCategory<RecipeRuneAltar
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull RecipeRuneAltar recipe, @Nonnull IIngredients ingredients) {
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRuneAltarRecipe recipe, @Nonnull IIngredients ingredients) {
recipeLayout.getItemStacks().init(0, true, 64, 52);
recipeLayout.getItemStacks().set(0, new ItemStack(ModBlocks.runeAltar));
@@ -14,8 +14,7 @@ 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.api.recipe.IBrewRecipe;
import vazkii.botania.common.Botania;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.item.ModItems;
@@ -24,14 +23,14 @@ import vazkii.patchouli.api.IVariableProvider;
import vazkii.patchouli.api.PatchouliAPI;
public class BrewRecipeProcessor implements IComponentProcessor {
private RecipeBrew recipe;
private IBrewRecipe recipe;
@Override
public void setup(IVariableProvider<String> variables) {
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;
if (recipe instanceof IBrewRecipe) {
this.recipe = (IBrewRecipe) recipe;
} else {
Botania.LOGGER.warn("Missing brew recipe " + id);
}
@@ -18,7 +18,7 @@ import net.minecraft.util.ResourceLocation;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.botania.common.Botania;
import vazkii.botania.common.crafting.AbstractElvenTradeRecipe;
import vazkii.botania.api.recipe.IElvenTradeRecipe;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
@@ -28,22 +28,22 @@ import java.util.List;
import java.util.stream.Collectors;
public class ElvenTradeProcessor implements IComponentProcessor {
private List<AbstractElvenTradeRecipe> recipes;
private List<IElvenTradeRecipe> recipes;
private int longestIngredientSize, mostInputs, mostOutputs;
@Override
public void setup(IVariableProvider<String> variables) {
ImmutableList.Builder<AbstractElvenTradeRecipe> builder = ImmutableList.builder();
ImmutableList.Builder<IElvenTradeRecipe> builder = ImmutableList.builder();
for (String s : variables.get("recipes").split(";")) {
IRecipe<?> recipe = Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.ELVEN_TRADE_TYPE).get(new ResourceLocation(s));
if (recipe instanceof AbstractElvenTradeRecipe) {
builder.add((AbstractElvenTradeRecipe) recipe);
if (recipe instanceof IElvenTradeRecipe) {
builder.add((IElvenTradeRecipe) recipe);
} else {
Botania.LOGGER.warn("Missing elven trade recipe " + s);
}
}
recipes = builder.build();
for (AbstractElvenTradeRecipe recipe : recipes) {
for (IElvenTradeRecipe recipe : recipes) {
List<Ingredient> inputs = recipe.getIngredients();
for (Ingredient ingredient : inputs) {
int length = ingredient.getMatchingStacks().length;
@@ -78,7 +78,7 @@ public class ElvenTradeProcessor implements IComponentProcessor {
if (key.startsWith("output")) {
int index = Integer.parseInt(key.substring(6)) - 1;
if (index < mostOutputs) {
return recipes.stream().map(AbstractElvenTradeRecipe::getOutputs)
return recipes.stream().map(IElvenTradeRecipe::getOutputs)
.map(l -> index < l.size() ? l.get(index) : ItemStack.EMPTY)
.map(PatchouliAPI.instance::serializeItemStack).collect(Collectors.joining(","));
} else {
@@ -89,7 +89,7 @@ public class ElvenTradeProcessor implements IComponentProcessor {
}
private String interweaveIngredients(int inputIndex) {
List<Ingredient> recipes = this.recipes.stream().map(AbstractElvenTradeRecipe::getIngredients).map(ingredients -> {
List<Ingredient> recipes = this.recipes.stream().map(IElvenTradeRecipe::getIngredients).map(ingredients -> {
if (inputIndex < ingredients.size()) {
return ingredients.get(inputIndex);
} else {
@@ -17,8 +17,7 @@ import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.api.recipe.IManaInfusionRecipe;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.patchouli.PatchouliUtils;
import vazkii.botania.common.Botania;
@@ -32,7 +31,7 @@ import java.util.List;
import java.util.stream.Collectors;
public class ManaInfusionProcessor implements IComponentProcessor {
private List<RecipeManaInfusion> recipes;
private List<IManaInfusionRecipe> recipes;
private boolean hasCustomHeading;
@Override
@@ -41,7 +40,7 @@ public class ManaInfusionProcessor implements IComponentProcessor {
Botania.LOGGER.warn("Mana infusion template has both 'recipes' and 'group', ignoring 'recipes'");
}
ImmutableList.Builder<RecipeManaInfusion> builder = ImmutableList.builder();
ImmutableList.Builder<IManaInfusionRecipe> builder = ImmutableList.builder();
if (variables.has("group")) {
String group = variables.get("group");
TilePool.manaInfusionRecipes(Minecraft.getInstance().world.getRecipeManager()).stream()
@@ -50,8 +49,8 @@ public class ManaInfusionProcessor implements IComponentProcessor {
} else {
for (String s : variables.get("recipes").split(";")) {
IRecipe<?> recipe = Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.MANA_INFUSION_TYPE).get(new ResourceLocation(s));
if (recipe instanceof RecipeManaInfusion) {
builder.add((RecipeManaInfusion) recipe);
if (recipe instanceof IManaInfusionRecipe) {
builder.add((IManaInfusionRecipe) recipe);
} else {
Botania.LOGGER.warn("Mana infusion template references nonexistent recipe {}", s);
}
@@ -74,11 +73,11 @@ public class ManaInfusionProcessor implements IComponentProcessor {
}
return null;
case "input":
return PatchouliUtils.interweaveIngredients(recipes.stream().map(RecipeManaInfusion::getInput).collect(Collectors.toList()));
return PatchouliUtils.interweaveIngredients(recipes.stream().map(r -> r.getIngredients().get(0)).collect(Collectors.toList()));
case "output":
return recipes.stream().map(RecipeManaInfusion::getRecipeOutput).map(PatchouliAPI.instance::serializeItemStack).collect(Collectors.joining(","));
return recipes.stream().map(IManaInfusionRecipe::getRecipeOutput).map(PatchouliAPI.instance::serializeItemStack).collect(Collectors.joining(","));
case "catalyst":
return recipes.stream().map(RecipeManaInfusion::getCatalyst)
return recipes.stream().map(IManaInfusionRecipe::getCatalyst)
.map(state -> {
if (state == null) {
return ItemStack.EMPTY;
@@ -88,7 +87,7 @@ public class ManaInfusionProcessor implements IComponentProcessor {
.map(PatchouliAPI.instance::serializeItemStack)
.collect(Collectors.joining(","));
case "mana":
return recipes.stream().mapToInt(RecipeManaInfusion::getManaToConsume).mapToObj(Integer::toString).collect(Collectors.joining(";"));
return recipes.stream().mapToInt(IManaInfusionRecipe::getManaToConsume).mapToObj(Integer::toString).collect(Collectors.joining(";"));
case "drop":
return I18n.format("botaniamisc.drop") + TextFormatting.BOLD + " (?)";
case "dropTip0":
@@ -11,8 +11,7 @@ package vazkii.botania.client.patchouli.processor;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.botania.api.recipe.IRuneAltarRecipe;
import vazkii.botania.common.Botania;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.patchouli.api.IVariableProvider;
@@ -30,7 +29,7 @@ public class RunicAltarProcessor extends PetalApothecaryProcessor {
@Override
public String process(String key) {
if (key.equals("mana")) {
return String.valueOf(((RecipeRuneAltar) recipe).getManaUsage());
return String.valueOf(((IRuneAltarRecipe) recipe).getManaUsage());
}
return super.process(key);
}
@@ -17,8 +17,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.registries.ObjectHolder;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipePureDaisy;
import vazkii.botania.api.recipe.IPureDaisyRecipe;
import vazkii.botania.api.subtile.RadiusDescriptor;
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
import vazkii.botania.client.fx.SparkleParticleData;
@@ -27,6 +26,7 @@ import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nullable;
import java.util.Arrays;
public class SubTilePureDaisy extends TileEntitySpecialFlower {
@@ -83,7 +83,7 @@ public class SubTilePureDaisy extends TileEntitySpecialFlower {
World world = getWorld();
if (!world.isAirBlock(coords)) {
world.getProfiler().startSection("findRecipe");
RecipePureDaisy recipe = findRecipe(coords);
IPureDaisyRecipe recipe = findRecipe(coords);
world.getProfiler().endSection();
if (recipe != null) {
@@ -117,12 +117,13 @@ public class SubTilePureDaisy extends TileEntitySpecialFlower {
}
}
private RecipePureDaisy findRecipe(BlockPos coords) {
@Nullable
private IPureDaisyRecipe findRecipe(BlockPos coords) {
BlockState state = getWorld().getBlockState(coords);
for (IRecipe<?> recipe : world.getRecipeManager().getRecipes(ModRecipeTypes.PURE_DAISY_TYPE).values()) {
if (recipe instanceof RecipePureDaisy && ((RecipePureDaisy) recipe).matches(getWorld(), coords, this, state)) {
return ((RecipePureDaisy) recipe);
if (recipe instanceof IPureDaisyRecipe && ((IPureDaisyRecipe) recipe).matches(getWorld(), coords, this, state)) {
return ((IPureDaisyRecipe) recipe);
}
}
@@ -38,7 +38,7 @@ import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.mana.BlockPool;
import vazkii.botania.common.block.tile.mana.TilePool;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.crafting.AbstractElvenTradeRecipe;
import vazkii.botania.api.recipe.IElvenTradeRecipe;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.item.ItemLexicon;
import vazkii.botania.common.lib.LibBlockNames;
@@ -174,7 +174,7 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
private boolean validateItemUsage(ItemEntity entity) {
ItemStack inputStack = entity.getItem();
for (IRecipe<?> recipe : world.getRecipeManager().getRecipes(ModRecipeTypes.ELVEN_TRADE_TYPE).values()) {
if (recipe instanceof AbstractElvenTradeRecipe && ((AbstractElvenTradeRecipe) recipe).containsItem(inputStack)) {
if (recipe instanceof IElvenTradeRecipe && ((IElvenTradeRecipe) recipe).containsItem(inputStack)) {
return true;
}
}
@@ -268,7 +268,7 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
}
}
public static Collection<AbstractElvenTradeRecipe> elvenTradeRecipes(RecipeManager rm) {
public static Collection<IElvenTradeRecipe> elvenTradeRecipes(RecipeManager rm) {
// By virtue of IRecipeType's type parameter,
// we know all the recipes in the map must be AbstractElvenTradeRecipe.
// However, vanilla's signature on this method is dumb (should be Map<ResourceLocation, T>)
@@ -278,10 +278,10 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
private void resolveRecipes() {
List<BlockPos> pylons = locatePylons();
for (IRecipe<?> r : world.getRecipeManager().getRecipes(ModRecipeTypes.ELVEN_TRADE_TYPE).values()) {
if (!(r instanceof AbstractElvenTradeRecipe)) {
if (!(r instanceof IElvenTradeRecipe)) {
continue;
}
AbstractElvenTradeRecipe recipe = (AbstractElvenTradeRecipe) r;
IElvenTradeRecipe recipe = (IElvenTradeRecipe) r;
Optional<List<ItemStack>> match = recipe.match(stacksIn);
if (match.isPresent()) {
if (consumeMana(pylons, 500, false)) {
@@ -43,11 +43,10 @@ import net.minecraftforge.items.wrapper.RecipeWrapper;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.item.IPetalApothecary;
import vazkii.botania.api.recipe.ICustomApothecaryColor;
import vazkii.botania.api.recipe.RecipePetals;
import vazkii.botania.api.recipe.IPetalRecipe;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.fx.SparkleParticleData;
@@ -148,7 +147,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
if (SEED_PATTERN.matcher(stack.getTranslationKey()).find()) {
RecipeWrapper inv = getRecipeWrapper();
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
Optional<IPetalRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
maybeRecipe.ifPresent(recipe -> {
saveLastRecipe();
@@ -390,7 +389,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
float anglePer = 360F / amt;
RecipeWrapper inv = getRecipeWrapper();
Optional<RecipePetals> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
Optional<IPetalRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.PETAL_TYPE, inv, world);
maybeRecipe.ifPresent(recipe -> {
RenderSystem.color4f(1F, 1F, 1F, 1F);
mc.textureManager.bindTexture(HUDHandler.manaBar);
@@ -26,7 +26,7 @@ import vazkii.botania.api.brew.IBrewContainer;
import vazkii.botania.api.brew.IBrewItem;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.mana.IManaReceiver;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.api.recipe.IBrewRecipe;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.fx.SparkleParticleData;
import vazkii.botania.client.fx.WispParticleData;
@@ -49,7 +49,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
private static final String TAG_MANA = "mana";
private static final int CRAFT_EFFECT_EVENT = 0;
public RecipeBrew recipe;
public IBrewRecipe recipe;
private int mana = 0;
private int manaLastTick = 0;
public int signal = 0;
@@ -92,7 +92,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver, I
}
private void findRecipe() {
Optional<RecipeBrew> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, getRecipeWrapper(), world);
Optional<IBrewRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.BREW_TYPE, getRecipeWrapper(), world);
maybeRecipe.ifPresent(recipeBrew -> {
this.recipe = recipeBrew;
world.setBlockState(pos, ModBlocks.brewery.getDefaultState().with(BlockStateProperties.POWERED, true));
@@ -30,7 +30,7 @@ import org.lwjgl.opengl.GL11;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.mana.IManaReceiver;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.botania.api.recipe.IRuneAltarRecipe;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.fx.SparkleParticleData;
@@ -60,7 +60,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
private static final int SET_COOLDOWN_EVENT = 1;
private static final int CRAFT_EFFECT_EVENT = 2;
private RecipeRuneAltar currentRecipe;
private IRuneAltarRecipe currentRecipe;
public int manaToGet = 0;
private int mana = 0;
@@ -208,7 +208,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
if (currentRecipe != null) {
this.manaToGet = currentRecipe.getManaUsage();
} else {
Optional<RecipeRuneAltar> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
Optional<IRuneAltarRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
if (maybeRecipe.isPresent()) {
this.manaToGet = maybeRecipe.get().getManaUsage();
break getMana;
@@ -248,12 +248,12 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver,
return;
}
RecipeRuneAltar recipe = null;
IRuneAltarRecipe recipe = null;
if (currentRecipe != null) {
recipe = currentRecipe;
} else {
Optional<RecipeRuneAltar> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
Optional<IRuneAltarRecipe> maybeRecipe = world.getRecipeManager().getRecipe(ModRecipeTypes.RUNE_TYPE, getRecipeWrapper(), world);
if (maybeRecipe.isPresent()) {
recipe = maybeRecipe.get();
}
@@ -42,7 +42,7 @@ import vazkii.botania.api.mana.IThrottledPacket;
import vazkii.botania.api.mana.ManaNetworkEvent;
import vazkii.botania.api.mana.spark.ISparkAttachable;
import vazkii.botania.api.mana.spark.ISparkEntity;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.api.recipe.IManaInfusionRecipe;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.fx.SparkleParticleData;
@@ -146,18 +146,18 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt
return val;
}
public static List<RecipeManaInfusion> manaInfusionRecipes(RecipeManager rm) {
public static List<IManaInfusionRecipe> manaInfusionRecipes(RecipeManager rm) {
return rm.getRecipes(ModRecipeTypes.MANA_INFUSION_TYPE).values().stream()
.filter(r -> r instanceof RecipeManaInfusion)
.map(r -> (RecipeManaInfusion) r)
.filter(r -> r instanceof IManaInfusionRecipe)
.map(r -> (IManaInfusionRecipe) r)
.collect(Collectors.toList());
}
public RecipeManaInfusion getMatchingRecipe(@Nonnull ItemStack stack, @Nonnull BlockState state) {
List<RecipeManaInfusion> matchingNonCatRecipes = new ArrayList<>();
List<RecipeManaInfusion> matchingCatRecipes = new ArrayList<>();
public IManaInfusionRecipe getMatchingRecipe(@Nonnull ItemStack stack, @Nonnull BlockState state) {
List<IManaInfusionRecipe> matchingNonCatRecipes = new ArrayList<>();
List<IManaInfusionRecipe> matchingCatRecipes = new ArrayList<>();
for (RecipeManaInfusion recipe : manaInfusionRecipes(world.getRecipeManager())) {
for (IManaInfusionRecipe recipe : manaInfusionRecipes(world.getRecipeManager())) {
if (recipe.matches(stack)) {
if (recipe.getCatalyst() == null) {
matchingNonCatRecipes.add(recipe);
@@ -186,7 +186,7 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt
return false;
}
RecipeManaInfusion recipe = getMatchingRecipe(stack, world.getBlockState(pos.down()));
IManaInfusionRecipe recipe = getMatchingRecipe(stack, world.getBlockState(pos.down()));
if (recipe != null) {
int mana = recipe.getManaToConsume();
@@ -14,6 +14,8 @@ import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.recipe.IElvenTradeRecipe;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.item.ItemLexicon;
import vazkii.botania.common.item.ModItems;
@@ -25,9 +27,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class LexiconElvenTradeRecipe extends AbstractElvenTradeRecipe {
public class LexiconElvenTradeRecipe implements IElvenTradeRecipe {
private final ResourceLocation id;
LexiconElvenTradeRecipe(ResourceLocation id) {
super(id);
this.id = id;
}
@Override
@@ -41,6 +45,18 @@ public class LexiconElvenTradeRecipe extends AbstractElvenTradeRecipe {
return NonNullList.withSize(1, Ingredient.fromItems(ModItems.lexicon));
}
@Nonnull
@Override
public ItemStack getIcon() {
return new ItemStack(ModBlocks.alfPortal);
}
@Nonnull
@Override
public ResourceLocation getId() {
return id;
}
@Override
public List<ItemStack> getOutputs() {
ItemStack stack = new ItemStack(ModItems.lexicon);
@@ -63,6 +79,7 @@ public class LexiconElvenTradeRecipe extends AbstractElvenTradeRecipe {
return Collections.singletonList(stack);
}
@Nonnull
@Override
public IRecipeSerializer<LexiconElvenTradeRecipe> getSerializer() {
return ModRecipeTypes.LEXICON_ELVEN_TRADE_SERIALIZER;
@@ -26,23 +26,23 @@ import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModRecipeTypes {
public static final IRecipeType<RecipeManaInfusion> MANA_INFUSION_TYPE = new RecipeType<>();
public static final IRecipeType<IManaInfusionRecipe> MANA_INFUSION_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipeManaInfusion> MANA_INFUSION_SERIALIZER = new RecipeManaInfusion.Serializer();
public static final IRecipeType<AbstractElvenTradeRecipe> ELVEN_TRADE_TYPE = new RecipeType<>();
public static final IRecipeType<IElvenTradeRecipe> ELVEN_TRADE_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipeElvenTrade> ELVEN_TRADE_SERIALIZER = new RecipeElvenTrade.Serializer();
public static final SpecialRecipeSerializer<LexiconElvenTradeRecipe> LEXICON_ELVEN_TRADE_SERIALIZER = new SpecialRecipeSerializer<>(LexiconElvenTradeRecipe::new);
public static final IRecipeType<RecipePureDaisy> PURE_DAISY_TYPE = new RecipeType<>();
public static final IRecipeType<IPureDaisyRecipe> 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 IRecipeType<IBrewRecipe> BREW_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipeBrew> BREW_SERIALIZER = new RecipeBrew.Serializer();
public static final IRecipeType<RecipePetals> PETAL_TYPE = new RecipeType<>();
public static final IRecipeType<IPetalRecipe> PETAL_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipePetals> PETAL_SERIALIZER = new RecipePetals.Serializer();
public static final IRecipeType<RecipeRuneAltar> RUNE_TYPE = new RecipeType<>();
public static final IRecipeType<IRuneAltarRecipe> RUNE_TYPE = new RecipeType<>();
public static final IRecipeSerializer<RecipeRuneAltar> RUNE_SERIALIZER = new RecipeRuneAltar.Serializer();
public static final IRecipeSerializer<HeadRecipe> RUNE_HEAD_SERIALIZER = new HeadRecipe.Serializer();
@@ -6,9 +6,8 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.recipe;
package vazkii.botania.common.crafting;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -16,33 +15,29 @@ 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.api.recipe.IBrewRecipe;
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 implements IRecipe<RecipeWrapper> {
public class RecipeBrew implements IBrewRecipe {
private final ResourceLocation id;
private final Brew brew;
private final NonNullList<Ingredient> inputs;
@@ -111,26 +106,17 @@ public class RecipeBrew implements IRecipe<RecipeWrapper> {
return ModRecipeTypes.BREW_SERIALIZER;
}
@Nonnull
@Override
public IRecipeType<?> getType() {
return ModRecipeTypes.BREW_TYPE;
}
@Nonnull
@Override
public ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
public Brew getBrew() {
return brew;
}
@Override
public int getManaUsage() {
return brew.getManaCost();
}
@Override
public ItemStack getOutput(ItemStack stack) {
if (stack.isEmpty() || !(stack.getItem() instanceof IBrewContainer)) {
return new ItemStack(Items.GLASS_BOTTLE); // Fallback...
@@ -152,18 +138,6 @@ public class RecipeBrew implements IRecipe<RecipeWrapper> {
&& inputs.equals(((RecipeBrew) o).inputs);
}
// Ignored IRecipe methods
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull RecipeWrapper inv) {
return ItemStack.EMPTY;
}
@Override
public boolean canFit(int width, int height) {
return false;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeBrew> {
@Nonnull
@Override
@@ -6,48 +6,39 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.recipe;
package vazkii.botania.common.crafting;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.inventory.IInventory;
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.registries.ForgeRegistryEntry;
import vazkii.botania.common.crafting.AbstractElvenTradeRecipe;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.api.recipe.IElvenTradeRecipe;
import vazkii.botania.common.block.ModBlocks;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class RecipeElvenTrade extends AbstractElvenTradeRecipe {
public class RecipeElvenTrade implements IElvenTradeRecipe {
private final ResourceLocation id;
private final ImmutableList<ItemStack> outputs;
private final NonNullList<Ingredient> inputs;
public RecipeElvenTrade(ResourceLocation id, ItemStack output, Ingredient... inputs) {
this(id, new ItemStack[] { output }, inputs);
}
public RecipeElvenTrade(ResourceLocation id, ItemStack[] outputs, Ingredient... inputs) {
super(id);
this.id = id;
this.outputs = ImmutableList.copyOf(outputs);
this.inputs = NonNullList.create();
this.inputs.addAll(Arrays.asList(inputs));
@@ -109,6 +100,17 @@ public class RecipeElvenTrade extends AbstractElvenTradeRecipe {
return inputs;
}
@Nonnull
@Override public ItemStack getIcon() {
return new ItemStack(ModBlocks.alfPortal);
}
@Nonnull
@Override
public ResourceLocation getId() {
return id;
}
@Override
public List<ItemStack> getOutputs() {
return outputs;
@@ -6,62 +6,50 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.recipe;
package vazkii.botania.common.crafting;
import com.google.common.base.Preconditions;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.command.arguments.BlockStateParser;
import net.minecraft.inventory.IInventory;
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.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry;
import net.minecraftforge.registries.ObjectHolder;
import vazkii.botania.common.Botania;
import vazkii.botania.api.recipe.IManaInfusionRecipe;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.crafting.ModRecipeTypes;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
public class RecipeManaInfusion implements IRecipe<IInventory> {
@ObjectHolder("botania:alchemy_catalyst") public static Block alchemy;
@ObjectHolder("botania:conjuration_catalyst") public static Block conjuration;
public class RecipeManaInfusion implements IManaInfusionRecipe {
private final ResourceLocation id;
private final ItemStack output;
private final Ingredient input;
private final int mana;
@Nullable private BlockState catalystState;
@Nullable private final BlockState catalystState;
private final String group;
public RecipeManaInfusion(ResourceLocation id, ItemStack output, Ingredient input, int mana, @Nullable String group) {
public RecipeManaInfusion(ResourceLocation id, ItemStack output, Ingredient input, int mana,
@Nullable String group, @Nullable BlockState catalystState) {
this.id = id;
this.output = output;
this.input = input;
this.mana = mana;
Preconditions.checkArgument(mana < 100000);
this.group = group == null ? "" : group;
this.catalystState = catalystState;
}
@Nonnull
@@ -76,29 +64,18 @@ public class RecipeManaInfusion implements IRecipe<IInventory> {
return ModRecipeTypes.MANA_INFUSION_SERIALIZER;
}
@Nonnull
@Override
public IRecipeType<?> getType() {
return ModRecipeTypes.MANA_INFUSION_TYPE;
}
public boolean matches(ItemStack stack) {
return input.test(stack);
}
@Nullable
@Override
public BlockState getCatalyst() {
return catalystState;
}
public void setCatalyst(@Nullable BlockState catalyst) {
catalystState = catalyst;
}
public Ingredient getInput() {
return input;
}
@Override
public int getManaToConsume() {
return mana;
}
@@ -127,24 +104,6 @@ public class RecipeManaInfusion implements IRecipe<IInventory> {
return new ItemStack(ModBlocks.manaPool);
}
// Ignored IRecipe stuff
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull IInventory inv) {
return output;
}
@Override
public boolean matches(@Nonnull IInventory inv, @Nonnull World world) {
return false;
}
@Override
public boolean canFit(int width, int height) {
return false;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeManaInfusion> {
@Nonnull
@@ -168,12 +127,11 @@ public class RecipeManaInfusion implements IRecipe<IInventory> {
}
catalystState = ForgeRegistries.BLOCKS.getValue(catalystId).getDefaultState();
} else {
catalystState = StateIngredient.readBlockState(JSONUtils.getJsonObject(json, "catalyst"));
catalystState = StateIngredientHelper.readBlockState(JSONUtils.getJsonObject(json, "catalyst"));
}
}
RecipeManaInfusion ret = new RecipeManaInfusion(id, output, ing, mana, group);
ret.setCatalyst(catalystState);
RecipeManaInfusion ret = new RecipeManaInfusion(id, output, ing, mana, group, catalystState);
return ret;
}
@@ -185,14 +143,13 @@ public class RecipeManaInfusion implements IRecipe<IInventory> {
int mana = buf.readVarInt();
int catalystId = buf.readInt();
String group = buf.readString();
RecipeManaInfusion ret = new RecipeManaInfusion(id, output, input, mana, group);
ret.setCatalyst(catalystId == -1 ? null : Block.getStateById(catalystId));
return ret;
BlockState catalystState = catalystId == -1 ? null : Block.getStateById(catalystId);
return new RecipeManaInfusion(id, output, input, mana, group, catalystState);
}
@Override
public void write(@Nonnull PacketBuffer buf, @Nonnull RecipeManaInfusion recipe) {
recipe.getInput().write(buf);
recipe.getIngredients().get(0).write(buf);
buf.writeItemStack(recipe.getRecipeOutput(), false);
buf.writeVarInt(recipe.getManaToConsume());
buf.writeInt(recipe.getCatalyst() == null ? -1 : Block.getStateId(recipe.getCatalyst()));
@@ -6,16 +6,14 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.recipe;
package vazkii.botania.common.crafting;
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;
@@ -26,15 +24,15 @@ import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import net.minecraftforge.registries.ForgeRegistryEntry;
import vazkii.botania.api.recipe.IPetalRecipe;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.crafting.ModRecipeTypes;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
public class RecipePetals implements IRecipe<RecipeWrapper> {
public class RecipePetals implements IPetalRecipe {
private final ResourceLocation id;
private final ItemStack output;
private final NonNullList<Ingredient> inputs;
@@ -111,17 +109,6 @@ public class RecipePetals implements IRecipe<RecipeWrapper> {
return ModRecipeTypes.PETAL_SERIALIZER;
}
@Nonnull
@Override
public IRecipeType<?> getType() {
return ModRecipeTypes.PETAL_TYPE;
}
@Override
public boolean canFit(int width, int height) {
return false;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipePetals> {
@Nonnull
@Override
@@ -6,18 +6,14 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.recipe;
package vazkii.botania.common.crafting;
import com.google.common.base.Preconditions;
import com.google.gson.JsonObject;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.inventory.IInventory;
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.network.PacketBuffer;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
@@ -25,13 +21,14 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistryEntry;
import vazkii.botania.api.recipe.IPureDaisyRecipe;
import vazkii.botania.api.recipe.StateIngredient;
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
import vazkii.botania.common.crafting.ModRecipeTypes;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class RecipePureDaisy implements IRecipe<IInventory> {
public class RecipePureDaisy implements IPureDaisyRecipe {
public static final int DEFAULT_TIME = 150;
@@ -40,10 +37,6 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
private final BlockState outputState;
private final int time;
public RecipePureDaisy(ResourceLocation id, StateIngredient input, BlockState state) {
this(id, input, state, DEFAULT_TIME);
}
/**
* @param id The ID for this recipe.
* @param input The input for the recipe. Can be a Block, BlockState, or Tag&lt;Block&gt;.
@@ -60,18 +53,12 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
this.time = time;
}
/**
* This gets called every tick, please be careful with your checks.
*/
@Override
public boolean matches(World world, BlockPos pos, TileEntitySpecialFlower pureDaisy, BlockState state) {
return input.test(state);
}
/**
* Returns true if the block was placed (and if the Pure Daisy should do particles and stuffs).
* Should only place the block if !world.isRemote, but should return true if it would've placed
* it otherwise. You may return false to cancel the normal particles and do your own.
*/
@Override
public boolean set(World world, BlockPos pos, TileEntitySpecialFlower pureDaisy) {
if (!world.isRemote) {
world.setBlockState(pos, outputState);
@@ -79,14 +66,17 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
return true;
}
@Override
public StateIngredient getInput() {
return input;
}
@Override
public BlockState getOutputState() {
return outputState;
}
@Override
public int getTime() {
return time;
}
@@ -101,38 +91,12 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
return ModRecipeTypes.PURE_DAISY_SERIALIZER;
}
@Override
public IRecipeType<?> getType() {
return ModRecipeTypes.PURE_DAISY_TYPE;
}
// Ignored IRecipe overrides
@Override
public boolean matches(IInventory p_77569_1_, World p_77569_2_) {
return false;
}
@Override
public ItemStack getCraftingResult(IInventory p_77572_1_) {
return ItemStack.EMPTY;
}
@Override
public boolean canFit(int p_194133_1_, int p_194133_2_) {
return false;
}
@Override
public ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipePureDaisy> {
@Nonnull
@Override
public RecipePureDaisy read(@Nonnull ResourceLocation id, JsonObject object) {
StateIngredient input = StateIngredient.deserialize(JSONUtils.getJsonObject(object, "input"));
BlockState output = StateIngredient.readBlockState(JSONUtils.getJsonObject(object, "output"));
StateIngredient input = StateIngredientHelper.deserialize(JSONUtils.getJsonObject(object, "input"));
BlockState output = StateIngredientHelper.readBlockState(JSONUtils.getJsonObject(object, "output"));
int time = JSONUtils.getInt(object, "time", DEFAULT_TIME);
return new RecipePureDaisy(id, input, output, time);
}
@@ -147,7 +111,7 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
@Nullable
@Override
public RecipePureDaisy read(@Nonnull ResourceLocation id, @Nonnull PacketBuffer buf) {
StateIngredient input = StateIngredient.read(buf);
StateIngredient input = StateIngredientHelper.read(buf);
BlockState output = Block.getStateById(buf.readVarInt());
int time = buf.readVarInt();
return new RecipePureDaisy(id, input, output, time);
@@ -6,18 +6,15 @@
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.api.recipe;
package vazkii.botania.common.crafting;
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;
@@ -25,19 +22,18 @@ 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.api.recipe.IRuneAltarRecipe;
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 IRecipe<RecipeWrapper> {
public class RecipeRuneAltar implements IRuneAltarRecipe {
private final ResourceLocation id;
private final ItemStack output;
private final NonNullList<Ingredient> inputs;
@@ -118,21 +114,11 @@ public class RecipeRuneAltar implements IRecipe<RecipeWrapper> {
return ModRecipeTypes.RUNE_SERIALIZER;
}
@Nonnull
@Override
public IRecipeType<?> getType() {
return ModRecipeTypes.RUNE_TYPE;
}
public int getManaUsage() {
return mana;
}
@Override
public boolean canFit(int width, int height) {
return false;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeRuneAltar> {
@Nonnull
@Override
@@ -0,0 +1,43 @@
package vazkii.botania.common.crafting;
import com.google.gson.JsonObject;
import net.minecraft.block.BlockState;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.botania.api.recipe.StateIngredient;
import java.util.Collections;
import java.util.List;
public class StateIngredientBlock implements StateIngredient {
private final net.minecraft.block.Block block;
public StateIngredientBlock(net.minecraft.block.Block block) {
this.block = block;
}
@Override
public boolean test(BlockState blockState) {
return block == blockState.getBlock();
}
@Override
public JsonObject serialize() {
JsonObject object = new JsonObject();
object.addProperty("type", "block");
object.addProperty("block", block.getRegistryName().toString());
return object;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeVarInt(1);
buffer.writeRegistryIdUnsafe(ForgeRegistries.BLOCKS, block);
}
@Override
public List<BlockState> getDisplayed() {
return Collections.singletonList(block.getDefaultState());
}
}
@@ -0,0 +1,42 @@
package vazkii.botania.common.crafting;
import com.google.gson.JsonObject;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.network.PacketBuffer;
import vazkii.botania.api.recipe.StateIngredient;
import java.util.Collections;
import java.util.List;
public class StateIngredientBlockState implements StateIngredient {
private final BlockState state;
public StateIngredientBlockState(BlockState state) {
this.state = state;
}
@Override
public boolean test(BlockState blockState) {
return false;
}
@Override
public JsonObject serialize() {
JsonObject object = StateIngredientHelper.serializeBlockState(state);
object.addProperty("type", "state");
return object;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeVarInt(2);
buffer.writeVarInt(Block.getStateId(state));
}
@Override
public List<BlockState> getDisplayed() {
return Collections.singletonList(state);
}
}
@@ -0,0 +1,90 @@
package vazkii.botania.common.crafting;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.JsonOps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.NBTDynamicOps;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.Tag;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.botania.api.recipe.StateIngredient;
import vazkii.botania.common.core.helper.ItemNBTHelper;
public class StateIngredientHelper {
public static StateIngredient of(Block block) {
return new StateIngredientBlock(block);
}
public static StateIngredient of(BlockState state) {
return new StateIngredientBlockState(state);
}
public static StateIngredient of(Tag<Block> tag) {
return new StateIngredientTag(tag);
}
public static StateIngredient of(ResourceLocation id) {
return new StateIngredientTag(id);
}
public static StateIngredient deserialize(JsonObject object) {
switch (JSONUtils.getString(object, "type")) {
case "tag":
return new StateIngredientTag(new BlockTags.Wrapper(new ResourceLocation(JSONUtils.getString(object, "tag"))));
case "block":
return new StateIngredientBlock(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(JSONUtils.getString(object, "block"))));
case "state":
return new StateIngredientBlockState(readBlockState(object));
default:
throw new JsonParseException("Unknown type!");
}
}
public static StateIngredient read(PacketBuffer buffer) {
switch (buffer.readVarInt()) {
case 0:
return new StateIngredientTag(buffer.readResourceLocation());
case 1:
return new StateIngredientBlock(buffer.readRegistryIdUnsafe(ForgeRegistries.BLOCKS));
case 2:
return new StateIngredientBlockState(Block.getStateById(buffer.readVarInt()));
default:
throw new IllegalArgumentException("Unknown input discriminator!");
}
}
/**
* Writes data about the block state to the provided json object.
*/
public static JsonObject serializeBlockState(BlockState state) {
CompoundNBT nbt = NBTUtil.writeBlockState(state);
ItemNBTHelper.renameTag(nbt, "Name", "name");
ItemNBTHelper.renameTag(nbt, "Properties", "properties");
Dynamic<INBT> dyn = new Dynamic<>(NBTDynamicOps.INSTANCE, nbt);
return dyn.convert(JsonOps.INSTANCE).getValue().getAsJsonObject();
}
/**
* Reads the block state from the provided json object.
*/
public static BlockState readBlockState(JsonObject object) {
CompoundNBT nbt = (CompoundNBT) new Dynamic<>(JsonOps.INSTANCE, object).convert(NBTDynamicOps.INSTANCE).getValue();
ItemNBTHelper.renameTag(nbt, "name", "Name");
ItemNBTHelper.renameTag(nbt, "properties", "Properties");
String name = nbt.getString("Name");
ResourceLocation id = ResourceLocation.tryCreate(name);
if (id == null || !ForgeRegistries.BLOCKS.containsKey(id)) {
throw new IllegalArgumentException("Invalid or unknown block ID: " + name);
}
return NBTUtil.readBlockState(nbt);
}
}
@@ -0,0 +1,50 @@
package vazkii.botania.common.crafting;
import com.google.gson.JsonObject;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.Tag;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.api.recipe.StateIngredient;
import java.util.List;
import java.util.stream.Collectors;
public class StateIngredientTag implements StateIngredient {
private final Tag<Block> tag;
public StateIngredientTag(Tag<Block> tag) {
this.tag = tag;
}
public StateIngredientTag(ResourceLocation id) {
this(new BlockTags.Wrapper(id));
}
@Override
public boolean test(BlockState state) {
return tag.contains(state.getBlock());
}
@Override
public JsonObject serialize() {
JsonObject object = new JsonObject();
object.addProperty("type", "tag");
object.addProperty("tag", tag.getId().toString());
return object;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeVarInt(0);
buffer.writeResourceLocation(tag.getId());
}
@Override
public List<BlockState> getDisplayed() {
return tag.getAllElements().stream().map(Block::getDefaultState).collect(Collectors.toList());
}
}
@@ -22,16 +22,14 @@ 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.crafting.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;
@@ -27,7 +27,7 @@ import thaumcraft.api.aspects.AspectHelper;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.AspectRegistryEvent;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.common.crafting.RecipeBrew;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.ModFluffBlocks;
@@ -23,7 +23,6 @@ import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.CraftingHelper;
import vazkii.botania.api.recipe.RecipeElvenTrade;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.crafting.ModRecipeTypes;
@@ -27,20 +27,18 @@ import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.Tags;
import vazkii.botania.api.recipe.StateIngredient;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.ModFluffBlocks;
import vazkii.botania.common.block.ModSubtiles;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.crafting.StateIngredientHelper;
import vazkii.botania.common.item.ModItems;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
@@ -249,7 +247,7 @@ public class ManaInfusionProvider extends RecipeProvider {
json.addProperty("group", group);
}
if (catalyst != null) {
json.add("catalyst", StateIngredient.serializeBlockState(catalyst));
json.add("catalyst", StateIngredientHelper.serializeBlockState(catalyst));
}
}
@@ -23,6 +23,7 @@ import net.minecraftforge.common.Tags;
import vazkii.botania.api.recipe.StateIngredient;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.crafting.ModRecipeTypes;
import vazkii.botania.common.crafting.StateIngredientHelper;
import javax.annotation.Nullable;
@@ -38,15 +39,15 @@ public class PureDaisyProvider extends RecipeProvider {
@Override
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
consumer.accept(new FinishedRecipe(id("livingrock"), StateIngredient.of(Tags.Blocks.STONE), ModBlocks.livingrock.getDefaultState()));
consumer.accept(new FinishedRecipe(id("livingwood"), StateIngredient.of(BlockTags.LOGS), ModBlocks.livingwood.getDefaultState()));
consumer.accept(new FinishedRecipe(id("livingrock"), StateIngredientHelper.of(Tags.Blocks.STONE), ModBlocks.livingrock.getDefaultState()));
consumer.accept(new FinishedRecipe(id("livingwood"), StateIngredientHelper.of(BlockTags.LOGS), ModBlocks.livingwood.getDefaultState()));
consumer.accept(new FinishedRecipe(id("cobblestone"), StateIngredient.of(Tags.Blocks.NETHERRACK), Blocks.COBBLESTONE.getDefaultState()));
consumer.accept(new FinishedRecipe(id("sand"), StateIngredient.of(Blocks.SOUL_SAND), Blocks.SAND.getDefaultState()));
consumer.accept(new FinishedRecipe(id("packed_ice"), StateIngredient.of(Blocks.ICE), Blocks.PACKED_ICE.getDefaultState()));
consumer.accept(new FinishedRecipe(id("blue_ice"), StateIngredient.of(Blocks.PACKED_ICE), Blocks.BLUE_ICE.getDefaultState()));
consumer.accept(new FinishedRecipe(id("obsidian"), StateIngredient.of(ModBlocks.blazeBlock), Blocks.OBSIDIAN.getDefaultState()));
consumer.accept(new FinishedRecipe(id("snow_block"), StateIngredient.of(Blocks.WATER), Blocks.SNOW_BLOCK.getDefaultState()));
consumer.accept(new FinishedRecipe(id("cobblestone"), StateIngredientHelper.of(Tags.Blocks.NETHERRACK), Blocks.COBBLESTONE.getDefaultState()));
consumer.accept(new FinishedRecipe(id("sand"), StateIngredientHelper.of(Blocks.SOUL_SAND), Blocks.SAND.getDefaultState()));
consumer.accept(new FinishedRecipe(id("packed_ice"), StateIngredientHelper.of(Blocks.ICE), Blocks.PACKED_ICE.getDefaultState()));
consumer.accept(new FinishedRecipe(id("blue_ice"), StateIngredientHelper.of(Blocks.PACKED_ICE), Blocks.BLUE_ICE.getDefaultState()));
consumer.accept(new FinishedRecipe(id("obsidian"), StateIngredientHelper.of(ModBlocks.blazeBlock), Blocks.OBSIDIAN.getDefaultState()));
consumer.accept(new FinishedRecipe(id("snow_block"), StateIngredientHelper.of(Blocks.WATER), Blocks.SNOW_BLOCK.getDefaultState()));
}
@Override
@@ -81,7 +82,7 @@ public class PureDaisyProvider extends RecipeProvider {
@Override
public void serialize(JsonObject json) {
json.add("input", input.serialize());
json.add("output", StateIngredient.serializeBlockState(outputState));
json.add("output", StateIngredientHelper.serializeBlockState(outputState));
if (time != DEFAULT_TIME) {
json.addProperty("time", time);
}
@@ -23,10 +23,8 @@ 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;