Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
C10udburst committed Aug 8, 2021
1 parent 393fc72 commit 5b71f9e
Show file tree
Hide file tree
Showing 12 changed files with 814 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ An addon to Meteor Client that adds modules and commands that were too useless t
- `.save-skin`
- `.heads`
- `.server` (Port scanning ported from [Cornos](https://github.com/cornos/Cornos/blob/master/src/main/java/me/zeroX150/cornos/features/command/impl/Scan.java))
- `.seed` (taken from an [unmerged pr](https://github.com/MeteorDevelopment/meteor-client/pull/1300))
- rewritten `.locate` (taken from an [unmerged pr](https://github.com/MeteorDevelopment/meteor-client/pull/1300))
- `.setblock`
- `.teleport`
- `.terrain-export` (Ported from [BleachHack](https://github.com/BleachDrinker420/BleachHack/blob/master/BleachHack-Fabric-1.17/src/main/java/bleach/hack/command/commands/CmdTerrain.java))
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ dependencies {
// You may need to force-disable transitiveness on them.

modImplementation "com.github.MeteorDevelopment:meteor-client:master-SNAPSHOT"

// Seed .locate features
modImplementation 'com.github.hube12:SEED:master-SNAPSHOT'
include 'com.github.hube12:SEED:master-SNAPSHOT'
}

processResources {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/cloudburst/rejects/MeteorRejectsAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public void onInitialize() {
commands.add(new GhostCommand());
commands.add(new GiveCommand());
commands.add(new SaveSkinCommand());
commands.add(new SeedCommand());
commands.add(new HeadsCommand());
// commands.add(new LocateCommand()); I wish it was that simple -_-
commands.add(new ServerCommand());
commands.add(new SetBlockCommand());
commands.add(new TeleportCommand());
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/cloudburst/rejects/arguments/EnumArgumentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cloudburst.rejects.arguments;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.lang.reflect.InvocationTargetException;

import net.minecraft.command.CommandSource;
import net.minecraft.text.LiteralText;

public class EnumArgumentType<T extends Enum<?>> implements ArgumentType<T> {
private static final DynamicCommandExceptionType NO_SUCH_TYPE = new DynamicCommandExceptionType(o ->
new LiteralText(o + " is not a valid argument."));

private T[] values;

public EnumArgumentType(T defaultValue) {
super();

try {
values = (T[]) defaultValue.getClass().getMethod("values").invoke(null);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}

public static <T extends Enum<?>> EnumArgumentType<T> enumArgument(T defaultValue) {
return new EnumArgumentType<T>(defaultValue);
}

public static <T extends Enum<?>> T getEnum(CommandContext<?> context, String name, T defaultValue) {
return (T) context.getArgument(name, defaultValue.getClass());
}

@Override
public T parse(StringReader reader) throws CommandSyntaxException {
String argument = reader.readString();
for (T t : values) {
if (t.toString().equals(argument)) return t;
}
throw NO_SUCH_TYPE.create(argument);
}


@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return CommandSource.suggestMatching(Arrays.stream(values).map(T::toString), builder);
}
}
194 changes: 194 additions & 0 deletions src/main/java/cloudburst/rejects/commands/LocateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package cloudburst.rejects.commands;

import baritone.api.BaritoneAPI;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.systems.commands.Command;
import cloudburst.rejects.arguments.EnumArgumentType;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import cloudburst.rejects.utils.WorldGenUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.BaseText;
import net.minecraft.text.LiteralText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

public class LocateCommand extends Command {

private final static DynamicCommandExceptionType NOT_FOUND = new DynamicCommandExceptionType(o -> {
if (o instanceof WorldGenUtils.Feature) {
return new LiteralText(String.format(
"%s not found.",
Utils.nameToTitle(o.toString().replaceAll("_", "-")))
);
}
return new LiteralText("Not found.");
});

private Vec3d firstStart;
private Vec3d firstEnd;
private Vec3d secondStart;
private Vec3d secondEnd;

public LocateCommand() {
super("locate", "Locates structures", "loc");
}

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("lodestone").executes(ctx -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (stack.getItem() != Items.COMPASS) {
error("You need to hold a lodestone compass");
return SINGLE_SUCCESS;
}
NbtCompound tag = stack.getTag();
if (tag == null) {
error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
return SINGLE_SUCCESS;
}
NbtCompound nbt1 = tag.getCompound("LodestonePos");
if (nbt1 == null) {
error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
return SINGLE_SUCCESS;
}

Vec3d coords = new Vec3d(nbt1.getDouble("X"),nbt1.getDouble("Y"),nbt1.getDouble("Z"));
BaseText text = new LiteralText("Lodestone located at ");
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
return SINGLE_SUCCESS;
}));

builder.then(argument("feature", EnumArgumentType.enumArgument(WorldGenUtils.Feature.stronghold)).executes(ctx -> {
WorldGenUtils.Feature feature = EnumArgumentType.getEnum(ctx, "feature", WorldGenUtils.Feature.stronghold);
BlockPos pos = WorldGenUtils.locateFeature(feature, mc.player.getBlockPos());
if (pos != null) {
BaseText text = new LiteralText(String.format(
"%s located at ",
Utils.nameToTitle(feature.toString().replaceAll("_", "-"))
));
Vec3d coords = new Vec3d(pos.getX(), pos.getY(), pos.getZ());
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
return SINGLE_SUCCESS;
}
if (feature == WorldGenUtils.Feature.stronghold) {
FindItemResult eye = InvUtils.findInHotbar(Items.ENDER_EYE);
if (eye.found()) {
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender");
firstStart = null;
firstEnd = null;
secondStart = null;
secondEnd = null;
MeteorClient.EVENT_BUS.subscribe(this);
info("Please throw the first Eye of Ender");
}
}
throw NOT_FOUND.create(feature);
}));

builder.then(literal("cancel").executes(s -> {
cancel();
return SINGLE_SUCCESS;
}));
}

private void cancel() {
warning("Locate canceled");
MeteorClient.EVENT_BUS.unsubscribe(this);
}

@EventHandler
private void onReadPacket(PacketEvent.Receive event) {
if (event.packet instanceof EntitySpawnS2CPacket) {
EntitySpawnS2CPacket packet = (EntitySpawnS2CPacket) event.packet;
if (packet.getEntityTypeId() == EntityType.EYE_OF_ENDER) {
firstPosition(packet.getX(),packet.getY(),packet.getZ());
}
}
if (event.packet instanceof PlaySoundS2CPacket) {
PlaySoundS2CPacket packet = (PlaySoundS2CPacket) event.packet;
if (packet.getSound() == SoundEvents.ENTITY_ENDER_EYE_DEATH) {
lastPosition(packet.getX(), packet.getY(), packet.getZ());
}
}
}

private void firstPosition(double x, double y, double z) {
Vec3d pos = new Vec3d(x, y, z);
if (this.firstStart == null) {
this.firstStart = pos;
}
else {
this.secondStart = pos;
}
}

private void lastPosition(double x, double y, double z) {
info("%s Eye of Ender's trajectory saved.", (this.firstEnd == null) ? "First" : "Second");
Vec3d pos = new Vec3d(x, y, z);
if (this.firstEnd == null) {
this.firstEnd = pos;
info("Please throw the second Eye Of Ender from a different location.");
}
else {
this.secondEnd = pos;
findStronghold();
}
}

private void findStronghold() {
if (this.firstStart == null || this.firstEnd == null || this.secondStart == null || this.secondEnd == null) {
error("Missing position data");
cancel();
return;
}
final double[] start = new double[]{this.secondStart.x, this.secondStart.z, this.secondEnd.x, this.secondEnd.z};
final double[] end = new double[]{this.firstStart.x, this.firstStart.z, this.firstEnd.x, this.firstEnd.z};
final double[] intersection = calcIntersection(start, end);
if (Double.isNaN(intersection[0]) || Double.isNaN(intersection[1]) || Double.isInfinite(intersection[0]) || Double.isInfinite(intersection[1])) {
error("Lines are parallel");
cancel();
return;
}
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("stop");
MeteorClient.EVENT_BUS.unsubscribe(this);
Vec3d coords = new Vec3d(intersection[0],0,intersection[1]);
BaseText text = new LiteralText("Stronghold roughly located at ");
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
}

private double[] calcIntersection(double[] line, double[] line2) {
final double a1 = line[3] - line[1];
final double b1 = line[0] - line[2];
final double c1 = a1 * line[0] + b1 * line[1];

final double a2 = line2[3] - line2[1];
final double b2 = line2[0] - line2[2];
final double c2 = a2 * line2[0] + b2 * line2[1];

final double delta = a1 * b2 - a2 * b1;

return new double[]{(b2 * c1 - b1 * c2) / delta, (a1 * c2 - a2 * c1) / delta};
}
}
68 changes: 68 additions & 0 deletions src/main/java/cloudburst/rejects/commands/SeedCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cloudburst.rejects.commands;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;

import net.minecraft.command.CommandSource;
import net.minecraft.text.BaseText;
import net.minecraft.text.LiteralText;

import kaptainwutax.mcutils.version.MCVersion;
import meteordevelopment.meteorclient.systems.commands.Command;
import cloudburst.rejects.arguments.EnumArgumentType;
import cloudburst.rejects.utils.seeds.Seed;
import cloudburst.rejects.utils.seeds.Seeds;
import meteordevelopment.meteorclient.utils.Utils;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

import com.mojang.brigadier.arguments.LongArgumentType;

public class SeedCommand extends Command {
private final static SimpleCommandExceptionType NO_SEED = new SimpleCommandExceptionType(new LiteralText("No seed for current world saved."));

public SeedCommand() {
super("seed", "Get or set seed for the current world.");
}

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(ctx -> {
Seed seed = Seeds.get().getSeed();
if (seed == null) throw NO_SEED.create();
info(seed.toText());
return SINGLE_SUCCESS;
});

builder.then(literal("list").executes(ctx -> {
Seeds.get().seeds.forEach((name, seed) -> {
BaseText text = new LiteralText(name + " ");
text.append(seed.toText());
info(text);
});
return SINGLE_SUCCESS;
}));

builder.then(literal("delete").executes(ctx -> {
Seed seed = Seeds.get().getSeed();
if (seed != null) {
BaseText text = new LiteralText("Deleted ");
text.append(seed.toText());
info(text);
}
Seeds.get().seeds.remove(Utils.getWorldName());
return SINGLE_SUCCESS;
}));

builder.then(argument("seed", LongArgumentType.longArg()).executes(ctx -> {
Seeds.get().setSeed(LongArgumentType.getLong(ctx, "seed"));
return SINGLE_SUCCESS;
}));

builder.then(argument("seed", LongArgumentType.longArg()).then(argument("version", EnumArgumentType.enumArgument(MCVersion.v1_17_1)).executes(ctx -> {
Seeds.get().setSeed(LongArgumentType.getLong(ctx, "seed"), EnumArgumentType.getEnum(ctx, "version", MCVersion.v1_17_1));
return SINGLE_SUCCESS;
})));
}

}
48 changes: 48 additions & 0 deletions src/main/java/cloudburst/rejects/mixin/meteor/CommandsMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cloudburst.rejects.mixin.meteor;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;

import meteordevelopment.meteorclient.systems.commands.Command;
import meteordevelopment.meteorclient.systems.commands.Commands;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandSource;

import java.util.List;
import java.util.Map;


@Mixin(Commands.class)
public class CommandsMixin {
@Shadow
@Final
private List<Command> commands;

@Shadow
@Final
private Map<Class<? extends Command>, Command> commandInstances;


@Shadow
@Final
private CommandDispatcher<CommandSource> DISPATCHER = new CommandDispatcher<>();

@Inject(method = "add", at=@At("HEAD"), remap = false, cancellable = true)
private void onAdd(Command cmd, CallbackInfo ci) {
if (cmd instanceof meteordevelopment.meteorclient.systems.commands.commands.LocateCommand) {
Command command = new cloudburst.rejects.commands.LocateCommand();
commands.removeIf(command1 -> command1.getName().equals(command.getName()));
commandInstances.values().removeIf(command1 -> command1.getName().equals(command.getName()));

command.registerTo(DISPATCHER);
commands.add(command);
commandInstances.put(command.getClass(), command);
ci.cancel();
}
}
}
Loading

0 comments on commit 5b71f9e

Please sign in to comment.