> For the complete documentation index, see [llms.txt](https://datapackhub.gitbook.io/slowcast/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://datapackhub.gitbook.io/slowcast/slowcast.md).

# Slowcast

If you look this up, I assume you already know what a normal Raycast does. A Slowcast is similar, but unlike a standard Raycast, it is not instant. You might think now: "Why do we need a Slowcast for that, you can just teleport a marker slowly forward to do the same?". You'd be right normally but now think about having a really fast projectile. To make it faster you would need to increase the distance the marker TPs ever tick. This is bad when the gap between the two points becomes too big and doesn't correctly recognize when hitting something. A Slowcast solves this problem by checking the gap between the two points in 0.2 block steps if it hits something on the way.

How do we make a Slowcast now?

First, add three commands to your load function that create new scoreboards:

{% code title="load.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
scoreboard objectives add temp dummy
scoreboard objectives add slowcastSteps dummy
scoreboard objectives add slowcastDuration dummy
```

{% endcode %}

Now you need an initialization command. This Command must be executed as and at the player that shoots the Slowcast.

{% code title="init.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
execute positioned ~ ~1 ~ summon minecraft:marker run function <namespace>:setup
```

{% endcode %}

This init command moves the position of the following command 1 block up, summons a marler, and then runs a function as and at the marker.

Next comes the setup function that gives the marker projectile all the necessary data and the temp\_tick function.

{% code title="setup.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
tag @s add slowcast

# The temp scoreboards are just to set the steps and duration of the Slowcast before calling it.
scoreboard players operation @s slowcastSteps = steps temp
scoreboard players operation @s slowcastDuration = duration temp

# Here is a bit of math to show how far the Slowcast will travel
#
# slowcastDuration = 50 (value in ticks)
# slowcastSteps = 3 (the steps per tick. One step is the distance it teleports itself forward which is defined later)
#
# step_distance * steps * duration  ==> 0.2 * 3 * 50 = 30 blocks
# 
# It will move 30 blocks in those 50 ticks 

function <namespace>:temp_tick
```

{% endcode %}

{% code title="temp\_tick.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
execute as @e[type=marker,tag=slowcast,scores={slowcastDuration=1..}] at @s run function <namespace>:duration

execute if entity @n[type=marker,tag=slowcast] run schedule function <namespace>:temp_tick 1t
```

{% endcode %}

Good, the projectile is all set up and has called the temporary tick function, which will run every tick as long as there are active Slowcasts. Let's create the actual Slowcast logic now.

First comes the duration function. It ensures, that the Slowcast ticks down its timer and kills it once it reaches 0. It also calls the step function to move to the next position.

{% code title="duration.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
scoreboard players remove @s slowcastDuration 1

scoreboard players reset hit temp
scoreboard players operation slowcastSteps temp = @s slowcastSteps
execute positioned ^ ^ ^.2 run function <namespace>:step

execute unless score @s slowcastDuration matches 1.. run kill
```

{% endcode %}

The step function, as stated in the introduction, is responsible for checking the gap between the two points the marker teleports between in one tick for collisions and ends the function early if it hits something.

{% code title="step.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
scoreboard players remove slowcastSteps temp 1

particle flame ~ ~ ~ .1 .1 .1 0 1

execute store success score hit temp as @e[type=!player,type=!marker,dx=0] positioned ~-.99 ~-.99 ~-.99 if entity @s[dx=0] positioned ~.99 ~.99 ~.99 run function <namespace>:end 
execute if score hit temp matches 1 run kill

tp ~ ~ ~

execute if score slowcastSteps temp matches 1.. positioned ^ ^ ^.2 run function <namespace>:step
```

{% endcode %}

The command in line 5 might look very intimidating because of its length but I assure you once you know what all the parts do it's not that bad anymore.

* `execute store success score hit temp` will store the success of the rest of the command in the `hit` fake player in the temp scoreboard.
* `as @e[type=!player,type=!marker,dx=0]` will execute the rest of the command as every non-player, non-marker entity if their hitbox intersects a 1x1x1 block big cube that extends from the position of the command in all 3 positive directions.
* `positioned ~-.99 ~-.99 ~-.99 if entity @s[dx=0] positioned ~.99 ~.99 ~.99` moves the command's position nearly one block into the negative and checks again if all entities that had intersecting hitboxes now still intersect with the moved 1x1x1 big cube. If yes, it continues by moving the command's position back to where it was.
* `run function <namespace>:end` simply runs the end function as the hit entity if all checks succeed.

Now you have the last function necessary for the Slowcast. This one has only one important command for all of this to work, the rest is up to you, what you want to happen when hitting something. In my case, the entity just says hi.

{% code title="end.mcfunction" lineNumbers="true" fullWidth="true" %}

```
say hi

# Here is the return command. It just gives the execute store a result value, that's it
return 1
```

{% endcode %}

That's it. This is how you make a Slowcast. If you want you can tweak some parts to do stuff a bit differently, for example, switch the marker with an item display or remove the kill command after hitting something to make it a piercing projectile or much more.
