Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetpack Thrust Orientation #7475

Merged
merged 9 commits into from
Mar 8, 2024
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 Expand Up @@ -1315,6 +1316,7 @@
"module.mekanism.inhalation_purification_unit": "ʇᴉu∩ uoᴉʇɐɔᴉɟᴉɹnԀ uoᴉʇɐꞁɐɥuI",
"module.mekanism.installed": "%s :pǝꞁꞁɐʇsuI",
"module.mekanism.jetpack_mode": "ǝpoW ʞɔɐdʇǝՐ",
"module.mekanism.jetpack_mult": "ɹǝᴉꞁdᴉʇꞁnW ʇsnɹɥ⟘",
"module.mekanism.jetpack_unit": "ʇᴉu∩ ʞɔɐdʇǝՐ",
"module.mekanism.jump_boost": "ʇsooᗺ dɯnՐ",
"module.mekanism.laser_dissipation_unit": "ʇᴉu∩ uoᴉʇɐdᴉssᴉᗡ ɹǝ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 Expand Up @@ -1315,6 +1316,7 @@
"module.mekanism.inhalation_purification_unit": "Inhalation Purification Unit",
"module.mekanism.installed": "Installed: %1$s",
"module.mekanism.jetpack_mode": "Jetpack Mode",
"module.mekanism.jetpack_mult": "Thrust Multiplier",
"module.mekanism.jetpack_unit": "Jetpack Unit",
"module.mekanism.jump_boost": "Jump Boost",
"module.mekanism.laser_dissipation_unit": "Laser Dissipation Unit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,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 Expand Up @@ -1470,6 +1471,7 @@ private void addMisc() {
add(MekanismLang.MODULE_EFFICIENCY, "Efficiency");
add(MekanismLang.MODULE_MODE_CHANGE, "%1$s bumped to: %2$s");
add(MekanismLang.MODULE_JETPACK_MODE, "Jetpack Mode");
add(MekanismLang.MODULE_JETPACK_MULT, "Thrust Multiplier");
add(MekanismLang.MODULE_GRAVITATIONAL_MODULATION, "Gravitational Modulation");
add(MekanismLang.MODULE_MAGNETIC_ATTRACTION, "Magnetic Attraction");
add(MekanismLang.MODULE_CHARGE_SUIT, "Charge Suit");
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 @@ -83,7 +83,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 @@ -199,7 +199,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
6 changes: 4 additions & 2 deletions src/main/java/mekanism/common/CommonPlayerTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ private void tickEnd(Player player) {
if (!jetpack.isEmpty()) {
ItemStack primaryJetpack = IJetpackItem.getPrimaryJetpack(player);
if (!primaryJetpack.isEmpty()) {
JetpackMode primaryMode = ((IJetpackItem) primaryJetpack.getItem()).getJetpackMode(primaryJetpack);
IJetpackItem jetpackItem = (IJetpackItem) primaryJetpack.getItem();
JetpackMode primaryMode = jetpackItem.getJetpackMode(primaryJetpack);
JetpackMode mode = IJetpackItem.getPlayerJetpackMode(player, primaryMode, () -> Mekanism.keyMap.has(player.getUUID(), KeySync.ASCEND));
if (mode != JetpackMode.DISABLED) {
if (IJetpackItem.handleJetpackMotion(player, mode, () -> Mekanism.keyMap.has(player.getUUID(), KeySync.ASCEND))) {
double jetpackThrust = jetpackItem.getJetpackThrust(primaryJetpack);
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
2 changes: 2 additions & 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 Expand Up @@ -825,6 +826,7 @@ public enum MekanismLang implements ILangEntry {
MODULE_EFFICIENCY("module", "efficiency"),
MODULE_BREATHING_HELD("module", "breathing.held"),
MODULE_JETPACK_MODE("module", "jetpack_mode"),
MODULE_JETPACK_MULT("module", "jetpack_mult"),
MODULE_GRAVITATIONAL_MODULATION("module", "gravitational_modulation"),
MODULE_MAGNETIC_ATTRACTION("module", "magnetic_attraction"),
MODULE_MODE_CHANGE("module", "mode_change"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.function.BiPredicate;
import java.util.function.LongSupplier;
import java.util.function.Predicate;
import java.util.function.ToLongFunction;
import mekanism.api.AutomationType;
import mekanism.api.IContentsListener;
import mekanism.api.chemical.Chemical;
Expand All @@ -18,22 +19,40 @@

public class ChemicalTankSpec<CHEMICAL extends Chemical<CHEMICAL>> extends GenericTankSpec<CHEMICAL> {

private static final LongSupplier EMPTY = () -> 0;

private final LongSupplier rate;
private final LongSupplier capacity;
@Nullable
private final ToLongFunction<ItemStack> stackBasedCapacity;
@Nullable
private final ChemicalAttributeValidator validator;

public ChemicalTankSpec(LongSupplier rate, LongSupplier capacity, BiPredicate<@NotNull CHEMICAL, @NotNull AutomationType> canExtract,
private ChemicalTankSpec(LongSupplier rate, LongSupplier capacity, BiPredicate<@NotNull CHEMICAL, @NotNull AutomationType> canExtract,
TriPredicate<@NotNull CHEMICAL, @NotNull AutomationType, @NotNull ItemStack> canInsert, Predicate<@NotNull CHEMICAL> isValid,
@Nullable ChemicalAttributeValidator validator, Predicate<@NotNull ItemStack> supportsStack) {
this(rate, capacity, null, canExtract, canInsert, isValid, validator, supportsStack);
}

private ChemicalTankSpec(LongSupplier rate, ToLongFunction<ItemStack> stackBasedCapacity, BiPredicate<@NotNull CHEMICAL, @NotNull AutomationType> canExtract,
TriPredicate<@NotNull CHEMICAL, @NotNull AutomationType, @NotNull ItemStack> canInsert, Predicate<@NotNull CHEMICAL> isValid,
@Nullable ChemicalAttributeValidator validator, Predicate<@NotNull ItemStack> supportsStack) {
this(rate, EMPTY, stackBasedCapacity, canExtract, canInsert, isValid, validator, supportsStack);
}

private ChemicalTankSpec(LongSupplier rate, LongSupplier capacity, @Nullable ToLongFunction<ItemStack> stackBasedCapacity,
BiPredicate<@NotNull CHEMICAL, @NotNull AutomationType> canExtract, TriPredicate<@NotNull CHEMICAL, @NotNull AutomationType, @NotNull ItemStack> canInsert,
Predicate<@NotNull CHEMICAL> isValid, @Nullable ChemicalAttributeValidator validator, Predicate<@NotNull ItemStack> supportsStack) {
super(canExtract, canInsert, isValid, supportsStack);
this.rate = rate;
this.capacity = capacity;
this.stackBasedCapacity = stackBasedCapacity;
this.validator = validator;
}

public <STACK extends ChemicalStack<CHEMICAL>, TANK extends IChemicalTank<CHEMICAL, STACK>> TANK createTank(TankFromSpecCreator<CHEMICAL, STACK, TANK> tankCreator,
ItemStack stack) {
LongSupplier capacity = stackBasedCapacity == null ? this.capacity : () -> stackBasedCapacity.applyAsLong(stack);
Dismissed Show dismissed Hide dismissed
return tankCreator.create(rate, capacity, canExtract, (chemical, automationType) -> canInsert.test(chemical, automationType, stack), isValid, validator, null);
}

Expand All @@ -53,6 +72,12 @@
return new ChemicalTankSpec<>(rate, capacity, ConstantPredicates.notExternal(), (chemical, automation, stack) -> supportsStack.test(stack), isValid, null, supportsStack);
}

public static <CHEMICAL extends Chemical<CHEMICAL>> ChemicalTankSpec<CHEMICAL> createFillOnly(LongSupplier rate, ToLongFunction<ItemStack> stackBasedCapacity,
Predicate<@NotNull CHEMICAL> isValid, Predicate<@NotNull ItemStack> supportsStack) {
return new ChemicalTankSpec<>(rate, stackBasedCapacity, ConstantPredicates.notExternal(),
(chemical, automation, stack) -> supportsStack.test(stack), isValid, null, supportsStack);
}

@FunctionalInterface
public interface TankFromSpecCreator<CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>, TANK extends IChemicalTank<CHEMICAL, STACK>> {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/common/config/GearConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ public class GearConfig extends BaseMekanismConfig {
.defineInRange("nutritionalMaxStorage", 128_000, 1, Integer.MAX_VALUE));
mekaSuitNutritionalTransferRate = CachedIntValue.wrap(this, builder.comment("Rate at which Nutritional Paste can be transferred into the nutritional injection unit.")
.defineInRange("nutritionalTransferRate", 256, 1, Integer.MAX_VALUE));
mekaSuitJetpackMaxStorage = CachedLongValue.wrap(this, builder.comment("Maximum amount of Hydrogen storable in the jetpack unit.")
.defineInRange("jetpackMaxStorage", 48_000, 1, Long.MAX_VALUE));
mekaSuitJetpackMaxStorage = CachedLongValue.wrap(this, builder.comment("Maximum amount of Hydrogen storable per installed jetpack unit.")
.defineInRange("jetpackMaxStorage", 24_000, 1, Long.MAX_VALUE));
mekaSuitJetpackTransferRate = CachedLongValue.wrap(this, builder.comment("Rate at which Hydrogen can be transferred into the jetpack unit.")
.defineInRange("jetpackTransferRate", 256, 1, Long.MAX_VALUE));
mekaSuitHelmetArmor = CachedIntValue.wrap(this, builder.comment("Armor value of MekaSuit Helmets.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mekanism.common.content.gear.mekasuit;

import java.util.function.Consumer;
import mekanism.api.annotations.NothingNullByDefault;
import mekanism.api.annotations.ParametersAreNotNullByDefault;
import mekanism.api.chemical.gas.GasStack;
import mekanism.api.chemical.gas.IGasHandler;
Expand All @@ -11,31 +12,36 @@
import mekanism.api.gear.config.IModuleConfigItem;
import mekanism.api.gear.config.ModuleConfigItemCreator;
import mekanism.api.gear.config.ModuleEnumData;
import mekanism.api.text.IHasTextComponent;
import mekanism.api.text.TextComponentUtil;
import mekanism.common.MekanismLang;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.config.MekanismConfig;
import mekanism.common.item.interfaces.IJetpackItem.JetpackMode;
import mekanism.common.registries.MekanismGases;
import mekanism.common.util.StorageUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

@ParametersAreNotNullByDefault
public class ModuleJetpackUnit implements ICustomModule<ModuleJetpackUnit> {

private IModuleConfigItem<JetpackMode> jetpackMode;
private IModuleConfigItem<ThrustMultiplier> thrustMultiplier;

@Override
public void init(IModule<ModuleJetpackUnit> module, ModuleConfigItemCreator configItemCreator) {
jetpackMode = configItemCreator.createConfigItem("jetpack_mode", MekanismLang.MODULE_JETPACK_MODE, new ModuleEnumData<>(JetpackMode.NORMAL));
thrustMultiplier = configItemCreator.createConfigItem("jetpack_mult", MekanismLang.MODULE_JETPACK_MULT, new ModuleEnumData<>(ThrustMultiplier.NORMAL, module.getInstalledCount() + 1));
}

@Override
public void addHUDElements(IModule<ModuleJetpackUnit> module, Player player, Consumer<IHUDElement> hudElementAdder) {
if (module.isEnabled()) {
IGasHandler gasHandler = module.getContainer().getCapabilityFromStack(Capabilities.GAS.item());
GasStack stored = StorageUtils.getContainedGas(gasHandler, MekanismGases.HYDROGEN.get());
double ratio = StorageUtils.getRatio(stored.getAmount(), MekanismConfig.gear.mekaSuitJetpackMaxStorage.getAsLong());
GasStack stored = StorageUtils.getContainedGas(gasHandler, MekanismGases.HYDROGEN);
long capacity = gasHandler == null ? 0 : gasHandler.getTankCapacity(0);
double ratio = StorageUtils.getRatio(stored.getAmount(), capacity);
hudElementAdder.accept(IModuleHelper.INSTANCE.hudElementPercent(jetpackMode.get().getHUDIcon(), ratio));
}
}
Expand All @@ -52,7 +58,54 @@ public void changeMode(IModule<ModuleJetpackUnit> module, Player player, ItemSta
}
}

@Override
public void onRemoved(IModule<ModuleJetpackUnit> module, boolean last) {
//Vent the excess hydrogen from the jetpack
IGasHandler gasHandler = module.getContainer().getCapabilityFromStack(Capabilities.GAS.item());
if (gasHandler != null) {
for (int tank = 0, tanks = gasHandler.getTanks(); tank < tanks; tank++) {
GasStack stored = gasHandler.getChemicalInTank(tank);
if (!stored.isEmpty()) {
long capacity = gasHandler.getTankCapacity(tank);
if (stored.getAmount() > capacity) {
gasHandler.setChemicalInTank(tank, new GasStack(stored, capacity));
}
}
}
}
}

public JetpackMode getMode() {
return jetpackMode.get();
}

public float getThrustMultiplier() {
return thrustMultiplier.get().getMultiplier();
}

@NothingNullByDefault
public enum ThrustMultiplier implements IHasTextComponent {
HALF(.5f),
NORMAL(1f),
FAST(2f),
FASTER(4f),
FASTEST(8f);
pupnewfster marked this conversation as resolved.
Show resolved Hide resolved

private final float mult;
private final Component label;

ThrustMultiplier(float mult) {
this.mult = mult;
this.label = TextComponentUtil.getString(Float.toString(mult));
}

@Override
public Component getTextComponent() {
return label;
}

public float getMultiplier() {
return mult;
}
}
}
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 @@ -87,6 +87,11 @@ public JetpackMode getJetpackMode(ItemStack stack) {
return getMode(stack);
}

@Override
public double getJetpackThrust(ItemStack stack) {
return 0.1D;
pupnewfster marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void useJetpackFuel(ItemStack stack) {
useGas(stack, 1);
Expand Down
Loading