diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 932ee25c0..492cc8972 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -17,7 +17,7 @@ import org.apache.logging.log4j.Logger; import ru.dbotthepony.mc.otm.block.entity.blackhole.ExplosionQueue; import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability; import ru.dbotthepony.mc.otm.capability.drive.DrivePool; -import ru.dbotthepony.mc.otm.client.ClientEventHandler; +import ru.dbotthepony.mc.otm.client.ClientEventHandlerKt; import ru.dbotthepony.mc.otm.client.MatteryGUI; import ru.dbotthepony.mc.otm.client.model.GravitationStabilizerModel; import ru.dbotthepony.mc.otm.client.model.TritaniumArmorModel; @@ -146,9 +146,9 @@ public final class OverdriveThatMatters { EVENT_BUS.addListener(EventPriority.NORMAL, MatteryGUI.INSTANCE::onRenderGuiEvent); EVENT_BUS.addListener(EventPriority.HIGH, MatteryGUI.INSTANCE::onLayerRenderEvent); - EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandler.INSTANCE::inputEvent); - EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandler.INSTANCE::screenOpen); - EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandler.INSTANCE::postScreenInit); + EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandlerKt::onMovementInputUpdate); + EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandlerKt::onScreenOpen); + EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandlerKt::onPostScreenInit); if (ModList.get().isLoaded("mekanism")) { EVENT_BUS.addListener(EventPriority.NORMAL, TooltipsKt::tooltipEvent); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt index fcfc18ab4..d2f56cfb8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt @@ -13,73 +13,71 @@ import ru.dbotthepony.mc.otm.client.screen.panels.Panel2Widget import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.registry.AndroidFeatures -object ClientEventHandler { - fun inputEvent(event: MovementInputUpdateEvent) { - val ply = event.entity - val input = event.input +fun onMovementInputUpdate(event: MovementInputUpdateEvent) { + val ply = event.entity + val input = event.input - val cap = ply.matteryPlayer ?: return + val cap = ply.matteryPlayer ?: return - if (!cap.isAndroid || cap.hasFeature(AndroidFeatures.AIR_BAGS)) - return + if (!cap.isAndroid || cap.hasFeature(AndroidFeatures.AIR_BAGS)) + return - if (ply.abilities.mayfly) { - cap.lastJumpTicks = 14 - } else { - if (ply.isInWater) { - if (ply.isOnGround) { - cap.lastJumpTicks = 14 - } + if (ply.abilities.mayfly) { + cap.lastJumpTicks = 14 + } else { + if (ply.isInWater) { + if (ply.isOnGround) { + cap.lastJumpTicks = 14 + } - if (ply.isSwimming) { - ply.isSwimming = false - } + if (ply.isSwimming) { + ply.isSwimming = false + } - if (cap.lastJumpTicks <= 0) { - input.jumping = false - input.up = false - } else { - cap.lastJumpTicks-- - } + if (cap.lastJumpTicks <= 0) { + input.jumping = false + input.up = false + } else { + cap.lastJumpTicks-- } } } +} - var shouldOpenVanillaInventory = false +var shouldOpenVanillaInventory = false - fun postScreenInit(event: ScreenEvent.Init.Post) { - val player = minecraft.player?.matteryPlayer ?: return +fun onPostScreenInit(event: ScreenEvent.Init.Post) { + val player = minecraft.player?.matteryPlayer ?: return - val screen = event.screen as? InventoryScreen ?: return + val screen = event.screen as? InventoryScreen ?: return - if (player.hasExoSuit) { - event.addListener(Panel2Widget(LargeSquareButtonPanel(event.screen as InventoryScreen, null, - x = screen.guiLeft + screen.xSize + 2f, - y = screen.guiTop.toFloat(), - skinElement = Widgets18.RETURN_ARROW_LEFT, - skinElementWinding = UVWindingOrder.FLOP, - onPress = { - shouldOpenVanillaInventory = false - val mouseX = minecraft.mouseHandler.xpos() - val mouseY = minecraft.mouseHandler.ypos() + if (player.hasExoSuit) { + event.addListener(Panel2Widget(LargeSquareButtonPanel(event.screen as InventoryScreen, null, + x = screen.guiLeft + screen.xSize + 2f, + y = screen.guiTop.toFloat(), + skinElement = Widgets18.RETURN_ARROW_LEFT, + skinElementWinding = UVWindingOrder.FLOP, + onPress = { + shouldOpenVanillaInventory = false + val mouseX = minecraft.mouseHandler.xpos() + val mouseY = minecraft.mouseHandler.ypos() - event.screen.onClose() - minecraft.setScreen(ExoSuitInventoryScreen(player.exoSuitMenu)) + event.screen.onClose() + minecraft.setScreen(ExoSuitInventoryScreen(player.exoSuitMenu)) - InputConstants.grabOrReleaseMouse(minecraft.window.window, 212993, mouseX, mouseY) - }).also { it.tooltip = TranslatableComponent("otm.gui.exosuit.go_in") })) - } - } - - fun screenOpen(event: ScreenEvent.Opening) { - if (shouldOpenVanillaInventory || minecraft.player?.isCreative == true) { - return - } - - val player = minecraft.player?.matteryPlayer ?: return - - if (player.hasExoSuit && event.newScreen is InventoryScreen) { - event.newScreen = ExoSuitInventoryScreen(player.exoSuitMenu) - } + InputConstants.grabOrReleaseMouse(minecraft.window.window, 212993, mouseX, mouseY) + }).also { it.tooltip = TranslatableComponent("otm.gui.exosuit.go_in") })) + } +} + +fun onScreenOpen(event: ScreenEvent.Opening) { + if (shouldOpenVanillaInventory || minecraft.player?.isCreative == true) { + return + } + + val player = minecraft.player?.matteryPlayer ?: return + + if (player.hasExoSuit && event.newScreen is InventoryScreen) { + event.newScreen = ExoSuitInventoryScreen(player.exoSuitMenu) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt index 2b5755c40..f969a37bf 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt @@ -3,11 +3,11 @@ package ru.dbotthepony.mc.otm.client.screen import com.mojang.blaze3d.platform.InputConstants import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.gui.screens.inventory.InventoryScreen -import ru.dbotthepony.mc.otm.client.ClientEventHandler import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.client.render.element import ru.dbotthepony.mc.otm.client.screen.panels.* +import ru.dbotthepony.mc.otm.client.shouldOpenVanillaInventory import ru.dbotthepony.mc.otm.menu.ExoSuitInventoryMenu import ru.dbotthepony.mc.otm.network.ExoSuitMenuOpen import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel @@ -129,7 +129,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen