|
| 1 | +package meteordevelopment.voyager; |
| 2 | + |
| 3 | +import meteordevelopment.meteorclient.pathing.IPathManager; |
| 4 | +import meteordevelopment.meteorclient.settings.*; |
| 5 | +import meteordevelopment.meteorclient.utils.render.color.Color; |
| 6 | +import meteordevelopment.meteorclient.utils.render.color.SettingColor; |
| 7 | +import meteordevelopment.voyager.goals.DirectionGoal; |
| 8 | +import meteordevelopment.voyager.goals.XYZGoal; |
| 9 | +import meteordevelopment.voyager.goals.XZGoal; |
| 10 | +import net.minecraft.block.Block; |
| 11 | +import net.minecraft.entity.Entity; |
| 12 | +import net.minecraft.util.math.BlockPos; |
| 13 | +import org.apache.commons.lang3.NotImplementedException; |
| 14 | + |
| 15 | +import java.util.HashMap; |
| 16 | +import java.util.Map; |
| 17 | +import java.util.function.Predicate; |
| 18 | + |
| 19 | +@SuppressWarnings("unused") |
| 20 | +public class PathManager implements IPathManager { |
| 21 | + private final VoyagerSettings settings = new VoyagerSettings(); |
| 22 | + |
| 23 | + @Override |
| 24 | + public String getName() { |
| 25 | + return "Voyager"; |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public boolean isPathing() { |
| 30 | + return Voyager.INSTANCE.isMoving(); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public void pause() { |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public void resume() { |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void stop() { |
| 43 | + Voyager.INSTANCE.stop(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void moveTo(BlockPos pos, boolean ignoreY) { |
| 48 | + if (ignoreY) { |
| 49 | + Voyager.INSTANCE.moveTo(new XZGoal(pos.getX(), pos.getY())); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + Voyager.INSTANCE.moveTo(new XYZGoal(pos)); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void moveInDirection(float yaw) { |
| 58 | + Voyager.INSTANCE.moveTo(new DirectionGoal(yaw)); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void mine(Block... blocks) { |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public void follow(Predicate<Entity> predicate) { |
| 67 | + for (Entity entity : Voyager.mc.world.getEntities()) { |
| 68 | + if (predicate.test(entity)) { |
| 69 | + Voyager.INSTANCE.moveTo(new XYZGoal(entity.getBlockPos())); |
| 70 | + return; |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public float getTargetYaw() { |
| 77 | + if (Voyager.mc.player.input instanceof VInput input) |
| 78 | + return input.getYaw(1); |
| 79 | + |
| 80 | + return 0; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public float getTargetPitch() { |
| 85 | + return isPathing() ? Voyager.mc.player.getPitch() : 0; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public ISettings getSettings() { |
| 90 | + return settings; |
| 91 | + } |
| 92 | + |
| 93 | + private static class VoyagerSettings implements ISettings { |
| 94 | + private final Settings settings = new Settings(); |
| 95 | + private final Setting<Boolean> setting = new BoolSetting.Builder().build(); |
| 96 | + |
| 97 | + @SuppressWarnings({"rawtypes", "unchecked"}) |
| 98 | + public VoyagerSettings() { |
| 99 | + Map<String, SettingGroup> groups = new HashMap<>(); |
| 100 | + |
| 101 | + for (var setting : Voyager.INSTANCE.getSettings().settings) { |
| 102 | + SettingGroup group = groups.computeIfAbsent(setting.category, settings::createGroup); |
| 103 | + |
| 104 | + if (setting instanceof meteordevelopment.voyager.settings.BoolSetting s) { |
| 105 | + group.add(new BoolSetting.Builder() |
| 106 | + .name(s.name) |
| 107 | + .description(s.description) |
| 108 | + .defaultValue(s.getDefaultValue()) |
| 109 | + .onChanged(s::set) |
| 110 | + .onModuleActivated(booleanSetting -> booleanSetting.set(s.get())) |
| 111 | + .build()); |
| 112 | + } |
| 113 | + else if (setting instanceof meteordevelopment.voyager.settings.EnumSetting s) { |
| 114 | + group.add(new EnumSetting.Builder<>() |
| 115 | + .name(s.name) |
| 116 | + .description(s.description) |
| 117 | + .defaultValue((Enum<?>) s.getDefaultValue()) |
| 118 | + .onChanged(anEnum -> s.set(anEnum)) |
| 119 | + .onModuleActivated(booleanSetting -> booleanSetting.set((Enum<?>) s.get())) |
| 120 | + .build()); |
| 121 | + } |
| 122 | + else if (setting instanceof meteordevelopment.voyager.settings.StringSetting s) { |
| 123 | + group.add(new StringSetting.Builder() |
| 124 | + .name(s.name) |
| 125 | + .description(s.description) |
| 126 | + .defaultValue(s.getDefaultValue()) |
| 127 | + .onChanged(s::set) |
| 128 | + .onModuleActivated(stringSetting -> stringSetting.set(s.get())) |
| 129 | + .build()); |
| 130 | + } |
| 131 | + else if (setting instanceof meteordevelopment.voyager.settings.ColorSetting s) { |
| 132 | + group.add(new ColorSetting.Builder() |
| 133 | + .name(s.name) |
| 134 | + .description(s.description) |
| 135 | + .defaultValue(new Color(s.getDefaultValue().pack())) |
| 136 | + .onChanged(settingColor -> s.set(new meteordevelopment.voyager.utils.Color(settingColor.getPacked()))) |
| 137 | + .onModuleActivated(settingColorSetting -> settingColorSetting.set(new SettingColor(s.get().pack()))) |
| 138 | + .build()); |
| 139 | + } |
| 140 | + else { |
| 141 | + throw new NotImplementedException(); |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public Settings get() { |
| 148 | + return settings; |
| 149 | + } |
| 150 | + |
| 151 | + @Override |
| 152 | + public Setting<Boolean> getWalkOnWater() { |
| 153 | + return setting; |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + public Setting<Boolean> getWalkOnLava() { |
| 158 | + return setting; |
| 159 | + } |
| 160 | + |
| 161 | + @Override |
| 162 | + public Setting<Boolean> getStep() { |
| 163 | + return setting; |
| 164 | + } |
| 165 | + |
| 166 | + @Override |
| 167 | + public Setting<Boolean> getNoFall() { |
| 168 | + return setting; |
| 169 | + } |
| 170 | + |
| 171 | + @Override |
| 172 | + public void save() { |
| 173 | + Voyager.INSTANCE.getSettings().save(); |
| 174 | + } |
| 175 | + } |
| 176 | +} |
0 commit comments