The "Cannot resolve symbol 'EventBusSubscriber'" error is likely due to a missing or incorrect import.
The @Mod.EventBusSubscriber annotation is part of the net.neoforged.fml.common.Mod class. You have already imported it correctly.
However, if you're still experiencing issues, here are a few potential solutions:
-
Check your NeoForge version: Ensure that you're using the correct version of NeoForge (1.21) and that your mod is correctly set up for this version.
-
Clean and rebuild your project: Sometimes, IDEs can get out of sync with the project's state. Try cleaning and rebuilding your project.
-
Check your dependencies: Make sure that your build.gradle or pom.xml file is correctly configured to include the necessary NeoForge dependencies.
-
IDE Configuration: If you're using an IDE like IntelliJ or Eclipse, try invalidating the cache and restarting the IDE. This can sometimes resolve issues with unresolved symbols.
Here's your code again with some minor adjustments for clarity:
package net.mattias.cobblesnapshot.util;
import net.mattias.cobblesnapshot.CobbleSnapshot;
import net.mattias.cobblesnapshot.event.ScreenshotHandler;
import net.mattias.cobblesnapshot.item.ModItems;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.world.item.ItemStack;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod.EventBusSubscriber;
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
import org.lwjgl.glfw.GLFW;
@EventBusSubscriber(modid = CobbleSnapshot.MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ScreenshotKeybind {
public static final KeyMapping TAKE_SNAPSHOT = new KeyMapping(
"key.cobblesnapshot.take_snapshot",
GLFW.GLFW_KEY_P,
"key.categories.misc"
);
@SubscribeEvent
public static void registerKeybindings(RegisterKeyMappingsEvent event) {
event.register(TAKE_SNAPSHOT);
}
@EventBusSubscriber(modid = CobbleSnapshot.MOD_ID, value = Dist.CLIENT)
public static class ClientForgeEvents {
@SubscribeEvent
public static void onKeyInput(InputEvent.Key event) {
Minecraft mc = Minecraft.getInstance();
if (TAKE_SNAPSHOT.consumeClick() && mc.player != null) {
ItemStack imageFilm = new ItemStack(ModItems.IMAGE_FILM.get());
ScreenshotHandler.captureScreenshot(imageFilm);
if (!mc.player.getInventory().add(imageFilm)) {
mc.player.drop(imageFilm, false);
}
}
}
}
}