#how to raycast
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
💬 While you wait, take this time to provide more context and details.
🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you
✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve
the raycasting is for detecting blocks mineable by the (netherite) pickaxe as it can only mine blocks in the pickaxe_mineable tag
If you've not made many datapacks, you might not be familiar with raycasting. It's a really useful tool which we can use to essentially find where the player is looking and then do stuff (such as spawn explosions 😎).
To create a raycast, we can use a recursive function. A recursive function is a function which will run itself over and over again. In our case, the function will run itself 0.1 blocks forward (^ ^ ^0.1) each time, and repeat until it hits something. It will do this all within the same tick - but bear in mind that the bigger the distance, the more laggy it will be. We can stop this unwanted behaviour by putting a distance limit on the raycast - each time it runs itself, it will count down on a scoreboard, and only repeat if it hasn't hit the limit.
start_raycast function:
# Set the distance limit on the raycast. (10 x limit in blocks, so 1000 would be 100 blocks)
scoreboard players set .limit <any objective> 1000
# Start the raycast
execute at @s anchored eyes positioned ^ ^ ^.1 run function <namespace>:raycast
raycast function:
# Remove one from the limit
scoreboard players remove .limit <objective> 1
# Optional - place a particle, to make the raycast leave a trail
particle minecraft:dust 1 0 0 1 ~ ~ ~
# If the raycast has hit a block, do something
execute unless block ~ ~ ~ #<namespace>:pass_through run setblock ~ ~ ~ diamond_block
# If the raycast hasn't hit a block, continue, but only if the limit is 1 or more (1..)
execute if block ~ ~ ~ #<namespace>:pass_through positioned ^ ^ ^0.1 if score .limit <objective> matches 1.. run function <namespace>:raycast```
namespace/tags/blocks/**pass_through**.json:```
{
"replace": false,
"values": [
"minecraft:air",
"minecraft:cave_air",
"minecraft:void_air"
]
}
This should be it! Make sure you add all the functions, and fill in all the blanks (indicated by <this>). Then, you can run the start_raycast function as a player, and it should work.
lmk if you have any issues or confusing moments with this method
well
literally 0.1 blocks forward
so it runs every tick?
raycast is essentially like a beam that first checks current position whether its a block, if its not it will move forward on 0.1 blocks it will repeat that over and over until it reaches a block and then you type your code like destroy the block or whatever
it runs recursively, as fast as your cpu allows (very fast, a lot faster than tick)
"eto" ?
like if the player is looking at a block, it signals the pickaxe if it is mineable with a tag from where the raycasting runs
am I right?
to
you could do that
so can it sense blocks around that
around what
as in the player looks at the centre block of the 3x3, how does it detect remaining blocks under the mineable tag
how?
oh
so I gotta setup 8 predicates linked to the raycast
so let me get it straight, If the block looking at by the player is under the tag, it runs the raycast which results in 8 more predicates and if not under the tag, doesn't at all.
lemme quickly go through the wiki to actually learn to input commands or functions
@wicked shadow can you suggest a tutorial or site to learn coding
8 predicates?
well it has to detect blocks in every single direction to the mined block so actually more than 8
so more like 27 predicates cuz a 3x3 miner mines in a cube of 3x3x3 so 27
am I correct? @wicked shadow
huh
where you get these numbers from
my small brain
how?
yea well usually when people mean 3x3 pickaxe it mines a 3x3x2 space 99% of the time, but if yours is 3x3x3 then ig yea its 27 blocks
yeah you're right cuz of air blocks
so, what is the command to execute ifblock at the right/left/diagonal
figure it out bruh
you never used relative coordinates
?
i am pretty sure there is a video on relative coordinates on youtube
ok
yeh I m not getting how to code it
did you make a raycast already?
umm not yrt
give me a min
@wicked shadow how do I code it in?
I know nothin about coding
huh then why are you saying you're not getting it? you're not even there
just code the raycast first
divide your main goal into small tasks
ok
kk
wait, what ais the difference?
exactly like it was written in the tutorial
one is raycast the other one is block detection
dont ask too many questions, sooner you get to work - the sooner you will realise
raycast as i explained is a beam, and block detection is... well a block detection
kk
ook
I have done it
so what now @wicked shadow
mhm
what did you test it on
wdym
this thing
..
i said
"do exactly like here"
okk so you shoot a block and then what happens
I am lost
-how did you test it, did you shoot a block or an entity?
-block
give me a minute
here you agreed that you tested it on a block
uhm no
screenshot evidence
no need to sorry
i am sorry for making you feel like you should apologize lmao
you wanna vc rn
nah all good
In school
online to be exact
uhh @wicked shadow
can you please tell me my mistake in the code
it ain't detecting
why are you even making datapack at school.......
can you just send it as a zip
or just copy the code
kk
online breh
oh alright
here
but the thing I don't get is how does the raycast link up with the block detection?
oh so it works?
no
I just went through the code and understood that it detects an creeper
but it did not load in for me
it didn't even detect my datpack
k
who tf made the tutorial
@deep pelican can you ask ppl to replace current raycast tutorial with a better one? maybe i will make a pr myself
p.s. i am sorry for ping, not relevant anymore
A quick tutorial on raycasting in Minecraft: how to raycast in a Minecraft data pack / using vanilla Minecraft commands.
NOTE: In newer versions of Minecraft some block names have changed, so the ray_permeable tag needs to be updated.
Introduction to data packs: https://youtu.be/x3ZSJr9NHGE
Raycasting demo project: https://www.danjb.com/files/...
😄
oh bro
oh
you should use this
2 yrs
ight
is bad
yeh 2 yrs old too
imma get to that 10-15minutes, I am getting a call, excuse me please
no prob
what does that even mean
@frozen pecan what do you mean not loading up
@frozen pecan whats not loading up
sorry, the datapack is not being recognized @wicked shadow
there is no way, screenshot the insides of your datapacks folder
@frozen pecan
KK
silabear set offline status
I think they meant the datapacks folder of your world
Where that data pack is placed into
Also - if you /datapack list - does it show up?
HELL YEAS
WORLD/datapacks/*
i am pretty damn sure your datapack is inside another folder and thats why it doesnt show up
because why elsse woudl there be extra folder in the zip you sent me
To be recognized and loaded, just the pack.mcmeta needs to be there and in the correct format
AH YES GOT IT... (NO SCREENSHOT)
sorry, I had to go run an errand
gimme a sec
my pc is dying
is dead right
wait bruh, my pc is shutting down every time I open VS code
I m panicking rn
do you have your minecraft open at that same time too?
nope
scary
and odd…
sorry idk why that might be 😭
yr
@wicked shadow I fixed it
I add to close bacground applications in task manager, my cpu as at 118% lol
lemme try it out
@frozen pecan down to vc like in 3 hours
I don think I can
It's like 7AM rn and I got school by 8:30-9 ish
@wicked shadow
the pack ain't working for some reason
it should send out a red beam wherever I looked and turn every block I run into to a diamond
bruh
does it still not show up ?
the folder structure should look like this
.minecraft/saves/YOUR WORLD/datapacks/raycasting/pack.mcmeta and it should show up
i am pretty sure what you have looks more like
.minecraft/saves/YOUR WORLD/datapacks/raycasting/raycasting/pack.mcmeta
because thats how you sent it here
do you ever create the gg scoreboard?
uhh
wdym
I changed that
he asks if you have
scoreboard objectives add gg dummy
in your load function
thats not important right now since datapack isnt even showing up but all the paths and pack.mcmeta are correct lol
If you never run the command to initialise the scoreboard, it won't exist and therefore won't store any values
.
it does show up bro
.
.
since then you've never said it shows up
Have you run this command?
I should've said that, mb
yea so ig just create the scoreboard in the load function
You need to put that in the file data/ray_demo/functions/load.mcfunction
load.json tells the game which functions to run on load, the commands then need to go in the functions themselves
ohk
You also need to create data/ray_demo/functions/load.mcfunction first
Then in that mcfunction you put the scoreboard command
IN LOAD
OK
done
so now what? @deep pelican
Does it work now?
nope
Lemme take a look at the files for a second, then I'll try and figure out what's wrong
kk
So does the function not run at all?
Do you correctly run the start_raycast function? Like what prints in chat when you run the command
it runs nothin
what command?
/function ray_demo:raycast_start
That means the function hasn't loaded properly
Show me the chat output of /datapack list
I have to go now, I'll be back later. Maybe someone else can help you in the mean time
Looks like your datapack is disabled. Run /datapack enable raycasting
ok
Now try the raycast function again
k
/datapacks enable raycasting
oh yea
Alright, see if this works
ok cool
soo uhm how doesit help me make a3x3mining pickaxe?
@wicked shadow so what do I do from here?
Basically, you want to detect the player using the pickaxe, then run a raycast to find the block they broke, and then destroy the 3 blocks around it
8*
YE
that, I can't maths
ight
ok lol
The only problem is, the block they just broke is now broken
Which means you can't detect it with raycast
So there's probably two ways that you could do this
hmm
One is to look for an item that is newly created, and assume that it came from the block they broke
The other is to check what block they are looking at each tick when holding that pickaxe, and then you know which block it is when they use it
hmm
Those are the two that I can think of, anyway
this seems more 'sane'
how do i DO IT ...
But I haven't really made something like this before, so maybe someone else has a better way
Sorry, I have to go now. I can help you later
np
<@&935561184806060073> <@&1202694677766348840>
Please note that you still might not immediately get a response since all helpers are human beings and volunteers (and also might be sleeping right now)
isnt this resolved already
not even close
you don't need raycasting, you can just check when the player uses the pickaxe, and once he does so mine the block around the block as well
but it should only be able to mine blocks that can only be possibly mined by a pickaxe
huh
what do you mean
do you mean blocks around it should only break if the correct tool is used?
yeah
oh
so umm how do I implement the code? @swift pike
you need to init a scoreboard that tracks when the player uses his pickaxe
if they have 1 or more score they'll get it removed and the adjacent blocks will get broken (if they are a part of #minecraft:mineable/pickaxe)
and there loot table will be dropped on the floor
you'd need the block coords of the recently mined block
raycast can't get you that info (unless you do it every tick)
since I got the raycast done, I think this is better
so I need to setup block detection now right?
...
execute if block ~ ~ ~ #minecraft:mineable/pickaxe
so how do I get the coordinates of the block? @swift pike
The only solution I can think of is to store the targeted block of the last tick somewhere
but that'll be really slow
on multiplayer, defintly
this seems more complicated than I thought
on singlplayer, maybe okay
yep its for my server
why don't you consider making a plugin instead
what do you mean?
a plugin
how would it help?
oh
I use aternos for hosting which doesn't allow to import plugins
I think I have to give a pause to this idea
and work on other concepts
I think I'll work on some basic things before reaching such stages like this
Time to close this ticket and open a different one
Thanks for the help!!
Your question, #1204314612095524864 (how to raycast), was resolved!
I am trying to restart my 3x3 mining pickaxe goal for which I got to know that I need raycasting which I know nothin about
1d5h37m
This thread has been inactive for some time, so I'm going to archive it.
If you're still using the thread, just send a message and it'll pop back on the thread list.
