Advertisement
Guest User

Event Class

a guest
Jan 27th, 2022
26
213 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.mcreator.modid;
  2.  
  3. import net.minecraftforge.fml.common.Mod;
  4. import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
  5. import net.minecraftforge.fml.network.NetworkRegistry;
  6. import net.minecraftforge.eventbus.api.SubscribeEvent;
  7. import net.minecraftforge.api.distmarker.OnlyIn;
  8. import net.minecraftforge.api.distmarker.Dist;
  9. import net.minecraftforge.client.event.InputEvent;
  10.  
  11. import net.minecraft.client.Minecraft;
  12. import net.minecraft.client.gui.widget.TextFieldWidget;
  13. import net.minecraft.client.gui.screen.inventory.ContainerScreen;
  14. import net.minecraft.entity.player.PlayerEntity;
  15.  
  16. import net.mcreator.modid.gui.SpecSelector2GuiWindow;
  17. import net.mcreator.modid.gui.DimensionalSwitcherGUIGuiWindow;
  18. import net.mcreator.modid.TextFieldPacketHandler;
  19. import net.mcreator.modid.ModIdMod;
  20.  
  21.  
  22. @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
  23. public class OnKeyPressed {
  24.     public OnKeyPressed() {
  25.     }
  26.  
  27.     @SubscribeEvent
  28.     public static void init(FMLCommonSetupEvent event) {
  29.         new OnKeyPressed();
  30.     }
  31.     @Mod.EventBusSubscriber
  32.     private static class ForgeBusEvents {
  33.         if (Minecraft.getInstance().currentScreen != null) {
  34.                     if (Minecraft.getInstance().currentScreen instanceof SpecSelector2GuiWindow) {
  35.                         SpecSelector2GuiWindow win = (SpecSelector2GuiWindow)((ContainerScreen)Minecraft.getInstance().currentScreen);
  36.                         String tmpText = (String) (new Object() {
  37.                             public String getText() {
  38.                                 TextFieldWidget _tf = (TextFieldWidget) win.Number;
  39.                                 if (_tf != null) {
  40.                                     return _tf.getText();
  41.                                 }
  42.                             return "";
  43.                             }
  44.                         }.getText());
  45.                         System.out.println("" + tmpText); // tmpText is always blank as characteris not added, because game crash before :/
  46.                         ModIdMod.PACKET_HANDLER.sendToServer(new TextFieldPacketHandler.TextFieldDataSyncMessage(tmpText))
  47.                     } else if (Minecraft.getInstance().currentScreen instanceof DimensionalSwitcherGUIGuiWindow) {
  48.                         if (Minecraft.getInstance().currentScreen != null) {
  49.                             DimensionalSwitcherGUIGuiWindow win = (DimensionalSwitcherGUIGuiWindow)((ContainerScreen)Minecraft.getInstance().currentScreen);
  50.                             String tmpText = (String) (new Object() {
  51.                                 public String getText() {
  52.                                     TextFieldWidget _tf = (TextFieldWidget) win.customInput;
  53.                                     if (_tf != null) {
  54.                                         return _tf.getText();
  55.                                     }
  56.                                 return "";
  57.                                 }
  58.                             }.getText());
  59.                             ModIdMod.PACKET_HANDLER.sendToServer(new TextFieldPacketHandler.TextFieldDataSyncMessage(tmpText));
  60.                         }
  61.                     }
  62.                 }
  63.         }
  64.     }
  65.  
  66.  
  67.  
Advertisement
RAW Paste Data Copied
Advertisement