feat: implement bullshitless recipe system

This commit is contained in:
LordMZTE 2023-10-14 18:32:34 +02:00
parent 5ff5eb668d
commit 8e94b921bd
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 102 additions and 1 deletions
src/main

View file

@ -3,6 +3,7 @@ package net.anvilcraft.ntx4core;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.util.Identifier;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
@ -27,4 +28,8 @@ public class Ntx4Core {
private void commonSetup(final FMLCommonSetupEvent event) {}
private void clientSetup(final FMLClientSetupEvent event) {}
public static Identifier id(String s) {
return new Identifier(MODID, s);
}
}

View file

@ -0,0 +1,31 @@
package net.anvilcraft.ntx4core;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.util.Identifier;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.IModBusEvent;
public class RecipesEvent extends Event implements IModBusEvent {
public Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes;
public Map<Identifier, Recipe<?>> recipesById;
public RecipesEvent(
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes,
Map<Identifier, Recipe<?>> recipesById
) {
this.recipes = recipes;
this.recipesById = recipesById;
}
public void registerRecipe(Recipe<?> recipe) {
if (!this.recipes.containsKey(recipe.getType()))
this.recipes.put(recipe.getType(), new HashMap<>());
this.recipes.get(recipe.getType()).put(recipe.getId(), recipe);
this.recipesById.put(recipe.getId(), recipe);
}
}

View file

@ -0,0 +1,48 @@
package net.anvilcraft.ntx4core.mixin.common;
import java.util.HashMap;
import java.util.Map;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.google.gson.JsonElement;
import net.anvilcraft.ntx4core.Ntx4Core;
import net.anvilcraft.ntx4core.RecipesEvent;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.RecipeType;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
import net.minecraftforge.fml.ModLoader;
@Mixin(RecipeManager.class)
public class RecipeManagerMixin {
@Shadow
private Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes;
@Shadow
private Map<Identifier, Recipe<?>> recipesById;
@Inject(method = "apply", at = @At("RETURN"))
private void afterLoad(
Map<Identifier, JsonElement> alec1,
ResourceManager alec2,
Profiler alec3,
CallbackInfo ci
) {
Ntx4Core.LOGGER.info("Firing Recipe Event");
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes = new HashMap<>();
this.recipes.forEach((k, v) -> recipes.put(k, new HashMap<>(v)));
var ev = new RecipesEvent(recipes, new HashMap<>(this.recipesById));
ModLoader.get().postEvent(ev);
this.recipes = ev.recipes;
this.recipesById = ev.recipesById;
}
}

View file

@ -0,0 +1,15 @@
package net.anvilcraft.ntx4core.recipes;
import net.anvilcraft.ntx4core.Ntx4Core;
import net.anvilcraft.ntx4core.RecipesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
@EventBusSubscriber(modid = Ntx4Core.MODID, bus = Bus.MOD)
public class ShapelessRecipes {
@SubscribeEvent
public static void onRecipeRegister(RecipesEvent ev) {
// TODO
}
}

View file

@ -3,7 +3,9 @@
"package": "net.anvilcraft.ntx4core.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"mixins": [],
"mixins": [
"common.RecipeManagerMixin"
],
"client": [
"client.SplashOverlayMixin",
"client.TitleScreenMixin"