feat: updated cursor commands, added block search
This commit is contained in:
parent
6201f66c85
commit
b71dcba7a2
2 changed files with 63 additions and 4 deletions
57
src/main/java/ftbsc/bscv/commands/BlockSearch.java
Normal file
57
src/main/java/ftbsc/bscv/commands/BlockSearch.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package ftbsc.bscv.commands;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import ftbsc.bscv.api.ILoadable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
|
||||
import static ftbsc.bscv.Boscovicino.log;
|
||||
|
||||
@AutoService(ILoadable.class)
|
||||
public class BlockSearch extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getName() { return "block"; }
|
||||
|
||||
public LiteralArgumentBuilder<CommandSource> register(LiteralArgumentBuilder<CommandSource> builder) {
|
||||
return builder
|
||||
.then(
|
||||
Commands.literal("search")
|
||||
.then(
|
||||
Commands.argument("id", IntegerArgumentType.integer(0))
|
||||
.executes( ctx -> {
|
||||
int block_id = ctx.getArgument("id", Integer.class);
|
||||
int block_number = block_id >> 4;
|
||||
int block_meta = block_id & 0b1111;
|
||||
BlockState state = Block.stateById(block_id);
|
||||
log("block #[%d:%d]::%d >> %s", block_number, block_meta, block_id, state.toString());
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
.then(
|
||||
Commands.argument("number", IntegerArgumentType.integer(0))
|
||||
.then(
|
||||
Commands.argument("meta", IntegerArgumentType.integer(0))
|
||||
.executes( ctx -> {
|
||||
int block_number = ctx.getArgument("number", Integer.class);
|
||||
int block_meta = ctx.getArgument("meta", Integer.class);
|
||||
int block_id = (block_number << 4) | block_meta;
|
||||
BlockState state = Block.stateById(block_id);
|
||||
log("block #[%d:%d]::%d >> %s", block_number, block_meta, block_id, state.toString());
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.executes(ctx -> {
|
||||
log("no block specified");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.google.auto.service.AutoService;
|
|||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import ftbsc.bscv.api.ILoadable;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.util.Direction;
|
||||
|
@ -18,17 +19,18 @@ public class Cursor extends AbstractCommand {
|
|||
public LiteralArgumentBuilder<CommandSource> register(LiteralArgumentBuilder<CommandSource> builder) {
|
||||
return builder
|
||||
.then(
|
||||
Commands.literal("pos")
|
||||
Commands.literal("info")
|
||||
.executes(ctx -> {
|
||||
switch (MC.hitResult.getType()) {
|
||||
case BLOCK:
|
||||
BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult;
|
||||
Direction dir = result.getDirection();
|
||||
BlockPos pos = result.getBlockPos();
|
||||
log("Block @ %s (%s)", pos.toString(), dir.toString());
|
||||
BlockState state = MC.level.getBlockState(pos);
|
||||
log("Block @ %s (%s): %s", pos.toString(), dir.toString(), state.toString());
|
||||
return 1;
|
||||
case ENTITY:
|
||||
log("Entity @ %s", MC.hitResult.getLocation().toString());
|
||||
log("Entity @ %s (TODO!)", MC.hitResult.getLocation().toString());
|
||||
return 1;
|
||||
default:
|
||||
case MISS:
|
||||
|
|
Loading…
Reference in a new issue