Advertisement
Sch0ll3r

Untitled

Apr 29th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import net.java.games.input.Controller;
  4. import net.java.games.input.Keyboard;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.Blocks;
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.client.settings.KeyBinding;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.player.PlayerEntity;
  11. import net.minecraft.util.Hand;
  12. import net.minecraft.util.text.StringTextComponent;
  13. import net.minecraftforge.client.event.GuiScreenEvent;
  14. import net.minecraftforge.client.event.InputEvent;
  15. import net.minecraftforge.common.MinecraftForge;
  16. import net.minecraftforge.event.RegistryEvent;
  17. import net.minecraftforge.event.TickEvent;
  18. import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
  19. import net.minecraftforge.eventbus.api.SubscribeEvent;
  20. import net.minecraftforge.fml.InterModComms;
  21. import net.minecraftforge.fml.client.registry.ClientRegistry;
  22. import net.minecraftforge.fml.common.Mod;
  23. import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
  24. import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
  25. import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
  26. import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
  27. import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
  28. import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
  29. import org.apache.logging.log4j.LogManager;
  30. import org.apache.logging.log4j.Logger;
  31.  
  32.  
  33. import javax.swing.*;
  34. import javax.xml.crypto.dsig.keyinfo.KeyValue;
  35. import java.security.Key;
  36. import java.util.stream.Collectors;
  37.  
  38. // The value here should match an entry in the META-INF/mods.toml file
  39. @Mod("examplemod")
  40. public class ExampleMod
  41. {
  42. // Directly reference a log4j logger.
  43. private static final Logger LOGGER = LogManager.getLogger();
  44.  
  45. public static KeyBinding[] keyBindings;
  46. Minecraft mc = Minecraft.getInstance();
  47.  
  48. public ExampleMod() {
  49. // Register the setup method for modloading
  50. FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
  51. // Register the enqueueIMC method for modloading
  52. FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
  53. // Register the processIMC method for modloading
  54. FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
  55. // Register the doClientStuff method for modloading
  56. FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
  57. keyBindings = new KeyBinding[3];
  58.  
  59. keyBindings[0] = something..
  60. keyBindings[1] = another thing
  61. keyBindings[2] = aand another one
  62. // Register ourselves for server and other game events we are interested in
  63. MinecraftForge.EVENT_BUS.register(this);
  64. MinecraftForge.EVENT_BUS.register(new RegistryEvents());
  65.  
  66. // some example code
  67. LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
  68. for (int i = 0; i < keyBindings.length; ++i)
  69. {
  70. ClientRegistry.registerKeyBinding(keyBindings[i]);
  71. }
  72. }
  73.  
  74. private void setup(final FMLCommonSetupEvent event)
  75. {
  76. Oher stuff
  77. }
  78.  
  79. private void doClientStuff(final FMLClientSetupEvent event) {
  80. // do something that can only be done on the client
  81. LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
  82. }
  83.  
  84. private void enqueueIMC(final InterModEnqueueEvent event)
  85. {
  86. // some example code to dispatch IMC to another mod
  87. InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
  88. }
  89.  
  90. private void processIMC(final InterModProcessEvent event)
  91. {
  92. // some example code to receive and process InterModComms from other mods
  93. LOGGER.info("Got IMC {}", event.getIMCStream().
  94. map(m->m.getMessageSupplier().get()).
  95. collect(Collectors.toList()));
  96. }
  97. // You can use SubscribeEvent and let the Event Bus discover methods to call
  98. @SubscribeEvent
  99. public void onServerStarting(FMLServerStartingEvent event) {
  100. // do something when the server starts
  101. LOGGER.info("HELLO from server starting");
  102. }
  103. A VOID HERE
  104.  
  105. // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
  106. // Event bus for receiving Registry Events)
  107. @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
  108. public class RegistryEvents {
  109. @SubscribeEvent
  110. public void onKey(InputEvent.KeyInputEvent e){
  111. System.out.println("KEY!");
  112. [...]
  113. WORKING PERFECTLY FINE.
  114. }
  115. @SubscribeEvent
  116. public void onKb (LivingKnockBackEvent e) {
  117. System.out.println("test1");
  118. Not working at all
  119. }
  120.  
  121.  
  122. @SubscribeEvent
  123. public void onTick (TickEvent.ClientTickEvent tick) {
  124. this also working
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement