Skip to content

Commit

Permalink
Meteor integration
Browse files Browse the repository at this point in the history
  • Loading branch information
MineGame159 committed Oct 22, 2023
1 parent d711c0a commit 5c140d3
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 7 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
176 changes: 176 additions & 0 deletions src/main/java/meteordevelopment/voyager/PathManager.java
Original file line number Diff line number Diff line change
@@ -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<Entity> 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<Boolean> setting = new BoolSetting.Builder().build();

@SuppressWarnings({"rawtypes", "unchecked"})
public VoyagerSettings() {
Map<String, SettingGroup> 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<Boolean> getWalkOnWater() {
return setting;
}

@Override
public Setting<Boolean> getWalkOnLava() {
return setting;
}

@Override
public Setting<Boolean> getStep() {
return setting;
}

@Override
public Setting<Boolean> getNoFall() {
return setting;
}

@Override
public void save() {
Voyager.INSTANCE.getSettings().save();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected void build(LiteralArgumentBuilder<CommandSource> builder) {
}));

builder.executes(context -> {
Voyager.INSTANCE.moveTo(new DirectionGoal(mc.player));
Voyager.INSTANCE.moveTo(new DirectionGoal(mc.player.getYaw()));
return SUCCESS;
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/meteordevelopment/voyager/goals/DirectionGoal.java
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class Settings {
private final File file;
private final List<Setting<?>> settings = new ArrayList<>();
public final List<Setting<?>> settings = new ArrayList<>();

public Settings(File file) {
this.file = file;
Expand Down

0 comments on commit 5c140d3

Please sign in to comment.