Skip to content

Commit

Permalink
Merge pull request #945 from Prunoideae/highlight-utils
Browse files Browse the repository at this point in the history
Added util methods to retrieve targeting block / entity directly
  • Loading branch information
LatvianModder authored Feb 20, 2025
2 parents c704911 + 53b0906 commit 9a8ac19
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.latvian.mods.kubejs.client.ClientPlayerKubeEvent;
import dev.latvian.mods.kubejs.color.KubeColor;
import dev.latvian.mods.kubejs.level.LevelBlock;
import dev.latvian.mods.kubejs.typings.Info;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.arguments.selector.EntitySelector;
Expand Down Expand Up @@ -128,4 +129,15 @@ public void addTarget(KubeColor color) {
addBlock(hit.getBlockPos(), color);
}
}

public LevelBlock getTargetBlock() {
if (mc.hitResult instanceof BlockHitResult block && mc.hitResult.getType() == HitResult.Type.BLOCK) {
return getLevel().kjs$getBlock(block.getBlockPos());
}
return null;
}

public Entity getTargetEntity() {
return mc.hitResult instanceof EntityHitResult hit ? hit.getEntity() : null;
}
}

0 comments on commit 9a8ac19

Please sign in to comment.