- Implemented a system that warns/disconnects you when your elytra health is low
- In rocket flight mode, the player will now ascend to the flying altitude faster
This commit is contained in:
parent
57b60deb48
commit
aac8e65b61
@ -1,7 +1,9 @@
|
|||||||
package fhannenheim.autopilot;
|
package fhannenheim.autopilot;
|
||||||
|
|
||||||
import fhannenheim.autopilot.chat.ChatCommandHandler;
|
import fhannenheim.autopilot.chat.ChatCommandHandler;
|
||||||
|
import fhannenheim.autopilot.flight.FlightHandler;
|
||||||
import fhannenheim.autopilot.util.Config;
|
import fhannenheim.autopilot.util.Config;
|
||||||
|
import fhannenheim.autopilot.util.KeybindHandler;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fhannenheim.autopilot.chat;
|
package fhannenheim.autopilot.chat;
|
||||||
|
|
||||||
import fhannenheim.autopilot.FlightHandler;
|
import fhannenheim.autopilot.flight.FlightHandler;
|
||||||
import fhannenheim.autopilot.util.FlightType;
|
import fhannenheim.autopilot.util.FlightType;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
@ -2,10 +2,9 @@ package fhannenheim.autopilot.flight;
|
|||||||
|
|
||||||
import com.sun.javafx.geom.Vec2d;
|
import com.sun.javafx.geom.Vec2d;
|
||||||
import fhannenheim.autopilot.Autopilot;
|
import fhannenheim.autopilot.Autopilot;
|
||||||
import fhannenheim.autopilot.FlightHandler;
|
|
||||||
import fhannenheim.autopilot.util.Config;
|
import fhannenheim.autopilot.util.Config;
|
||||||
import fhannenheim.autopilot.util.InventoryUtils;
|
import fhannenheim.autopilot.util.InventoryUtils;
|
||||||
import fhannenheim.autopilot.util.OnArrive;
|
import fhannenheim.autopilot.util.SpecialActions;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.play.client.CPlayerTryUseItemPacket;
|
import net.minecraft.network.play.client.CPlayerTryUseItemPacket;
|
||||||
@ -16,6 +15,7 @@ public class FlightExecutor {
|
|||||||
public FlightHandler flightHandler;
|
public FlightHandler flightHandler;
|
||||||
public int ticksSinceRocket;
|
public int ticksSinceRocket;
|
||||||
private FlightPhase flightPhase;
|
private FlightPhase flightPhase;
|
||||||
|
public boolean preventRocket;
|
||||||
|
|
||||||
public FlightExecutor(FlightHandler flightHandler) {
|
public FlightExecutor(FlightHandler flightHandler) {
|
||||||
this.flightHandler = flightHandler;
|
this.flightHandler = flightHandler;
|
||||||
@ -25,26 +25,27 @@ public class FlightExecutor {
|
|||||||
public void rocketFlight(PlayerEntity playerEntity) {
|
public void rocketFlight(PlayerEntity playerEntity) {
|
||||||
ticksSinceRocket++;
|
ticksSinceRocket++;
|
||||||
|
|
||||||
playerEntity.rotationPitch = -3;
|
|
||||||
|
playerEntity.rotationPitch = playerEntity.getPosY() + 10 < Config.flight_level.get() ? -15 : -3;
|
||||||
|
|
||||||
// Place new rockets in hand if needed
|
// Place new rockets in hand if needed
|
||||||
InventoryUtils.refillRockets(playerEntity);
|
InventoryUtils.refillRockets(playerEntity);
|
||||||
|
|
||||||
if (flightHandler.destination == null || Vec2d.distance(flightHandler.destination.x, flightHandler.destination.z, playerEntity.getPosX(), playerEntity.getPosZ()) > 3) {
|
if (flightHandler.destination == null || Vec2d.distance(flightHandler.destination.x, flightHandler.destination.z, playerEntity.getPosX(), playerEntity.getPosZ()) > 3) {
|
||||||
// If the player is lower than the flying altitude and is flying too slow, use a rocket to boost speed
|
// If the player is lower than the flying altitude and is flying too slow, use a rocket to boost speed
|
||||||
if (Math.sqrt(Math.pow(playerEntity.getMotion().x, 2) + Math.pow(playerEntity.getMotion().z, 2)) < 1.5f
|
if (Math.sqrt(Math.pow(playerEntity.getMotion().x, 2) + Math.pow(playerEntity.getMotion().z, 2)) < (playerEntity.getPosY() + 10 < Config.flight_level.get() ? 1 : 1.5f)
|
||||||
&& playerEntity.getPosition().getY() < Config.flight_level.get()
|
&& playerEntity.getPosition().getY() < Config.flight_level.get()
|
||||||
&& ticksSinceRocket > 3) {
|
&& ticksSinceRocket > 3) {
|
||||||
useRocket();
|
useRocket();
|
||||||
ticksSinceRocket = 0;
|
ticksSinceRocket = 0;
|
||||||
}
|
}
|
||||||
} else if (flightHandler.destination != null) {
|
} else if (flightHandler.destination != null) {
|
||||||
if (Config.on_arrive.get() == OnArrive.Disconnect) {
|
if (Config.on_arrive.get() == SpecialActions.Disconnect) {
|
||||||
flightHandler.shallDisconnect = true;
|
flightHandler.shallDisconnect = true;
|
||||||
playerEntity.rotationPitch = -90;
|
playerEntity.rotationPitch = -90;
|
||||||
useRocket();
|
useRocket();
|
||||||
ticksSinceRocket = 0;
|
ticksSinceRocket = 0;
|
||||||
} else if (Config.on_arrive.get() == OnArrive.TryToLand) {
|
} else if (Config.on_arrive.get() == SpecialActions.Alert) {
|
||||||
playerEntity.playSound(SoundEvents.BLOCK_BELL_USE, 4, 1);
|
playerEntity.playSound(SoundEvents.BLOCK_BELL_USE, 4, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,14 +76,20 @@ public class FlightExecutor {
|
|||||||
flightPhase = FlightPhase.ASCEND;
|
flightPhase = FlightPhase.ASCEND;
|
||||||
else if (flightPhase == FlightPhase.ASCEND && velocity < 0.224041611f)
|
else if (flightPhase == FlightPhase.ASCEND && velocity < 0.224041611f)
|
||||||
flightPhase = FlightPhase.DESCEND;
|
flightPhase = FlightPhase.DESCEND;
|
||||||
if (
|
if (flightPhase == FlightPhase.ASCEND && playerEntity.getPosY() < Config.flight_level.get() && velocity < 0.75f) {
|
||||||
flightPhase == FlightPhase.ASCEND &&
|
|
||||||
playerEntity.getPosY() + 50 < Config.flight_level.get() &&
|
|
||||||
velocity < 0.75f
|
|
||||||
) {
|
|
||||||
useRocket();
|
useRocket();
|
||||||
ticksSinceRocket = 0;
|
ticksSinceRocket = 0;
|
||||||
}
|
}
|
||||||
|
if (flightHandler.destination != null && Vec2d.distance(flightHandler.destination.x, flightHandler.destination.z, playerEntity.getPosX(), playerEntity.getPosZ()) < 3) {
|
||||||
|
if (Config.on_arrive.get() == SpecialActions.Disconnect) {
|
||||||
|
flightHandler.shallDisconnect = true;
|
||||||
|
playerEntity.rotationPitch = -90;
|
||||||
|
useRocket();
|
||||||
|
ticksSinceRocket = 0;
|
||||||
|
} else if (Config.on_arrive.get() == SpecialActions.Alert) {
|
||||||
|
playerEntity.playSound(SoundEvents.BLOCK_BELL_USE, 4, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getVelocity(PlayerEntity playerEntity) {
|
private double getVelocity(PlayerEntity playerEntity) {
|
||||||
@ -95,6 +102,8 @@ public class FlightExecutor {
|
|||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void useRocket() {
|
private void useRocket() {
|
||||||
|
if (preventRocket)
|
||||||
|
return;
|
||||||
try {
|
try {
|
||||||
Minecraft.getInstance().getConnection().sendPacket(new CPlayerTryUseItemPacket(Hand.MAIN_HAND));
|
Minecraft.getInstance().getConnection().sendPacket(new CPlayerTryUseItemPacket(Hand.MAIN_HAND));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package fhannenheim.autopilot;
|
package fhannenheim.autopilot.flight;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.tree.RootCommandNode;
|
import com.mojang.brigadier.tree.RootCommandNode;
|
||||||
import com.sun.javafx.geom.Vec2d;
|
import com.sun.javafx.geom.Vec2d;
|
||||||
import fhannenheim.autopilot.flight.FlightExecutor;
|
import fhannenheim.autopilot.Autopilot;
|
||||||
import fhannenheim.autopilot.util.FlightType;
|
import fhannenheim.autopilot.util.*;
|
||||||
import fhannenheim.autopilot.util.InventoryUtils;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screen.DirtMessageScreen;
|
import net.minecraft.client.gui.screen.DirtMessageScreen;
|
||||||
import net.minecraft.client.gui.screen.MainMenuScreen;
|
import net.minecraft.client.gui.screen.MainMenuScreen;
|
||||||
@ -16,6 +15,7 @@ import net.minecraft.command.arguments.EntityAnchorArgument;
|
|||||||
import net.minecraft.command.arguments.Vec2Argument;
|
import net.minecraft.command.arguments.Vec2Argument;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.play.client.CEntityActionPacket;
|
import net.minecraft.network.play.client.CEntityActionPacket;
|
||||||
|
import net.minecraft.util.SoundEvents;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
import net.minecraftforge.client.event.InputEvent;
|
import net.minecraftforge.client.event.InputEvent;
|
||||||
@ -100,17 +100,28 @@ public class FlightHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isAutoFlying) {
|
if (isAutoFlying) {
|
||||||
|
flightExecutor.preventRocket = false;
|
||||||
if (!playerEntity.isElytraFlying() && !playerEntity.onGround) {
|
if (!playerEntity.isElytraFlying() && !playerEntity.onGround) {
|
||||||
// If the player isn't elytra flying but the autopilot is still on the elytra has probably broken. Replace it
|
// If the player isn't elytra flying but the autopilot is still on the elytra has probably broken. Replace it
|
||||||
InventoryUtils.replaceElytra(playerEntity);
|
InventoryUtils.replaceElytra(playerEntity);
|
||||||
|
|
||||||
// Start flying again
|
// Start flying again
|
||||||
playerEntity.startFallFlying();
|
|
||||||
Minecraft.getInstance().getConnection().sendPacket(new CEntityActionPacket(playerEntity, CEntityActionPacket.Action.START_FALL_FLYING));
|
Minecraft.getInstance().getConnection().sendPacket(new CEntityActionPacket(playerEntity, CEntityActionPacket.Action.START_FALL_FLYING));
|
||||||
}
|
}
|
||||||
if (destination != null) {
|
if (destination != null) {
|
||||||
playerEntity.lookAt(EntityAnchorArgument.Type.EYES, destination);
|
playerEntity.lookAt(EntityAnchorArgument.Type.EYES, destination);
|
||||||
}
|
}
|
||||||
|
Autopilot.LOGGER.info(InventoryUtils.hasDurableElytra(playerEntity));
|
||||||
|
if (InventoryUtils.currentElytraDurability(playerEntity) < Config.low_durability.get() && !InventoryUtils.hasDurableElytra(playerEntity)) {
|
||||||
|
if (Config.on_low_durability.get() == SpecialActions.Alert) {
|
||||||
|
flightExecutor.preventRocket = true;
|
||||||
|
playerEntity.playSound(SoundEvents.BLOCK_BELL_USE, 4, 1);
|
||||||
|
} else {
|
||||||
|
shallDisconnect = true;
|
||||||
|
isAutoFlying = false;
|
||||||
|
destination = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (flightType == FlightType.ROCKETS)
|
if (flightType == FlightType.ROCKETS)
|
||||||
flightExecutor.rocketFlight(playerEntity);
|
flightExecutor.rocketFlight(playerEntity);
|
@ -14,7 +14,10 @@ public class Config {
|
|||||||
|
|
||||||
public static ForgeConfigSpec.IntValue flight_level;
|
public static ForgeConfigSpec.IntValue flight_level;
|
||||||
public static ForgeConfigSpec.EnumValue<FlightType> default_flight_type;
|
public static ForgeConfigSpec.EnumValue<FlightType> default_flight_type;
|
||||||
public static ForgeConfigSpec.EnumValue<OnArrive> on_arrive;
|
public static ForgeConfigSpec.EnumValue<SpecialActions> on_arrive;
|
||||||
|
public static ForgeConfigSpec.IntValue low_durability;
|
||||||
|
public static ForgeConfigSpec.EnumValue<SpecialActions> on_low_durability;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
init(builder);
|
init(builder);
|
||||||
|
|
||||||
@ -25,15 +28,22 @@ public class Config {
|
|||||||
config.comment("Autopilot config");
|
config.comment("Autopilot config");
|
||||||
flight_level = config
|
flight_level = config
|
||||||
.comment("Altitude the autopilot flies at. It will slowly rise to the specified y level and then stay there.\n" +
|
.comment("Altitude the autopilot flies at. It will slowly rise to the specified y level and then stay there.\n" +
|
||||||
"The default is 400 so the Autopilot won't run into blocks")
|
"The default is 350 so the Autopilot won't run into blocks")
|
||||||
.defineInRange("autopilot.flight_level", 400, 1, 1000000);
|
.defineInRange("autopilot.flight_level", 350, 1, 1000000);
|
||||||
default_flight_type = config
|
default_flight_type = config
|
||||||
.comment("The default flight type that will be used if you don't specify anything in the flyto command.")
|
.comment("The default flight type that will be used if you don't specify anything in the flyto command.")
|
||||||
.defineEnum("autopilot.default_flight_type", FlightType.ROCKETS);
|
.defineEnum("autopilot.default_flight_type", FlightType.ROCKETS);
|
||||||
on_arrive = config
|
on_arrive = config
|
||||||
.comment("What to do if the autopilot arrives at the destination." +
|
.comment("What to do if the autopilot arrives at the destination." +
|
||||||
"\nIt can either disconnect, or try to land and then disconnect.")
|
"\nIt can either disconnect, or try to land and alert you.")
|
||||||
.defineEnum("autopilot.on_arrive", OnArrive.Disconnect);
|
.defineEnum("autopilot.on_arrive", SpecialActions.Disconnect);
|
||||||
|
low_durability = config
|
||||||
|
.comment("What is defined as low durability")
|
||||||
|
.defineInRange("autopilot.low_durability", 20, 1, 200);
|
||||||
|
on_low_durability = config
|
||||||
|
.comment("What to do if the current elytra has less than 20 durability and there's no other to replace it in your inventory." +
|
||||||
|
"\nIt can either disconnect, or try to land and alert you.")
|
||||||
|
.defineEnum("autopilot.on_low_durability", SpecialActions.Disconnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class InventoryUtils {
|
|||||||
slot = i;
|
slot = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (slot != -1) {
|
if (slot != -1 && toServerSlotId(slot) != 6) {
|
||||||
PlayerContainer container = player.container;
|
PlayerContainer container = player.container;
|
||||||
click(container, toServerSlotId(slot));
|
click(container, toServerSlotId(slot));
|
||||||
click(container, 6);
|
click(container, 6);
|
||||||
@ -54,6 +54,27 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasDurableElytra(PlayerEntity player) {
|
||||||
|
PlayerInventory inventory = player.inventory;
|
||||||
|
if (inventory.hasAny(ImmutableSet.of(Items.ELYTRA))) {
|
||||||
|
int slot = -1;
|
||||||
|
for (int i = 0; i < inventory.mainInventory.size(); ++i) {
|
||||||
|
if (inventory.getStackInSlot(i).getItem() == Items.ELYTRA &&
|
||||||
|
inventory.getStackInSlot(i).getDamage() < inventory.getStackInSlot(i).getMaxDamage() - Config.low_durability.get()) {
|
||||||
|
slot = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slot != -1 && toServerSlotId(slot) != 6;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int currentElytraDurability(PlayerEntity player) {
|
||||||
|
ItemStack elytra = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
|
||||||
|
return elytra.getMaxDamage() - elytra.getDamage();
|
||||||
|
}
|
||||||
|
|
||||||
private static void click(Container container, int slotId) {
|
private static void click(Container container, int slotId) {
|
||||||
final PlayerController playerController = Minecraft.getInstance().playerController;
|
final PlayerController playerController = Minecraft.getInstance().playerController;
|
||||||
if (playerController != null && Minecraft.getInstance().player != null)
|
if (playerController != null && Minecraft.getInstance().player != null)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package fhannenheim.autopilot;
|
package fhannenheim.autopilot.util;
|
||||||
|
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
@ -1,6 +1,6 @@
|
|||||||
package fhannenheim.autopilot.util;
|
package fhannenheim.autopilot.util;
|
||||||
|
|
||||||
public enum OnArrive{
|
public enum SpecialActions {
|
||||||
TryToLand,
|
Alert,
|
||||||
Disconnect
|
Disconnect
|
||||||
}
|
}
|
@ -2,5 +2,5 @@
|
|||||||
"keybind.autopilot.flyforwardrockets": "Fly Forward Using Rockets",
|
"keybind.autopilot.flyforwardrockets": "Fly Forward Using Rockets",
|
||||||
"keybind.autopilot.flyforward4040": "Fly Forward Using The 4040 Method",
|
"keybind.autopilot.flyforward4040": "Fly Forward Using The 4040 Method",
|
||||||
"category.autopilot": "Auto Elytra",
|
"category.autopilot": "Auto Elytra",
|
||||||
"autopilot.disconnect": "You where disconnected because the autopilot arrived at the destination."
|
"autopilot.disconnect": "Disconnected because you arrived at your destination or the elytra has low durability."
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user