ReAdd disabling of machines crafting recipes

This commit is contained in:
Tom Elfring committed 2017-07-10 13:33:40 +02:00
1 parent 8cb3d73b39
commit 2b44ab8666
77 files changed
+469 -68

No files matched your search

@@ -612,8 +612,6 @@ public class CommonProxy implements IGuiProvider
}
BlockStateMachine.MachineType.updateAllUsages();
TypeConfigManager.updateConfigRecipes(MachineType.getValidMachines(), general.machinesManager);
if(fromPacket)
{
+5 -8
View File
@@ -281,7 +281,7 @@ public class Mekanism
*/
public void addRecipes()
{
if(false) // Generate JSON files from code, disabled.
if(true) // Generate JSON files from code, disabled.
{
MekanismRecipes.generate();
MekanismToolsRecipes.generate();
@@ -700,6 +700,10 @@ public class Mekanism
//Set the mod's configuration
configuration = new Configuration(config);
//Load configuration
proxy.loadConfiguration();
proxy.onConfigSync(false);
//Register tier information
Tier.init();
@@ -775,10 +779,6 @@ public class Mekanism
//Register with TransmitterNetworkRegistry
TransmitterNetworkRegistry.initiate();
//Load configuration
proxy.loadConfiguration();
proxy.onConfigSync(false);
//Add baby skeleton spawner
if(general.spawnBabySkeletons)
{
@@ -836,9 +836,6 @@ public class Mekanism
OreDictManager.init();
//Update the config-dependent recipes after the recipes have actually been added in the first place
TypeConfigManager.updateConfigRecipes(MachineType.getValidMachines(), general.machinesManager);
logger.info("Hooking complete.");
}
@@ -198,24 +198,6 @@ public class BlockStateMachine extends ExtendedBlockState
return general.machinesManager.isEnabled(blockName);
}
// @Override
// public void addRecipes(Collection<ShapedMekanismRecipe> recipes)
// {
// blockRecipes.addAll(recipes);
// }
//
// @Override
// public void addRecipe(ShapedMekanismRecipe recipe)
// {
// blockRecipes.add(recipe);
// }
//
// @Override
// public Collection<ShapedMekanismRecipe> getRecipes()
// {
// return blockRecipes;
// }
public static List<MachineType> getValidMachines()
{
List<MachineType> ret = new ArrayList<MachineType>();
@@ -20,21 +20,4 @@ public class TypeConfigManager
{
config.put(type, enabled);
}
public static void updateConfigRecipes(List blocks, TypeConfigManager manager)
{
for(Object obj : blocks) //enums are quirky
{
IBlockType type = (IBlockType)obj;
if(manager.isEnabled(type.getBlockName()))
{
// CraftingManager.getInstance().getRecipeList().removeAll(type.getRecipes());
// CraftingManager.getInstance().getRecipeList().addAll(type.getRecipes());
}
else {
// CraftingManager.getInstance().getRecipeList().removeAll(type.getRecipes());
}
}
}
}
@@ -0,0 +1,31 @@
package mekanism.common.recipe;
import com.google.gson.JsonObject;
import mekanism.common.Mekanism;
import mekanism.common.config.MekanismConfig;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.JsonContext;
import java.util.function.BooleanSupplier;
public class MekanismRecipeEnabledCondition implements IConditionFactory
{
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json)
{
String machineType = JsonUtils.getString(json, "machineType");
if(!machineType.isEmpty())
{
return () -> MekanismConfig.general.machinesManager.isEnabled(machineType);
}
String generatorType = JsonUtils.getString(json, "generatorType");
if(!generatorType.isEmpty())
{
return () -> MekanismConfig.generators.generatorsManager.isEnabled(generatorType);
}
throw new IllegalStateException("Config defined with machine_enabled condition without a machine/generator type!");
}
}
@@ -3,6 +3,10 @@ package mekanism.common.recipe.generation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine;
import mekanism.common.block.states.BlockStateMachine;
import mekanism.common.item.ItemBlockMachine;
import mekanism.generators.common.block.states.BlockStateGenerator;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -82,6 +86,24 @@ public class RecipeGenerator {
return;
}
// Add machine_enabled condition to all available machine types.
BlockStateMachine.MachineType machineType = BlockStateMachine.MachineType.get(result);
if(machineType != null) {
Map<String, String> condition = new HashMap<>();
condition.put("type", "machine_enabled");
condition.put("machineType", machineType.blockName);
json.put("conditions", new Object[]{condition});
}
// Add machine_enabled condition to generator types which can be disabled.
BlockStateGenerator.GeneratorType generatorType = BlockStateGenerator.GeneratorType.get(result);
if(generatorType != null && result.getItemDamage() <= BlockStateGenerator.GeneratorType.WIND_GENERATOR.meta) {
Map<String, String> condition = new HashMap<>();
condition.put("type", "machine_enabled");
condition.put("generatorType", generatorType.blockName);
json.put("conditions", new Object[]{condition});
}
// names the json the same name as the output's registry name
// repeatedly adds _alt if a file already exists
// janky I know but it works
@@ -126,9 +126,6 @@ public class MekanismGenerators implements IModule
BuildcraftFuelRegistry.fuel.addFuel(MekanismFluids.Ethene.getFluid(), (int)(240 * general.TO_RF), 40 * Fluid.BUCKET_VOLUME);
}
//Update the config-dependent recipes after the recipes have actually been added in the first place
TypeConfigManager.updateConfigRecipes(GeneratorType.getGeneratorsForConfig(), generators.generatorsManager);
for(ItemStack ore : OreDictionary.getOres("dustGold"))
{
RecipeHandler.addMetallurgicInfuserRecipe(InfuseRegistry.get("CARBON"), 10, MekanismUtils.size(ore, 4), GeneratorsItems.Hohlraum.getEmptyItem());
@@ -222,7 +219,6 @@ public class MekanismGenerators implements IModule
if(event.getModID().equals("mekanismgenerators"))
{
proxy.loadConfiguration();
TypeConfigManager.updateConfigRecipes(GeneratorType.getGeneratorsForConfig(), generators.generatorsManager);
}
}
}
@@ -122,7 +122,6 @@ public class BlockStateGenerator extends ExtendedBlockState
public double maxEnergy;
public Class<? extends TileEntity> tileEntityClass;
public boolean hasModel;
// public Collection<ShapedMekanismRecipe> blockRecipes = new HashSet<ShapedMekanismRecipe>();
public Predicate<EnumFacing> facingPredicate;
public boolean activable;
@@ -171,24 +170,6 @@ public class BlockStateGenerator extends ExtendedBlockState
return generators.generatorsManager.isEnabled(blockName);
}
// @Override
// public void addRecipes(Collection<ShapedMekanismRecipe> recipes)
// {
// blockRecipes.addAll(recipes);
// }
//
// @Override
// public void addRecipe(ShapedMekanismRecipe recipe)
// {
// blockRecipes.add(recipe);
// }
//
// @Override
// public Collection<ShapedMekanismRecipe> getRecipes()
// {
// return blockRecipes;
// }
public static GeneratorType get(IBlockState state)
{
if(state.getBlock() instanceof BlockGenerator)