Jump to content

Recommended Posts

Posted (edited)

I was making a mod and I gave up because I don't understand what they mean. So can someone explain what each thing does in a mod?

here's the code:

package com.jun2040.sourcemod;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

@Mod("sourcemod")
public class SourceMod {
    private static final Logger LOGGER = LogManager.getLogger();

    public SourceMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {

    }

    private void doClientStuff(final FMLClientSetupEvent event) {

    }

    private void enqueueIMC(final InterModEnqueueEvent event) {

    }

    private void processIMC(final InterModProcessEvent event) {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m -> m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }

    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        LOGGER.info("HELLO from server starting");
    }

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            LOGGER.info("HELLO from Register Block");
        }
    }
}
Edited by jun2040
Posted

The @Mod annotation sets some values for your mod and marks the class it annotates as the entrance point to your mod.

More information

You've got a bunch of events that are being set up, and the methods that will be run when each event triggers.

More information

The most important among them would probably be the registry events (you've got only one at the moment: the Block event).

More information on registries

The annotation above your RegistryEvents class registers the method within (marked with @SubscribeEvent) to the Forge event bus, meaning it will be called when the Block registry event is fired (instead of never).

 

Basically, you set up some information in @Mod, can do things that need to be done inside the events, and register Blocks and Items inside the registry events.

If you have a more specific question I'd be happy to answer it if I can, but in general I'd just suggest reading the Documentation and other sources to learn what things do.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted
8 hours ago, SerpentDagger said:

The @Mod annotation sets some values for your mod and marks the class it annotates as the entrance point to your mod.

More information

You've got a bunch of events that are being set up, and the methods that will be run when each event triggers.

More information

The most important among them would probably be the registry events (you've got only one at the moment: the Block event).

More information on registries

The annotation above your RegistryEvents class registers the method within (marked with @SubscribeEvent) to the Forge event bus, meaning it will be called when the Block registry event is fired (instead of never).

 

Basically, you set up some information in @Mod, can do things that need to be done inside the events, and register Blocks and Items inside the registry events.

If you have a more specific question I'd be happy to answer it if I can, but in general I'd just suggest reading the Documentation and other sources to learn what things do.

Can you tell me what setup, doClientStuff, enqueueIMC, and processIMC does and how to use them?

Thx!

Posted
26 minutes ago, jun2040 said:

setup, doClientStuff, enqueueIMC, and processIMC does and how to use them?

The first three are empty methods, so they currently do nothing. 

"setup" is just a generic point in time to do "setup" style tasks. It's called setup because the event that fires it is the FMLCommonSetupEvent.

 

The Two IMC methods are for handling IMC things: Inter Mod Communication. In this case the mod only receives messages and simply logs them to the log file. Some older info can be found here. The events have changed, but the usage is the same.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.