Skip to content

Commit

Permalink
WIP JEI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
DisasterMoo committed Jul 19, 2019
1 parent 43ea9d9 commit bf19101
Show file tree
Hide file tree
Showing 23 changed files with 554 additions and 17 deletions.
26 changes: 23 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ buildscript {
// Go Forge go!
apply plugin: "net.minecraftforge.gradle.forge"

// Load properties file, easier to manage versions of required dependencies
file "build.properties" withReader {
def prop = new Properties()
prop.load(it)
ext.config = new ConfigSlurper().parse prop
}

/**
* Versioning rules: (Highly based on Semantic Versioning 2.0.0, https://semver.org/)
*
Expand Down Expand Up @@ -61,19 +68,32 @@ ext.getChangeLog = { -> // Create a new function that gets the changelog from gi
}

minecraft { // Only change any of this with prior approval from the dev team!
version = "1.12.2-14.23.5.2768"
version = "${config.minecraft.version}-${config.forge.version}"
runDir = "run"
mappings = "snapshot_20180814"
}

repositories {
// Repositories required for dependencies, not ForgeGradle go here.
mavenCentral()
maven {
name = "CraftTweaker Maven"
url = "https://maven.blamejared.com/"
}
maven {
// location of the maven that hosts JEI files
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
}

String mcVersion = config.minecraft.version
String shortVersion = mcVersion.substring(0, mcVersion.lastIndexOf('.'))
String strippedVersion = shortVersion.replace(".", "") + "0"

dependencies {
// Mod dependencies go here.
// Do not add dependencies without prior approval from the dev team. You can update existing ones.
deobfCompile "CraftTweaker2:CraftTweaker2-MC${strippedVersion}-Main:${config.crafttweaker.version}"
deobfCompile "mezz.jei:jei_${config.minecraft.version}:${config.jei.version}"
}

processResources {
Expand Down
4 changes: 4 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minecraft.version=1.12.2
forge.version=14.23.5.2768
jei.version=4.13.1.222
crafttweaker.version=1.12-4.1.8.9
15 changes: 14 additions & 1 deletion src/main/java/net/dries007/tfc/api/recipes/AnvilRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.jei.IJEIRecipeWrapper;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;
import net.dries007.tfc.objects.te.TEAnvilTFC;
import net.dries007.tfc.util.forge.ForgeRule;
Expand All @@ -30,7 +31,7 @@
* todo: in 1.13+ move this to a json recipe type
*/
@ParametersAreNonnullByDefault
public class AnvilRecipe extends IForgeRegistryEntry.Impl<AnvilRecipe>
public class AnvilRecipe extends IForgeRegistryEntry.Impl<AnvilRecipe> implements IJEIRecipeWrapper
{
public static final NonNullList<ItemStack> EMPTY = NonNullList.create();
private static final Random RNG = new Random();
Expand Down Expand Up @@ -105,4 +106,16 @@ public int getTarget(long worldSeed)
RNG.setSeed(worldSeed + workingSeed);
return 40 + RNG.nextInt(TEAnvilTFC.WORK_MAX + -2 * 40);
}

@Override
public NonNullList<IIngredient<ItemStack>> getItemIngredients()
{
return NonNullList.withSize(1, ingredient);
}

@Override
public NonNullList<ItemStack> getItemOutputs()
{
return NonNullList.withSize(1, output);
}
}
16 changes: 15 additions & 1 deletion src/main/java/net/dries007/tfc/api/recipes/QuernRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import javax.annotation.Nullable;

import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.registries.IForgeRegistryEntry;

import net.dries007.tfc.api.capability.food.CapabilityFood;
import net.dries007.tfc.api.capability.food.IFood;
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.jei.IJEIRecipeWrapper;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

public class QuernRecipe extends IForgeRegistryEntry.Impl<QuernRecipe>
public class QuernRecipe extends IForgeRegistryEntry.Impl<QuernRecipe> implements IJEIRecipeWrapper
{
@Nullable
public static QuernRecipe get(ItemStack item)
Expand Down Expand Up @@ -52,6 +54,18 @@ public ItemStack getOutputItem(ItemStack stack)
return out;
}

@Override
public NonNullList<IIngredient<ItemStack>> getItemIngredients()
{
return NonNullList.withSize(1, inputItem);
}

@Override
public NonNullList<ItemStack> getItemOutputs()
{
return NonNullList.withSize(1, outputItem);
}

private boolean isValidInput(ItemStack inputItem)
{
return this.inputItem.testIgnoreCount(inputItem);
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/net/dries007/tfc/api/recipes/WeldingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistryEntry;

import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.jei.IJEIRecipeWrapper;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

/**
* Welding Recipe
* This takes two items and produces a single item out
* todo: in 1.13+ move this to a json recipe type
*/
@ParametersAreNonnullByDefault
public class WeldingRecipe extends IForgeRegistryEntry.Impl<WeldingRecipe>
public class WeldingRecipe extends IForgeRegistryEntry.Impl<WeldingRecipe> implements IJEIRecipeWrapper
{
private final Metal.Tier minTier;
private final ItemStack input1;
private final ItemStack input2;
private final IIngredient<ItemStack> input1;
private final IIngredient<ItemStack> input2;
private final ItemStack output;

public WeldingRecipe(ResourceLocation name, ItemStack input1, ItemStack input2, ItemStack output, Metal.Tier minTier)
public WeldingRecipe(ResourceLocation name, IIngredient<ItemStack> input1, IIngredient<ItemStack> input2, ItemStack output, Metal.Tier minTier)
{
this.input1 = input1;
this.input2 = input2;
this.output = output;
if (input1.isEmpty() || input2.isEmpty() || output.isEmpty())
throw new IllegalArgumentException("Input and output are not allowed to be empty");

this.minTier = minTier;

setRegistryName(name);
Expand All @@ -55,7 +55,21 @@ public ItemStack getOutput()
public boolean matches(ItemStack input1, ItemStack input2)
{
// Need to check both orientations
return (this.input1.isItemEqual(input1) && this.input2.isItemEqual(input2)) || (this.input1.isItemEqual(input2) && this.input2.isItemEqual(input1));
return (this.input1.test(input1) && this.input2.test(input2)) || (this.input1.test(input2) && this.input2.test(input1));
}

@Override
public NonNullList<IIngredient<ItemStack>> getItemIngredients()
{
NonNullList<IIngredient<ItemStack>> list = NonNullList.create();
list.add(input1);
list.add(input2);
return list;
}

@Override
public NonNullList<ItemStack> getItemOutputs()
{
return NonNullList.withSize(1, output);
}
}
58 changes: 58 additions & 0 deletions src/main/java/net/dries007/tfc/jei/IJEIRecipeWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.jei;

import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fluids.FluidStack;

import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

/**
* Wraps recipe ingredients and outputs for JEI
*/
public interface IJEIRecipeWrapper
{
/**
* Returns a list of Item Ingredients for JEI
*
* @return NonNullList with ItemStack IIngredients
*/
default NonNullList<IIngredient<ItemStack>> getItemIngredients()
{
return NonNullList.create();
}

/**
* Returns a list of Fluid Ingredients for JEI
*
* @return NonNullList with FluidStack IIngredients
*/
default NonNullList<IIngredient<FluidStack>> getFluidIngredients()
{
return NonNullList.create();
}

/**
* Returns a list of Item Outputs
*
* @return NonNullList with ItemStacks
*/
default NonNullList<ItemStack> getItemOutputs()
{
return NonNullList.create();
}

/**
* Returns a list of Fluid Outputs
*
* @return NonNullList with FluidStacks
*/
default NonNullList<FluidStack> getFluidOutputs()
{
return NonNullList.create();
}
}
62 changes: 62 additions & 0 deletions src/main/java/net/dries007/tfc/jei/TFCJEIPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.jei;

import java.util.List;
import java.util.stream.Collectors;

import net.minecraft.item.ItemStack;

import mezz.jei.api.IModPlugin;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.JEIPlugin;
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.api.util.TFCConstants;
import net.dries007.tfc.jei.categories.AnvilCategory;
import net.dries007.tfc.jei.categories.QuernCategory;
import net.dries007.tfc.jei.wrappers.AnvilWrapper;
import net.dries007.tfc.jei.wrappers.QuernWrapper;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.blocks.metal.BlockAnvilTFC;

@JEIPlugin
public final class TFCJEIPlugin implements IModPlugin
{
public static final String QUERN_UID = TFCConstants.MOD_ID + ".quern";
public static final String ANVIL_UID = TFCConstants.MOD_ID + ".anvil";

@Override
public void registerCategories(IRecipeCategoryRegistration registry)
{
//Add new JEI recipe categories
registry.addRecipeCategories(new QuernCategory(registry.getJeiHelpers().getGuiHelper())); //Quern
registry.addRecipeCategories(new AnvilCategory(registry.getJeiHelpers().getGuiHelper())); //Anvil
}

@Override
public void register(IModRegistry registry)
{
//Wraps all quern recipes
List<QuernWrapper> quernList = TFCRegistries.QUERN.getValuesCollection()
.stream()
.map(QuernWrapper::new)
.collect(Collectors.toList());

registry.addRecipes(quernList, QUERN_UID); //Register recipes to quern category
registry.addRecipeCatalyst(new ItemStack(BlocksTFC.QUERN), QUERN_UID); //Register BlockQuern as the device that do quern recipes

//Wraps all anvil recipes
List<AnvilWrapper> anvilList = TFCRegistries.ANVIL.getValuesCollection()
.stream()
.map(AnvilWrapper::new)
.collect(Collectors.toList());

registry.addRecipes(anvilList, ANVIL_UID);
registry.addRecipeCatalyst(BlockAnvilTFC.get(Metal.WROUGHT_IRON, 1), ANVIL_UID); //This is returning air :/
}
}
68 changes: 68 additions & 0 deletions src/main/java/net/dries007/tfc/jei/categories/AnvilCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package net.dries007.tfc.jei.categories;

import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import mcp.MethodsReturnNonnullByDefault;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawableAnimated;
import mezz.jei.api.gui.IDrawableStatic;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.ingredients.VanillaTypes;
import net.dries007.tfc.api.util.TFCConstants;
import net.dries007.tfc.jei.TFCJEIPlugin;
import net.dries007.tfc.jei.wrappers.AnvilWrapper;
import net.dries007.tfc.objects.items.ItemsTFC;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class AnvilCategory extends TFCRecipeCategory<AnvilWrapper>
{
private final IDrawableStatic slot;
private final IDrawableStatic arrow;
private final IDrawableAnimated arrowAnimated;

public AnvilCategory(IGuiHelper helper)
{
super(helper.createBlankDrawable(120, 38), "anvil");
ResourceLocation resourceLocation = new ResourceLocation(TFCConstants.MOD_ID, "textures/gui/jei/recipes.png");
arrow = helper.createDrawable(resourceLocation, 0, 14, 22, 16);
IDrawableStatic arrowAnimated = helper.createDrawable(resourceLocation, 22, 14, 22, 16);
this.arrowAnimated = helper.createAnimatedDrawable(arrowAnimated, 160, IDrawableAnimated.StartDirection.LEFT, false);
this.slot = helper.getSlotDrawable();
}

@Override
public String getUid()
{
return TFCJEIPlugin.ANVIL_UID;
}

@Override
public void drawExtras(Minecraft minecraft)
{
arrow.draw(minecraft, 50, 16);
arrowAnimated.draw(minecraft, 50, 16);
slot.draw(minecraft, 0, 16);
slot.draw(minecraft, 20, 16);
slot.draw(minecraft, 84, 16);
}

@Override
public void setRecipe(IRecipeLayout recipeLayout, AnvilWrapper recipeWrapper, IIngredients ingredients)
{
IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
itemStackGroup.init(0, true, 0, 16);
itemStackGroup.init(1, true, 20, 16);
itemStackGroup.init(2, false, 84, 16);

itemStackGroup.set(0, ingredients.getInputs(VanillaTypes.ITEM).get(0));
itemStackGroup.set(1, new ItemStack(ItemsTFC.HANDSTONE)); //TODO change to hammer
itemStackGroup.set(2, ingredients.getOutputs(VanillaTypes.ITEM).get(0));
}
}
Loading

0 comments on commit bf19101

Please sign in to comment.