initial commit

master
Frieder Hannenheim 2020-10-06 16:31:21 +02:00
commit bf36f74d4b
19 changed files with 858 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/build
/.idea
/.gradle
/run

2
AutoElytra.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

91
build.gradle Normal file
View File

@ -0,0 +1,91 @@
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
apply plugin: 'net.minecraftforge.gradle'
version = modVersion
group = modGroup
archivesBaseName = modBaseName
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20201002-1.15.1'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
autopilot {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
autopilot {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
args '--mod', 'autopilot', '--all', '--output', file('src/generated/resources/')
mods {
autopilot {
source sourceSets.main
}
}
}
}
}
dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.15.2-31.2.9'
}

3
gradle.properties Normal file
View File

@ -0,0 +1,3 @@
modGroup=fhannenheim
modVersion=1.0
modBaseName=autopilot

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
#Fri Oct 02 18:04:07 CEST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

172
gradlew vendored Normal file
View File

@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

84
gradlew.bat vendored Normal file
View File

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,46 @@
package fhannenheim.autopilot;
import fhannenheim.autopilot.chat.ChatCommandHandler;
import fhannenheim.autopilot.util.Config;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Mod("autopilot")
@Mod.EventBusSubscriber(modid = Autopilot.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class Autopilot {
public static final Logger LOGGER = LogManager.getLogger();
public static final String MOD_ID = "autopilot";
public Autopilot() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.CONFIG);
Config.loadConfig(Config.CONFIG, FMLPaths.CONFIGDIR.get().resolve("autopilot-client.toml").toString());
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new ChatCommandHandler());
}
private void setup(final FMLCommonSetupEvent event) {
}
private void doClientStuff(final FMLClientSetupEvent event) {
FlightHandler handler = new FlightHandler();
MinecraftForge.EVENT_BUS.register(handler);
handler.onClientSetup();
}
}

View File

@ -0,0 +1,258 @@
package fhannenheim.autopilot;
import com.google.common.collect.ImmutableSet;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.RootCommandNode;
import com.sun.javafx.geom.Vec2d;
import fhannenheim.autopilot.util.Config;
import fhannenheim.autopilot.util.FlightType;
import fhannenheim.autopilot.util.OnArrive;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.DirtMessageScreen;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.multiplayer.PlayerController;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.ISuggestionProvider;
import net.minecraft.command.arguments.EntityAnchorArgument;
import net.minecraft.command.arguments.Vec2Argument;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.play.client.CEntityActionPacket;
import net.minecraft.network.play.client.CPlayerTryUseItemPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.concurrent.TickDelayedTask;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import org.lwjgl.glfw.GLFW;
import java.io.IOException;
public class FlightHandler {
public static KeyBinding flyForward;
public static FlightHandler instance;
public boolean isAutoFlying;
public Vec3d destination;
public FlightType type;
private int ticksSinceRocket;
private boolean shallDisconnect;
public void onClientSetup() {
flyForward = new KeyBinding("keybind.autopilot.flyforward",
GLFW.GLFW_KEY_V, "category.autopilot");
ClientRegistry.registerKeyBinding(flyForward);
instance = this;
}
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
PlayerEntity playerEntity = Minecraft.getInstance().player;
if (Minecraft.getInstance().currentScreen instanceof ChatScreen) {
TextFieldWidget inputField = ((ChatScreen) Minecraft.getInstance().currentScreen).inputField;
// Don't read this. It is bad. It could probably be improved but I don't care since it works
if (inputField.getText().startsWith(".")) {
inputField.setSuggestion(".flyto ~ ~".replace(inputField.getText(), ""));
if (inputField.getText().startsWith(".flyto ")) {
inputField.setSuggestion("~ ~".substring(
MathHelper.clamp(numberOfSpaces(
inputField.getText().replace(".flyto ", "")) * 2 + 1, 0, 3)));
if (numberOfSpaces(inputField.getText().replace(".flyto ", "")) * 2 + 1 >= 4 && inputField.getText().charAt(inputField.getText().length() - 1) == ' ') {
inputField.setSuggestion("[rockets,4040]");
}
} else {
if (event.getKey() == GLFW.GLFW_KEY_TAB) {
inputField.setText(".flyto ");
}
}
}
}
if (playerEntity != null && flyForward.isPressed()) {
if (!isAutoFlying) {
playerEntity.rotationPitch = -3;
if (!playerEntity.isElytraFlying()) {
destination = null;
playerEntity.startFallFlying();
}
destination = null;
type = FlightType.ROCKETS;
isAutoFlying = true;
} else {
isAutoFlying = false;
}
}
}
public void flyTo(Vec3d _destination, FlightType flightType) {
destination = _destination;
type = flightType;
isAutoFlying = true;
}
@SubscribeEvent
public void tick(TickEvent.ClientTickEvent event) throws IOException {
if (event.side != LogicalSide.CLIENT || event.phase != TickEvent.Phase.END)
return;
ticksSinceRocket++;
PlayerEntity playerEntity = Minecraft.getInstance().player;
if (playerEntity == null)
return;
CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<CommandSource>((RootCommandNode)Minecraft.getInstance().getConnection().commandDispatcher.getRoot());
dispatcher.register(Commands.literal("flyto")
.then(Commands.argument("location", Vec2Argument.vec2())
.then(Commands.literal("rockets"))
.then(Commands.literal("4040")))
.then(Commands.argument("location", Vec2Argument.vec2()))
);
Minecraft.getInstance().getConnection().commandDispatcher = new CommandDispatcher<ISuggestionProvider>((RootCommandNode)dispatcher.getRoot());
if (isAutoFlying) {
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
replaceElytra(playerEntity);
// Start flying again
playerEntity.startFallFlying();
Minecraft.getInstance().getConnection().sendPacket(new CEntityActionPacket(playerEntity, CEntityActionPacket.Action.START_FALL_FLYING));
}
if (destination != null) {
playerEntity.lookAt(EntityAnchorArgument.Type.EYES, destination);
}
playerEntity.rotationPitch = -3;
PlayerInventory inventory = playerEntity.inventory;
// Place new rockets in hand if needed
refillRockets(playerEntity);
if (destination != null && Vec2d.distance(destination.x , playerEntity.getPosX(), destination.z, playerEntity.getPosZ()) > 5) {
// 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(Math.abs(playerEntity.getMotion().x), 2) + Math.pow(Math.abs(playerEntity.getMotion().z), 2)) < 1.5f
&& playerEntity.getPosition().getY() < Config.flight_level.get()
&& ticksSinceRocket > 3) {
Minecraft.getInstance().getConnection().sendPacket(new CPlayerTryUseItemPacket(Hand.MAIN_HAND));
ticksSinceRocket = 0;
}
}
else {
if (Config.on_arrive.get() == OnArrive.Disconnect) {
Autopilot.LOGGER.info("gae");
shallDisconnect = true;
}else if(Config.on_arrive.get() == OnArrive.TryToLand){
playerEntity.playSound(SoundEvents.BLOCK_BELL_USE,4,1);
}
}
}
}
@SubscribeEvent
public void disconnect(TickEvent.RenderTickEvent event){
if(shallDisconnect){
shallDisconnect = false;
isAutoFlying = false;
if (Minecraft.getInstance().world != null) {
Minecraft.getInstance().world.sendQuittingDisconnectingPacket();
}
Minecraft.getInstance().unloadWorld(new DirtMessageScreen(new TranslationTextComponent("menu.savingLevel")));
Minecraft.getInstance().displayGuiScreen(new MainMenuScreen());
}
}
public void flyToCoord(Vec3d pos, FlightType flightType) {
destination = pos;
type = flightType;
}
private void refillRockets(PlayerEntity player) {
PlayerInventory inventory = player.inventory;
if (inventory.mainInventory.get(inventory.currentItem).getItem() != Items.FIREWORK_ROCKET) {
if (inventory.hasAny(ImmutableSet.of(Items.FIREWORK_ROCKET))) {
int slot = -1;
for (int i = 0; i < inventory.mainInventory.size(); ++i) {
if (inventory.mainInventory.get(i).getItem() == Items.FIREWORK_ROCKET) {
slot = i;
}
}
if (slot != -1) {
PlayerContainer container = player.container;
click(container, toServerSlotId(slot));
click(container, toServerSlotId(inventory.currentItem));
}
}
}
}
private void replaceElytra(PlayerEntity player) {
PlayerInventory inventory = player.inventory;
ItemStack elytra = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
Autopilot.LOGGER.info(inventory.getSlotFor(elytra));
if (elytra.getDamage() == elytra.getMaxDamage() - 1) {
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() - 1) {
slot = i;
}
}
if (slot != -1) {
Autopilot.LOGGER.info("le why?");
PlayerContainer container = player.container;
click(container, toServerSlotId(slot));
click(container, 6);
click(container, toServerSlotId(slot));
}
}
}
}
private void click(Container container, int slotId) {
final PlayerController playerController = Minecraft.getInstance().playerController;
if (playerController != null)
playerController.windowClick(container.windowId, slotId, 0, ClickType.PICKUP, Minecraft.getInstance().player);
}
private int toServerSlotId(final int clientSlotId) {
// Hotbar
if (clientSlotId <= 8)
return clientSlotId + 36;
// Offhand
if (clientSlotId == 40)
return 45;
return clientSlotId;
}
private int numberOfSpaces(String string) {
int counter = 0;
for (int i = 0; i < string.length(); ++i) {
if (string.charAt(i) == ' ')
counter++;
}
return counter;
}
}

View File

@ -0,0 +1,70 @@
package fhannenheim.autopilot.chat;
import com.mojang.brigadier.CommandDispatcher;
import fhannenheim.autopilot.Autopilot;
import fhannenheim.autopilot.FlightHandler;
import fhannenheim.autopilot.util.FlightType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.Vec3Argument;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.http.auth.AUTH;
import org.lwjgl.glfw.GLFW;
public class ChatCommandHandler {
@SubscribeEvent
public void onChatInput(ClientChatEvent event){
String message = event.getMessage();
Autopilot.LOGGER.warn(message);
if(message.startsWith("/flyto "))
{
String[] commands = message.split(" ");
if(commands.length < 3){
showSyntax();
event.setCanceled(true);
return;
}
Vec3d pos = Vec3d.ZERO;
FlightType flightType = FlightType.ROCKETS;
try {
pos = new Vec3d(Integer.parseInt(commands[1]),0,Integer.parseInt(commands[2]));
} catch (NumberFormatException e){
showSyntax();
event.setCanceled(true);
return;
}
if(commands.length > 3){
switch (commands[3]){
case "rockets":
break;
case "4040":
flightType = FlightType.ANGLE4040;
break;
default:
showSyntax();
event.setCanceled(true);
return;
}
}
FlightHandler.instance.flyTo(pos,flightType);
event.setCanceled(true);
}
}
private void showSyntax(){
Minecraft.getInstance().ingameGUI.getChatGUI().printChatMessage(new StringTextComponent("Invalid Syntax").applyTextStyle(TextFormatting.RED));
Minecraft.getInstance().ingameGUI.getChatGUI().printChatMessage(new StringTextComponent("Usage:\n" +
" /flyto ~ ~ [rockets/4040]\n" +
"Example:\n /flyto 123 456 rockets"));
}
}

View File

@ -0,0 +1,45 @@
package fhannenheim.autopilot.util;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import fhannenheim.autopilot.Autopilot;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;
import java.io.File;
@Mod.EventBusSubscriber
public class Config {
private static final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec CONFIG;
public static ForgeConfigSpec.IntValue flight_level;
public static ForgeConfigSpec.EnumValue<FlightType> default_flight_type;
public static ForgeConfigSpec.EnumValue<OnArrive> on_arrive;
static {
init(builder);
CONFIG = builder.build();
}
public static void init(ForgeConfigSpec.Builder config){
config.comment("Autopilot config");
flight_level = config
.comment("altitude the autopilot flies at. It will slowly rise to the specified y level and then stay there.")
.defineInRange("autopilot.flight_level",300,1,1000000);
default_flight_type = config
.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);
on_arrive = config
.comment("What to do if the autopilot arrives at the destination." +
"\nIt can either disconnect, or try to land and then disconnect.")
.defineEnum("autopilot.on_arrive",OnArrive.Disconnect);
}
public static void loadConfig(ForgeConfigSpec config, String path){
final CommentedFileConfig file = CommentedFileConfig.builder(new File(path)).sync().autosave().writingMode(WritingMode.REPLACE).build();
file.load();
config.setConfig(file);
}
}

View File

@ -0,0 +1,6 @@
package fhannenheim.autopilot.util;
public enum FlightType{
ROCKETS,
ANGLE4040, // The exact angles aren't 40 40 but this flight method is known as the 40 40 method so I'll use that name
}

View File

@ -0,0 +1,6 @@
package fhannenheim.autopilot.util;
public enum OnArrive{
TryToLand,
Disconnect
}

View File

@ -0,0 +1,2 @@
public net.minecraft.client.gui.screen.ChatScreen field_146415_a # inputField
public net.minecraft.client.network.play.ClientPlayNetHandler field_195517_n # commandDispatcher

View File

@ -0,0 +1,50 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[31,)" #mandatory (26 is current forge version)
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="autopilot" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Autopilot" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
#updateJSONURL="http://myurl.me/" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="http://example.com/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
#logoFile="autopilot.png" #optional
# A text field displayed in the mod UI
#credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
#authors="Love, Cheese and small house plants" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.autopilot]] #optional
# the modid of the dependency
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[31,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.autopilot]]
modId="minecraft"
mandatory=true
versionRange="[1.15.2]"
ordering="NONE"
side="BOTH"

View File

@ -0,0 +1,5 @@
{
"keybind.autopilot.flyforward":"Start flying forward",
"category.autopilot":"Auto Elytra",
"autopilot.disconnect": "You where disconnected because the autopilot arrived at the destination"
}

View File

@ -0,0 +1,7 @@
{
"pack": {
"description": "autopilot resources",
"pack_format": 4,
"_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods."
}
}

1
todo.txt Normal file
View File

@ -0,0 +1 @@
Estimated time left + Flying from and to