Add autowalk
This commit is contained in:
parent
1eb9c2be88
commit
32ca414de0
6 changed files with 111 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
libzontreck=1.9.121923.1104
|
libzontreck=1.9.121923.1513
|
||||||
|
|
||||||
## Environment Properties
|
## Environment Properties
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ mod_name=Aria's Essentials
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=GPLv3
|
mod_license=GPLv3
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.1.121923.1046
|
mod_version=1.1.122123.1048
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||||
|
import dev.zontreck.essentials.client.Keybindings;
|
||||||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||||
import dev.zontreck.essentials.configs.AEClientConfig;
|
import dev.zontreck.essentials.configs.AEClientConfig;
|
||||||
import dev.zontreck.essentials.configs.AEServerConfig;
|
import dev.zontreck.essentials.configs.AEServerConfig;
|
||||||
|
@ -22,9 +23,12 @@ import dev.zontreck.essentials.rtp.RandomPositionFactory;
|
||||||
import dev.zontreck.essentials.util.BackPositionCaches;
|
import dev.zontreck.essentials.util.BackPositionCaches;
|
||||||
import dev.zontreck.libzontreck.events.RegisterPacketsEvent;
|
import dev.zontreck.libzontreck.events.RegisterPacketsEvent;
|
||||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.client.event.InputEvent;
|
||||||
|
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
|
@ -133,6 +137,13 @@ public class AriasEssentials {
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(new HeartsRenderer());
|
MinecraftForge.EVENT_BUS.register(new HeartsRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRegisterKeyBinds(RegisterKeyMappingsEvent ev)
|
||||||
|
{
|
||||||
|
ev.register(Keybindings.AUTOWALK);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
64
src/main/java/dev/zontreck/essentials/client/AutoWalk.java
Normal file
64
src/main/java/dev/zontreck/essentials/client/AutoWalk.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package dev.zontreck.essentials.client;
|
||||||
|
|
||||||
|
import dev.zontreck.essentials.AriasEssentials;
|
||||||
|
import dev.zontreck.essentials.Messages;
|
||||||
|
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.client.event.InputEvent;
|
||||||
|
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(modid = AriasEssentials.MODID, value = Dist.CLIENT)
|
||||||
|
public class AutoWalk {
|
||||||
|
private static boolean isWalking = false;
|
||||||
|
private static boolean autoJump = false;
|
||||||
|
static Thread runner;
|
||||||
|
static long lastPress;
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onKeyPress(InputEvent.Key event) {
|
||||||
|
if(Keybindings.AUTOWALK.matches(event.getKey(), event.getScanCode()) && Minecraft.getInstance().screen == null && lastPress+5 < Instant.now().getEpochSecond() && Keybindings.AUTOWALK.isDown())
|
||||||
|
{
|
||||||
|
lastPress = Instant.now().getEpochSecond();
|
||||||
|
if(isWalking)
|
||||||
|
{
|
||||||
|
stopWalking();
|
||||||
|
} else startWalking();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void startWalking() {
|
||||||
|
isWalking=true;
|
||||||
|
autoJump = Minecraft.getInstance().options.autoJump().get();
|
||||||
|
Minecraft.getInstance().options.autoJump().set(true);
|
||||||
|
|
||||||
|
Minecraft.getInstance().player.sendSystemMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking started"));
|
||||||
|
|
||||||
|
runner = new Thread(()->{
|
||||||
|
while(AutoWalk.isWalking)
|
||||||
|
{
|
||||||
|
if(!Minecraft.getInstance().options.keyUp.isDown())
|
||||||
|
Minecraft.getInstance().options.keyUp.setDown(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
runner.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void stopWalking() {
|
||||||
|
isWalking=false;
|
||||||
|
runner.interrupt();
|
||||||
|
runner=null;
|
||||||
|
Minecraft.getInstance().options.autoJump().set(autoJump);
|
||||||
|
Minecraft.getInstance().options.keyUp.setDown(false);
|
||||||
|
|
||||||
|
Minecraft.getInstance().player.sendSystemMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking stopped"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package dev.zontreck.essentials.client;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class Keybindings {
|
||||||
|
public static final String KEY_CATEGORY_ESSENTIALS = "key.category.ariasessentials";
|
||||||
|
public static final String KEY_AUTOWALK = "key.ariasessentials.autowalk";
|
||||||
|
|
||||||
|
public static final KeyMapping AUTOWALK = createKeyMapping(KEY_AUTOWALK, InputConstants.KEY_CAPSLOCK, KEY_CATEGORY_ESSENTIALS);
|
||||||
|
|
||||||
|
private static KeyMapping createKeyMapping(String name, int keycode, String category){
|
||||||
|
final KeyMapping key = new KeyMapping(name, keycode, category);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerKeyMappings(RegisterKeyMappingsEvent event)
|
||||||
|
{
|
||||||
|
event.register(AUTOWALK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class AEClientConfig
|
||||||
|
|
||||||
public static final ForgeConfigSpec.ConfigValue<Boolean> ENABLE_HEARTS_RENDER;
|
public static final ForgeConfigSpec.ConfigValue<Boolean> ENABLE_HEARTS_RENDER;
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
BUILDER.push("overlay");
|
BUILDER.push("overlay");
|
||||||
ENABLE_HEARTS_RENDER = BUILDER.comment("Enable compressed hearts? This puts all the hearts in a single row").define("enable_hearts", true);
|
ENABLE_HEARTS_RENDER = BUILDER.comment("Enable compressed hearts? This puts all the hearts in a single row").define("enable_hearts", true);
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"key.category.ariasessentials": "Aria's Essentials",
|
||||||
|
"key.ariasessentials.autowalk": "Auto Walk"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue