feat: implement bullshitless recipe system
This commit is contained in:
parent
5ff5eb668d
commit
8e94b921bd
5 changed files with 102 additions and 1 deletions
src/main
java/net/anvilcraft/ntx4core
resources
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
31
src/main/java/net/anvilcraft/ntx4core/RecipesEvent.java
Normal file
31
src/main/java/net/anvilcraft/ntx4core/RecipesEvent.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -3,7 +3,9 @@
|
|||
"package": "net.anvilcraft.ntx4core.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"mixins": [],
|
||||
"mixins": [
|
||||
"common.RecipeManagerMixin"
|
||||
],
|
||||
"client": [
|
||||
"client.SplashOverlayMixin",
|
||||
"client.TitleScreenMixin"
|
||||
|
|
Loading…
Add table
Reference in a new issue