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

Implement flight inertia cancellation #2612

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/util/input/KeyBind.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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--;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -157,6 +173,11 @@ public void addInfo(ItemStack itemStack, List<String> 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);
}

Expand Down Expand Up @@ -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();
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/gregtech/common/items/armor/IJetpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -89,14 +89,31 @@ 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 = flyKeyDown || descendKeyDown;
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;
}

/* 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;
}

if (!player.getEntityWorld().isRemote) {
player.fallDistance = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/items/armor/Jetpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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--;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down