Files
Stalinium/src/main/java/net/krituximon/stalinium/Stalinium.java
T
IM23a-spirgif 7007a9684b Added StaliniumCharge effect and integrated it with sword.
- Created `StaliniumChargeEffect` with speed/knockback buffs.
- Registered `ModEffects` and `StaliniumChargeEffect`.
- Updated `StaliniumSwordItem` to apply the custom effect and added cooldown handling.
- Simplified effect logic, replacing vanilla effects with the custom one.
- Ensured sword remains unbreakable.
2025-05-26 17:09:26 +02:00

134 lines
5.8 KiB
Java

package net.krituximon.stalinium;
import net.krituximon.stalinium.block.ModBlocks;
import net.krituximon.stalinium.block.entity.ModBlockEntities;
import net.krituximon.stalinium.datagen.ModEffects;
import net.krituximon.stalinium.item.ModCreativeModeTabs;
import net.krituximon.stalinium.item.ModItems;
import net.krituximon.stalinium.particle.BloodParticle;
import net.krituximon.stalinium.particle.ModParticles;
import net.krituximon.stalinium.screen.ModMenuTypes;
import net.krituximon.stalinium.screen.custom.StaliniumPressMenu;
import net.krituximon.stalinium.screen.custom.StaliniumPressScreen;
import net.krituximon.stalinium.sound.ModSounds;
import net.krituximon.stalinium.util.PlacedLogStorage;
import net.krituximon.stalinium.util.PlayerLogEvents;
import net.krituximon.stalinium.worldgen.ModFeatures;
import net.krituximon.stalinium.worldgen.StaliniumVeinFeature;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import static net.krituximon.stalinium.worldgen.ModFeatures.FEATURES;
// The value here should match an entry in the META-INF/neoforge.mods.toml file
@Mod(Stalinium.MODID)
public class Stalinium
{
// Define mod id in a common place for everything to reference
public static final String MODID = "stalinium";
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
// Create a Deferred Register to hold Blocks which will all be registered under the "stalinium" namespace
// The constructor for the mod class is the first code that is run when your mod is loaded.
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
public Stalinium(IEventBus modEventBus, ModContainer modContainer)
{
// Register the commonSetup method for modloading
modEventBus.addListener(this::commonSetup);
ModItems.register(modEventBus);
ModBlocks.register(modEventBus);
ModSounds.register(modEventBus);
ModParticles.register(modEventBus);
ModCreativeModeTabs.register(modEventBus);
PlayerLogEvents.register();
// Register ourselves for server and other game events we are interested in.
// Note that this is necessary if and only if we want *this* class (Stalinium) to respond directly to events.
// Do not add this line if there are no @SubscribeEvent-annotated functions in this class, like onServerStarting() below.
NeoForge.EVENT_BUS.register(this);
// Register the item to a creative tab
modEventBus.addListener(this::addCreative);
// Register our mod's ModConfigSpec so that FML can create and load the config file for us
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
ModFeatures.register(modEventBus);
ModBlockEntities.register(modEventBus);
ModMenuTypes.register(modEventBus);
ModEffects.register(modEventBus);
}
private void commonSetup(final FMLCommonSetupEvent event)
{
// Some common setup code
LOGGER.info("HELLO FROM COMMON SETUP");
if (Config.logDirtBlock)
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));
LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);
Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
}
// Add the example block item to the building blocks tab
private void addCreative(BuildCreativeModeTabContentsEvent event)
{
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event)
{
// Do something when the server starts
LOGGER.info("HELLO from server starting");
}
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
@EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents
{
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event)
{
// Some client setup code
LOGGER.info("HELLO FROM CLIENT SETUP");
LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
}
@SubscribeEvent
public static void registerParticleFactories(RegisterParticleProvidersEvent event) {
event.registerSpriteSet(ModParticles.BLOOD_PARTICLE.get(), BloodParticle.Provider::new);
}
@SubscribeEvent
public static void registerScreens(RegisterMenuScreensEvent event) {
event.register(ModMenuTypes.STALINIUM_PRESS_MENU.get(), StaliniumPressScreen::new);
}
}
}