ClientEvents.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.zjinja.mcmod.zry_client_utils_mod.events;
  2. import com.mojang.blaze3d.vertex.PoseStack;
  3. import com.mojang.logging.LogUtils;
  4. import com.zjinja.mcmod.zry_client_utils_mod.ZRYClientUtilsMod;
  5. import com.zjinja.mcmod.zry_client_utils_mod.commands.CommandGetWESelPos;
  6. import com.zjinja.mcmod.zry_client_utils_mod.commands.CommandMarker;
  7. import com.zjinja.mcmod.zry_client_utils_mod.commands.CommandReloadConfig;
  8. import com.zjinja.mcmod.zry_client_utils_mod.cui.CUIRegionManager;
  9. import com.zjinja.mcmod.zry_client_utils_mod.gui.GuiWEHelpPanel;
  10. import com.zjinja.mcmod.zry_client_utils_mod.keybinds.KeyBindings;
  11. import com.zjinja.mcmod.zry_client_utils_mod.marker.MarkerMgr;
  12. import com.zjinja.mcmod.zry_client_utils_mod.networking.NetworkHandlerWECUI;
  13. import com.zjinja.mcmod.zry_client_utils_mod.renderer.RenderContext;
  14. import com.zjinja.mcmod.zry_client_utils_mod.utils.ConfigMgr;
  15. import com.zjinja.mcmod.zry_client_utils_mod.utils.ZLogUtil;
  16. import net.minecraft.client.Minecraft;
  17. import net.minecraft.client.renderer.LevelRenderer;
  18. import net.minecraft.client.renderer.culling.Frustum;
  19. import net.minecraftforge.api.distmarker.Dist;
  20. import net.minecraftforge.client.event.*;
  21. import net.minecraftforge.eventbus.api.SubscribeEvent;
  22. import net.minecraftforge.fml.common.Mod;
  23. import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
  24. public class ClientEvents {
  25. @Mod.EventBusSubscriber(modid = ZRYClientUtilsMod.MODID, value = Dist.CLIENT)
  26. public static class ClientForgeEvents{
  27. @SubscribeEvent
  28. public static void onKeyInput(InputEvent.Key event){
  29. var mc = Minecraft.getInstance();
  30. var player = mc.player;
  31. if (player == null) {
  32. ZLogUtil.log(
  33. LogUtils.getLogger(), ZLogUtil.Level.WARN,
  34. "key-event", "error in onKeyInput event: player is null."
  35. );
  36. return;
  37. }
  38. if(KeyBindings.KEY_MAPPING_WE_PANEL.consumeClick()){
  39. ZLogUtil.log(
  40. LogUtils.getLogger(), ZLogUtil.Level.INFO,
  41. "key-event", "we_panel key pressed."
  42. );
  43. mc.setScreen(new GuiWEHelpPanel());
  44. }
  45. }
  46. @SubscribeEvent
  47. public static void registerClientCommand(RegisterClientCommandsEvent event) {
  48. new CommandGetWESelPos().register(event.getDispatcher());
  49. new CommandReloadConfig().register(event.getDispatcher());
  50. new CommandMarker().register(event.getDispatcher());
  51. }
  52. @SubscribeEvent
  53. public static void loggedIn(ClientPlayerNetworkEvent.LoggingIn event) {
  54. ZLogUtil.log(
  55. LogUtils.getLogger(), ZLogUtil.Level.INFO,
  56. "client-logged-in", "Logged into server."
  57. );
  58. NetworkHandlerWECUI.onEnterServer();
  59. }
  60. @SubscribeEvent
  61. public static void loggedOut(ClientPlayerNetworkEvent.LoggingOut event) {
  62. ZLogUtil.log(
  63. LogUtils.getLogger(), ZLogUtil.Level.INFO,
  64. "client-logged-out", "Logged out of server."
  65. );
  66. NetworkHandlerWECUI.onQuitServer();
  67. }
  68. @SubscribeEvent
  69. public static void onRenderLevel(RenderLevelStageEvent event) {
  70. //if(event.getStage().equals(RenderLevelStageEvent.Stage.AFTER_CUTOUT_MIPPED_BLOCKS_BLOCKS)) {
  71. if(true) {
  72. PoseStack ps = event.getPoseStack();
  73. Frustum fr = event.getFrustum();
  74. RenderContext rctx = new RenderContext(ps, fr);
  75. CUIRegionManager.render(rctx);
  76. MarkerMgr.render(rctx);
  77. }
  78. }
  79. }
  80. @Mod.EventBusSubscriber(modid = ZRYClientUtilsMod.MODID, value = Dist.CLIENT, bus=Mod.EventBusSubscriber.Bus.MOD)
  81. public static class ClientModBusEvents {
  82. @SubscribeEvent
  83. public static void onClientSetup(FMLClientSetupEvent event)
  84. {
  85. // Some client setup code
  86. ZLogUtil.log(
  87. LogUtils.getLogger(), ZLogUtil.Level.INFO,
  88. "client-setup", "ZRY Client Utils Mod Loaded."
  89. );
  90. ConfigMgr cm = ConfigMgr.getInstance();
  91. if(cm == null) {
  92. ZLogUtil.log(
  93. LogUtils.getLogger(), ZLogUtil.Level.INFO,
  94. "client-setup", "Failed get ConfigMgr: is null."
  95. );
  96. }else{
  97. cm.init();
  98. }
  99. NetworkHandlerWECUI.hook();
  100. }
  101. @SubscribeEvent
  102. public static void onKeyRegister(RegisterKeyMappingsEvent event){
  103. event.register(KeyBindings.KEY_MAPPING_WE_PANEL);
  104. }
  105. }
  106. }