I'm currently making a datapack (for singleplayer, at least now) with WW1 or WW2 riefle with realistic recocking and relading mechacics but some problems occured and I still don't know how to make it work.
1. Item detection
The plan was to check if player holds a specific item (carrot_on_a_stick) to give him/her a tag that allows next commands to run only if that item is selected.
So I used those commands to detect if player holds it or not:
/execute as @e[tag=!with_riefle,nbt={SelectedItem:{id:"carrot_on_a_stick",tag:{display:{Name:"{\"text\":\"Riefle\",\"color\":\"gold\",\"bold\":\"true\"}"}}}}] run tag @s add with_riefle
/execute as @e[tag=with_riefle,nbt=!{SelectedItem:{id:"carrot_on_a_stick",tag:{display:{Name:"{\"text\":\"Riefle\",\"color\":\"gold\",\"bold\":\"true\"}"}}}}] run tag @s remove with_riefle
Even when I previously made version with all those details from /give command it doesn't work. The same thing propably happend in other commands with diffrent items.
2. Health scoreboard
In this datapack if you want to recock the riefle after shot you have to press F hoding it, than Left click and than after an animation ends just move it back to the main hand and return to shooting. After 5 shots reloading is nessesary, to do it you have to press F, Left click, then Left click holding an ammo clip, Left click and then you can press F again, after an animation.
I have used invisible villagers to detect left click.
And I set a scoreboard to check if villager gets any demage.
/scoreboard objectives add hp health
I could give the villager 1 health point but I wanted to avoid those death particles so when villager gets demage and its hp is below 10, it should get teleported into the void and die there.
/execute as @e[type=villager,tag=detect,scores={hp=..10}] run teleport @s ~ ~-300 ~
3. Setting motion of an arrow
This is the most problematic part of the whole datapack, with out it this datapack makes no sense.
Arrows are those little, stubborn, annoying entities - you just cannot rotate them without giving them motion NBT data. I saw suggestions that you could use your position (Pos) NBT data, store in a scroreboard, scale and then apply on arrow but I checked them and it doesn't work.
1. position is just an xyz location of an entity2. applying those values to motion NBT data didn't work I think
Theoreticly it should work - an arrow would just fly away in some wierd direction.
So I thought, motion NBT data look like this: ... ,Motion:[1.0,0.1,0.2], ... just some vectors in xyz directions and an entity moves on resultant of those vectors (without gravity).
My idea was to summon two invisible armor stands, first ^ ^ ^5 from player, second ^ ^ ^1 from player and store postion of first and second in 6 scoreboards (xyz scoreboards for first, xyz scoreboards for second) and than function substracts x score of second from x of first, than y, z.
After this operation you get diffrences between positions of those armor stands - vectors, their resultant stays the same no matter what direction you are looking, now you can scale it as you wish and apply...
/summon armor_stand ^ ^ ^5 {NoGravity:1b,Invulnerable:1b,Invisible:1b,Tags:["way","first"],DisabledSlots:4144959}
/summon armor_stand ^ ^ ^1 {NoGravity:1b,Invulnerable:1b,Invisible:1b,Tags:["way","second"],DisabledSlots:4144959}
/summon arrow ^ ^ ^1 {NoGravity:1b,pickup:0b,player:0b,damage:20d,Tags:["bullet"],Color:-1}
/execute as @e[tag=first,limit=1] store result score @s dx run data get entity @s Pos[0] 1000
/execute as @e[tag=first,limit=1] store result score @s dy run data get entity @s Pos[1] 1000
/execute as @e[tag=first,limit=1] store result score @s dz run data get entity @s Pos[2] 1000
/execute as @e[tag=second,limit=1] store result score @s x run data get entity @s Pos[0] 1000
/execute as @e[tag=second,limit=1] store result score @s y run data get entity @s Pos[1] 1000
/execute as @e[tag=second,limit=1] store result score @s z run data get entity @s Pos[2] 1000
/scoreboard players operation @e[tag=first,limit=1] dx -= @e[tag=second,limit=1] x
/scoreboard players operation @e[tag=first,limit=1] dy -= @e[tag=second,limit=1] y
/scoreboard players operation @e[tag=first,limit=1] dz -= @e[tag=second,limit=1] z
/execute as @e[tag=bullet,tag=!away] store result entity @s Motion[0] double 0.01 run scoreboard players get @e[tag=first,limit=1] dx
/execute as @e[tag=bullet,tag=!away] store result entity @s Motion[1] double 0.01 run scoreboard players get @e[tag=first,limit=1] dy
/execute as @e[tag=bullet,tag=!away] store result entity @s Motion[2] double 0.01 run scoreboard players get @e[tag=first,limit=1] dz
/execute as @e[tag=bullet,tag=!away] run tag @s add away
/kill @e[tag=way,tag=second]
But for some damned reason it doesn't work even if it applies those scores in the loop.
I will be satisfied with any suggestions and tips.
For the detecting villager, simply make it spawn with regeneration 255, no particles, it should work
I made myself some guns, I'll get you what I have done
Testing now if I could make the item detection work
But I guess instead of putting the gun in offhand and all kinds of tricks like that are not the best : You could use simply right-click detection for reloading and all the stuff, I would know how to do.
Rollback Post to RevisionRollBack
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Here is for your detection : You simply forgot to put the "minecraft." before your item name :
/execute as @a[tag=!with_riefle,nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"{\"text\":\"Riefle\",\"color\":\"gold\",\"bold\":\"true\"}"}}}}] run say yo
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Now, here's a system I made for "TNT gun", similar to your Riefle system (Uh, I'm sorry, I'm french so some parts of the commands might be in this langage, lol) :
It takes only one armor stand and works in multiplayer without switching players' armor stands.
There're also 5 dummy scores "pos_x", "pos_y", "pos_z", "ReloadTnt","Time" and 1 minecraft.used:minecraft.carrot_on_a_stick "Clic"
-The give gun command (I took my tnt gun as an example) :
First, the give command (You could include some stats in your guns as lores, Like what I did here) :
/give @p minecraft:carrot_on_a_stick{display:{Name:"{\"text\":\"Tnt\",\"color\":\"dark_red\",\"italic\":\"false\",\"extra\":[{\"text\":\"Gun\",\"color\":\"dark_gray\"}]}",Lore:["Caractéristiques de l'arme :","Cadence de tir ▇▇▁▁▁","Poids ▇▇▇▇▁","Portée ▇▁▁▁▁","","Projectiles :","TNT","Explosion après 10 secondes"]}} 1
If you want to do this in your own world, make sure you type these 3 commands :
scoreboard players set @a[scores={ReloadTnt=0}] Clic 0
Third :
/execute as @a[scores={ReloadTnt=1..}] unless entity @s[nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",Count:1b,tag:{display:{Name:"{\"text\":\"Tnt\",\"color\":\"dark_red\",\"italic\":\"false\",\"extra\":[{\"text\":\"Gun\",\"color\":\"dark_gray\"}]}"}}}}] run scoreboard players set @s ReloadTnt 60
Fourth :
/execute as @a[scores={ReloadTnt=40}] at @s run playsound minecraft:block.chest.open ambient @s ~ ~ ~ 1 0.8
Five :
/execute as @a[scores={ReloadTnt=1}] at @s run playsound minecraft:block.chest.close ambient @s ~ ~ ~ 1 0.8
So the system works with ReloadTnt score : once you shot, you get a score of 60. Then the reload system remove 1 ReloadTnt each ticks unless the gun is no longer in hand, in which case the ReloadTnt score would be set again to 60.
When ReloadTnt reaches 0, the player get a score of 0 for "Clic", which allow him to shoot again.
Now, the huge part : The shooting event
Note : This is a tnt gun, so it should shoot tnt, but there's a trick : When you summon an arrow or falling sand then give them motion, they fall straight down a short time before getting motion, but it's not the case of armor stands : For the shot "Tnt", I just used a small invisible armor stand with a Tnt head.
(Uh... Not sure you could see... Anyway, you can still open the one in attachments...)
First command :
execute as @a[scores={Clic=1..,ReloadTnt=0},nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",Count:1b,tag:{display:{Name:"{\"text\":\"Tnt\",\"color\":\"dark_red\",\"italic\":\"false\",\"extra\":[{\"text\":\"Gun\",\"color\":\"dark_gray\"}]}"}}}}] at @s run summon minecraft:armor_stand ^ ^ ^20 {NoGravity:1b,Tags:["ShootDirection"],Invisible:1b}
2 :
scoreboard players set @a[scores={ReloadTnt=0,Clic=1..}] ReloadTnt 61
3 :
scoreboard players set @a[scores={ReloadTnt=61,Clic=1..}] Clic 0
4 :
execute as @a[scores={ReloadTnt=61,Clic=0}] run execute store result score @s pos_x run data get entity @s Pos[0] 10
5 :
execute as @a[scores={ReloadTnt=61,Clic=0}] run execute store result score @s pos_y run data get entity @s Pos[1] 10
6 :
execute as @a[scores={ReloadTnt=61,Clic=0}] run execute store result score @s pos_z run data get entity @s Pos[2] 10
7 :
execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run execute store result score @e[type=armor_stand,tag=ShootDirection,distance=19.8..20.2] pos_x run data get entity @e[type=minecraft:armor_stand,tag=ShootDirection,limit=1,distance=19.8..20.2] Pos[0] 10
8 :
execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run execute store result score @e[type=armor_stand,tag=ShootDirection,distance=19.8..20.2] pos_y run data get entity @e[type=minecraft:armor_stand,tag=ShootDirection,limit=1,distance=19.8..20.2] Pos[1] 10
9 :
execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run execute store result score @e[type=armor_stand,tag=ShootDirection,distance=19.8..20.2] pos_z run data get entity @e[type=minecraft:armor_stand,tag=ShootDirection,limit=1,distance=19.8..20.2] Pos[2] 10
10 :
execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run tp @e[type=minecraft:armor_stand,tag=ShootDirection,distance=19.8..20.2] @s
11 :
/execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run scoreboard players operation @s pos_x -= @e[type=armor_stand,tag=ShootDirection,limit=1,sort=nearest] pos_x
12 :
/execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run scoreboard players operation @s pos_y -= @e[type=armor_stand,tag=ShootDirection,limit=1,sort=nearest] pos_y
13 :
/execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run scoreboard players operation @s pos_z -= @e[type=armor_stand,tag=ShootDirection,limit=1,sort=nearest] pos_z
14 :
execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run kill @e[type=minecraft:armor_stand,tag=ShootDirection,limit=1,sort=nearest]
15 :
execute as @a[scores={Clic=0,ReloadTnt=61},nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",Count:1b,tag:{display:{Name:"{\"text\":\"Tnt\",\"color\":\"dark_red\",\"italic\":\"false\",\"extra\":[{\"text\":\"Gun\",\"color\":\"dark_gray\"}]}"}}}}] at @a[scores={Clic=0,ReloadTnt=61},nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",Count:1b,tag:{display:{Name:"{\"text\":\"Tnt\",\"color\":\"dark_red\",\"italic\":\"false\",\"extra\":[{\"text\":\"Gun\",\"color\":\"dark_gray\"}]}"}}}}] anchored eyes positioned ^ ^ ^0 run summon armor_stand ~ ~ ~ {Invisible:1b,ShowArms:0b,Pose:{Head:[180f,0f,0f]},ArmorItems:[{},{},{},{id:"minecraft:tnt",Count:1}],Small:1b,Tags:["TntBlock"]}
16 :
/execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run execute store result entity @e[tag=TntBlock,limit=1,sort=nearest] Motion[0] double -0.005 run scoreboard players get @s pos_x
17 :
/execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run execute store result entity @e[tag=TntBlock,limit=1,sort=nearest] Motion[1] double -0.005 run scoreboard players get @s pos_y
18 :
/execute as @a[scores={ReloadTnt=61,Clic=0}] at @s run execute store result entity @e[tag=TntBlock,limit=1,sort=nearest] Motion[2] double -0.005 run scoreboard players get @s pos_z
19 :
scoreboard players set @a[scores={ReloadTnt=61}] Clic 0
20 :
scoreboard players set @a[scores={ReloadTnt=61}] ReloadTnt 60
21 :
/execute as @a[scores={ReloadTnt=60}] at @s run playsound minecraft:entity.blaze.shoot ambient @s ~ ~ ~ 1 1
I hope you're still here lol
So the firing player (ReloadTnt=0, Clic=1..) have "Clic" set to 0 and "ReloadTnt" set to 61. All the chain will affect players with "ReloadTnt=61". An armor stand is summonned 20 blocks in front of the player, then the player's coords are registered in their scores pos_x,pos_y and pos_z. After that, the players make the nearest armor stand at a distance between 19.8 and 20.2 blocks store his own coordinates in his pos scores (This way, it's always detecting the right armor stand, even if another player is shooting meanwhile. Of course, it is tagged).
Once it's done, the armor stand is teleported to his player, then the 2 entities' pos scores are substracted to get the ammo's direction and the result is stored as shooting player's pos scores. The armor stand is killed then a "tnt" armor stand is summonned. Finally, this new armor stand is given the values of pos scores of the player as their motion stats. Finally, the Reload score is set to 60, which make the reloading system affect the player
Note about the "Clic" score : As long as a player has a "Clic" score greater than 1, once it gets a reloaded gun in hand, the gun will shoot automatically. So it's better to be set to 0 every time a process is finished (Not as a clock, as it might be set to 0 in the middle of the shooting process, causing dysfunctionment).
Finally, there's the system that turns the armor stand into a real tnt, if you want to reproduce it :
Only 3 command blocks :
1 :
execute at @e[tag=TntBlock,type=armor_stand,nbt={OnGround:1b}] run summon tnt ~ ~ ~ {Fuse:60s}
2 :
execute at @e[tag=TntBlock,nbt={OnGround:1b}] run particle minecraft:block minecraft:tnt ~ ~ ~ 0.5 0.5 0.5 1 10 normal
3 :
kill @e[tag=TntBlock,nbt={OnGround:1b}]
Pretty simple : When the armor stand lands on any block, it make little particles, the summons a tnt and finally kills himself.
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Uh I could make a datapack with this, would be easier to show commands...
Rollback Post to RevisionRollBack
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
I'm currently making a datapack (for singleplayer, at least now) with WW1 or WW2 riefle with realistic recocking and relading mechacics but some problems occured and I still don't know how to make it work.
1. Item detection
The plan was to check if player holds a specific item (carrot_on_a_stick) to give him/her a tag that allows next commands to run only if that item is selected.
So I used those commands to detect if player holds it or not:
Even when I previously made version with all those details from /give command it doesn't work. The same thing propably happend in other commands with diffrent items.
2. Health scoreboard
In this datapack if you want to recock the riefle after shot you have to press F hoding it, than Left click and than after an animation ends just move it back to the main hand and return to shooting. After 5 shots reloading is nessesary, to do it you have to press F, Left click, then Left click holding an ammo clip, Left click and then you can press F again, after an animation.
I have used invisible villagers to detect left click.
And I set a scoreboard to check if villager gets any demage.
I could give the villager 1 health point but I wanted to avoid those death particles so when villager gets demage and its hp is below 10, it should get teleported into the void and die there.
3. Setting motion of an arrow
This is the most problematic part of the whole datapack, with out it this datapack makes no sense.
Arrows are those little, stubborn, annoying entities - you just cannot rotate them without giving them motion NBT data. I saw suggestions that you could use your position (Pos) NBT data, store in a scroreboard, scale and then apply on arrow but I checked them and it doesn't work.
1. position is just an xyz location of an entity 2. applying those values to motion NBT data didn't work I think
Theoreticly it should work - an arrow would just fly away in some wierd direction.
So I thought, motion NBT data look like this: ... ,Motion:[1.0,0.1,0.2], ... just some vectors in xyz directions and an entity moves on resultant of those vectors (without gravity).
My idea was to summon two invisible armor stands, first ^ ^ ^5 from player, second ^ ^ ^1 from player and store postion of first and second in 6 scoreboards (xyz scoreboards for first, xyz scoreboards for second) and than function substracts x score of second from x of first, than y, z.
After this operation you get diffrences between positions of those armor stands - vectors, their resultant stays the same no matter what direction you are looking, now you can scale it as you wish and apply...
But for some damned reason it doesn't work even if it applies those scores in the loop.
I will be satisfied with any suggestions and tips.
.
For the detecting villager, simply make it spawn with regeneration 255, no particles, it should work
I made myself some guns, I'll get you what I have done
Testing now if I could make the item detection work
But I guess instead of putting the gun in offhand and all kinds of tricks like that are not the best : You could use simply right-click detection for reloading and all the stuff, I would know how to do.
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Here is for your detection : You simply forgot to put the "minecraft." before your item name :
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Now, here's a system I made for "TNT gun", similar to your Riefle system (Uh, I'm sorry, I'm french so some parts of the commands might be in this langage, lol) :
It takes only one armor stand and works in multiplayer without switching players' armor stands.
There're also 5 dummy scores "pos_x", "pos_y", "pos_z", "ReloadTnt","Time" and 1 minecraft.used:minecraft.carrot_on_a_stick "Clic"
-The give gun command (I took my tnt gun as an example) :
First, the give command (You could include some stats in your guns as lores, Like what I did here) :
If you want to do this in your own world, make sure you type these 3 commands :
-The reload system :
First command :
Second :
Third :
Fourth :
Five :
So the system works with ReloadTnt score : once you shot, you get a score of 60. Then the reload system remove 1 ReloadTnt each ticks unless the gun is no longer in hand, in which case the ReloadTnt score would be set again to 60.
When ReloadTnt reaches 0, the player get a score of 0 for "Clic", which allow him to shoot again.
Now, the huge part : The shooting event
Note : This is a tnt gun, so it should shoot tnt, but there's a trick : When you summon an arrow or falling sand then give them motion, they fall straight down a short time before getting motion, but it's not the case of armor stands : For the shot "Tnt", I just used a small invisible armor stand with a Tnt head.
(Uh... Not sure you could see... Anyway, you can still open the one in attachments...)
First command :
2 :
3 :
4 :
5 :
6 :
7 :
8 :
9 :
10 :
11 :
12 :
13 :
14 :
15 :
16 :
17 :
18 :
19 :
20 :
21 :
I hope you're still here lol
So the firing player (ReloadTnt=0, Clic=1..) have "Clic" set to 0 and "ReloadTnt" set to 61. All the chain will affect players with "ReloadTnt=61". An armor stand is summonned 20 blocks in front of the player, then the player's coords are registered in their scores pos_x,pos_y and pos_z. After that, the players make the nearest armor stand at a distance between 19.8 and 20.2 blocks store his own coordinates in his pos scores (This way, it's always detecting the right armor stand, even if another player is shooting meanwhile. Of course, it is tagged).
Once it's done, the armor stand is teleported to his player, then the 2 entities' pos scores are substracted to get the ammo's direction and the result is stored as shooting player's pos scores. The armor stand is killed then a "tnt" armor stand is summonned. Finally, this new armor stand is given the values of pos scores of the player as their motion stats. Finally, the Reload score is set to 60, which make the reloading system affect the player
Note about the "Clic" score : As long as a player has a "Clic" score greater than 1, once it gets a reloaded gun in hand, the gun will shoot automatically. So it's better to be set to 0 every time a process is finished (Not as a clock, as it might be set to 0 in the middle of the shooting process, causing dysfunctionment).
Finally, there's the system that turns the armor stand into a real tnt, if you want to reproduce it :
Only 3 command blocks :
1 :
2 :
3 :
Pretty simple : When the armor stand lands on any block, it make little particles, the summons a tnt and finally kills himself.
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Uh I could make a datapack with this, would be easier to show commands...
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).