mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Fermenting JEI Plugin baby...
This commit is contained in:
parent
4cfef87a60
commit
a8ba206b27
5 changed files with 191 additions and 6 deletions
|
@ -2,6 +2,7 @@ package de.ellpeck.actuallyadditions.mod.crafting;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.inventory.gui.FluidDisplay;
|
||||||
import net.minecraft.data.IFinishedRecipe;
|
import net.minecraft.data.IFinishedRecipe;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
|
@ -19,13 +20,17 @@ import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class FermentingRecipe implements IRecipe<IInventory> {
|
public class FermentingRecipe implements IRecipe<IInventory> {
|
||||||
public static final String NAME = "fermenting";
|
public static final String NAME = "fermenting";
|
||||||
private final ResourceLocation ID;
|
private final ResourceLocation ID;
|
||||||
private final FluidStack input;
|
private final FluidStack input;
|
||||||
private final FluidStack output;
|
private final FluidStack output;
|
||||||
private int time;
|
private final int time;
|
||||||
|
|
||||||
|
private Optional<FluidDisplay> inputDisplay;
|
||||||
|
private Optional<FluidDisplay> outputDisplay;
|
||||||
|
|
||||||
public FermentingRecipe(ResourceLocation ID, FluidStack input, FluidStack output, int timeIn) {
|
public FermentingRecipe(ResourceLocation ID, FluidStack input, FluidStack output, int timeIn) {
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
|
@ -42,6 +47,22 @@ public class FermentingRecipe implements IRecipe<IInventory> {
|
||||||
return input.isFluidEqual(this.input) && (output.isEmpty() || output.isFluidEqual(this.output) && input.getAmount() >= this.input.getAmount());
|
return input.isFluidEqual(this.input) && (output.isEmpty() || output.isFluidEqual(this.output) && input.getAmount() >= this.input.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<FluidDisplay> getInputDisplay() {
|
||||||
|
return inputDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInputDisplay(FluidDisplay inputDisplay) {
|
||||||
|
this.inputDisplay = Optional.of(inputDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<FluidDisplay> getOutputDisplay() {
|
||||||
|
return outputDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputDisplay(FluidDisplay outputDisplay) {
|
||||||
|
this.outputDisplay = Optional.of(outputDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
public int getTime() {
|
public int getTime() {
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,11 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidTank;
|
import net.minecraftforge.fluids.IFluidTank;
|
||||||
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
@ -43,6 +45,8 @@ public class FluidDisplay extends AbstractGui {
|
||||||
|
|
||||||
private boolean drawTextNextTo;
|
private boolean drawTextNextTo;
|
||||||
|
|
||||||
|
private boolean drawCapacityInTooltip = true;
|
||||||
|
|
||||||
public FluidDisplay(int x, int y, IFluidTank fluidReference, boolean outline, boolean drawTextNextTo) {
|
public FluidDisplay(int x, int y, IFluidTank fluidReference, boolean outline, boolean drawTextNextTo) {
|
||||||
this.setData(x, y, fluidReference, outline, drawTextNextTo);
|
this.setData(x, y, fluidReference, outline, drawTextNextTo);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +55,17 @@ public class FluidDisplay extends AbstractGui {
|
||||||
this(x, y, fluidReference, false, false);
|
this(x, y, fluidReference, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FluidDisplay(int x, int y, FluidStack stack, int capacity, boolean drawCapacity) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.drawCapacityInTooltip = drawCapacity;
|
||||||
|
this.fluidReference = new DummyTank(stack, capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDrawCapacityInTooltip(boolean drawCapacityInTooltip) {
|
||||||
|
this.drawCapacityInTooltip = drawCapacityInTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
public void setData(int x, int y, IFluidTank fluidReference, boolean outline, boolean drawTextNextTo) {
|
public void setData(int x, int y, IFluidTank fluidReference, boolean outline, boolean drawTextNextTo) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
@ -122,6 +137,54 @@ public class FluidDisplay extends AbstractGui {
|
||||||
String cap = format.format(this.fluidReference.getCapacity());
|
String cap = format.format(this.fluidReference.getCapacity());
|
||||||
return stack.isEmpty()
|
return stack.isEmpty()
|
||||||
? "0/" + cap + " mB"
|
? "0/" + cap + " mB"
|
||||||
: format.format(this.fluidReference.getFluidAmount()) + "/" + cap + " mB " + stack.getDisplayName().getString();
|
: format.format(this.fluidReference.getFluidAmount()) + (drawCapacityInTooltip?"/" + cap + " mB ":" mB ") + stack.getDisplayName().getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyTank implements IFluidTank {
|
||||||
|
private final FluidStack fluid;
|
||||||
|
private final int capacity;
|
||||||
|
|
||||||
|
public DummyTank(FluidStack fluid, int capacity) {
|
||||||
|
this.fluid = fluid;
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public FluidStack getFluid() {
|
||||||
|
return fluid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFluidAmount() {
|
||||||
|
return fluid.getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCapacity() {
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFluidValid(FluidStack stack) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int fill(FluidStack resource, IFluidHandler.FluidAction action) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) {
|
||||||
|
return FluidStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public FluidStack drain(FluidStack resource, IFluidHandler.FluidAction action) {
|
||||||
|
return FluidStack.EMPTY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package de.ellpeck.actuallyadditions.mod.jei;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.crafting.FermentingRecipe;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.inventory.gui.FluidDisplay;
|
||||||
|
import mezz.jei.api.constants.VanillaTypes;
|
||||||
|
import mezz.jei.api.gui.IRecipeLayout;
|
||||||
|
import mezz.jei.api.gui.drawable.IDrawable;
|
||||||
|
import mezz.jei.api.gui.drawable.IDrawableStatic;
|
||||||
|
import mezz.jei.api.helpers.IGuiHelper;
|
||||||
|
import mezz.jei.api.ingredients.IIngredients;
|
||||||
|
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fluids.FluidAttributes;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class FermentingCategory implements IRecipeCategory<FermentingRecipe> {
|
||||||
|
public static final ResourceLocation ID = new ResourceLocation(ActuallyAdditions.MODID, "fermenting_jei");
|
||||||
|
|
||||||
|
private final IDrawableStatic background;
|
||||||
|
|
||||||
|
public FermentingCategory(IGuiHelper guiHelper) {
|
||||||
|
background = guiHelper.drawableBuilder(new ResourceLocation(ActuallyAdditions.MODID, "textures/gui/gui_fermenting_barrel.png"), 41, 4, 94, 86).setTextureSize(256,256).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getUid() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends FermentingRecipe> getRecipeClass() {
|
||||||
|
return FermentingRecipe.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
return "Fermenting Recipe";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IDrawable getBackground() {
|
||||||
|
return background;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IDrawable getIcon() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIngredients(@Nonnull FermentingRecipe fermentingRecipe, @Nonnull IIngredients ingredients) {
|
||||||
|
ingredients.setInput(VanillaTypes.FLUID, fermentingRecipe.getInput());
|
||||||
|
ingredients.setOutput(VanillaTypes.FLUID, fermentingRecipe.getOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull FermentingRecipe fermentingRecipe, @Nonnull IIngredients ingredients) {
|
||||||
|
int maxFluid = Math.max(FluidAttributes.BUCKET_VOLUME, Math.max(fermentingRecipe.getInput().getAmount(), fermentingRecipe.getOutput().getAmount()));
|
||||||
|
|
||||||
|
fermentingRecipe.setInputDisplay(new FluidDisplay(19, 1, fermentingRecipe.getInput(), maxFluid, false));
|
||||||
|
fermentingRecipe.setOutputDisplay(new FluidDisplay(19+38, 1, fermentingRecipe.getOutput(), maxFluid, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(FermentingRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) {
|
||||||
|
IRecipeCategory.super.draw(recipe, matrixStack, mouseX, mouseY);
|
||||||
|
|
||||||
|
recipe.getInputDisplay().ifPresent(display -> {
|
||||||
|
display.draw(matrixStack);
|
||||||
|
display.render(matrixStack, (int) mouseX, (int) mouseY);
|
||||||
|
});
|
||||||
|
|
||||||
|
recipe.getOutputDisplay().ifPresent(display -> {
|
||||||
|
display.draw(matrixStack);
|
||||||
|
display.render(matrixStack, (int) mouseX, (int) mouseY);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//TODO draw the progress indicator, scaled to the recipe duration.
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,8 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.jei;
|
package de.ellpeck.actuallyadditions.mod.jei;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
||||||
import mezz.jei.api.IModPlugin;
|
import mezz.jei.api.IModPlugin;
|
||||||
import mezz.jei.api.JeiPlugin;
|
import mezz.jei.api.JeiPlugin;
|
||||||
|
@ -19,8 +21,10 @@ import mezz.jei.api.helpers.IJeiHelpers;
|
||||||
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
||||||
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
||||||
import mezz.jei.api.registration.IRecipeRegistration;
|
import mezz.jei.api.registration.IRecipeRegistration;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
@JeiPlugin
|
@JeiPlugin
|
||||||
public class JEIActuallyAdditionsPlugin implements IModPlugin {
|
public class JEIActuallyAdditionsPlugin implements IModPlugin {
|
||||||
|
@ -33,12 +37,17 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void registerCategories(IRecipeCategoryRegistration registry) {
|
public void registerCategories(IRecipeCategoryRegistration registry) {
|
||||||
IJeiHelpers helpers = registry.getJeiHelpers();
|
IJeiHelpers helpers = registry.getJeiHelpers();
|
||||||
|
|
||||||
|
registry.addRecipeCategories(new FermentingCategory(helpers.getGuiHelper()));
|
||||||
|
|
||||||
//registry.addRecipeCategories(new CoffeeMachineRecipeCategory(helpers.getGuiHelper()), new CompostRecipeCategory(helpers.getGuiHelper()), new CrusherRecipeCategory(helpers.getGuiHelper()), new ReconstructorRecipeCategory(helpers.getGuiHelper()), new EmpowererRecipeCategory(helpers.getGuiHelper()), new BookletRecipeCategory(helpers.getGuiHelper()));
|
//registry.addRecipeCategories(new CoffeeMachineRecipeCategory(helpers.getGuiHelper()), new CompostRecipeCategory(helpers.getGuiHelper()), new CrusherRecipeCategory(helpers.getGuiHelper()), new ReconstructorRecipeCategory(helpers.getGuiHelper()), new EmpowererRecipeCategory(helpers.getGuiHelper()), new BookletRecipeCategory(helpers.getGuiHelper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registry) {
|
public void registerRecipeCatalysts(IRecipeCatalystRegistration registry) {
|
||||||
registry.addRecipeCatalyst(new ItemStack(ActuallyItems.CRAFTER_ON_A_STICK.get()), VanillaRecipeCategoryUid.CRAFTING);
|
registry.addRecipeCatalyst(new ItemStack(ActuallyItems.CRAFTER_ON_A_STICK.get()), VanillaRecipeCategoryUid.CRAFTING);
|
||||||
|
registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.FERMENTING_BARREL.getItem()), FermentingCategory.ID);
|
||||||
|
|
||||||
// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockFurnaceDouble.get()), VanillaRecipeCategoryUid.SMELTING);
|
// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockFurnaceDouble.get()), VanillaRecipeCategoryUid.SMELTING);
|
||||||
// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinder.get()), CrusherRecipeCategory.NAME);
|
// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinder.get()), CrusherRecipeCategory.NAME);
|
||||||
// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinderDouble.get()), CrusherRecipeCategory.NAME);
|
// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinderDouble.get()), CrusherRecipeCategory.NAME);
|
||||||
|
@ -51,6 +60,11 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerRecipes(IRecipeRegistration registry) {
|
public void registerRecipes(IRecipeRegistration registry) {
|
||||||
|
World level = Minecraft.getInstance().level;
|
||||||
|
|
||||||
|
registry.addRecipes(level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.FERMENTING), FermentingCategory.ID);
|
||||||
|
|
||||||
|
|
||||||
//registry.addRecipes(ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA, BookletRecipeCategory.NAME);
|
//registry.addRecipes(ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA, BookletRecipeCategory.NAME);
|
||||||
//registry.addRecipes(ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS, CoffeeMachineRecipeCategory.NAME);
|
//registry.addRecipes(ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS, CoffeeMachineRecipeCategory.NAME);
|
||||||
//registry.addRecipes(ActuallyAdditionsAPI.CRUSHER_RECIPES, CrusherRecipeCategory.NAME);
|
//registry.addRecipes(ActuallyAdditionsAPI.CRUSHER_RECIPES, CrusherRecipeCategory.NAME);
|
||||||
|
|
|
@ -77,6 +77,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (currentRecipe == null) {
|
if (currentRecipe == null) {
|
||||||
|
//No recipe currently selected, check for one every 20 ticks
|
||||||
|
if (ticksElapsed % 20 == 0)
|
||||||
this.currentRecipe = ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.matches(this.tanks.getFluidInTank(0), this.tanks.getFluidInTank(1))).findFirst().orElse(null);
|
this.currentRecipe = ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.matches(this.tanks.getFluidInTank(0), this.tanks.getFluidInTank(1))).findFirst().orElse(null);
|
||||||
} else {
|
} else {
|
||||||
if (this.tanks.getFluidInTank(0).getAmount() >= currentRecipe.getInput().getAmount() &&
|
if (this.tanks.getFluidInTank(0).getAmount() >= currentRecipe.getInput().getAmount() &&
|
||||||
|
@ -154,6 +156,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
||||||
return Direction.values();
|
return Direction.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ITextComponent getDisplayName() {
|
public ITextComponent getDisplayName() {
|
||||||
return new TranslationTextComponent("container.actuallyadditions.fermenting_barrel");
|
return new TranslationTextComponent("container.actuallyadditions.fermenting_barrel");
|
||||||
|
@ -161,7 +164,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Container createMenu(int windowId, PlayerInventory playerInventory, PlayerEntity p_createMenu_3_) {
|
public Container createMenu(int windowId, @Nonnull PlayerInventory playerInventory, @Nonnull PlayerEntity p_createMenu_3_) {
|
||||||
return new ContainerFermentingBarrel(windowId, playerInventory, this);
|
return new ContainerFermentingBarrel(windowId, playerInventory, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,9 +177,9 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class FermentingBarrelMultiTank implements IFluidHandler {
|
public static class FermentingBarrelMultiTank implements IFluidHandler {
|
||||||
|
|
||||||
private int capacity = FluidAttributes.BUCKET_VOLUME * 2;
|
private final int capacity = FluidAttributes.BUCKET_VOLUME * 2;
|
||||||
public FluidTank inputTank = new FluidTank(capacity);
|
public FluidTank inputTank = new FluidTank(capacity);
|
||||||
public FluidTank outputTank = new FluidTank(capacity);
|
public FluidTank outputTank = new FluidTank(capacity);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue