From c978d5839c31133012981a1fe508880ab34c610e Mon Sep 17 00:00:00 2001 From: mewacaser Date: Tue, 7 Jun 2022 17:20:33 -0500 Subject: [PATCH] Jetpack thrust vectorization --- .../mekanism/assets/mekanism/lang/en_ud.json | 1 + .../mekanism/assets/mekanism/lang/en_us.json | 1 + .../client/lang/MekanismLangProvider.java | 1 + .../mekanism/client/ClientTickHandler.java | 5 ++- .../common/CommonPlayerTickHandler.java | 3 +- .../java/mekanism/common/MekanismLang.java | 1 + .../common/item/gear/ItemJetpack.java | 5 +++ .../common/item/gear/ItemMekaSuitArmor.java | 9 ++++ .../common/item/interfaces/IJetpackItem.java | 41 +++++++++++------- .../common/registries/MekanismModules.java | 2 +- .../mekanism/gui/hud/jetpack_vector.png | Bin 0 -> 1866 bytes 11 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 src/main/resources/assets/mekanism/gui/hud/jetpack_vector.png diff --git a/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json b/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json index ebe4c28a493..51868799bdf 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json @@ -1220,6 +1220,7 @@ "jetpack.mekanism.hover": "ɹǝʌoH", "jetpack.mekanism.mode_change": "%s :oʇ pǝᵷuɐɥɔ ǝpoɯ ʞɔɐdʇǝՐ", "jetpack.mekanism.normal": "ɹɐꞁnᵷǝᴚ", + "jetpack.mekanism.vector": "ɹoʇɔǝΛ", "key.mekanism.chest_mode": "ɥɔʇᴉʍS ǝpoW ʇsǝɥƆ", "key.mekanism.description": "uoᴉʇdᴉɹɔsǝᗡ ʍoɥS", "key.mekanism.details": "sꞁᴉɐʇǝᗡ ʍoɥS", diff --git a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json index 1d86331aad7..307f70e6336 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json @@ -1220,6 +1220,7 @@ "jetpack.mekanism.hover": "Hover", "jetpack.mekanism.mode_change": "Jetpack mode changed to: %1$s", "jetpack.mekanism.normal": "Regular", + "jetpack.mekanism.vector": "Vector", "key.mekanism.chest_mode": "Chest Mode Switch", "key.mekanism.description": "Show Description", "key.mekanism.details": "Show Details", diff --git a/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java b/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java index ea3e0d7bad9..1014a097f38 100644 --- a/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java +++ b/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java @@ -1299,6 +1299,7 @@ private void addMisc() { add(MekanismLang.JETPACK_MODE_CHANGE, "Jetpack mode changed to: %1$s"); add(MekanismLang.JETPACK_NORMAL, "Regular"); add(MekanismLang.JETPACK_HOVER, "Hover"); + add(MekanismLang.JETPACK_VECTOR, "Vector"); add(MekanismLang.JETPACK_DISABLED, "Disabled"); //Disassembler Mode add(MekanismLang.DISASSEMBLER_MODE_CHANGE, "Mode toggled to: %1$s (%2$s)"); diff --git a/src/main/java/mekanism/client/ClientTickHandler.java b/src/main/java/mekanism/client/ClientTickHandler.java index 479cf87de23..b4260b0c1c9 100644 --- a/src/main/java/mekanism/client/ClientTickHandler.java +++ b/src/main/java/mekanism/client/ClientTickHandler.java @@ -85,7 +85,7 @@ public static boolean isJetpackInUse(Player player, ItemStack jetpack) { boolean guiOpen = minecraft.screen != null; boolean ascending = minecraft.player.input.jumping; boolean rising = ascending && !guiOpen; - if (mode == JetpackMode.NORMAL) { + if (mode == JetpackMode.NORMAL || mode == JetpackMode.VECTOR) { return rising; } else if (mode == JetpackMode.HOVER) { boolean descending = minecraft.player.input.shiftKeyDown; @@ -203,7 +203,8 @@ public void tickStart() { JetpackMode primaryMode = ((IJetpackItem) primaryJetpack.getItem()).getJetpackMode(primaryJetpack); JetpackMode mode = IJetpackItem.getPlayerJetpackMode(minecraft.player, primaryMode, () -> minecraft.player.input.jumping); MekanismClient.updateKey(minecraft.player.input.jumping, KeySync.ASCEND); - if (jetpackInUse && IJetpackItem.handleJetpackMotion(minecraft.player, mode, () -> minecraft.player.input.jumping)) { + double jetpackThrust = ((IJetpackItem) primaryJetpack.getItem()).getJetpackThrust(primaryJetpack); + if (jetpackInUse && IJetpackItem.handleJetpackMotion(minecraft.player, mode, jetpackThrust, () -> minecraft.player.input.jumping)) { minecraft.player.resetFallDistance(); } } diff --git a/src/main/java/mekanism/common/CommonPlayerTickHandler.java b/src/main/java/mekanism/common/CommonPlayerTickHandler.java index 17246b89e3b..1c11ede43ca 100644 --- a/src/main/java/mekanism/common/CommonPlayerTickHandler.java +++ b/src/main/java/mekanism/common/CommonPlayerTickHandler.java @@ -128,8 +128,9 @@ private void tickEnd(Player player) { if (!primaryJetpack.isEmpty()) { JetpackMode primaryMode = ((IJetpackItem) primaryJetpack.getItem()).getJetpackMode(primaryJetpack); JetpackMode mode = IJetpackItem.getPlayerJetpackMode(player, primaryMode, () -> Mekanism.keyMap.has(player.getUUID(), KeySync.ASCEND)); + double jetpackThrust = ((IJetpackItem) primaryJetpack.getItem()).getJetpackThrust(primaryJetpack); if (mode != JetpackMode.DISABLED) { - if (IJetpackItem.handleJetpackMotion(player, mode, () -> Mekanism.keyMap.has(player.getUUID(), KeySync.ASCEND))) { + if (IJetpackItem.handleJetpackMotion(player, mode, jetpackThrust, () -> Mekanism.keyMap.has(player.getUUID(), KeySync.ASCEND))) { player.resetFallDistance(); if (player instanceof ServerPlayer serverPlayer) { serverPlayer.connection.aboveGroundTickCount = 0; diff --git a/src/main/java/mekanism/common/MekanismLang.java b/src/main/java/mekanism/common/MekanismLang.java index 007a7644f76..d601c6ce53f 100644 --- a/src/main/java/mekanism/common/MekanismLang.java +++ b/src/main/java/mekanism/common/MekanismLang.java @@ -643,6 +643,7 @@ public enum MekanismLang implements ILangEntry { JETPACK_MODE_CHANGE("jetpack", "mode_change"), JETPACK_NORMAL("jetpack", "normal"), JETPACK_HOVER("jetpack", "hover"), + JETPACK_VECTOR("jetpack", "vector"), JETPACK_DISABLED("jetpack", "disabled"), //Disassembler Mode DISASSEMBLER_MODE_CHANGE("disassembler", "mode_change"), diff --git a/src/main/java/mekanism/common/item/gear/ItemJetpack.java b/src/main/java/mekanism/common/item/gear/ItemJetpack.java index c69cc4889a0..31cf614267f 100644 --- a/src/main/java/mekanism/common/item/gear/ItemJetpack.java +++ b/src/main/java/mekanism/common/item/gear/ItemJetpack.java @@ -82,6 +82,11 @@ public JetpackMode getJetpackMode(ItemStack stack) { return JetpackMode.byIndexStatic(ItemDataUtils.getInt(stack, NBTConstants.MODE)); } + @Override + public double getJetpackThrust(ItemStack stack) { + return 0.15D; + } + @Override public void useJetpackFuel(ItemStack stack) { useGas(stack, 1); diff --git a/src/main/java/mekanism/common/item/gear/ItemMekaSuitArmor.java b/src/main/java/mekanism/common/item/gear/ItemMekaSuitArmor.java index bb80bca3566..132239b7db5 100644 --- a/src/main/java/mekanism/common/item/gear/ItemMekaSuitArmor.java +++ b/src/main/java/mekanism/common/item/gear/ItemMekaSuitArmor.java @@ -386,6 +386,15 @@ public JetpackMode getJetpackMode(ItemStack stack) { return JetpackMode.DISABLED; } + @Override + public double getJetpackThrust(ItemStack stack) { + IModule module = getModule(stack, MekanismModules.JETPACK_UNIT); + if (module != null && module.isEnabled()) { + return 0.15D * module.getInstalledCount(); + } + return 0D; + } + @Override public void useJetpackFuel(ItemStack stack) { useGas(stack, MekanismGases.HYDROGEN.get(), 1); diff --git a/src/main/java/mekanism/common/item/interfaces/IJetpackItem.java b/src/main/java/mekanism/common/item/interfaces/IJetpackItem.java index 250c77a1a31..55c92f43f83 100644 --- a/src/main/java/mekanism/common/item/interfaces/IJetpackItem.java +++ b/src/main/java/mekanism/common/item/interfaces/IJetpackItem.java @@ -16,6 +16,7 @@ import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; @@ -29,12 +30,15 @@ public interface IJetpackItem { JetpackMode getJetpackMode(ItemStack stack); + double getJetpackThrust(ItemStack stack); + void useJetpackFuel(ItemStack stack); @NothingNullByDefault enum JetpackMode implements IIncrementalEnum, IHasTextComponent { NORMAL(MekanismLang.JETPACK_NORMAL, EnumColor.DARK_GREEN, MekanismUtils.getResource(ResourceType.GUI_HUD, "jetpack_normal.png")), HOVER(MekanismLang.JETPACK_HOVER, EnumColor.DARK_AQUA, MekanismUtils.getResource(ResourceType.GUI_HUD, "jetpack_hover.png")), + VECTOR(MekanismLang.JETPACK_VECTOR, EnumColor.ORANGE, MekanismUtils.getResource(ResourceType.GUI_HUD, "jetpack_vector.png")), DISABLED(MekanismLang.JETPACK_DISABLED, EnumColor.DARK_RED, MekanismUtils.getResource(ResourceType.GUI_HUD, "jetpack_off.png")); private static final JetpackMode[] MODES = values(); @@ -108,33 +112,38 @@ private static ItemStack getJetpack(LivingEntity entity, Predicate ma /** * @return If fall distance should get reset or not */ - static boolean handleJetpackMotion(Player player, JetpackMode mode, BooleanSupplier ascendingSupplier) { + static boolean handleJetpackMotion(Player player, JetpackMode mode, double thrust, BooleanSupplier ascendingSupplier) { Vec3 motion = player.getDeltaMovement(); - if (mode == JetpackMode.NORMAL) { - if (player.isFallFlying()) { - Vec3 forward = player.getLookAngle(); - Vec3 delta = forward.multiply(forward.scale(0.15)) - .add(forward.scale(1.5).subtract(motion).scale(0.5)); - player.setDeltaMovement(motion.add(delta)); - return false; - } else { - player.setDeltaMovement(motion.x(), Math.min(motion.y() + 0.15D, 0.5D), motion.z()); - } + if ((mode == JetpackMode.NORMAL || mode == JetpackMode.VECTOR) && player.isFallFlying()) { + Vec3 forward = player.getLookAngle(); + Vec3 delta = forward.multiply(forward.scale(thrust)) + .add(forward.scale(1.5).subtract(motion).scale(0.5)); + player.setDeltaMovement(motion.add(delta)); + return false; + } else if (mode == JetpackMode.NORMAL) { + player.setDeltaMovement(motion.x(), Math.min(motion.y() + thrust, 0.5D), motion.z()); + } else if (mode == JetpackMode.VECTOR) { + Vec3 forward = player.getLookAngle(); + float theta = player.getYRot() * ((float) Math.PI / 180F); + Vec3 left = new Vec3(Mth.cos(theta), 0, Mth.sin(theta)); + Vec3 up = forward.cross(left); + Vec3 velocity = motion.add(up.scale(thrust)); + player.setDeltaMovement(new Vec3(velocity.x, Math.min(0.5D, velocity.y), velocity.z)); } else if (mode == JetpackMode.HOVER) { boolean ascending = ascendingSupplier.getAsBoolean(); boolean descending = player.isDescending(); if (ascending == descending) { if (motion.y() > 0) { - player.setDeltaMovement(motion.x(), Math.max(motion.y() - 0.15D, 0), motion.z()); + player.setDeltaMovement(motion.x(), Math.max(motion.y() - thrust, 0), motion.z()); } else if (motion.y() < 0) { if (!CommonPlayerTickHandler.isOnGroundOrSleeping(player)) { - player.setDeltaMovement(motion.x(), Math.min(motion.y() + 0.15D, 0), motion.z()); + player.setDeltaMovement(motion.x(), Math.min(motion.y() + thrust, 0), motion.z()); } } } else if (ascending) { - player.setDeltaMovement(motion.x(), Math.min(motion.y() + 0.15D, 0.2D), motion.z()); + player.setDeltaMovement(motion.x(), Math.min(motion.y() + thrust, 0.2D), motion.z()); } else if (!CommonPlayerTickHandler.isOnGroundOrSleeping(player)) { - player.setDeltaMovement(motion.x(), Math.max(motion.y() - 0.15D, -0.2D), motion.z()); + player.setDeltaMovement(motion.x(), Math.max(motion.y() - thrust, -0.2D), motion.z()); } } return true; @@ -148,7 +157,7 @@ static JetpackMode getPlayerJetpackMode(Player player, JetpackMode mode, Boolean if (ascending && !player.isDescending() || !CommonPlayerTickHandler.isOnGroundOrSleeping(player)) { return mode; } - } else if (mode == JetpackMode.NORMAL && ascending) { + } else if (ascending) { return mode; } } diff --git a/src/main/java/mekanism/common/registries/MekanismModules.java b/src/main/java/mekanism/common/registries/MekanismModules.java index 8405c04149f..ec58ad094b3 100644 --- a/src/main/java/mekanism/common/registries/MekanismModules.java +++ b/src/main/java/mekanism/common/registries/MekanismModules.java @@ -89,7 +89,7 @@ private MekanismModules() { public static final ModuleRegistryObject GEIGER_UNIT = MODULES.register("geiger_unit", ModuleGeigerUnit::new, () -> MekanismItems.MODULE_GEIGER.asItem(), builder -> builder.rarity(Rarity.UNCOMMON).rendersHUD()); public static final ModuleRegistryObject JETPACK_UNIT = MODULES.register("jetpack_unit", - ModuleJetpackUnit::new, () -> MekanismItems.MODULE_JETPACK.asItem(), builder -> builder.rarity(Rarity.RARE).handlesModeChange().rendersHUD() + ModuleJetpackUnit::new, () -> MekanismItems.MODULE_JETPACK.asItem(), builder -> builder.maxStackSize(4).rarity(Rarity.RARE).handlesModeChange().rendersHUD() .exclusive(ExclusiveFlag.OVERRIDE_JUMP)); public static final ModuleRegistryObject CHARGE_DISTRIBUTION_UNIT = MODULES.register("charge_distribution_unit", ModuleChargeDistributionUnit::new, () -> MekanismItems.MODULE_CHARGE_DISTRIBUTION.asItem(), builder -> builder.rarity(Rarity.RARE)); diff --git a/src/main/resources/assets/mekanism/gui/hud/jetpack_vector.png b/src/main/resources/assets/mekanism/gui/hud/jetpack_vector.png new file mode 100644 index 0000000000000000000000000000000000000000..066fd8582c7b83e634a979daa64d26a9a476e38d GIT binary patch literal 1866 zcmV-Q2etT#P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+TB-MvMVPH{AU$e0+JAdDc^CBqk~t=$9n(glguE>85NMwXdLem_ z%$@x+x{;4*+3CimUmWS+%L(9{olY8jPD}?8zD^X`q25XEy@uY~wYucIGU``FO|oH! zQOB&5(|pWp8$nseGF#LZY_dfqueR8%tw01+Rk{HO6%ur4voBB-qQi!&2_hDxX$z`R z#6m+SHyU&lic~46k_DR~QZpVbF!RQluRzeu71R|$gTa*l7tMS(`AIXqmq8KOaJW)j zIOF0QshVuvnl}0SQR8XB9BHe;K;4d2uxp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