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
Changes from 1 commit
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
Next Next commit
fix MinecraftForge#5092 and enable coding register
Ecdcaeb committed Feb 24, 2024
commit 71a520e8a99e8780d153b0ace59d2d056a694130
Original file line number Diff line number Diff line change
@@ -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;

@@ -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));
}
@@ -633,6 +639,8 @@ else if (revertFrozen)
Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes);
Loader.instance().setActiveModContainer(null);

MinecraftForge.EVENT_BUS.post(new CraftingFactoriesRegisterEvent(conditions, ingredients, recipes));

GameData.fireRegistryEvents(rl -> rl.equals(GameData.RECIPES));

//reg.freeze();
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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;

/**
* @Project Cleanroom
* @Author Hileb
* @Date 2024/2/24 15:54
**/
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);
}
}