Skip to content

Commit

Permalink
修复forge recipes注册
Browse files Browse the repository at this point in the history
  • Loading branch information
DancingSnow0517 committed Apr 13, 2024
1 parent 4454e8f commit 31d02da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.config.AnvilCraftConfig;
import dev.dubhe.anvilcraft.init.ModCommands;
import dev.dubhe.anvilcraft.init.forge.ModRecipeTypesForge;
import dev.dubhe.anvilcraft.util.BlockHighlightUtil;
import me.shedaniel.autoconfig.AutoConfig;
import net.minecraft.client.Minecraft;
Expand All @@ -11,8 +12,10 @@
import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.jetbrains.annotations.NotNull;

@Mod(AnvilCraft.MOD_ID)
Expand All @@ -22,20 +25,23 @@ public class AnvilCraftForge {
*/
public AnvilCraftForge() {
AnvilCraft.init();
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
bus.addListener(ModRecipeTypesForge::register);

MinecraftForge.EVENT_BUS.addListener(AnvilCraftForge::registerCommand);
MinecraftForge.EVENT_BUS.addListener((RenderLevelStageEvent event) -> {
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_ENTITIES) return;
if (BlockHighlightUtil.SUBCHUNKS.isEmpty()) return;
ClientLevel level = Minecraft.getInstance().level;
if (level == null) return;
BlockHighlightUtil.render(level, Minecraft.getInstance().renderBuffers().bufferSource(),
event.getPoseStack(), event.getCamera());
event.getPoseStack(), event.getCamera());
});

ModLoadingContext.get().registerExtensionPoint(
ConfigScreenHandler.ConfigScreenFactory.class,
() -> new ConfigScreenHandler.ConfigScreenFactory(
(mc, screen) -> AutoConfig.getConfigScreen(AnvilCraftConfig.class, screen).get()
(mc, screen) -> AutoConfig.getConfigScreen(AnvilCraftConfig.class, screen).get()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@
import dev.dubhe.anvilcraft.init.ModRecipeTypes;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;

import java.util.Map;

@Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID)
public class ModRecipeTypesForge {
/**
* 注册配方类型
*
* @param event 事件
*/
@SubscribeEvent
public static void register(RegisterEvent event) {
System.out.println("Registering AnvilCraft recipes");
for (Map.Entry<String, Pair<RecipeSerializer<?>, RecipeType<?>>> entry
: ModRecipeTypes.RECIPE_TYPES.entrySet()) {
: ModRecipeTypes.RECIPE_TYPES.entrySet()) {
if (entry.getValue().getFirst() != null) {
event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, (helper) ->
helper.register(AnvilCraft.of(entry.getKey()), entry.getValue().getFirst()));
helper.register(AnvilCraft.of(entry.getKey()), entry.getValue().getFirst()));
}
if (entry.getValue().getSecond() != null) {
event.register(ForgeRegistries.Keys.RECIPE_TYPES, (helper) ->
helper.register(AnvilCraft.of(entry.getKey()), entry.getValue().getSecond()));
helper.register(AnvilCraft.of(entry.getKey()), entry.getValue().getSecond()));
}
}
}
Expand Down

0 comments on commit 31d02da

Please sign in to comment.