diff --git a/build.gradle b/build.gradle index cd8a252..f552515 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,14 @@ repositories { name "TerraformersMC" url "https://maven.terraformersmc.com/releases" } + maven { + name "Meteor - Releases" + url "https://maven.meteordev.org/releases" + } + maven { + name "Meteor - Snapshots" + url "https://maven.meteordev.org/snapshots" + } } dependencies { @@ -25,6 +33,8 @@ dependencies { include "me.shedaniel.cloth:cloth-config-fabric:12.0.109" modApi "com.terraformersmc:modmenu:8.0.0-beta.2" + + modCompileOnly "meteordevelopment:meteor-client:0.5.5-SNAPSHOT" } loom { diff --git a/src/main/java/meteordevelopment/voyager/PathManager.java b/src/main/java/meteordevelopment/voyager/PathManager.java new file mode 100644 index 0000000..615db47 --- /dev/null +++ b/src/main/java/meteordevelopment/voyager/PathManager.java @@ -0,0 +1,176 @@ +package meteordevelopment.voyager; + +import meteordevelopment.meteorclient.pathing.IPathManager; +import meteordevelopment.meteorclient.settings.*; +import meteordevelopment.meteorclient.utils.render.color.Color; +import meteordevelopment.meteorclient.utils.render.color.SettingColor; +import meteordevelopment.voyager.goals.DirectionGoal; +import meteordevelopment.voyager.goals.XYZGoal; +import meteordevelopment.voyager.goals.XZGoal; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import org.apache.commons.lang3.NotImplementedException; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Predicate; + +@SuppressWarnings("unused") +public class PathManager implements IPathManager { + private final VoyagerSettings settings = new VoyagerSettings(); + + @Override + public String getName() { + return "Voyager"; + } + + @Override + public boolean isPathing() { + return Voyager.INSTANCE.isMoving(); + } + + @Override + public void pause() { + } + + @Override + public void resume() { + } + + @Override + public void stop() { + Voyager.INSTANCE.stop(); + } + + @Override + public void moveTo(BlockPos pos, boolean ignoreY) { + if (ignoreY) { + Voyager.INSTANCE.moveTo(new XZGoal(pos.getX(), pos.getY())); + return; + } + + Voyager.INSTANCE.moveTo(new XYZGoal(pos)); + } + + @Override + public void moveInDirection(float yaw) { + Voyager.INSTANCE.moveTo(new DirectionGoal(yaw)); + } + + @Override + public void mine(Block... blocks) { + } + + @Override + public void follow(Predicate predicate) { + for (Entity entity : Voyager.mc.world.getEntities()) { + if (predicate.test(entity)) { + Voyager.INSTANCE.moveTo(new XYZGoal(entity.getBlockPos())); + return; + } + } + } + + @Override + public float getTargetYaw() { + if (Voyager.mc.player.input instanceof VInput input) + return input.getYaw(1); + + return 0; + } + + @Override + public float getTargetPitch() { + return isPathing() ? Voyager.mc.player.getPitch() : 0; + } + + @Override + public ISettings getSettings() { + return settings; + } + + private static class VoyagerSettings implements ISettings { + private final Settings settings = new Settings(); + private final Setting setting = new BoolSetting.Builder().build(); + + @SuppressWarnings({"rawtypes", "unchecked"}) + public VoyagerSettings() { + Map groups = new HashMap<>(); + + for (var setting : Voyager.INSTANCE.getSettings().settings) { + SettingGroup group = groups.computeIfAbsent(setting.category, settings::createGroup); + + if (setting instanceof meteordevelopment.voyager.settings.BoolSetting s) { + group.add(new BoolSetting.Builder() + .name(s.name) + .description(s.description) + .defaultValue(s.getDefaultValue()) + .onChanged(s::set) + .onModuleActivated(booleanSetting -> booleanSetting.set(s.get())) + .build()); + } + else if (setting instanceof meteordevelopment.voyager.settings.EnumSetting s) { + group.add(new EnumSetting.Builder<>() + .name(s.name) + .description(s.description) + .defaultValue((Enum) s.getDefaultValue()) + .onChanged(anEnum -> s.set(anEnum)) + .onModuleActivated(booleanSetting -> booleanSetting.set((Enum) s.get())) + .build()); + } + else if (setting instanceof meteordevelopment.voyager.settings.StringSetting s) { + group.add(new StringSetting.Builder() + .name(s.name) + .description(s.description) + .defaultValue(s.getDefaultValue()) + .onChanged(s::set) + .onModuleActivated(stringSetting -> stringSetting.set(s.get())) + .build()); + } + else if (setting instanceof meteordevelopment.voyager.settings.ColorSetting s) { + group.add(new ColorSetting.Builder() + .name(s.name) + .description(s.description) + .defaultValue(new Color(s.getDefaultValue().pack())) + .onChanged(settingColor -> s.set(new meteordevelopment.voyager.utils.Color(settingColor.getPacked()))) + .onModuleActivated(settingColorSetting -> settingColorSetting.set(new SettingColor(s.get().pack()))) + .build()); + } + else { + throw new NotImplementedException(); + } + } + } + + @Override + public Settings get() { + return settings; + } + + @Override + public Setting getWalkOnWater() { + return setting; + } + + @Override + public Setting getWalkOnLava() { + return setting; + } + + @Override + public Setting getStep() { + return setting; + } + + @Override + public Setting getNoFall() { + return setting; + } + + @Override + public void save() { + Voyager.INSTANCE.getSettings().save(); + } + } +} diff --git a/src/main/java/meteordevelopment/voyager/commands/ThiswayCommand.java b/src/main/java/meteordevelopment/voyager/commands/ThiswayCommand.java index 99787b3..8acdc85 100644 --- a/src/main/java/meteordevelopment/voyager/commands/ThiswayCommand.java +++ b/src/main/java/meteordevelopment/voyager/commands/ThiswayCommand.java @@ -24,7 +24,7 @@ protected void build(LiteralArgumentBuilder builder) { })); builder.executes(context -> { - Voyager.INSTANCE.moveTo(new DirectionGoal(mc.player)); + Voyager.INSTANCE.moveTo(new DirectionGoal(mc.player.getYaw())); return SUCCESS; }); } diff --git a/src/main/java/meteordevelopment/voyager/goals/DirectionGoal.java b/src/main/java/meteordevelopment/voyager/goals/DirectionGoal.java index 6c017b3..f0d5e05 100644 --- a/src/main/java/meteordevelopment/voyager/goals/DirectionGoal.java +++ b/src/main/java/meteordevelopment/voyager/goals/DirectionGoal.java @@ -1,15 +1,15 @@ package meteordevelopment.voyager.goals; -import net.minecraft.entity.Entity; +import meteordevelopment.voyager.Voyager; public class DirectionGoal implements IGoal { private final double yaw; private int x, z; - public DirectionGoal(Entity entity) { - this.x = (int) Math.floor(entity.getX()); - this.z = (int) Math.floor(entity.getZ()); - this.yaw = Math.toRadians(entity.getYaw()); + public DirectionGoal(float yaw) { + this.x = (int) Math.floor(Voyager.mc.player.getX()); + this.z = (int) Math.floor(Voyager.mc.player.getZ()); + this.yaw = Math.toRadians(yaw); recalculate(); } diff --git a/src/main/java/meteordevelopment/voyager/settings/Settings.java b/src/main/java/meteordevelopment/voyager/settings/Settings.java index 5a726f6..0006eb4 100644 --- a/src/main/java/meteordevelopment/voyager/settings/Settings.java +++ b/src/main/java/meteordevelopment/voyager/settings/Settings.java @@ -21,7 +21,7 @@ public class Settings { private final File file; - private final List> settings = new ArrayList<>(); + public final List> settings = new ArrayList<>(); public Settings(File file) { this.file = file;