Config options added.

This commit is contained in:
stfwi 2019-03-29 21:05:36 +01:00
parent ba873eaf7e
commit 6f611cbfa7
12 changed files with 432 additions and 26 deletions

View file

@ -11,6 +11,7 @@ buildscript {
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'idea'
sourceCompatibility = targetCompatibility = '1.8'
compileJava { // Need this here so eclipse task generates correctly.
sourceCompatibility = targetCompatibility = '1.8'
@ -47,7 +48,13 @@ minecraft {
replaceIn "ModEngineersDecor.java"
}
repositories {
maven { name = "Progwml6 maven"; url = "https://dvs1.progwml6.com/files/maven/" } // JEI files
maven { name = "ModMaven"; url = "modmaven.k-4u.nl" } // JEI files, fallback
}
dependencies {
deobfProvided "mezz.jei:jei_${version_minecraft}:${version_jei}:api"
runtime "mezz.jei:jei_${version_minecraft}:${version_jei}"
}
processResources {
@ -63,7 +70,7 @@ processResources {
}
task signJar(type: SignJar, dependsOn: reobfJar) {
onlyIf { signing.getProperty("keystore_file"); }
onlyIf { signing.getProperty("keystore_file") }
keyStore = signing.getProperty("keystore_file")
alias = signing.getProperty("keystore_alias")
storePass = signing.getProperty("keystore_pass")

View file

@ -3,12 +3,5 @@ org.gradle.daemon=false
org.gradle.jvmargs=-Xmx8G
version_minecraft=1.12.2
version_forge=14.23.5.2768
version_engineersdecor=1.0.3-b1
#
# jar signing data loaded from signing.properties in the project root.
#
#signing.keystore_file=
#signing.keystore_alias=
#signing.keystore_pass=
#signing.keystore_keypass=
#fingerprint_sha1.fp_sha1=
version_jei=4.10.0.198
version_engineersdecor=1.0.3-b2

View file

@ -1,6 +1,7 @@
{
"homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/",
"1.12.2": {
"1.0.3-b2": "[A] Added config options for selective feature opt-outs (soft opt-out).\n[A] Added config skip registration of opt-out features (hard opt-out).\n[A] Added config to disable all internal recipes (for packs).\n[A] Added JEI API adapter for soft opt-outs.\n[A] Added lab furnace recipe override config to smelt ores to nuggets that would normally be smelted into ingots. Can be changed on-the-fly.",
"1.0.3-b1": "[A] Added small laboratory furnace.\n[M] Panzer glass opacity/light level set explicitly 0.",
"1.0.2": "[R] Release based on v1.0.2-b3 * Fixes: Spawning. * Crafting table: Shift-click. * Ladders: Faster climbing/descending. * Concrete: Rebar tiles, tile stairs. * Treated wood: window, windowsill. * Slag brick: wall. * Panzer glass: added. * Recipes: Adaptions, added decompositions.",
"1.0.2-b3": "[A] Added slag brick wall.\n[A] Added wall decomposition recipes.\n[A] Added treated wood window.\n[M] Climbing/descending mod ladders is faster when looking up or down and not sneaking.\n[M] Panzer glass material definition changed.\n[M] Explicitly preventing spawning in and on \"non-full\" blocks of the mod.",
@ -19,6 +20,6 @@
},
"promos": {
"1.12.2-recommended": "1.0.2",
"1.12.2-latest": "1.0.3-b1"
"1.12.2-latest": "1.0.3-b2"
}
}

View file

@ -10,6 +10,13 @@ Mod sources for Minecraft version 1.12.2.
----
## Revision history
- v1.0.3-b2 [A] Added config options for selective feature opt-outs (soft opt-out).
[A] Added config skip registration of opt-out features (hard opt-out).
[A] Added config to disable all internal recipes (for packs).
[A] Added JEI API adapter for soft opt-outs.
[A] Added lab furnace recipe override config to smelt ores to nuggets
that would normally be smelted into ingots. Can be changed on-the-fly.
- v1.0.3-b1 [A] Added small laboratory furnace.
[M] Panzer glass opacity/light level set explicitly 0.

View file

@ -37,6 +37,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import org.apache.logging.log4j.Logger;
import wile.engineersdecor.detail.RecipeCondModSpecific;
import javax.annotation.Nonnull;
@Mod(
@ -95,7 +97,12 @@ public class ModEngineersDecor
@Mod.EventHandler
public void postInit(final FMLPostInitializationEvent event)
{ ModConfig.onPostInit(event); proxy.postInit(event); }
{
ModConfig.onPostInit(event);
proxy.postInit(event);
if(RecipeCondModSpecific.num_skipped > 0) logger.info("Excluded " + RecipeCondModSpecific.num_skipped + " recipes due to config opt-out.");
if(ModConfig.zmisc.with_experimental) logger.info("Included experimental features due to mod config.");
}
@Mod.EventBusSubscriber
public static final class RegistrationSubscriptions

View file

@ -8,6 +8,8 @@
*/
package wile.engineersdecor.blocks;
import com.google.common.collect.Maps;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.init.SoundEvents;
import wile.engineersdecor.ModEngineersDecor;
import net.minecraft.stats.StatList;
@ -46,6 +48,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Random;
@ -238,12 +241,61 @@ public class BlockDecorFurnace extends BlockDecorDirected
{ super(inv, index, xpos, ypos); }
}
public static class BSlotOutFifo extends SlotFurnaceOutput
public static class BSlotOutFifo extends BSlotResult
{
public BSlotOutFifo(EntityPlayer player, BTileEntity te, int index, int xpos, int ypos)
{ super(player, te, index, xpos, ypos); }
}
public static class BSlotResult extends Slot
{
// This class is basically SlotFurnaceOutput.onCrafting(), except that the recipe overrides
// are used, unfortunately a copy is needed due to private instance variables.
private final EntityPlayer player;
private int removeCount = 0;
public BSlotResult(EntityPlayer player, BTileEntity te, int index, int xpos, int ypos)
{ super(te, index, xpos, ypos); this.player = player; }
@Override
public boolean isItemValid(ItemStack stack)
{ return false; }
@Override
public ItemStack decrStackSize(int amount)
{ removeCount += getHasStack() ? Math.min(amount, getStack().getCount()) : 0; return super.decrStackSize(amount); }
@Override
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{ onCrafting(stack); super.onTake(thePlayer, stack); return stack; }
@Override
protected void onCrafting(ItemStack stack, int amount)
{ removeCount += amount; onCrafting(stack); }
@Override
protected void onCrafting(ItemStack stack)
{
stack.onCrafting(player.world, player, removeCount);
if(!player.world.isRemote) {
int xp = removeCount;
float sxp = BRecipes.instance().getSmeltingExperience(stack);
if(sxp == 0) {
xp = 0;
} else if(sxp < 1.0) {
xp = (int)((sxp*xp) + Math.round(Math.random()+0.75));
}
while(xp > 0) {
int k = EntityXPOrb.getXPSplit(xp);
xp -= k;
player.world.spawnEntity(new EntityXPOrb(player.world, player.posX, player.posY+0.5, player.posZ+0.5, k));
}
}
removeCount = 0;
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);
}
}
//--------------------------------------------------------------------------------------------------------------------
// container
//--------------------------------------------------------------------------------------------------------------------
@ -268,7 +320,7 @@ public class BlockDecorFurnace extends BlockDecorDirected
this.te = te;
addSlotToContainer(new Slot(te, 0, 59, 17)); // smelting input
addSlotToContainer(new SlotFurnaceFuel(te, 1, 59, 53)); // fuel
addSlotToContainer(new SlotFurnaceOutput(playerInventory.player, te, 2, 101, 35)); // smelting result
addSlotToContainer(new BSlotResult(playerInventory.player, te, 2, 101, 35)); // smelting result
addSlotToContainer(new BSlotInpFifo(te, 3, 34, 17)); // input fifo 0
addSlotToContainer(new BSlotInpFifo(te, 4, 16, 17)); // input fifo 1
addSlotToContainer(new BSlotFuelFifo(te, 5, 34, 53)); // fuel fifo 0
@ -338,7 +390,7 @@ public class BlockDecorFurnace extends BlockDecorDirected
if(!mergeItemStack(slot_stack, PLAYER_INV_START_SLOTNO, PLAYER_INV_START_SLOTNO+36, false)) return ItemStack.EMPTY;
} else if((index >= PLAYER_INV_START_SLOTNO) && (index <= PLAYER_INV_START_SLOTNO+36)) {
// Player inventory
if(!FurnaceRecipes.instance().getSmeltingResult(slot_stack).isEmpty()) {
if(!BRecipes.instance().getSmeltingResult(slot_stack).isEmpty()) {
if(
(!mergeItemStack(slot_stack, 0, 1, false)) && // smelting input
(!mergeItemStack(slot_stack, 3, 4, false)) && // fifo0
@ -684,7 +736,7 @@ public class BlockDecorFurnace extends BlockDecorDirected
private boolean canSmelt()
{
if(stacks_.get(SMELTING_INPUT_SLOT_NO).isEmpty()) return false;
final ItemStack recipe_result_items = FurnaceRecipes.instance().getSmeltingResult(stacks_.get(SMELTING_INPUT_SLOT_NO));
final ItemStack recipe_result_items = BRecipes.instance().getSmeltingResult(stacks_.get(SMELTING_INPUT_SLOT_NO));
if(recipe_result_items.isEmpty()) return false;
final ItemStack result_stack = stacks_.get(SMELTING_OUTPUT_SLOT_NO);
if(result_stack.isEmpty()) return true;
@ -697,7 +749,7 @@ public class BlockDecorFurnace extends BlockDecorDirected
{
if(!canSmelt()) return;
final ItemStack smelting_input_stack = stacks_.get(SMELTING_INPUT_SLOT_NO);
final ItemStack recipe_result_items = FurnaceRecipes.instance().getSmeltingResult(smelting_input_stack);
final ItemStack recipe_result_items = BRecipes.instance().getSmeltingResult(smelting_input_stack);
final ItemStack smelting_output_stack = stacks_.get(SMELTING_OUTPUT_SLOT_NO);
final ItemStack fuel_stack = stacks_.get(SMELTING_FUEL_SLOT_NO);
if(smelting_output_stack.isEmpty()) {
@ -746,4 +798,74 @@ public class BlockDecorFurnace extends BlockDecorDirected
}
//--------------------------------------------------------------------------------------------------------------------
// Furnace recipe overrides
//--------------------------------------------------------------------------------------------------------------------
// Based on net.minecraft.item.crafting.FurnaceRecipes, copy as
// needed methods are private.
public static class BRecipes
{
private static final BRecipes RECIPPE_OVERRIDES = new BRecipes();
private final Map<ItemStack, ItemStack> recipes_ = Maps.<ItemStack, ItemStack>newHashMap();
private final Map<ItemStack, Float> experiences_ = Maps.<ItemStack, Float>newHashMap();
public static BRecipes instance()
{ return RECIPPE_OVERRIDES; }
private BRecipes()
{}
public Map<ItemStack, ItemStack> getRecipes()
{ return recipes_; }
public void reset()
{ recipes_.clear(); experiences_.clear(); }
public ItemStack getSmeltingResult(final ItemStack stack)
{
ItemStack res = override_result(stack);
if(res.isEmpty()) res = FurnaceRecipes.instance().getSmeltingResult(stack);
return res;
}
public float getSmeltingExperience(ItemStack stack)
{
float ret = stack.getItem().getSmeltingExperience(stack);
if(ret != -1) return ret;
for(Map.Entry<ItemStack, Float> e : experiences_.entrySet()) {
if(compare(stack, e.getKey())) return e.getValue();
}
return FurnaceRecipes.instance().getSmeltingExperience(stack);
}
public void add(Block input, ItemStack stack, float experience)
{ add(Item.getItemFromBlock(input), stack, experience); }
public void add(Item input, ItemStack stack, float experience)
{ add(new ItemStack(input, 1, 32767), stack, experience); }
public void add(ItemStack input, ItemStack stack, float xp)
{
// Forced override setting
if(input==ItemStack.EMPTY) return;
if(recipes_.containsKey(input)) recipes_.remove(input);
if(experiences_.containsKey(input)) experiences_.remove(input);
if((stack==null) || (stack==ItemStack.EMPTY)) return;
recipes_.put(input, stack);
experiences_.put(stack, xp);
}
public ItemStack override_result(ItemStack stack)
{
for(Map.Entry<ItemStack, ItemStack> e:recipes_.entrySet()) {
if(compare(stack, e.getKey())) return e.getValue();
}
return ItemStack.EMPTY;
}
private boolean compare(final ItemStack stack1, final ItemStack stack2)
{ return (stack2.getItem() == stack1.getItem()) && ((stack2.getMetadata() == 32767) || (stack2.getMetadata() == stack1.getMetadata())); }
}
}

View file

@ -149,20 +149,31 @@ public class ModBlocks
private static ArrayList<Block> registeredBlocks = new ArrayList<>();
@Nonnull
public static List getRegisteredBlocks()
public static List<Block> getRegisteredBlocks()
{ return Collections.unmodifiableList(registeredBlocks); }
// Invoked from CommonProxy.registerBlocks()
public static final void registerBlocks(RegistryEvent.Register<Block> event)
{
// Config based registry selection
int num_registrations_skipped = 0;
ArrayList<Block> allBlocks = new ArrayList<>();
Collections.addAll(allBlocks, modBlocks);
//if(Loader.isModLoaded("immersiveengineering")){}
if(ModConfig.zmisc.with_experimental) Collections.addAll(allBlocks, devBlocks);
for(Block e:allBlocks) registeredBlocks.add(e);
final boolean woor = ModConfig.isWithoutOptOutRegistration();
for(Block e:allBlocks) {
if((!woor) || (!ModConfig.isOptedOut(e))) {
registeredBlocks.add(e);
} else {
++num_registrations_skipped;
}
}
for(Block e:registeredBlocks) event.getRegistry().register(e);
ModEngineersDecor.logger.info("Registered " + Integer.toString(registeredBlocks.size()) + " blocks.");
if(num_registrations_skipped > 0) {
ModEngineersDecor.logger.info("Skipped registration of " + num_registrations_skipped + " blocks due to no-register-opt-out config.");
}
// TEs
GameRegistry.registerTileEntity(BlockDecorCraftingTable.BTileEntity.class, new ResourceLocation(ModEngineersDecor.MODID, "te_crafting_table"));
GameRegistry.registerTileEntity(BlockDecorFurnace.BTileEntity.class, new ResourceLocation(ModEngineersDecor.MODID, "te_small_lab_furnace"));

View file

@ -9,6 +9,7 @@
*/
package wile.engineersdecor.detail;
import net.minecraft.block.Block;
import wile.engineersdecor.ModEngineersDecor;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
@ -16,11 +17,85 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import wile.engineersdecor.blocks.*;
import javax.annotation.Nullable;
@Config(modid = ModEngineersDecor.MODID)
@Config.LangKey("engineersdecor.config.title")
public class ModConfig
{
@Config.Comment({"Allows disabling specific features."})
@Config.Name("Feature opt-outs")
public static final SettingsOptouts optout = new SettingsOptouts();
public static final class SettingsOptouts
{
@Config.Comment({"Disable clinker bricks and derived blocks."})
@Config.Name("Without clinker bricks")
@Config.RequiresMcRestart
public boolean without_clinker_bricks = false;
@Config.Comment({"Disable slag bricks and derived blocks."})
@Config.Name("Without slag bricks")
@Config.RequiresMcRestart
public boolean without_slag_bricks = false;
@Config.Comment({"Disable rebar concrete and derived blocks."})
@Config.Name("Without rebar concrete")
@Config.RequiresMcRestart
public boolean without_rebar_concrete = false;
@Config.Comment({"Disable all mod wall blocks."})
@Config.Name("Without walls")
@Config.RequiresMcRestart
public boolean without_walls = false;
@Config.Comment({"Disable all mod stairs blocks."})
@Config.Name("Without stairs")
@Config.RequiresMcRestart
public boolean without_stairs = false;
@Config.Comment({"Disable IE concrete wall."})
@Config.Name("Without concrete wall")
@Config.RequiresMcRestart
public boolean without_ie_concrete_wall = false;
@Config.Comment({"Disable panzer glass and derived blocks."})
@Config.Name("Without panzer glass")
@Config.RequiresMcRestart
public boolean without_panzer_glass = false;
@Config.Comment({"Disable treated wood crafting table."})
@Config.Name("Without crafting table")
@Config.RequiresMcRestart
public boolean without_crafting_table = false;
@Config.Comment({"Disable small lab furnace."})
@Config.Name("Without lab furnace")
@Config.RequiresMcRestart
public boolean without_lab_furnace = false;
@Config.Comment({"Disable treated wood table, stool, windowsill, pole, etc."})
@Config.Name("Without tr. wood furniture")
@Config.RequiresMcRestart
public boolean without_treated_wood_furniture = false;
@Config.Comment({"Disable treated wood window, etc."})
@Config.Name("Without windows")
@Config.RequiresMcRestart
public boolean without_windows = false;
@Config.Comment({"Disable light sources"})
@Config.Name("Without lights")
@Config.RequiresMcRestart
public boolean without_light_sources = false;
@Config.Comment({"Disable ladders"})
@Config.Name("Without ladders")
@Config.RequiresMcRestart
public boolean without_ladders = false;
}
@Config.Comment({
"Settings for beta testing and trouble shooting. Some of the settings " +
"may be moved to other categories after testing."
@ -31,7 +106,31 @@ public class ModConfig
{
@Config.Comment({ "Enables experimental features. Use at own risk." })
@Config.Name("With experimental")
@Config.RequiresMcRestart
public boolean with_experimental = false;
@Config.Comment({ "Disable all internal recipes, allowing to use alternative pack recipes." })
@Config.Name("Without recipes")
@Config.RequiresMcRestart
public boolean without_recipes = false;
@Config.Comment({"Disable registration of opt'ed out blocks. That is normally not a good idea. Your choice."})
@Config.Name("Without opt-out registration")
@Config.RequiresMcRestart
public boolean without_optout_registration = false;
}
@Config.Comment({"Tweaks and block behaviour adaptions."})
@Config.Name("Tweaks")
public static final SettingsTweaks tweaks = new SettingsTweaks();
public static final class SettingsTweaks
{
@Config.Comment({
"Smelts ores to nuggets that are normally smelted to ingots, " +
"if detectable in the Forge ore dict. Prefers IE recipe results."
})
@Config.Name("Furnace: Nugget smelting")
public boolean furnace_smelts_nuggets = false;
}
@SuppressWarnings("unused")
@ -42,11 +141,51 @@ public class ModConfig
public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) {
if(!event.getModID().equals(ModEngineersDecor.MODID)) return;
ConfigManager.sync(ModEngineersDecor.MODID, Config.Type.INSTANCE);
apply();
}
}
@SuppressWarnings("unused")
public static final void onPostInit(FMLPostInitializationEvent event)
{}
{ apply(); }
public static final boolean isWithoutOptOutRegistration()
{ return (zmisc!=null) && (zmisc.without_optout_registration); }
public static final boolean isWithoutRecipes()
{ return (zmisc==null) || (zmisc.without_recipes); }
public static final boolean isOptedOut(final @Nullable Block block)
{
if((block == null) || (optout==null)) return true;
final String rn = block.getRegistryName().getPath();
if(optout.without_clinker_bricks && rn.startsWith("clinker_brick_")) return true;
if(optout.without_slag_bricks && rn.startsWith("slag_brick_")) return true;
if(optout.without_rebar_concrete && rn.startsWith("rebar_concrete")) return true;
if(optout.without_ie_concrete_wall && rn.startsWith("concrete_wall")) return true;
if(optout.without_panzer_glass && rn.startsWith("panzerglass_")) return true;
if(optout.without_crafting_table && (block instanceof BlockDecorCraftingTable)) return true;
if(optout.without_lab_furnace && (block instanceof BlockDecorFurnace)) return true;
if(optout.without_windows && rn.endsWith("_window")) return true;
if(optout.without_light_sources && rn.endsWith("_light")) return true;
if(optout.without_ladders && (block instanceof BlockDecorLadder)) return true;
if(optout.without_walls && rn.endsWith("_wall")) return true;
if(optout.without_stairs && rn.endsWith("_stairs")) return true;
if(optout.without_treated_wood_furniture) {
if(block instanceof BlockDecorChair) return true;
if(rn.equals("treated_wood_pole")) return true;
if(rn.equals("treated_wood_table")) return true;
if(rn.equals("treated_wood_stool")) return true;
if(rn.equals("treated_wood_windowsill")) return true;
if(rn.equals("treated_wood_window")) return true;
}
return false;
}
public static final void apply()
{
ModRecipes.furnaceRecipeOverrideReset();
if(tweaks.furnace_smelts_nuggets) ModRecipes.furnaceRecipeOverrideSmeltsOresToNuggets();
}
}

View file

@ -0,0 +1,68 @@
/*
* @file ModAuxiliaries.java
* @author Stefan Wilhelm (wile)
* @copyright (C) 2018 Stefan Wilhelm
* @license MIT (see https://opensource.org/licenses/MIT)
*
* General commonly used functionality.
*/
package wile.engineersdecor.detail;
import wile.engineersdecor.ModEngineersDecor;
import wile.engineersdecor.blocks.BlockDecorFurnace;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.NonNullList;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraft.item.ItemStack;
import java.util.*;
public class ModRecipes
{
public static final void furnaceRecipeOverrideReset()
{ BlockDecorFurnace.BRecipes.instance().reset(); }
public static final void furnaceRecipeOverrideSmeltsOresToNuggets()
{
try {
ArrayList<String> ores = new ArrayList<String>();
ArrayList<String> ingots = new ArrayList<String>();
ArrayList<String> nuggets = new ArrayList<String>();
String[] names = OreDictionary.getOreNames();
for(String name:names) {
if(name.startsWith("ore")) ores.add(name);
if(name.startsWith("ingot")) ingots.add(name);
if(name.startsWith("nugget")) nuggets.add(name);
}
for(String ore_name:ores) {
final String ingot_name = ore_name.replace("ore", "ingot");
if(!ingots.contains(ingot_name)) continue;
final String nugget_name = ore_name.replace("ore", "nugget");
if(!nuggets.contains(nugget_name)) continue;
final NonNullList<ItemStack> ore_list = OreDictionary.getOres(ore_name, false);
final NonNullList<ItemStack> ingot_list = OreDictionary.getOres(ingot_name, false);
final NonNullList<ItemStack> nugget_list = OreDictionary.getOres(nugget_name, false);
if(ore_list.isEmpty() || ingot_list.isEmpty() || nugget_list.isEmpty()) continue;
final ItemStack ore_stack = ore_list.get(0);
final ItemStack ingot_stack = ingot_list.get(0);
ItemStack nugget_stack = nugget_list.get(0);
for(ItemStack stack:nugget_list) {
if(stack.getItem().getRegistryName().getNamespace() == "immersiveengineering") {
nugget_stack = stack;
break;
}
}
if(ore_stack.isEmpty() || ingot_stack.isEmpty() || nugget_stack.isEmpty()) continue;
if(FurnaceRecipes.instance().getSmeltingResult(ore_stack).getItem().equals(ingot_stack.getItem())) {
final float xp = FurnaceRecipes.instance().getSmeltingExperience(ore_stack);
BlockDecorFurnace.BRecipes.instance().add(ore_stack, nugget_stack, xp);
ModEngineersDecor.logger.info("Lab furnace override: " + ore_name + " -> " + nugget_name);
}
}
} catch(Throwable e) {
ModEngineersDecor.logger.error("Lab furnace override failed with exception, skipping further override processing.");
ModEngineersDecor.logger.error("Exception is: ", e);
}
}
}

View file

@ -29,8 +29,14 @@ public class RecipeCondModSpecific implements IConditionFactory
public static final BooleanSupplier RECIPE_INCLUDE = ()->true;
public static final BooleanSupplier RECIPE_EXCLUDE = ()->false;
public static int num_skipped = 0;
private static BooleanSupplier exclude()
{ ++num_skipped; return RECIPE_EXCLUDE; }
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json) {
if(ModConfig.isWithoutRecipes()) return exclude();
try {
final IForgeRegistry<Block> block_registry = ForgeRegistries.BLOCKS;
final IForgeRegistry<Item> item_registry = ForgeRegistries.ITEMS;
@ -39,13 +45,14 @@ public class RecipeCondModSpecific implements IConditionFactory
for(JsonElement e: items) {
if(!e.isJsonPrimitive()) continue;
final ResourceLocation rl = new ResourceLocation(((JsonPrimitive)e).getAsString());
if((!block_registry.containsKey(rl)) && (!item_registry.containsKey(rl))) return RECIPE_EXCLUDE; // required item not registered
if((!block_registry.containsKey(rl)) && (!item_registry.containsKey(rl))) return exclude(); // required item not registered
}
}
final JsonPrimitive result = json.getAsJsonPrimitive("result");
if(result != null) {
final ResourceLocation rl = new ResourceLocation(result.getAsString());
if((!block_registry.containsKey(rl)) && (!item_registry.containsKey(rl))) return RECIPE_EXCLUDE; // required result not registered
if((!block_registry.containsKey(rl)) && (!item_registry.containsKey(rl))) return exclude(); // required result not registered
if(ModConfig.isOptedOut(block_registry.getValue(rl))) return exclude(); // disabled in mod config
}
final JsonArray missing = json.getAsJsonArray("missing");
if((missing!=null) && (missing.size() > 0)) {
@ -55,15 +62,15 @@ public class RecipeCondModSpecific implements IConditionFactory
// At least one item missing, enable this recipe as alternative recipe for another one that check the missing item as required item.
// --> e.g. if IE not installed there is no slag. One recipe requires slag, and another one (for the same result) is used if there
// is no slag.
if((!block_registry.containsKey(rl)) && (!item_registry.containsKey(rl))) return RECIPE_INCLUDE;
if((!block_registry.containsKey(rl)) && (!item_registry.containsKey(rl))) return exclude();
}
return RECIPE_EXCLUDE; // all required there, but there is no item missing, so another recipe
return exclude(); // all required there, but there is no item missing, so another recipe
} else {
return RECIPE_INCLUDE; // no missing given, means include if result and required are all there.
}
} catch(Throwable ex) {
ModEngineersDecor.logger.error("rsgauges::ResultRegisteredCondition failed: " + ex.toString());
}
return RECIPE_EXCLUDE; // skip on exception.
return exclude(); // skip on exception.
}
}

View file

@ -0,0 +1,43 @@
/*
* @file JEIPlugin.java
* @author Stefan Wilhelm (wile)
* @copyright (C) 2019 Stefan Wilhelm
* @license MIT (see https://opensource.org/licenses/MIT)
*
* JEI plugin (see https://github.com/mezz/JustEnoughItems/wiki/Creating-Plugins)
*/
package wile.engineersdecor.eapi.jei;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import wile.engineersdecor.ModEngineersDecor;
import wile.engineersdecor.blocks.ModBlocks;
import wile.engineersdecor.detail.ModConfig;
@mezz.jei.api.JEIPlugin
public class JEIPlugin implements mezz.jei.api.IModPlugin
{
@Override
@SuppressWarnings("deprecation")
public void register(mezz.jei.api.IModRegistry registry)
{
try {
for(Block e:ModBlocks.getRegisteredBlocks()) {
if(ModConfig.isOptedOut(e)) {
ItemStack stack = new ItemStack(Item.getItemFromBlock(e));
if(stack != null) {
if(!registry.getJeiHelpers().getIngredientBlacklist().isIngredientBlacklisted(stack)) {
registry.getJeiHelpers().getIngredientBlacklist().addIngredientToBlacklist(stack);
}
if(!registry.getJeiHelpers().getItemBlacklist().isItemBlacklisted(stack)) {
registry.getJeiHelpers().getItemBlacklist().addItemToBlacklist(stack);
}
}
}
}
} catch(Throwable e) {
ModEngineersDecor.logger.warn("Exception in JEI opt-out processing: '" + e.getMessage() + "', skipping further JEI processing.");
}
}
}