mojira.dev
MC-306611

Entities instantly lose momentum when using function

The situation:

I’m trying spawn entity and insert calculated motion into it within one function using datapack. The problem is that this motion lasts only a few ticks, if not only one, before it completely resets. I have tried this with the command block, but it doesn’t seem to be affected. Regardless how strong the “Motion“ data is, or which direction the motion vector is directed towards, it almost instantly resets to [0.0f,0.0f,0.0f]. I have tried it with different entities, like snowballs or armor stands, but the effect is the same.

How does my function look like?

  1. Spawn entity.

  2. Store first position (all three values) into scoreboards.

  3. Teleport entity one block towards any direction it is looking at.

  4. Store second position (all three values) into scoreboards.

  5. Subtract the second position scoreboards from the first position scoreboards.

  6. Insert the calculated values into the “Motion“ data. (I’m using “execute store“.)

  7. Reset the scoreboards. (Not the “Motion“ data.)

  8. End the function.

Anything else?

It is more likely to be just datapack thing, because again, the “Motion“ data inserting did work with command block, even with one tick redstone pulse. It could also be partly because of the “Macro“ data, but I think it’s more just because the function itself is called only once.


Function:

Here is the function if you want to check it yourself, but I’m sure that there are no errors. It is possible to just copy-paste it and run it directly in the game as the player.

#Create the "Constructor" entity.
$execute as @s at @s run execute anchored eyes run execute positioned ^0 ^0 ^0 run summon minecraft:armor_stand ~0 ~0 ~0 {Tags:["Datapack.datapack-constructor.function.Main","Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}},Rotation:$(Rotation),DisabledSlots:4144959,CustomNameVisible:false,ShowArms:false,Small:true,NoBasePlate:true,Silent:true,Invisible:true,Invulnerable:true,Passengers:[{id:"minecraft:item_display",Tags:["Datapack.datapack-constructor.function.Main","Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Model"],transformation:{scale:[1.0f,1.0f,1.0f],translation:[0.0f,0.0f,0.0f],left_rotation:[0.0f,0.0f,0.0f,1.0f],right_rotation:[0.0f,0.0f,0.0f,1.0f]},Rotation:$(Rotation),NoGravity:true,Silent:true,Invulnerable:true,item:{id:"minecraft:command_block",count:1,components:{"minecraft:item_model":"minecraft:netherite_block"}}}]}
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run data modify entity @s Rotation[1] set value 0.0f
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute on passengers run execute as @s at @s run data modify entity @s Rotation[1] set value 0.0f

#Calculate and insert the throwing motion into the "Constructor" entity.
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result score @s Datapack.datapack-constructor.value.FirstPosition_X run data get entity @s Pos[0] 1000
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result score @s Datapack.datapack-constructor.value.FirstPosition_Y run data get entity @s Pos[1] 1000
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result score @s Datapack.datapack-constructor.value.FirstPosition_Z run data get entity @s Pos[2] 1000
$execute as @s at @s run execute anchored eyes run execute positioned ^0 ^0 ^3 run tp @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] ~0 ~0 ~0 ~0 0
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result score @s Datapack.datapack-constructor.value.SecondPosition_X run data get entity @s Pos[0] 1000
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result score @s Datapack.datapack-constructor.value.SecondPosition_Y run data get entity @s Pos[1] 1000
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result score @s Datapack.datapack-constructor.value.SecondPosition_Z run data get entity @s Pos[2] 1000
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players operation @s Datapack.datapack-constructor.value.FirstPosition_X -= @s Datapack.datapack-constructor.value.SecondPosition_X
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players operation @s Datapack.datapack-constructor.value.FirstPosition_Y -= @s Datapack.datapack-constructor.value.SecondPosition_Y
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players operation @s Datapack.datapack-constructor.value.FirstPosition_Z -= @s Datapack.datapack-constructor.value.SecondPosition_Z
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result entity @s data.Motion[0] float 0.001 run scoreboard players get @s Datapack.datapack-constructor.value.FirstPosition_X
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result entity @s data.Motion[1] float 0.001 run scoreboard players get @s Datapack.datapack-constructor.value.FirstPosition_Y
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run execute store result entity @s data.Motion[2] float 0.001 run scoreboard players get @s Datapack.datapack-constructor.value.FirstPosition_Z
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run data modify entity @s Motion set from entity @s data.DummyData.Motion
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players reset @s Datapack.datapack-constructor.value.FirstPosition_X
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players reset @s Datapack.datapack-constructor.value.FirstPosition_Y
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players reset @s Datapack.datapack-constructor.value.FirstPosition_Z
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players reset @s Datapack.datapack-constructor.value.SecondPosition_X
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players reset @s Datapack.datapack-constructor.value.SecondPosition_Y
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run scoreboard players reset @s Datapack.datapack-constructor.value.SecondPosition_Z
$execute as @e[nbt={Tags:["Datapack.datapack-constructor.entity.Constructor","Datapack.datapack-constructor.tag.Entity_Main"],data:{DummyData:{Player:$(UUID)}}},distance=0..10,limit=1,sort=nearest] run execute as @s at @s run data remove entity @s data.DummyData

#Remove the "Constructor" item from the player's hand.
execute as @s at @s run item replace entity @s weapon.mainhand with minecraft:air 1

Here are the scoreboards:

scoreboard objectives add Datapack.datapack-constructor.value.FirstPosition_X dummy
scoreboard objectives add Datapack.datapack-constructor.value.FirstPosition_Y dummy
scoreboard objectives add Datapack.datapack-constructor.value.FirstPosition_Z dummy
scoreboard objectives add Datapack.datapack-constructor.value.SecondPosition_X dummy
scoreboard objectives add Datapack.datapack-constructor.value.SecondPosition_Y dummy
scoreboard objectives add Datapack.datapack-constructor.value.SecondPosition_Z dummy

Comments 2

The bug tracker is not for command/datapack help. If you think you have found an actual bug, please narrow it down to a minimal, simple reproducible example.

I am not asking for command/datapack help. I am certain that there is a bug somewhere when it comes to motion preservation in calling function. I simply gave my own datapack code for replicating the issue, since I’m not certain if it is more related to macro values, or just the functions.

Again, I’m certain that there are no errors in my code and I’m not asking for command/datapack help. I tested motion transfer with command block and the entities are supposed to keep and calculate their momentum, but when function is used, they do not.

Personal Information

(Unassigned)

Unconfirmed

(Unassigned)

26.1 Snapshot 10

Retrieved