Minecraft Data Packs / Other

Customize/predict entities motion

  • check_circle Functions
  • check_circle Loot Tables
  • check_circle Predicates
  • 635 views, 1 today
  • 18 downloads, 0 today
  • 2
  • 1
Pexzpig's Avatar Pexzpig
Level 4 : Apprentice Miner
0
The functions are as follows: (Translated by AI)


1. Prediction of the movement of most entities, provided that the movement does not involve fluid motion or block collisions.

Entities without AI acceleration (such as projectiles) can be accurately predicted after any tick, while entities with AI acceleration (mainly living entities) can be effectively predicted within approximately 10 ticks based on tests and comparison of predicted and actual positions of the entities (by recording videos and comparing the alignment of frames before and after prediction). Player movement prediction is supported, but occasional strange errors may occur. In most cases, effective prediction can be achieved within 10 ticks, although the error issue has not been resolved.
* Prediction of living entities is more complex compared to flying entities, and the prediction results may not be ideal (especially in the y-axis prediction). This data pack is primarily recommended for predicting the movement of flying entities.


2. Customization of entity movement parameters.

The parameters that can be defined are drag and gravity. Drag is expressed as the proportion of velocity reduction per tick. Currently, changing the order of motion calculations is not supported.
The aforementioned prediction effect can be applied to custom entities. Custom movements involving fluid or block collisions are not handled. If a custom entity enters fluid or experiences collisions, unexpected bugs may occur.


3. Player WASD detection.

Players with the "pex_wasd_test" tag will have their actual WASD inputs recorded on the "pex_wasd" scoreboard. By calculating player AI acceleration detection, accurate results can be maintained in motion scenarios, but it may not be compatible with players in riding states. The following command can be used to confirm one's WASD input on the sidebar:

tag @s add pex_wasd_test

The specific keyboard inputs corresponding to each value are as follows:
No input - 0;
W - 1, D - 2, S - 3, A - 4;
WD - 5, DS - 6, SA - 7, AW - 8;


The requirements for the detection environment are as follows:

AI acceleration is only provided by player WASD inputs. Therefore, unexpected errors may occur in the following scenarios: sprinting and jumping, horizontal block collisions, fluid movement, entity squeezing, riding entities (boats, minecarts, creatures), elytra flight, etc. (The common point in these error scenarios is the presence of other sources of acceleration).

*** Make sure the frame rate is stable at multiples of 20 (important!). Frame rate locking is required. There may be fluctuations during initial game loading, and errors at that time are considered normal. For specific reasons, you can refer to my original post.


* Version-related issues:
Some code for custom entities uses "execute on", and without modifying the data pack, it is only available in version 1.19.4. However, the tag_add file provides corresponding code that can be used in lower versions.


Note:
This data pack currently does not include a graphical module. It does not provide an intuitive in-game interface, only a data pack interface. If you do not modify any content in the data pack, you will have the following functionalities:

1. Prediction of the position of most flying entities* after 1 second, represented by soul_fire_flame particles indicating the movement trajectory.
2. Adding the "pex_motion_test" tag to any living entity* will display a floating target block representing the position of the entity 0.5 seconds (10 ticks) later.
3. Snowballs and fishing rods with different movement trajectories than normal ones. The commands:
loot give @s loot pex_motion:farther_fishing_rod
loot give @s loot pex_motion:heavy_snowball


If you want to modify the content of the data pack to obtain more features or integrate it with your own data pack, here are the parts you can modify:

1. In the "function/main.mcfunction" file, there are corresponding comments for modification. You can modify the entities to be detected (by adding tags to specific entities) and the number of ticks to predict (the position returned will be the position after the specified number of ticks, stored in the scoreboard).
2. Set the output in the "function/result_pos.mcfunction" file. This function will execute once per tick at the predicted position. The default settings are a small particle effect (for projectiles) or a target block (for living entities).
3. In the "function/custom_entity/tag_add.mcfunction" file, you can modify the drag and gravity values for custom entities.
CompatibilityMinecraft 1.19
Tags

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome