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
21 changes: 21 additions & 0 deletions src/api/java/mekanism/api/gear/config/IHasModeIcon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mekanism.api.gear.config;

import mekanism.api.text.IHasTextComponent;
import net.minecraft.resources.ResourceLocation;

/**
* Conveys that an option should be represented by the corresponding mode icon when displayed in the module tweaker.
*
* @apiNote Currently only supported for {@link ModuleEnumData}.
* @since 10.5.3
*/
public interface IHasModeIcon extends IHasTextComponent {

/**
* @return The icon to use for displaying this mode.
*
* @implNote The file is currently expected to be 16x16, and be 5 wide, down two pixels and eight pixels tall. Ideally this will be made less strict, but for now just
* look at how the jetpack icons are.
*/
ResourceLocation getModeIcon();
}
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package mekanism.client.gui.element.custom.module;

import java.util.List;
import mekanism.api.gear.config.IHasModeIcon;
import mekanism.api.gear.config.ModuleEnumData;
import mekanism.api.text.IHasTextComponent;
import mekanism.client.gui.GuiUtils;
import mekanism.common.MekanismLang;
import mekanism.common.content.gear.ModuleConfigItem;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
Expand All @@ -20,18 +23,21 @@ class EnumToggle<TYPE extends Enum<TYPE> & IHasTextComponent> extends MiniElemen
private final int BAR_LENGTH;
private final ModuleConfigItem<TYPE> data;
private final int optionDistance;
private final boolean usesIcons;
boolean dragging = false;

EnumToggle(GuiModuleScreen parent, ModuleConfigItem<TYPE> data, int xPos, int yPos) {
super(parent, xPos, yPos);
this.data = data;
BAR_LENGTH = this.parent.getScreenWidth() - 24;
this.optionDistance = (BAR_LENGTH / (getData().getEnums().size() - 1));
List<TYPE> options = getData().getEnums();
this.optionDistance = (BAR_LENGTH / (options.size() - 1));
this.usesIcons = options.stream().findFirst().filter(option -> option instanceof IHasModeIcon).isPresent();
}

@Override
protected int getNeededHeight() {
return 28;
return usesIcons ? 31 : 28;
}

private ModuleEnumData<TYPE> getData() {
Expand All @@ -48,25 +54,42 @@ protected void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY)
@Override
protected void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) {
int textColor = parent.screenTextColor();
parent.drawTextWithScale(guiGraphics, data.getDescription(), getRelativeX() + 3, getRelativeY(), textColor, 0.8F);
Component description = data.getDescription();
if (usesIcons) {
description = MekanismLang.GENERIC_STORED.translate(description, getData().get());
}
parent.drawTextWithScale(guiGraphics, description, getRelativeX() + 3, getRelativeY(), textColor, usesIcons ? 0.75F : 0.8F);
List<TYPE> options = getData().getEnums();
for (int i = 0, count = options.size(); i < count; i++) {
int center = optionDistance * i;
Component text = options.get(i).getTextComponent();
TYPE option = options.get(i);
Component text = option.getTextComponent();
//Similar to logic for drawScaledCenteredText except shifts values slightly if they go past the max length
int textWidth = parent.getStringWidth(text);
float widthScaling = (textWidth / 2F) * TEXT_SCALE;
float left = BAR_START + center - widthScaling;
float widthScaling = usesIcons ? 2.5F : (textWidth / 2F) * TEXT_SCALE;
int optionCenter = BAR_START + center;
float left = optionCenter - widthScaling;
if (left < 0) {
left = 0;
} else {
int max = parent.getScreenWidth() - 1;
int end = xPos + Mth.ceil(left + textWidth * TEXT_SCALE);
float objectWidth = usesIcons ? 5 : textWidth * TEXT_SCALE;
int end = xPos + Mth.ceil(left + objectWidth);
if (end > max) {
left -= end - max;
}
}
parent.drawTextWithScale(guiGraphics, text, getRelativeX() + left, getRelativeY() + 20, textColor, TEXT_SCALE);
int color = textColor;
if (text.getStyle().getColor() != null) {
color = 0xFF000000 | text.getStyle().getColor().getValue();
}
GuiUtils.fill(guiGraphics, getRelativeX() + optionCenter, getRelativeY() + 17, 1, 3, color);
if (usesIcons) {
IHasModeIcon hasModeIcon = (IHasModeIcon) option;
guiGraphics.blit(hasModeIcon.getModeIcon(), (int) (getRelativeX() + optionCenter - 8), getRelativeY() + 19, 0, 0, 16, 16, 16, 16);
} else {
parent.drawTextWithScale(guiGraphics, text, getRelativeX() + left, getRelativeY() + 20, textColor, TEXT_SCALE);
}
}
}

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 @@ public static <CHEMICAL extends Chemical<CHEMICAL>> ChemicalTankSpec<CHEMICAL> c
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
7 changes: 6 additions & 1 deletion src/main/java/mekanism/common/content/gear/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ boolean remove() {

@Override
public void displayModeChange(Player player, Component modeName, IHasTextComponent mode) {
player.sendSystemMessage(MekanismUtils.logFormat(MekanismLang.MODULE_MODE_CHANGE.translate(modeName, EnumColor.INDIGO, mode)));
Component modeComponent = mode.getTextComponent();
if (modeComponent.getStyle().getColor() != null) {
player.sendSystemMessage(MekanismUtils.logFormat(MekanismLang.MODULE_MODE_CHANGE.translate(modeName, modeComponent)));
} else {
player.sendSystemMessage(MekanismUtils.logFormat(MekanismLang.MODULE_MODE_CHANGE.translate(modeName, EnumColor.INDIGO, modeComponent)));
}
}

@Override
Expand Down
Loading