Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymoose77756 committed Sep 2, 2024
1 parent fef076a commit 3f6cb9f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
- Gamemode notifier
- Ghost Mode (Taken from an [unmerged PR](https://github.com/MeteorDevelopment/meteor-client/pull/1932))
- Glide (Ported from [Wurst](https://github.com/Wurst-Imperium/Wurst7/tree))
- Insta Mine (Removed from Meteor in [62cd0](https://github.com/MeteorDevelopment/meteor-client/commit/62cd0461e48a6c50f040bf48de25be1fa4eba77e))
- Item generator (Ported from [Wurst](https://github.com/Wurst-Imperium/Wurst7/tree))
- InteractionMenu (Ported from [BleachHack](https://github.com/BleachDrinker420/BleachHack/pull/211))
- Jetpack
Expand Down Expand Up @@ -107,6 +106,7 @@
## Commands
- `.center`
- `.clear-chat` (Removed from meteor in [9aebf](https://github.com/MeteorDevelopment/meteor-client/commit/9aebf6a0e4ffa739d901c8b8d7f48d07af2fe839))
- `.fill`
- `.ghost` (Ported from [AntiGhost](https://github.com/gbl/AntiGhost/blob/fabric_1_16/src/main/java/de/guntram/mcmod/antighost/AntiGhost.java))
- `.save-skin`
- `.heads`
Expand Down
1 change: 1 addition & 0 deletions src/main/java/anticope/rejects/MeteorRejectsAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void onInitialize() {
// Commands
Commands.add(new CenterCommand());
Commands.add(new ClearChatCommand());
Commands.add(new FillCommand());
Commands.add(new GhostCommand());
Commands.add(new GiveCommand());
Commands.add(new HeadsCommand());
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/anticope/rejects/commands/FillCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package anticope.rejects.commands;

import anticope.rejects.arguments.ClientPosArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command;
import net.minecraft.block.BlockState;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.BlockStateArgument;
import net.minecraft.command.argument.BlockStateArgumentType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

public class FillCommand extends Command {

public FillCommand() {
super("fill", "Fills a specified area with a block");
}
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(argument("from-pos", ClientPosArgumentType.pos()).then(argument("to-pos", ClientPosArgumentType.pos()).then(argument("block", BlockStateArgumentType.blockState(REGISTRY_ACCESS)).executes(ctx -> {
Vec3d fromPos = ClientPosArgumentType.getPos(ctx, "from-pos");
Vec3d toPos = ClientPosArgumentType.getPos(ctx, "to-pos");
BlockState blockState = ctx.getArgument("block", BlockStateArgument.class).getBlockState();

fillArea(fromPos, toPos, blockState, null);

return SINGLE_SUCCESS;
}))));

builder.then(argument("from-pos", ClientPosArgumentType.pos()).then(argument("to-pos", ClientPosArgumentType.pos()).then(argument("block", BlockStateArgumentType.blockState(REGISTRY_ACCESS)).then(argument("replace", StringArgumentType.string()).then(argument("filter", BlockStateArgumentType.blockState(REGISTRY_ACCESS)).executes(ctx -> {
Vec3d fromPos = ClientPosArgumentType.getPos(ctx, "from-pos");
Vec3d toPos = ClientPosArgumentType.getPos(ctx, "to-pos");
BlockState findBlock = ctx.getArgument("block", BlockStateArgument.class).getBlockState();
BlockState filterBlock = ctx.getArgument("filter", BlockStateArgument.class).getBlockState();

fillArea(fromPos, toPos, findBlock, filterBlock);

return SINGLE_SUCCESS;
}))))));
}

private void fillArea(Vec3d fromPos, Vec3d toPos, BlockState blockState, BlockState filterBlock) {
MinMaxCoords coords = getMinMaxCoords(fromPos, toPos);

for (int x = coords.minX; x <= coords.maxX; x++) {
for (int y = coords.minY; y <= coords.maxY; y++) {
for (int z = coords.minZ; z <= coords.maxZ; z++) {
BlockPos pos = new BlockPos(x, y, z);

if (filterBlock == null || mc.world.getBlockState(pos).equals(filterBlock)) {
mc.world.setBlockState(pos, blockState);
}
}
}
}
}

//Send help
private MinMaxCoords getMinMaxCoords(Vec3d fromPos, Vec3d toPos) {
int minX = Math.min((int) fromPos.getX(), (int) toPos.getX());
int maxX = Math.max((int) fromPos.getX(), (int) toPos.getX());
int minY = Math.min((int) fromPos.getY(), (int) toPos.getY());
int maxY = Math.max((int) fromPos.getY(), (int) toPos.getY());
int minZ = Math.min((int) fromPos.getZ(), (int) toPos.getZ());
int maxZ = Math.max((int) fromPos.getZ(), (int) toPos.getZ());

return new MinMaxCoords(minX, maxX, minY, maxY, minZ, maxZ);
}
//gotta have that clean code
private static class MinMaxCoords {
public final int minX, maxX, minY, maxY, minZ, maxZ;

public MinMaxCoords(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
this.minX = minX;
this.maxX = maxX;
this.minY = minY;
this.maxY = maxY;
this.minZ = minZ;
this.maxZ = maxZ;
}
}

}

0 comments on commit 3f6cb9f

Please sign in to comment.