From a6e00d22e881712de63c293c907ba6feb7ce58de Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 18 Aug 2021 23:49:38 +0700 Subject: [PATCH] Water handling in android capability --- .../capability/AndroidCapabilityPlayer.java | 34 +++++++++++++++++++ .../dbotthepony/mc/otm/client/AndroidGui.java | 6 +++- 2 files changed, 39 insertions(+), 1 deletion(-) 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 eea1b5c9f..5ed5ceb1b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapabilityPlayer.java @@ -5,6 +5,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.food.FoodData; +import net.minecraftforge.client.event.InputUpdateEvent; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.player.PlayerEvent; @@ -132,6 +133,36 @@ public class AndroidCapabilityPlayer extends AndroidCapability { }); } + private int last_jump_ticks = 20; + + @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 (ply.getAbilities().mayfly) { + cap.last_jump_ticks = 20; + } else { + if (ply.isInWater()) { + if (ply.isOnGround()) { + cap.last_jump_ticks = 20; + } + + if (cap.last_jump_ticks <= 0) { + event.getMovementInput().jumping = false; + event.getMovementInput().up = false; + } else { + cap.last_jump_ticks--; + } + } + } + }); + } + private final Player ply; public AndroidCapabilityPlayer(Player ent) { @@ -154,6 +185,9 @@ public class AndroidCapabilityPlayer extends AndroidCapability { // TODO: Maybe passive drain? // extractEnergyInner(BigDecimal.valueOf(new Random().nextDouble()), false); + if (ply.getAirSupply() < ply.getMaxAirSupply()) + ply.setAirSupply(ply.getMaxAirSupply()); + FoodData stats = ply.getFoodData(); if (stats.needsFood()) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java b/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java index 38dd2d77d..f7d3f7a8b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/AndroidGui.java @@ -26,7 +26,7 @@ public class AndroidGui { @SubscribeEvent public void onLayerRenderEvent(RenderGameOverlayEvent.PreLayer event) { - if (event.getOverlay() != ForgeIngameGui.FOOD_LEVEL_ELEMENT) + if (event.getOverlay() != ForgeIngameGui.FOOD_LEVEL_ELEMENT && event.getOverlay() != ForgeIngameGui.AIR_LEVEL_ELEMENT) return; LocalPlayer ply = mc.player; @@ -55,6 +55,10 @@ public class AndroidGui { event.setCanceled(true); last_state = android; + if (event.getOverlay() == ForgeIngameGui.AIR_LEVEL_ELEMENT) { + return; + } + float level; if (android.getMaxBatteryLevel().compareTo(BigDecimal.ZERO) == 0) {