BigPapi13 / Delta

Explosion-based player motion library for Minecraft
MIT License
114 stars 14 forks source link

NOTE: Delta is no longer being maintained!

Check out Player Motion instead: https://modrinth.com/datapack/player_motion

Some kind folk from the MCC Discord server have been keeping up this project for newer versions as I have not had the time, and I recommend using their version instead!


Delta

Delta is an explosion-based player motion library that uses subtick timing to ensure that only one player is pushed by the blast.

How to use

Launching a player where in a specific direction

scoreboard players set $strength delta.api.launch 10000
function delta:api/launch_looking

Launching a player with xyz vector

scoreboard players set $x delta.api.launch 500
scoreboard players set $y delta.api.launch 12000
scoreboard players set $z delta.api.launch -3125
function delta:api/launch_xyz

Note: These functions are additive* and will apply motion in addition to existing motion rather than directly setting it to whatever input you send

Launching player via creeper directly

If you'd like more fine-grain control, you can summon the creepers yourself and simply use delta for the subticking with the following format:

function delta:internal/subtick/begin_launch_context
summon creeper <x y+1000 z> {Tags:["delta.launcher","delta.init"],Silent:1b,Invulnerable:1b,ExplosionRadius:-1b,Fuse:0s,PersistenceRequired:1b}
scoreboard players operation $temp delta.internal.id = @s delta.internal.id
execute as @e[type=creeper,tag=delta.init] at @s run function delta:internal/summon/initialize_creepers
function delta:internal/subtick/end_launch_context

Note: Creepers with an ExplosionRadius of -1 are recommended for more powerful pushes, and 1 for weaker ones. The direction of the push is determined by the angle from the creeper's feet to the player's eyes. You can place as many summon commands as you want, as long as they are between the launch context functions, which must be ran from a player. Make sure to summon the creeper 1000 blocks above* where you want it to spawn.

Replicating explosion effects

If you choose to remove the explosion sounds and particles with the resource pack, you can still use those effects with the following API calls:

# Creates a single explosion particle
function delta:api/explosion_particle

# Creates an explosion emitter, which is what creepers and TNT display when they explode
function delta:api/explosion_emitter_particle

# Plays an explosion sound
function delta:api/explosion_sound

Advanced particles

If you would like to replicate the arguments of the particle command such as the spread and count, Delta provides a rough approximation like so: particle minecraft:explosion ~ ~ ~ 3.5 1.2 0.24 0 10 will instead be written as:

scoreboard players set $dx delta.api.particle 350
scoreboard players set $dy delta.api.particle 120
scoreboard players set $dz delta.api.particle 24
scoreboard players set $count delta.api.particle 10
function delta:api/explosion_particle

Note: All of the above parameters must be set every time the function is called, otherwise it will default to a single particle. The parameters work for both explosion and explosion_emitter

Limitations + Known Issues

While this library is likely the closest we've gotten to perfect player motion manipulation, there are some limitations worth mentioning:

If you know any possible solutions or would like to help fixing these problems, please let me know!