From 38d34de609549ed9231f2d6497e3e8101fc0a051 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 22 Aug 2021 23:31:43 +0700 Subject: [PATCH] Update code to work on dedicated servers --- .../mc/otm/OverdriveThatMatters.java | 2 + .../capability/AndroidCapabilityPlayer.java | 38 +--------------- .../mc/otm/client/EventHandler.java | 44 +++++++++++++++++++ 3 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/main/java/ru/dbotthepony/mc/otm/client/EventHandler.java diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 8d06df395..561d8d6d5 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.capability.AndroidCapability; import ru.dbotthepony.mc.otm.capability.AndroidCapabilityPlayer; import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.client.AndroidGui; +import ru.dbotthepony.mc.otm.client.EventHandler; import ru.dbotthepony.mc.otm.matter.MatterGrid; import ru.dbotthepony.mc.otm.matter.MatterRegistry; import ru.dbotthepony.mc.otm.network.MatteryNetworking; @@ -84,6 +85,7 @@ public class OverdriveThatMatters { ANDROID_GUI = new AndroidGui(); MinecraftForge.EVENT_BUS.register(ANDROID_GUI); MinecraftForge.EVENT_BUS.register(AndroidGui.class); + MinecraftForge.EVENT_BUS.register(EventHandler.class); } private void enqueueIMC(final InterModEnqueueEvent event) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java index 3794c9a94..8bf1ebcda 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java @@ -159,43 +159,7 @@ public class AndroidCapabilityPlayer extends AndroidCapability { }); } - private int last_jump_ticks = 14; - - @SubscribeEvent - public static void inputEvent(InputUpdateEvent event) { - var ply = event.getPlayer(); - var input = event.getMovementInput(); - - ply.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> { - if (!(_cap instanceof AndroidCapabilityPlayer cap)) - return; - - if (cap.hasFeature(Registry.AndroidFeatures.AIR_BAGS)) - return; - - if (ply.getAbilities().mayfly) { - cap.last_jump_ticks = 14; - } else { - if (ply.isInWater()) { - if (ply.isOnGround()) { - cap.last_jump_ticks = 14; - } - - if (ply.isSwimming()) { - ply.setSwimming(false); - } - - if (cap.last_jump_ticks <= 0) { - event.getMovementInput().jumping = false; - event.getMovementInput().up = false; - } else { - cap.last_jump_ticks--; - } - } - } - }); - } - + public int last_jump_ticks = 14; public final Player ply; public AndroidCapabilityPlayer(Player ent) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/EventHandler.java b/src/main/java/ru/dbotthepony/mc/otm/client/EventHandler.java new file mode 100644 index 000000000..5ef8ee1f6 --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/client/EventHandler.java @@ -0,0 +1,44 @@ +package ru.dbotthepony.mc.otm.client; + +import net.minecraftforge.client.event.InputUpdateEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import ru.dbotthepony.mc.otm.Registry; +import ru.dbotthepony.mc.otm.capability.AndroidCapabilityPlayer; +import ru.dbotthepony.mc.otm.capability.MatteryCapability; + +public class EventHandler { + @SubscribeEvent + public static void inputEvent(InputUpdateEvent event) { + var ply = event.getPlayer(); + var input = event.getMovementInput(); + + ply.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> { + if (!(_cap instanceof AndroidCapabilityPlayer cap)) + return; + + if (cap.hasFeature(Registry.AndroidFeatures.AIR_BAGS)) + return; + + if (ply.getAbilities().mayfly) { + cap.last_jump_ticks = 14; + } else { + if (ply.isInWater()) { + if (ply.isOnGround()) { + cap.last_jump_ticks = 14; + } + + if (ply.isSwimming()) { + ply.setSwimming(false); + } + + if (cap.last_jump_ticks <= 0) { + event.getMovementInput().jumping = false; + event.getMovementInput().up = false; + } else { + cap.last_jump_ticks--; + } + } + } + }); + } +}