aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/bscv/commands/Cursor.java
blob: a54433d2625a0bcf497adf6c27d83fed8cc45c26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ftbsc.bscv.commands;

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;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;

import static ftbsc.bscv.Boscovicino.log;

@AutoService(ILoadable.class)
public class Cursor extends AbstractCommand {

   public LiteralArgumentBuilder<CommandSource> register(LiteralArgumentBuilder<CommandSource> builder) {
      return builder
         .then(
            Commands.literal("info")
               .executes(ctx -> {
                  switch (MC.hitResult.getType()) {
                     case BLOCK:
                        BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult;
                        Direction dir = result.getDirection();
                        BlockPos pos = result.getBlockPos();
                        BlockState state = MC.level.getBlockState(pos);
                        log("Block @ %s (%s): %s", pos.toString(), dir.toString(), state.toString());
                        return 1;
                     case ENTITY:
                        log("Entity @ %s (TODO!)", MC.hitResult.getLocation().toString());
                        return 1;
                     default:
                     case MISS:
                        log("[!] nothing under cursor");
                        return 0;
                  }
               })
         )
         .executes(ctx -> {
            log("[!] no domain specified");
            return 0;
         });
   }

}