Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5092] CraftingFactoriesRegisterEvent & Allow for actual Resource Locations #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

import javax.annotation.Nonnull;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CraftingFactoriesRegisterEvent;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -589,7 +591,11 @@ private static <T> void loadFactory(JsonObject json, JsonContext context, Factor
{
for (Entry<String, JsonElement> entry : JsonUtils.getJsonObject(json, loader.name).entrySet())
{
ResourceLocation key = new ResourceLocation(context.getModId(), entry.getKey());
ResourceLocation key;
if (entry.getKey().contains(":")){
key = new ResourceLocation(entry.getKey());
}else key = new ResourceLocation(context.getModId(), entry.getKey());

String clsName = JsonUtils.getString(entry.getValue(), loader.name + "[" + entry.getValue() + "]");
loader.consumer.accept(key, getClassInstance(clsName, loader.type));
}
Expand Down Expand Up @@ -630,6 +636,7 @@ else if (revertFrozen)
//ModContainer old = Loader.instance().activeModContainer();
Loader.instance().setActiveModContainer(null);
Loader.instance().getActiveModList().forEach(CraftingHelper::loadFactories);
MinecraftForge.EVENT_BUS.post(new CraftingFactoriesRegisterEvent(conditions, ingredients, recipes));
Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes);
Loader.instance().setActiveModContainer(null);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.minecraftforge.event;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.IIngredientFactory;
import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.fml.common.eventhandler.Event;

import java.util.Map;

public class CraftingFactoriesRegisterEvent extends Event {
public CraftingFactoriesRegisterEvent(Map<ResourceLocation, IConditionFactory> m1, Map<ResourceLocation, IIngredientFactory> m2, Map<ResourceLocation, IRecipeFactory> m3){
conditions=m1;
ingredients=m2;
recipes=m3;
}
private final Map<ResourceLocation, IConditionFactory> conditions;
private final Map<ResourceLocation, IIngredientFactory> ingredients;
private final Map<ResourceLocation, IRecipeFactory> recipes;
public void register(ResourceLocation name, IConditionFactory fac) {
conditions.put(name, fac);
}
public IConditionFactory unregisterC(ResourceLocation name) {
return conditions.remove(name);
}
public void register(ResourceLocation name, IRecipeFactory fac) {
recipes.put(name, fac);
}
public IRecipeFactory unregisterR(ResourceLocation name) {
return recipes.remove(name);
}
public void register(ResourceLocation name, IIngredientFactory fac) {
ingredients.put(name, fac);
}
public IIngredientFactory unregisterI(ResourceLocation name) {
return ingredients.remove(name);
}
}