Close #441
This commit is contained in:
parent
b09577861d
commit
1c88a2e4ce
5 changed files with 156 additions and 63 deletions
|
@ -55,7 +55,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
deobfCompile "com.blamejared:MTLib:1.0.0.7"
|
||||
deobfCompile "com.blamejared:MTLib:1.0.2.10"
|
||||
deobfCompile "MCMultiPart:MCMultiPart:1.3.0:universal"
|
||||
deobfCompile "mezz.jei:jei_1.10.2:3.14.7.416"
|
||||
}
|
||||
|
|
48
src/main/java/modtweaker/JEIAddonPlugin.java
Normal file
48
src/main/java/modtweaker/JEIAddonPlugin.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package modtweaker;
|
||||
|
||||
import mezz.jei.api.*;
|
||||
import mezz.jei.api.gui.IDrawable;
|
||||
import mezz.jei.api.ingredients.*;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.compat.DummyJEIRecipeRegistry;
|
||||
import minetweaker.mods.jei.JEIRecipeRegistry;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
@mezz.jei.api.JEIPlugin
|
||||
public class JEIAddonPlugin implements IModPlugin {
|
||||
|
||||
public static IJeiHelpers jeiHelpers;
|
||||
public static IIngredientRegistry itemRegistry;
|
||||
public static IRecipeRegistry recipeRegistry;
|
||||
|
||||
public static IDrawable castingTable;
|
||||
public static IDrawable castingBasin;
|
||||
|
||||
@Override
|
||||
public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIngredients(IModIngredientRegistration registry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(IModRegistry registry) {
|
||||
jeiHelpers = registry.getJeiHelpers();
|
||||
itemRegistry = registry.getIngredientRegistry();
|
||||
ResourceLocation rec = new ResourceLocation("tconstruct", "textures/gui/jei/casting.png");
|
||||
this.castingTable = jeiHelpers.getGuiHelper().createDrawable(rec, 141, 0, 16, 16);
|
||||
this.castingBasin = jeiHelpers.getGuiHelper().createDrawable(rec, 141, 16, 16, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(IJeiRuntime iJeiRuntime) {
|
||||
recipeRegistry = iJeiRuntime.getRecipeRegistry();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -57,5 +57,4 @@ public abstract class ForestryListAddition<T extends IForestryRecipe> extends Ba
|
|||
}
|
||||
}
|
||||
|
||||
public abstract IRecipeWrapper wrapRecipe(T recipe);
|
||||
}
|
||||
|
|
|
@ -58,5 +58,4 @@ public abstract class ForestryListRemoval<T extends IForestryRecipe, C extends I
|
|||
}
|
||||
}
|
||||
|
||||
public abstract IRecipeWrapper wrapRecipe(T recipe);
|
||||
}
|
||||
|
|
|
@ -1,149 +1,196 @@
|
|||
package modtweaker.mods.tconstruct.handlers;
|
||||
|
||||
import com.blamejared.mtlib.helpers.*;
|
||||
import com.blamejared.mtlib.utils.*;
|
||||
import mezz.jei.api.recipe.*;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IngredientAny;
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import com.blamejared.mtlib.helpers.LogHelper;
|
||||
import minetweaker.mc1102.item.MCItemStack;
|
||||
import modtweaker.JEIAddonPlugin;
|
||||
import modtweaker.mods.tconstruct.TConstructHelper;
|
||||
import com.blamejared.mtlib.utils.BaseListAddition;
|
||||
import com.blamejared.mtlib.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import slimeknights.mantle.util.RecipeMatch;
|
||||
import slimeknights.tconstruct.library.smeltery.CastingRecipe;
|
||||
import slimeknights.tconstruct.library.smeltery.ICastingRecipe;
|
||||
import slimeknights.tconstruct.library.smeltery.*;
|
||||
import slimeknights.tconstruct.plugin.jei.CastingRecipeWrapper;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static com.blamejared.mtlib.helpers.InputHelper.*;
|
||||
import static com.blamejared.mtlib.helpers.StackHelper.matches;
|
||||
|
||||
@ZenClass("mods.tconstruct.Casting")
|
||||
public class Casting {
|
||||
|
||||
|
||||
protected static final String name = "TConstruct Casting";
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addBasinRecipe(IItemStack output, ILiquidStack liquid, @Optional IItemStack cast, @Optional boolean consumeCast, @Optional int timeInTicks) {
|
||||
if (liquid == null || output == null) {
|
||||
if(liquid == null || output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
RecipeMatch match = null;
|
||||
if (cast != null) {
|
||||
if(cast != null) {
|
||||
match = RecipeMatch.of(toStack(cast));
|
||||
}
|
||||
FluidStack fluid = toFluid(liquid);
|
||||
if (timeInTicks == 0) {
|
||||
if(timeInTicks == 0) {
|
||||
timeInTicks = CastingRecipe.calcCooldownTime(fluid.getFluid(), fluid.amount);
|
||||
}
|
||||
CastingRecipe rec = new CastingRecipe(toStack(output), match, fluid, timeInTicks, consumeCast, false);
|
||||
MineTweakerAPI.apply(new Add(rec, (LinkedList<ICastingRecipe>) TConstructHelper.basinCasting));
|
||||
MineTweakerAPI.apply(new Add(rec, (LinkedList<ICastingRecipe>) TConstructHelper.basinCasting, false));
|
||||
}
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addTableRecipe(IItemStack output, ILiquidStack liquid, @Optional IItemStack cast, @Optional boolean consumeCast, @Optional int timeInTicks) {
|
||||
if (liquid == null || output == null) {
|
||||
if(liquid == null || output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
RecipeMatch match = null;
|
||||
if (cast != null) {
|
||||
if(cast != null) {
|
||||
match = RecipeMatch.of(toStack(cast));
|
||||
}
|
||||
FluidStack fluid = toFluid(liquid);
|
||||
if (timeInTicks == 0) {
|
||||
if(timeInTicks == 0) {
|
||||
timeInTicks = CastingRecipe.calcCooldownTime(fluid.getFluid(), fluid.amount);
|
||||
}
|
||||
CastingRecipe rec = new CastingRecipe(toStack(output), match, fluid, timeInTicks, consumeCast, false);
|
||||
MineTweakerAPI.apply(new Add(rec, (LinkedList<ICastingRecipe>) TConstructHelper.tableCasting));
|
||||
MineTweakerAPI.apply(new Add(rec, (LinkedList<ICastingRecipe>) TConstructHelper.tableCasting, true));
|
||||
}
|
||||
|
||||
|
||||
//Passes the list to the base list implementation, and adds the recipe
|
||||
private static class Add extends BaseListAddition<ICastingRecipe> {
|
||||
public Add(CastingRecipe recipe, LinkedList<ICastingRecipe> list) {
|
||||
|
||||
final boolean table;
|
||||
|
||||
public Add(CastingRecipe recipe, LinkedList<ICastingRecipe> list, boolean table) {
|
||||
super(Casting.name, list);
|
||||
this.recipes.add(recipe);
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(ICastingRecipe recipe) {
|
||||
return LogHelper.getStackDescription(((CastingRecipe) recipe).getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeWrapper wrapRecipe(ICastingRecipe recipe) {
|
||||
if(table) {
|
||||
return new CastingRecipeWrapper((CastingRecipe) recipe, JEIAddonPlugin.castingTable);
|
||||
} else {
|
||||
return new CastingRecipeWrapper((CastingRecipe) recipe, JEIAddonPlugin.castingBasin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void removeTableRecipe(IIngredient output, @Optional IIngredient liquid, @Optional IIngredient cast) {
|
||||
removeRecipe(output, liquid, cast, TConstructHelper.tableCasting);
|
||||
removeRecipe(output, liquid, cast, TConstructHelper.tableCasting, true);
|
||||
}
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void removeBasinRecipe(IIngredient output, @Optional IIngredient liquid, @Optional IIngredient cast) {
|
||||
|
||||
removeRecipe(output, liquid, cast, TConstructHelper.basinCasting);
|
||||
removeRecipe(output, liquid, cast, TConstructHelper.basinCasting, false);
|
||||
}
|
||||
|
||||
public static void removeRecipe(IIngredient output, IIngredient liquid, IIngredient cast, List<ICastingRecipe> list) {
|
||||
if (output == null) {
|
||||
|
||||
public static void removeRecipe(IIngredient output, IIngredient liquid, IIngredient cast, List<ICastingRecipe> list, boolean table) {
|
||||
if(output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
if (liquid == null) {
|
||||
|
||||
if(liquid == null) {
|
||||
liquid = IngredientAny.INSTANCE;
|
||||
}
|
||||
|
||||
List<ICastingRecipe> recipes = new LinkedList<ICastingRecipe>();
|
||||
|
||||
for (ICastingRecipe recipe : list) {
|
||||
if (recipe instanceof CastingRecipe) {
|
||||
if (!matches(output, toIItemStack(((CastingRecipe) recipe).getResult()))) {
|
||||
|
||||
|
||||
List<ICastingRecipe> recipes = new LinkedList<>();
|
||||
|
||||
for(ICastingRecipe recipe : list) {
|
||||
if(recipe instanceof CastingRecipe) {
|
||||
if(((CastingRecipe) recipe).getResult() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!matches(liquid, toILiquidStack(((CastingRecipe) recipe).getFluid()))) {
|
||||
|
||||
if(!matches(output, toIItemStack(((CastingRecipe) recipe).getResult()))) {
|
||||
continue;
|
||||
}
|
||||
if ((((CastingRecipe) recipe).cast != null && cast != null) && (((CastingRecipe) recipe).cast.matches(toStacks(cast.getItems().toArray(new IItemStack[0]))) == null)) {
|
||||
|
||||
if(!matches(liquid, toILiquidStack(((CastingRecipe) recipe).getFluid()))) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if((((CastingRecipe) recipe).cast != null && cast != null) && (((CastingRecipe) recipe).cast.matches(toStacks(cast.getItems().toArray(new IItemStack[0]))) == null)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
recipes.add((CastingRecipe) recipe);
|
||||
}
|
||||
}
|
||||
|
||||
if (!recipes.isEmpty())
|
||||
|
||||
{
|
||||
MineTweakerAPI.apply(new Remove(list, recipes));
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(list, recipes, table));
|
||||
} else
|
||||
|
||||
|
||||
{
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for output %s, material %s and cast %s. Command ignored!", Casting.name, output.toString(), liquid.toString(), cast != null ? cast.toString() : null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Removes all matching recipes, apply is never the same for anything, so will always need to override it
|
||||
private static class Remove extends BaseListRemoval<ICastingRecipe> {
|
||||
public Remove(List<ICastingRecipe> list, List<ICastingRecipe> recipes) {
|
||||
|
||||
final boolean table;
|
||||
|
||||
public Remove(List<ICastingRecipe> list, List<ICastingRecipe> recipes, boolean table) {
|
||||
super(Casting.name, list, recipes);
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(ICastingRecipe recipe) {
|
||||
return LogHelper.getStackDescription(((CastingRecipe) recipe).getResult());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IRecipeWrapper wrapRecipe(ICastingRecipe recipe) {
|
||||
IFocus<ItemStack> focus = JEIAddonPlugin.recipeRegistry.createFocus(IFocus.Mode.OUTPUT, ((CastingRecipe) recipe).getResult());
|
||||
List<IRecipeCategory> categories = JEIAddonPlugin.recipeRegistry.getRecipeCategories(focus);
|
||||
Iterator var4 = categories.iterator();
|
||||
outer:
|
||||
while(true) {
|
||||
IRecipeCategory category;
|
||||
do {
|
||||
if(!var4.hasNext()) {
|
||||
if(table) {
|
||||
return new CastingRecipeWrapper((CastingRecipe) recipe, JEIAddonPlugin.castingTable);
|
||||
} else {
|
||||
return new CastingRecipeWrapper((CastingRecipe) recipe, JEIAddonPlugin.castingBasin);
|
||||
}
|
||||
}
|
||||
|
||||
category = (IRecipeCategory) var4.next();
|
||||
} while(!category.getUid().equals("tconstruct.casting_table"));
|
||||
|
||||
List<IRecipeWrapper> wrappers = JEIAddonPlugin.recipeRegistry.getRecipeWrappers(category, focus);
|
||||
Iterator var7 = wrappers.iterator();
|
||||
|
||||
while(var7.hasNext()) {
|
||||
CastingRecipeWrapper wrapper = (CastingRecipeWrapper) var7.next();
|
||||
if(StackHelper.matches(new MCItemStack(wrapper.lazyInitOutput().get(0)), new MCItemStack(((CastingRecipe) recipe).getResult()))) {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue