Skip to content

Commit

Permalink
Huge code cleanup, Grinder support, should close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrapplexz committed Mar 22, 2018
1 parent 615dffb commit b793310
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 250 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mc_version=1.12.2
forge_version=14.23.2.2619
jei_mcversion=1.12.2
jei_version=4.8.5.158
mod_dependencies=required-after:harvestcraft@[1.12.2q,);required-after:jei@[4.7,);
mod_dependencies=required-after:harvestcraft@[1.12.2r,);required-after:jei@[4.7,);
mappings_version=snapshot_20180224
accepted_mc_versions=[1.12]
mod_version=1.4.1
mod_version=1.5.0
build_number=0
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/ru/pearx/jehc/JEHC.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.pearx.jehc;

import mezz.jei.api.IGuiHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/ru/pearx/jehc/jei/JEHCPlugin.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
package ru.pearx.jehc.jei;

import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.JEIPlugin;
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import ru.pearx.jehc.jei.apiary.ApiaryRecipeCategory;
import ru.pearx.jehc.jei.presser.PresserRecipeCategory;
import ru.pearx.jehc.jei.machine.GrinderRecipeCategory;
import ru.pearx.jehc.jei.machine.PresserRecipeCategory;
import ru.pearx.jehc.jei.sbm.MarketRecipeCategory;
import ru.pearx.jehc.jei.sbm.ShippingBinRecipeCategory;
import ru.pearx.jehc.jei.trap.GroundTrapRecipeCategory;
import ru.pearx.jehc.jei.trap.WaterTrapRecipeCategory;

import java.util.ArrayList;
import java.util.List;

/*
* Created by mrAppleXZ on 20.05.17 16:23.
*/
@JEIPlugin
@SideOnly(Side.CLIENT)
public class JEHCPlugin implements IModPlugin
{
private List<JehcRecipeCategory> cats = new ArrayList<>();

@Override
public void register(IModRegistry registry)
{
PresserRecipeCategory.setup(registry);
ShippingBinRecipeCategory.setup(registry);
MarketRecipeCategory.setup(registry);
ApiaryRecipeCategory.setup(registry);
GroundTrapRecipeCategory.setup(registry);
WaterTrapRecipeCategory.setup(registry);
for(JehcRecipeCategory cat : cats)
cat.setup(registry);
}

@Override
public void registerCategories(IRecipeCategoryRegistration reg)
{
reg.addRecipeCategories(new PresserRecipeCategory(reg.getJeiHelpers().getGuiHelper()));
reg.addRecipeCategories(new ShippingBinRecipeCategory(reg.getJeiHelpers().getGuiHelper()));
reg.addRecipeCategories(new MarketRecipeCategory(reg.getJeiHelpers().getGuiHelper()));
reg.addRecipeCategories(new ApiaryRecipeCategory(reg.getJeiHelpers().getGuiHelper()));
reg.addRecipeCategories(new GroundTrapRecipeCategory(reg.getJeiHelpers().getGuiHelper()));
reg.addRecipeCategories(new WaterTrapRecipeCategory(reg.getJeiHelpers().getGuiHelper()));
IGuiHelper h = reg.getJeiHelpers().getGuiHelper();
cats.add(new PresserRecipeCategory(h));
cats.add(new ShippingBinRecipeCategory(h));
cats.add(new MarketRecipeCategory(h));
cats.add(new ApiaryRecipeCategory(h));
cats.add(new GroundTrapRecipeCategory(h));
cats.add(new WaterTrapRecipeCategory(h));
cats.add(new GrinderRecipeCategory(h));
for(JehcRecipeCategory cat : cats)
{
reg.addRecipeCategories(cat);
}
}
}
56 changes: 56 additions & 0 deletions src/main/java/ru/pearx/jehc/jei/JehcRecipeCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.pearx.jehc.jei;

import com.pam.harvestcraft.Reference;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/*
* Created by mrAppleXZ on 22.03.18 20:48.
*/
@SideOnly(Side.CLIENT)
public abstract class JehcRecipeCategory<T extends IRecipeWrapper> implements IRecipeCategory<T>
{
private String uid;
private String unlocalizedTitle;
private IDrawable background;

public JehcRecipeCategory(String uid, String unlocalizedTitle, IDrawable background)
{
this.uid = uid;
this.unlocalizedTitle = unlocalizedTitle;
this.background = background;
}

public abstract void setup(IModRegistry reg);

@Override
public String getUid()
{
return uid;
}

@Override
public String getTitle()
{
return I18n.format(unlocalizedTitle);
}

@Override
public String getModName()
{
return Reference.NAME;
}

@Override
public IDrawable getBackground()
{
return background;
}
}
44 changes: 7 additions & 37 deletions src/main/java/ru/pearx/jehc/jei/apiary/ApiaryRecipeCategory.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,39 @@
package ru.pearx.jehc.jei.apiary;

import com.pam.harvestcraft.Reference;
import com.pam.harvestcraft.blocks.BlockRegistry;
import com.pam.harvestcraft.item.ItemRegistry;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import ru.pearx.jehc.jei.JehcRecipeCategory;

import java.util.Arrays;

/*
* Created by mrAppleXZ on 21.05.17 11:51.
*/
@SideOnly(Side.CLIENT)
public class ApiaryRecipeCategory implements IRecipeCategory<ApiaryRecipeWrapper>
public class ApiaryRecipeCategory extends JehcRecipeCategory<ApiaryRecipeWrapper>
{
public static final String UID = "jehc.apiary";
private final IDrawable bg;

public ApiaryRecipeCategory(IGuiHelper help)
{
bg = help.createDrawable(new ResourceLocation("harvestcraft", "textures/gui/apiary.png"), 3, 8, 170, 66);
super("jehc.apiary", "jehc.apiary.name", help.createDrawable(new ResourceLocation("harvestcraft", "textures/gui/apiary.png"), 3, 8, 170, 66));
}

public static void setup(IModRegistry registry)
@Override
public void setup(IModRegistry registry)
{
registry.addRecipeCatalyst(new ItemStack(BlockRegistry.apiaryItemBlock), UID);
registry.handleRecipes(ApiaryRecipeWrapper.class, recipe -> recipe, UID);
registry.addRecipeCatalyst(new ItemStack(BlockRegistry.apiaryItemBlock), getUid());
registry.addRecipes(Arrays.asList(
new ApiaryRecipeWrapper(new ItemStack(ItemRegistry.queenbeeItem), new ItemStack(ItemRegistry.waxcombItem), 50),
new ApiaryRecipeWrapper(new ItemStack(ItemRegistry.queenbeeItem), new ItemStack(ItemRegistry.honeycombItem), 45),
new ApiaryRecipeWrapper(new ItemStack(ItemRegistry.queenbeeItem), new ItemStack(ItemRegistry.grubItem), 5)
), UID);
}

@Override
public String getUid()
{
return UID;
}

@Override
public String getTitle()
{
return I18n.format("jehc.apiary.name");
}

@Override
public IDrawable getBackground()
{
return bg;
), getUid());
}

@Override
Expand All @@ -68,10 +44,4 @@ public void setRecipe(IRecipeLayout recipeLayout, ApiaryRecipeWrapper recipeWrap
recipeLayout.getItemStacks().init(1, false, 58, 8);
recipeLayout.getItemStacks().set(1, ingredients.getOutputs(ItemStack.class).get(0));
}

@Override
public String getModName()
{
return Reference.NAME;
}
}
44 changes: 44 additions & 0 deletions src/main/java/ru/pearx/jehc/jei/machine/GrinderRecipeCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.pearx.jehc.jei.machine;

import com.pam.harvestcraft.Reference;
import com.pam.harvestcraft.blocks.BlockRegistry;
import com.pam.harvestcraft.item.GrinderRecipes;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.reflect.FieldUtils;
import ru.pearx.jehc.JEHC;
import ru.pearx.jehc.jei.machine.MachineRecipeCategory;
import ru.pearx.jehc.jei.machine.MachineRecipeWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/*
* Created by mrAppleXZ on 22.03.18 20:29.
*/
@SideOnly(Side.CLIENT)
public class GrinderRecipeCategory extends MachineRecipeCategory
{
public GrinderRecipeCategory(IGuiHelper helper)
{
super("jehc.grinder", "jehc.grinder.name", "grinder", GrinderRecipes.class, "grindingList", helper);
}

@Override
public void setup(IModRegistry registry)
{
registry.addRecipeCatalyst(new ItemStack(BlockRegistry.grinderItemBlock), getUid());
super.setup(registry);
}
}
65 changes: 65 additions & 0 deletions src/main/java/ru/pearx/jehc/jei/machine/MachineRecipeCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ru.pearx.jehc.jei.machine;

import com.pam.harvestcraft.blocks.BlockRegistry;
import com.pam.harvestcraft.item.GrinderRecipes;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.lang3.reflect.FieldUtils;
import ru.pearx.jehc.JEHC;
import ru.pearx.jehc.jei.JehcRecipeCategory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/*
* Created by mrAppleXZ on 22.03.18 20:46.
*/
public class MachineRecipeCategory extends JehcRecipeCategory<MachineRecipeWrapper>
{
private Class recClass;
private String recField;

public MachineRecipeCategory(String uid, String unlocalizedTitle, String png, Class recClass, String recField, IGuiHelper helper)
{
super(uid, unlocalizedTitle, helper.createDrawable(new ResourceLocation("harvestcraft", "textures/gui/" + png + ".png"), 3, 8, 170, 66));
this.recClass = recClass;
this.recField = recField;
}

@Override
public void setup(IModRegistry registry)
{
List<MachineRecipeWrapper> rec = new ArrayList<>();
try
{
for (Map.Entry<ItemStack, ItemStack[]> entr : ((Map<ItemStack, ItemStack[]>)FieldUtils.readStaticField(recClass, recField, true)).entrySet())
{
rec.add(new MachineRecipeWrapper(entr.getKey(), entr.getValue()));
}
} catch (IllegalAccessException e)
{
JEHC.INSTANCE.getLog().error("An IllegalAccessException occurred while setting up the " + recClass.getSimpleName() + " recipes.", e);
}
registry.addRecipes(rec, getUid());
}

@Override
public void setRecipe(IRecipeLayout recipeLayout, MachineRecipeWrapper recipeWrapper, IIngredients ingredients)
{
recipeLayout.getItemStacks().init(0, true, 76, 14);
recipeLayout.getItemStacks().set(0, ingredients.getInputs(ItemStack.class).get(0));
recipeLayout.getItemStacks().init(1, false, 58, 45);
recipeLayout.getItemStacks().set(1, ingredients.getOutputs(ItemStack.class).get(0));
if(ingredients.getOutputs(ItemStack.class).size() == 2)
{
recipeLayout.getItemStacks().init(2, false, 94, 45);
recipeLayout.getItemStacks().set(2, ingredients.getOutputs(ItemStack.class).get(1));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package ru.pearx.jehc.jei.presser;
package ru.pearx.jehc.jei.machine;

import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.ArrayList;
import java.util.List;

/*
* Created by mrAppleXZ on 20.05.17 16:07.
* Created by mrAppleXZ on 22.03.18 20:58.
*/
@SideOnly(Side.CLIENT)
public class PresserRecipeWrapper implements IRecipeWrapper
public class MachineRecipeWrapper implements IRecipeWrapper
{
private final ItemStack in;
private final ItemStack[] out;

public PresserRecipeWrapper(ItemStack in, ItemStack[] out)
public MachineRecipeWrapper(ItemStack in, ItemStack[] out)
{
this.in = in;
this.out = out;
Expand All @@ -36,5 +33,4 @@ public void getIngredients(IIngredients ingredients)
}
ingredients.setOutputs(ItemStack.class, outputs);
}

}
Loading

0 comments on commit b793310

Please sign in to comment.