Skip to content

Commit 5b71f9e

Browse files
committed
1 parent 393fc72 commit 5b71f9e

File tree

12 files changed

+814
-0
lines changed

12 files changed

+814
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ An addon to Meteor Client that adds modules and commands that were too useless t
5555
- `.save-skin`
5656
- `.heads`
5757
- `.server` (Port scanning ported from [Cornos](https://github.com/cornos/Cornos/blob/master/src/main/java/me/zeroX150/cornos/features/command/impl/Scan.java))
58+
- `.seed` (taken from an [unmerged pr](https://github.com/MeteorDevelopment/meteor-client/pull/1300))
59+
- rewritten `.locate` (taken from an [unmerged pr](https://github.com/MeteorDevelopment/meteor-client/pull/1300))
5860
- `.setblock`
5961
- `.teleport`
6062
- `.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))

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ dependencies {
3030
// You may need to force-disable transitiveness on them.
3131

3232
modImplementation "com.github.MeteorDevelopment:meteor-client:master-SNAPSHOT"
33+
34+
// Seed .locate features
35+
modImplementation 'com.github.hube12:SEED:master-SNAPSHOT'
36+
include 'com.github.hube12:SEED:master-SNAPSHOT'
3337
}
3438

3539
processResources {

src/main/java/cloudburst/rejects/MeteorRejectsAddon.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public void onInitialize() {
7676
commands.add(new GhostCommand());
7777
commands.add(new GiveCommand());
7878
commands.add(new SaveSkinCommand());
79+
commands.add(new SeedCommand());
7980
commands.add(new HeadsCommand());
81+
// commands.add(new LocateCommand()); I wish it was that simple -_-
8082
commands.add(new ServerCommand());
8183
commands.add(new SetBlockCommand());
8284
commands.add(new TeleportCommand());
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cloudburst.rejects.arguments;
2+
3+
import java.util.Arrays;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
import com.mojang.brigadier.StringReader;
7+
import com.mojang.brigadier.arguments.ArgumentType;
8+
import com.mojang.brigadier.context.CommandContext;
9+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
10+
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
11+
import com.mojang.brigadier.suggestion.Suggestions;
12+
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
13+
import java.lang.reflect.InvocationTargetException;
14+
15+
import net.minecraft.command.CommandSource;
16+
import net.minecraft.text.LiteralText;
17+
18+
public class EnumArgumentType<T extends Enum<?>> implements ArgumentType<T> {
19+
private static final DynamicCommandExceptionType NO_SUCH_TYPE = new DynamicCommandExceptionType(o ->
20+
new LiteralText(o + " is not a valid argument."));
21+
22+
private T[] values;
23+
24+
public EnumArgumentType(T defaultValue) {
25+
super();
26+
27+
try {
28+
values = (T[]) defaultValue.getClass().getMethod("values").invoke(null);
29+
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
30+
e.printStackTrace();
31+
}
32+
}
33+
34+
public static <T extends Enum<?>> EnumArgumentType<T> enumArgument(T defaultValue) {
35+
return new EnumArgumentType<T>(defaultValue);
36+
}
37+
38+
public static <T extends Enum<?>> T getEnum(CommandContext<?> context, String name, T defaultValue) {
39+
return (T) context.getArgument(name, defaultValue.getClass());
40+
}
41+
42+
@Override
43+
public T parse(StringReader reader) throws CommandSyntaxException {
44+
String argument = reader.readString();
45+
for (T t : values) {
46+
if (t.toString().equals(argument)) return t;
47+
}
48+
throw NO_SUCH_TYPE.create(argument);
49+
}
50+
51+
52+
@Override
53+
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
54+
return CommandSource.suggestMatching(Arrays.stream(values).map(T::toString), builder);
55+
}
56+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package cloudburst.rejects.commands;
2+
3+
import baritone.api.BaritoneAPI;
4+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
5+
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
6+
import meteordevelopment.meteorclient.MeteorClient;
7+
import meteordevelopment.meteorclient.events.packets.PacketEvent;
8+
import meteordevelopment.meteorclient.systems.commands.Command;
9+
import cloudburst.rejects.arguments.EnumArgumentType;
10+
import meteordevelopment.meteorclient.utils.Utils;
11+
import meteordevelopment.meteorclient.utils.player.ChatUtils;
12+
import meteordevelopment.meteorclient.utils.player.FindItemResult;
13+
import meteordevelopment.meteorclient.utils.player.InvUtils;
14+
import cloudburst.rejects.utils.WorldGenUtils;
15+
import meteordevelopment.orbit.EventHandler;
16+
import net.minecraft.command.CommandSource;
17+
import net.minecraft.entity.EntityType;
18+
import net.minecraft.item.ItemStack;
19+
import net.minecraft.item.Items;
20+
import net.minecraft.nbt.NbtCompound;
21+
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
22+
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
23+
import net.minecraft.sound.SoundEvents;
24+
import net.minecraft.text.BaseText;
25+
import net.minecraft.text.LiteralText;
26+
import net.minecraft.util.math.BlockPos;
27+
import net.minecraft.util.math.Vec3d;
28+
29+
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
30+
31+
public class LocateCommand extends Command {
32+
33+
private final static DynamicCommandExceptionType NOT_FOUND = new DynamicCommandExceptionType(o -> {
34+
if (o instanceof WorldGenUtils.Feature) {
35+
return new LiteralText(String.format(
36+
"%s not found.",
37+
Utils.nameToTitle(o.toString().replaceAll("_", "-")))
38+
);
39+
}
40+
return new LiteralText("Not found.");
41+
});
42+
43+
private Vec3d firstStart;
44+
private Vec3d firstEnd;
45+
private Vec3d secondStart;
46+
private Vec3d secondEnd;
47+
48+
public LocateCommand() {
49+
super("locate", "Locates structures", "loc");
50+
}
51+
52+
@Override
53+
public void build(LiteralArgumentBuilder<CommandSource> builder) {
54+
builder.then(literal("lodestone").executes(ctx -> {
55+
ItemStack stack = mc.player.getInventory().getMainHandStack();
56+
if (stack.getItem() != Items.COMPASS) {
57+
error("You need to hold a lodestone compass");
58+
return SINGLE_SUCCESS;
59+
}
60+
NbtCompound tag = stack.getTag();
61+
if (tag == null) {
62+
error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
63+
return SINGLE_SUCCESS;
64+
}
65+
NbtCompound nbt1 = tag.getCompound("LodestonePos");
66+
if (nbt1 == null) {
67+
error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
68+
return SINGLE_SUCCESS;
69+
}
70+
71+
Vec3d coords = new Vec3d(nbt1.getDouble("X"),nbt1.getDouble("Y"),nbt1.getDouble("Z"));
72+
BaseText text = new LiteralText("Lodestone located at ");
73+
text.append(ChatUtils.formatCoords(coords));
74+
text.append(".");
75+
info(text);
76+
return SINGLE_SUCCESS;
77+
}));
78+
79+
builder.then(argument("feature", EnumArgumentType.enumArgument(WorldGenUtils.Feature.stronghold)).executes(ctx -> {
80+
WorldGenUtils.Feature feature = EnumArgumentType.getEnum(ctx, "feature", WorldGenUtils.Feature.stronghold);
81+
BlockPos pos = WorldGenUtils.locateFeature(feature, mc.player.getBlockPos());
82+
if (pos != null) {
83+
BaseText text = new LiteralText(String.format(
84+
"%s located at ",
85+
Utils.nameToTitle(feature.toString().replaceAll("_", "-"))
86+
));
87+
Vec3d coords = new Vec3d(pos.getX(), pos.getY(), pos.getZ());
88+
text.append(ChatUtils.formatCoords(coords));
89+
text.append(".");
90+
info(text);
91+
return SINGLE_SUCCESS;
92+
}
93+
if (feature == WorldGenUtils.Feature.stronghold) {
94+
FindItemResult eye = InvUtils.findInHotbar(Items.ENDER_EYE);
95+
if (eye.found()) {
96+
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender");
97+
firstStart = null;
98+
firstEnd = null;
99+
secondStart = null;
100+
secondEnd = null;
101+
MeteorClient.EVENT_BUS.subscribe(this);
102+
info("Please throw the first Eye of Ender");
103+
}
104+
}
105+
throw NOT_FOUND.create(feature);
106+
}));
107+
108+
builder.then(literal("cancel").executes(s -> {
109+
cancel();
110+
return SINGLE_SUCCESS;
111+
}));
112+
}
113+
114+
private void cancel() {
115+
warning("Locate canceled");
116+
MeteorClient.EVENT_BUS.unsubscribe(this);
117+
}
118+
119+
@EventHandler
120+
private void onReadPacket(PacketEvent.Receive event) {
121+
if (event.packet instanceof EntitySpawnS2CPacket) {
122+
EntitySpawnS2CPacket packet = (EntitySpawnS2CPacket) event.packet;
123+
if (packet.getEntityTypeId() == EntityType.EYE_OF_ENDER) {
124+
firstPosition(packet.getX(),packet.getY(),packet.getZ());
125+
}
126+
}
127+
if (event.packet instanceof PlaySoundS2CPacket) {
128+
PlaySoundS2CPacket packet = (PlaySoundS2CPacket) event.packet;
129+
if (packet.getSound() == SoundEvents.ENTITY_ENDER_EYE_DEATH) {
130+
lastPosition(packet.getX(), packet.getY(), packet.getZ());
131+
}
132+
}
133+
}
134+
135+
private void firstPosition(double x, double y, double z) {
136+
Vec3d pos = new Vec3d(x, y, z);
137+
if (this.firstStart == null) {
138+
this.firstStart = pos;
139+
}
140+
else {
141+
this.secondStart = pos;
142+
}
143+
}
144+
145+
private void lastPosition(double x, double y, double z) {
146+
info("%s Eye of Ender's trajectory saved.", (this.firstEnd == null) ? "First" : "Second");
147+
Vec3d pos = new Vec3d(x, y, z);
148+
if (this.firstEnd == null) {
149+
this.firstEnd = pos;
150+
info("Please throw the second Eye Of Ender from a different location.");
151+
}
152+
else {
153+
this.secondEnd = pos;
154+
findStronghold();
155+
}
156+
}
157+
158+
private void findStronghold() {
159+
if (this.firstStart == null || this.firstEnd == null || this.secondStart == null || this.secondEnd == null) {
160+
error("Missing position data");
161+
cancel();
162+
return;
163+
}
164+
final double[] start = new double[]{this.secondStart.x, this.secondStart.z, this.secondEnd.x, this.secondEnd.z};
165+
final double[] end = new double[]{this.firstStart.x, this.firstStart.z, this.firstEnd.x, this.firstEnd.z};
166+
final double[] intersection = calcIntersection(start, end);
167+
if (Double.isNaN(intersection[0]) || Double.isNaN(intersection[1]) || Double.isInfinite(intersection[0]) || Double.isInfinite(intersection[1])) {
168+
error("Lines are parallel");
169+
cancel();
170+
return;
171+
}
172+
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("stop");
173+
MeteorClient.EVENT_BUS.unsubscribe(this);
174+
Vec3d coords = new Vec3d(intersection[0],0,intersection[1]);
175+
BaseText text = new LiteralText("Stronghold roughly located at ");
176+
text.append(ChatUtils.formatCoords(coords));
177+
text.append(".");
178+
info(text);
179+
}
180+
181+
private double[] calcIntersection(double[] line, double[] line2) {
182+
final double a1 = line[3] - line[1];
183+
final double b1 = line[0] - line[2];
184+
final double c1 = a1 * line[0] + b1 * line[1];
185+
186+
final double a2 = line2[3] - line2[1];
187+
final double b2 = line2[0] - line2[2];
188+
final double c2 = a2 * line2[0] + b2 * line2[1];
189+
190+
final double delta = a1 * b2 - a2 * b1;
191+
192+
return new double[]{(b2 * c1 - b1 * c2) / delta, (a1 * c2 - a2 * c1) / delta};
193+
}
194+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cloudburst.rejects.commands;
2+
3+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
4+
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
5+
6+
import net.minecraft.command.CommandSource;
7+
import net.minecraft.text.BaseText;
8+
import net.minecraft.text.LiteralText;
9+
10+
import kaptainwutax.mcutils.version.MCVersion;
11+
import meteordevelopment.meteorclient.systems.commands.Command;
12+
import cloudburst.rejects.arguments.EnumArgumentType;
13+
import cloudburst.rejects.utils.seeds.Seed;
14+
import cloudburst.rejects.utils.seeds.Seeds;
15+
import meteordevelopment.meteorclient.utils.Utils;
16+
17+
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
18+
19+
import com.mojang.brigadier.arguments.LongArgumentType;
20+
21+
public class SeedCommand extends Command {
22+
private final static SimpleCommandExceptionType NO_SEED = new SimpleCommandExceptionType(new LiteralText("No seed for current world saved."));
23+
24+
public SeedCommand() {
25+
super("seed", "Get or set seed for the current world.");
26+
}
27+
28+
@Override
29+
public void build(LiteralArgumentBuilder<CommandSource> builder) {
30+
builder.executes(ctx -> {
31+
Seed seed = Seeds.get().getSeed();
32+
if (seed == null) throw NO_SEED.create();
33+
info(seed.toText());
34+
return SINGLE_SUCCESS;
35+
});
36+
37+
builder.then(literal("list").executes(ctx -> {
38+
Seeds.get().seeds.forEach((name, seed) -> {
39+
BaseText text = new LiteralText(name + " ");
40+
text.append(seed.toText());
41+
info(text);
42+
});
43+
return SINGLE_SUCCESS;
44+
}));
45+
46+
builder.then(literal("delete").executes(ctx -> {
47+
Seed seed = Seeds.get().getSeed();
48+
if (seed != null) {
49+
BaseText text = new LiteralText("Deleted ");
50+
text.append(seed.toText());
51+
info(text);
52+
}
53+
Seeds.get().seeds.remove(Utils.getWorldName());
54+
return SINGLE_SUCCESS;
55+
}));
56+
57+
builder.then(argument("seed", LongArgumentType.longArg()).executes(ctx -> {
58+
Seeds.get().setSeed(LongArgumentType.getLong(ctx, "seed"));
59+
return SINGLE_SUCCESS;
60+
}));
61+
62+
builder.then(argument("seed", LongArgumentType.longArg()).then(argument("version", EnumArgumentType.enumArgument(MCVersion.v1_17_1)).executes(ctx -> {
63+
Seeds.get().setSeed(LongArgumentType.getLong(ctx, "seed"), EnumArgumentType.getEnum(ctx, "version", MCVersion.v1_17_1));
64+
return SINGLE_SUCCESS;
65+
})));
66+
}
67+
68+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cloudburst.rejects.mixin.meteor;
2+
3+
import org.spongepowered.asm.mixin.Final;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.Shadow;
6+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
7+
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
11+
import meteordevelopment.meteorclient.systems.commands.Command;
12+
import meteordevelopment.meteorclient.systems.commands.Commands;
13+
import com.mojang.brigadier.CommandDispatcher;
14+
import net.minecraft.command.CommandSource;
15+
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
20+
@Mixin(Commands.class)
21+
public class CommandsMixin {
22+
@Shadow
23+
@Final
24+
private List<Command> commands;
25+
26+
@Shadow
27+
@Final
28+
private Map<Class<? extends Command>, Command> commandInstances;
29+
30+
31+
@Shadow
32+
@Final
33+
private CommandDispatcher<CommandSource> DISPATCHER = new CommandDispatcher<>();
34+
35+
@Inject(method = "add", at=@At("HEAD"), remap = false, cancellable = true)
36+
private void onAdd(Command cmd, CallbackInfo ci) {
37+
if (cmd instanceof meteordevelopment.meteorclient.systems.commands.commands.LocateCommand) {
38+
Command command = new cloudburst.rejects.commands.LocateCommand();
39+
commands.removeIf(command1 -> command1.getName().equals(command.getName()));
40+
commandInstances.values().removeIf(command1 -> command1.getName().equals(command.getName()));
41+
42+
command.registerTo(DISPATCHER);
43+
commands.add(command);
44+
commandInstances.put(command.getClass(), command);
45+
ci.cancel();
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)