Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.examplemod;
- import net.java.games.input.Controller;
- import net.java.games.input.Keyboard;
- import net.minecraft.block.Block;
- import net.minecraft.block.Blocks;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.settings.KeyBinding;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.util.Hand;
- import net.minecraft.util.text.StringTextComponent;
- import net.minecraftforge.client.event.GuiScreenEvent;
- import net.minecraftforge.client.event.InputEvent;
- import net.minecraftforge.common.MinecraftForge;
- import net.minecraftforge.event.RegistryEvent;
- import net.minecraftforge.event.TickEvent;
- import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
- import net.minecraftforge.eventbus.api.SubscribeEvent;
- import net.minecraftforge.fml.InterModComms;
- import net.minecraftforge.fml.client.registry.ClientRegistry;
- 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 javax.swing.*;
- import javax.xml.crypto.dsig.keyinfo.KeyValue;
- import java.security.Key;
- import java.util.stream.Collectors;
- // The value here should match an entry in the META-INF/mods.toml file
- @Mod("examplemod")
- public class ExampleMod
- {
- // Directly reference a log4j logger.
- private static final Logger LOGGER = LogManager.getLogger();
- public static KeyBinding[] keyBindings;
- Minecraft mc = Minecraft.getInstance();
- public ExampleMod() {
- // Register the setup method for modloading
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
- // Register the enqueueIMC method for modloading
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
- // Register the processIMC method for modloading
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
- // Register the doClientStuff method for modloading
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
- keyBindings = new KeyBinding[3];
- keyBindings[0] = something..
- keyBindings[1] = another thing
- keyBindings[2] = aand another one
- // Register ourselves for server and other game events we are interested in
- MinecraftForge.EVENT_BUS.register(this);
- MinecraftForge.EVENT_BUS.register(new RegistryEvents());
- // some example code
- LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
- for (int i = 0; i < keyBindings.length; ++i)
- {
- ClientRegistry.registerKeyBinding(keyBindings[i]);
- }
- }
- private void setup(final FMLCommonSetupEvent event)
- {
- Oher stuff
- }
- private void doClientStuff(final FMLClientSetupEvent event) {
- // do something that can only be done on the client
- LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
- }
- private void enqueueIMC(final InterModEnqueueEvent event)
- {
- // some example code to dispatch IMC to another mod
- InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
- }
- private void processIMC(final InterModProcessEvent event)
- {
- // some example code to receive and process InterModComms from other mods
- LOGGER.info("Got IMC {}", event.getIMCStream().
- map(m->m.getMessageSupplier().get()).
- collect(Collectors.toList()));
- }
- // You can use SubscribeEvent and let the Event Bus discover methods to call
- @SubscribeEvent
- public void onServerStarting(FMLServerStartingEvent event) {
- // do something when the server starts
- LOGGER.info("HELLO from server starting");
- }
- A VOID HERE
- // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
- // Event bus for receiving Registry Events)
- @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
- public class RegistryEvents {
- @SubscribeEvent
- public void onKey(InputEvent.KeyInputEvent e){
- System.out.println("KEY!");
- [...]
- WORKING PERFECTLY FINE.
- }
- @SubscribeEvent
- public void onKb (LivingKnockBackEvent e) {
- System.out.println("test1");
- Not working at all
- }
- @SubscribeEvent
- public void onTick (TickEvent.ClientTickEvent tick) {
- this also working
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement