Compatibility
Minecraft: Java Edition
Platforms
Creators
Details
Custom Raycasting
Do you want to do be able to detect what block you clicked, or whether a mob is within your field of view? Custom Raycasting (CRC) is a datapack that allows you to do just that, but without the hassle of having to code all of it yourself.
This datapack's method of raycasting involves a marker
entity tagged ray
, that moves forward by step_count
until it hits a block, or a non-player entity, also ensuring that the entity is not a marker tagged with ray
. When the marker hits one of the two, it will run its corresponding command which is stored in its data.
Below is a command that gives a carrot_on_a_stick
with the required custom_data
tags. Give it a go with the datapack installed. Note that the command is more than 256 characters long, and requires a command block to run.
give @p minecraft:carrot_on_a_stick[item_name= '"Custom Raycaster"', custom_data= {raycast_config: {step_size: 0.25, max_steps: 1280, passable_blocks: "minecraft:air", detectable_entity_range: 3, actions: {on_block_collision: 'say Block!', on_entity_collision: 'say Entity!', in_motion: "particle cloud ~ ~ ~ 0 0 0 0 1 force"}}}, item_model= "minecraft:nether_star", enchantment_glint_override= true]
Another command can also be found within the datapack as 'test.mccommand', under data/crc/function/raycasting
, however I forgot to remove the '!' at the end of the on_entity_collision
action! I'll fix that in version 1.1, as it does not affect the way that the actual .mcfunction
files work.