From fdbf4529ea3555543a3b3f34acbd4684d31f337b Mon Sep 17 00:00:00 2001 From: mpaxlamitsounas Date: Fri, 6 Sep 2024 02:16:36 +0300 Subject: [PATCH 1/2] Implement inertia cancellation --- .../java/gregtech/api/util/input/KeyBind.java | 1 + .../common/items/armor/AdvancedJetpack.java | 2 +- .../items/armor/AdvancedNanoMuscleSuite.java | 2 +- .../items/armor/AdvancedQuarkTechSuite.java | 29 ++++++++++++++++++- .../gregtech/common/items/armor/IJetpack.java | 26 +++++++++++++---- .../gregtech/common/items/armor/Jetpack.java | 2 +- .../common/items/armor/PowerlessJetpack.java | 2 +- .../resources/assets/gregtech/lang/en_us.lang | 4 +++ 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/main/java/gregtech/api/util/input/KeyBind.java b/src/main/java/gregtech/api/util/input/KeyBind.java index 74ec9442afb..b15f55ad92b 100644 --- a/src/main/java/gregtech/api/util/input/KeyBind.java +++ b/src/main/java/gregtech/api/util/input/KeyBind.java @@ -38,6 +38,7 @@ public enum KeyBind { VANILLA_RIGHT(() -> () -> Minecraft.getMinecraft().gameSettings.keyBindRight), ARMOR_MODE_SWITCH("gregtech.key.armor_mode_switch", KeyConflictContext.IN_GAME, Keyboard.KEY_M), ARMOR_HOVER("gregtech.key.armor_hover", KeyConflictContext.IN_GAME, Keyboard.KEY_H), + ARMOR_CANCEL_INERTIA("gregtech.key.armor_cancel_inertia", KeyConflictContext.IN_GAME, Keyboard.KEY_I), ARMOR_CHARGING("gregtech.key.armor_charging", KeyConflictContext.IN_GAME, Keyboard.KEY_N), TOOL_AOE_CHANGE("gregtech.key.tool_aoe_change", KeyConflictContext.IN_GAME, Keyboard.KEY_V); diff --git a/src/main/java/gregtech/common/items/armor/AdvancedJetpack.java b/src/main/java/gregtech/common/items/armor/AdvancedJetpack.java index 2b54aa3f9b3..771c7d48203 100644 --- a/src/main/java/gregtech/common/items/armor/AdvancedJetpack.java +++ b/src/main/java/gregtech/common/items/armor/AdvancedJetpack.java @@ -44,7 +44,7 @@ public void onArmorTick(World world, EntityPlayer player, @NotNull ItemStack ite } } - performFlying(player, hoverMode, item); + performFlying(player, hoverMode, false, item); if (toggleTimer > 0) toggleTimer--; diff --git a/src/main/java/gregtech/common/items/armor/AdvancedNanoMuscleSuite.java b/src/main/java/gregtech/common/items/armor/AdvancedNanoMuscleSuite.java index 74c256262e8..5e7765521f1 100644 --- a/src/main/java/gregtech/common/items/armor/AdvancedNanoMuscleSuite.java +++ b/src/main/java/gregtech/common/items/armor/AdvancedNanoMuscleSuite.java @@ -76,7 +76,7 @@ else if (canShare) data.setBoolean("canShare", canShare); } - performFlying(player, hoverMode, item); + performFlying(player, hoverMode, false, item); // Charging mechanics if (canShare && !world.isRemote) { diff --git a/src/main/java/gregtech/common/items/armor/AdvancedQuarkTechSuite.java b/src/main/java/gregtech/common/items/armor/AdvancedQuarkTechSuite.java index a0607a6e825..90fbfb8b145 100644 --- a/src/main/java/gregtech/common/items/armor/AdvancedQuarkTechSuite.java +++ b/src/main/java/gregtech/common/items/armor/AdvancedQuarkTechSuite.java @@ -46,6 +46,7 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack item) { NBTTagCompound data = GTUtility.getOrCreateNbtCompound(item); boolean hoverMode = data.hasKey("hover") && data.getBoolean("hover"); + boolean cancelInertiaMode = data.hasKey("cancelInertia") && data.getBoolean("cancelInertia"); byte toggleTimer = data.hasKey("toggleTimer") ? data.getByte("toggleTimer") : 0; boolean canShare = data.hasKey("canShare") && data.getBoolean("canShare"); @@ -61,6 +62,20 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack item) { } } + if (toggleTimer == 0 && KeyBind.ARMOR_CANCEL_INERTIA.isKeyDown(player)) { + cancelInertiaMode = !cancelInertiaMode; + toggleTimer = 5; + data.setBoolean("cancelInertia", cancelInertiaMode); + if (!world.isRemote) { + if (cancelInertiaMode) + player.sendStatusMessage(new TextComponentTranslation("metaarmor.jetpack.cancel_inertia.enable"), + true); + else + player.sendStatusMessage(new TextComponentTranslation("metaarmor.jetpack.cancel_inertia.disable"), + true); + } + } + if (toggleTimer == 0 && KeyBind.ARMOR_CHARGING.isKeyDown(player)) { canShare = !canShare; toggleTimer = 5; @@ -78,7 +93,7 @@ else if (canShare) data.setBoolean("canShare", canShare); } - performFlying(player, hoverMode, item); + performFlying(player, hoverMode, cancelInertiaMode, item); if (player.isBurning()) player.extinguish(); @@ -130,6 +145,7 @@ else if (canShare) if (toggleTimer > 0) toggleTimer--; data.setBoolean("canShare", canShare); + data.setBoolean("cancelInertia", cancelInertiaMode); data.setBoolean("hover", hoverMode); data.setByte("toggleTimer", toggleTimer); player.inventoryContainer.detectAndSendChanges(); @@ -157,6 +173,11 @@ public void addInfo(ItemStack itemStack, List lines) { status = I18n.format("metaarmor.hud.status.enabled"); } lines.add(I18n.format("metaarmor.hud.hover_mode", status)); + if (data.hasKey("cancelInertia")) { + if (data.getBoolean("cancelInertia")) + status = I18n.format("metaarmor.hud.status.enabled"); + } + lines.add(I18n.format("metaarmor.hud.cancel_inertia_mode", status)); super.addInfo(itemStack, lines); } @@ -210,6 +231,12 @@ public void drawHUD(ItemStack item) { "metaarmor.hud.status.disabled"; this.HUD.newString(I18n.format("metaarmor.hud.hover_mode", I18n.format(status))); } + + if (data.hasKey("cancelInertia")) { + String status = data.getBoolean("cancelInertia") ? "metaarmor.hud.status.enabled" : + "metaarmor.hud.status.disabled"; + this.HUD.newString(I18n.format("metaarmor.hud.cancel_inertia_mode", I18n.format(status))); + } } this.HUD.draw(); this.HUD.reset(); diff --git a/src/main/java/gregtech/common/items/armor/IJetpack.java b/src/main/java/gregtech/common/items/armor/IJetpack.java index 1043a159db7..a31692bd5ef 100644 --- a/src/main/java/gregtech/common/items/armor/IJetpack.java +++ b/src/main/java/gregtech/common/items/armor/IJetpack.java @@ -59,7 +59,7 @@ default float getFallDamageReduction() { boolean hasEnergy(ItemStack stack); - default void performFlying(@NotNull EntityPlayer player, boolean hover, ItemStack stack) { + default void performFlying(@NotNull EntityPlayer player, boolean hover, boolean cancelInertia, ItemStack stack) { double currentAccel = getVerticalAcceleration() * (player.motionY < 0.3D ? 2.5D : 1.0D); double currentSpeedVertical = getVerticalSpeed() * (player.isInWater() ? 0.4D : 1.0D); boolean flyKeyDown = KeyBind.VANILLA_JUMP.isKeyDown(player); @@ -89,14 +89,30 @@ default void performFlying(@NotNull EntityPlayer player, boolean hover, ItemStac float speedForward = (float) (player.isSprinting() ? speedSideways * getSprintSpeedModifier() : speedSideways); - if (KeyBind.VANILLA_FORWARD.isKeyDown(player)) + boolean anyKeyPressed = false; + if (KeyBind.VANILLA_FORWARD.isKeyDown(player)) { player.moveRelative(0, 0, speedForward, speedForward); - if (KeyBind.VANILLA_BACKWARD.isKeyDown(player)) + anyKeyPressed = true; + } + if (KeyBind.VANILLA_BACKWARD.isKeyDown(player)) { player.moveRelative(0, 0, -speedSideways, speedSideways * 0.8f); - if (KeyBind.VANILLA_LEFT.isKeyDown(player)) + anyKeyPressed = true; + } + if (KeyBind.VANILLA_LEFT.isKeyDown(player)) { player.moveRelative(speedSideways, 0, 0, speedSideways); - if (KeyBind.VANILLA_RIGHT.isKeyDown(player)) + anyKeyPressed = true; + } + if (KeyBind.VANILLA_RIGHT.isKeyDown(player)) { player.moveRelative(-speedSideways, 0, 0, speedSideways); + anyKeyPressed = true; + } + + if (!anyKeyPressed && hover && cancelInertia) { + player.motionX *= 0.75; + player.motionY *= 0.75; + player.motionZ *= 0.75; + } + if (!player.getEntityWorld().isRemote) { player.fallDistance = 0; } diff --git a/src/main/java/gregtech/common/items/armor/Jetpack.java b/src/main/java/gregtech/common/items/armor/Jetpack.java index ec15c14df85..e6ef1dbd276 100644 --- a/src/main/java/gregtech/common/items/armor/Jetpack.java +++ b/src/main/java/gregtech/common/items/armor/Jetpack.java @@ -59,7 +59,7 @@ public void onArmorTick(World world, EntityPlayer player, @NotNull ItemStack sta } } - performFlying(player, hover, stack); + performFlying(player, hover, false, stack); if (toggleTimer > 0) toggleTimer--; diff --git a/src/main/java/gregtech/common/items/armor/PowerlessJetpack.java b/src/main/java/gregtech/common/items/armor/PowerlessJetpack.java index 0f9e2867193..17a87b8ca16 100644 --- a/src/main/java/gregtech/common/items/armor/PowerlessJetpack.java +++ b/src/main/java/gregtech/common/items/armor/PowerlessJetpack.java @@ -92,7 +92,7 @@ public void onArmorTick(World world, EntityPlayer player, @NotNull ItemStack sta if (currentRecipe == null) findNewRecipe(stack); - performFlying(player, hover, stack); + performFlying(player, hover, false, stack); if (toggleTimer > 0) toggleTimer--; diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 042607af612..d5a15915e4d 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -1136,6 +1136,9 @@ metaarmor.qts.nightvision.error=QuarkTech™ Suite: §cNot enough power! metaarmor.jetpack.hover.enable=Jetpack: Hover Mode Enabled metaarmor.jetpack.hover.disable=Jetpack: Hover Mode Disabled +metaarmor.jetpack.cancel_inertia.enable=Jetpack: Inertia Cancellation Enabled +metaarmor.jetpack.cancel_inertia.disable=Jetpack: Inertia Cancellation Disabled + metaarmor.jetpack.emergency_hover_mode=Emergency Hover Mode Enabled! metaarmor.nms.share.enable=NanoMuscle™ Suite: Charging Enabled @@ -1164,6 +1167,7 @@ metaarmor.hud.status.disabled=§cOFF metaarmor.hud.energy_lvl=Energy Level: %s metaarmor.hud.fuel_lvl=Fuel Level: %s metaarmor.hud.hover_mode=Hover Mode: %s +metaarmor.hud.cancel_inertia_mode=Inertia Cancellation: %s mataarmor.hud.supply_mode=Supply Mode: %s metaarmor.hud.gravi_engine=GraviEngine: %s From 81cc5d655d3dc336c3dcb1c07447dd9763637215 Mon Sep 17 00:00:00 2001 From: mpaxlamitsounas Date: Thu, 19 Sep 2024 12:08:05 +0300 Subject: [PATCH 2/2] Improve logic --- src/main/java/gregtech/common/items/armor/IJetpack.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/common/items/armor/IJetpack.java b/src/main/java/gregtech/common/items/armor/IJetpack.java index a31692bd5ef..422f468b547 100644 --- a/src/main/java/gregtech/common/items/armor/IJetpack.java +++ b/src/main/java/gregtech/common/items/armor/IJetpack.java @@ -89,7 +89,7 @@ default void performFlying(@NotNull EntityPlayer player, boolean hover, boolean float speedForward = (float) (player.isSprinting() ? speedSideways * getSprintSpeedModifier() : speedSideways); - boolean anyKeyPressed = false; + boolean anyKeyPressed = flyKeyDown || descendKeyDown; if (KeyBind.VANILLA_FORWARD.isKeyDown(player)) { player.moveRelative(0, 0, speedForward, speedForward); anyKeyPressed = true; @@ -107,7 +107,8 @@ default void performFlying(@NotNull EntityPlayer player, boolean hover, boolean anyKeyPressed = true; } - if (!anyKeyPressed && hover && cancelInertia) { + /* hover check not needed, because of "flyKeyDown || hover && !player.onGround" check */ + if (!anyKeyPressed && cancelInertia) { player.motionX *= 0.75; player.motionY *= 0.75; player.motionZ *= 0.75;