Skip to content

Commit

Permalink
Jetpack thrust vectorization
Browse files Browse the repository at this point in the history
  • Loading branch information
mewacaser committed Jan 7, 2024
1 parent 296c1de commit c978d58
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mekanism/client/ClientTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mekanism/common/CommonPlayerTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mekanism/common/MekanismLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/mekanism/common/item/gear/ItemJetpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ public JetpackMode getJetpackMode(ItemStack stack) {
return JetpackMode.DISABLED;
}

@Override
public double getJetpackThrust(ItemStack stack) {
IModule<ModuleJetpackUnit> 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);
Expand Down
41 changes: 25 additions & 16 deletions src/main/java/mekanism/common/item/interfaces/IJetpackItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,12 +30,15 @@ public interface IJetpackItem {

JetpackMode getJetpackMode(ItemStack stack);

double getJetpackThrust(ItemStack stack);

void useJetpackFuel(ItemStack stack);

@NothingNullByDefault
enum JetpackMode implements IIncrementalEnum<JetpackMode>, 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();
Expand Down Expand Up @@ -108,33 +112,38 @@ private static ItemStack getJetpack(LivingEntity entity, Predicate<ItemStack> 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;
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private MekanismModules() {
public static final ModuleRegistryObject<ModuleGeigerUnit> GEIGER_UNIT = MODULES.register("geiger_unit",
ModuleGeigerUnit::new, () -> MekanismItems.MODULE_GEIGER.asItem(), builder -> builder.rarity(Rarity.UNCOMMON).rendersHUD());
public static final ModuleRegistryObject<ModuleJetpackUnit> 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<ModuleChargeDistributionUnit> CHARGE_DISTRIBUTION_UNIT = MODULES.register("charge_distribution_unit",
ModuleChargeDistributionUnit::new, () -> MekanismItems.MODULE_CHARGE_DISTRIBUTION.asItem(), builder -> builder.rarity(Rarity.RARE));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c978d58

Please sign in to comment.