Started by
Taras Ogurtsov
on
Topic category: Help with Minecraft modding (Java Edition)
Can anyone tell me how to make an achievement like "Sniper Duel", so that the player gets it when hitting a block from a certain distance?
Topic category: Help with Minecraft modding (Java Edition)
Can anyone tell me how to make an achievement like "Sniper Duel", so that the player gets it when hitting a block from a certain distance?
Hello!
You could do this by running a procedure where the block is hit by the arrow.
You just need an if not statement and a "does entity exist at in square cube with size [] of type Player" block. [found in world data]
If you are using a custom ranged weapon, just set the procedure to run when the projectile hits a block.
Hope this helps!
It works, thank you!
Glad to help ^^ Have a good day!
There is a problem, if there is someone else standing not far from the block you need to hit, the player who shot will not get the achievement, even if he shot from the right distance. So, is it possible to make the procedure take into account only the player who shoots?
It should theoretically still work, since player and server player are different entities
There is another problem, it turns out that the achievement is not even being given to the player. Before I used to use the chat message to know that everything was working properly, but now I replaced it with the procedure for giving the achievement to the player and realized that now it doesn't work at all. This procedure just doesn't understand exactly who to give the achievement to. I've tried changing the Event/target entity to other components, but mcreator says there is a problem in this and even other procedures related to the block you need to hit. Could you please explain to me how to fix this?
Can you send a picture of your procedure?
of course
Try replacing "event target entity" with "get nearest entity at x y z in square cube with size 20 of type player
I get your idea, but it doesn't work. First of all, the main condition for the achievement is to be outside the specified distance, i.e. the player can be at the minimum distance of 10 blocks, or at a much greater distance. And the second problem is that with this method, the achievement can be obtained by a completely different player who didn't even shoot at the block. I still haven't found a way to make this achievement work, so if anyone has any ideas, please help!
Instead of verifying a player's proximity to the block that was hit, just compute the distance between the two (there should be a procedure to get entity's X, Y and Z value).
You can add a check to ensure that arrow was shot by a player before calculating distance and granting advancement.
Distance formula:
d = √((x2 - x1)² + (y2 - y1)² + (z2 - z1)²)
Here,
x1, y1, z1
are the player's coordinates, whilex2, y2, z2
pertain to the block's location (x, y, z from provided dependencies). Thed
represents the distance between them.Afterwards, check if the calculated distance equals or exceeds a set threshold:
√((x2 - x1)² + (y2 - y1)² + (z2 - z1)²) >= Threshold
For more efficient, omit the square root computation and compare the squared distance against your squared desired threshold:
((x2 - x1)² + (y2 - y1)² + (z2 - z1)²) >= Threshold²
Bypassing the square root is beneficial as it's a resource-intensive operation, and you can simply compare the squared distances since precise values aren't necessary.
This method is really interesting, but how do I get the coordinates of the player who is shooting? As I wrote in one of the posts above, the problem is that the game just doesn't understand who to give the achievement to, and in our case whose coordinates it needs to take. Moreover, I tried to make it so that when an arrow hits a block, a block is spawned at x y z coordinates of event/target entity, and I noticed that the block is spawned either exactly at the place of the arrow or within a radius of 1-2 blocks from it. Could you please explain me how to solve this problem?
X
,Y
, andZ
denote the coordinates of the hit block. In theEntity Data
section, on top, you will find three procedures that provide the entity's position, one for x, y and z. Theevent/target entity
refers to the entity that fired this arrow (also known as the owner).Something like this should work:
Just replace
5
with a distance you want or entire5^2
with a squared distance you want and pick your advancement ofc.PS. For the future: in this trigger, arrow is available as
immediate source entity
inMinecraft Components
sectionYes, I understand how the procedure works, but again, in my case the game sees the arrow as an event/target entity, not the player.