Arqade Asked by LiamSnow on September 13, 2020
I have been trying to figure out throwing knives in Minecraft.
Is there an easy way (besides a ton of command blocks) to summon an object where the player is with motion according to where the player is looking, besides using an arrow?
I want to summon an armor stand and have the arrow break the armor stand, but if the armor stand is invulnerable the arrow should hit it and fall down. The same should happen with eye of ender, ender pearls and snowballs.
I got this to work:
/execute @e[type=snowball,tag=!standSummoned] ~ ~ ~ summon armor_stand ~ ~0.1 ~ {Marker:1,Small:1b,CustomName:snowballStand,NoGravity:1}
(in repeating command block)
/scoreboard players tag @e[type=snowball,tag=!standSummoned] add standSummoned
(in conditional chain command block)
/execute @e[type=snowball,tag=standSummoned] ~ ~ ~ /teleport @e[name=snowballStand] ~ ~-0.1 ~
(in regular chain command block)
the Marker:1
tag gives it a really tiny hitbox, so offsetting it slightly is enough to keep it from getting in the snowball's way. Note that this summons the armor stand with its feet at the snowball, you might want to offset it farther down to get the effect you want.
EDIT:
I may have misunderstood the problem. Were you trying to get a projectile to kill an existing invulnerable armor stand on hit? If so, this is what you want:
/execute @e[type=arrow] ~ ~ ~ scoreboard players tag @e[type=armor_stand,name=targetedArmorStandName,r=3] remove vulnerable
/execute @e[type=arrow] ~ ~ ~ scoreboard players tag @e[type=armor_stand,name=targetedArmorStandName,r=2] add vulnerable
/entitydata @e[tag=vulnerable] {Invulnerable:0}
/entitydata @e[tag=!vulnerable,type=armor_stand,name=targetedArmorStandName] {Invulnerable:1}
Answered by TenNineAce on September 13, 2020
EDIT: I just realized that this might not be what you want, as it doesn't actually support vertical throws. I'll leave it up anyway in case it's helpful to anyone though.
Here's a video detailing translational dynamics using boats (what you are looking for). Here's are the actual commands I recommend you do:
Summon a boat with two passengers (impulse command block):
execute @a[tag=playerThrowingTheKnife] ~ ~ ~ summon Boat ~ ~100 ~ {NoGravity:1b,Tags:["knife","knifeBase"],Passengers:[{id:"area_effect_cloud",Tags:["knife","knifeFront"],particle:take,Duration:100000},{id:"area_effect_cloud",Tags:["knife"],particle:take,Duration:100000}]}
This entity stack will serve as part of the throwing knife that travels in the direction the player is facing.
Next, run this command during the same tick (put a chain block after the impulse, set it to always active):
execute @p[tag=playerThrowingTheKnife] ~ ~ ~ teleport @e[tag=knife,type=Boat,c=1] ~ ~100 ~ ~ ~
This will copy the rotation of the player onto the boat (the knife).
Then run this command in a repeat block:
execute @e[tag=knifeFront] ~ ~ ~ teleport @e[tag=knifeBase,c=1] ~ ~0.1 ~
This will teleport the boat to its front passenger, moving it forward in the direction it is facing. If you want it to move faster (by default it is 0.2 blocks/tick), just summon the first entity stack with more passengers towards the front of the boat. To double its speed, for example, you'd use this data tag instead of the one above when summoning the boat:
{NoGravity:1b,Tags:["knife","knifeBase"],Passengers:[{id:"area_effect_cloud",Tags:["knife"],particle:take,Duration:100000,Passengers:[{id:"Boat",Tags:["knife"],Passengers:[{id:"area_effect_cloud",Tags:["knife","knifeFront"],particle:take,Duration:100000},{id:"area_effect_cloud",Tags:["knife"],particle:take,Duration:100000}]}]},{id:"area_effect_cloud",Tags:["knife"],particle:take,Duration:100000}]}
You would also have ~ ~-0.175 ~ at the end of the repeat block instead of ~ ~0.1 ~ because the height of the stack changed. To find this y value, run "tp @e[tag=knifeFront] ~ ~ ~" and subtract the Y value it gives you from the Y value you get from "tp @e[tag=knifeBase] ~ ~ ~". Also, if you change the speed, you must change the c=1 in the chain block to c=x where x is the multiplier at which you changed the speed (the number of boats in the stack). In this example, to double the speed you'd change it to c=2. This rotates ALL boats in the stack to have the player's rotation, and will still function properly whether or not multiple throwing knives exist at a time.
If you don't want the ugly boat model (which you probably don't), put this chain block (always active) following the impulse block's chain (the one summoning the boat stack):
execute @a[tag=playerThrowingTheKnife] ~ ~ ~ summon armor_stand ~ ~ ~ {NoGravity:1b,Invisible:1,Tags:["knife","knifeVisual"],ArmorItems:[{},{},{},{id:dye,Damage:1,Count:1b}]}
In this case, I put a rose red dye on the armor stand's head slot, but you can replace it with whatever you want to represent the throwing knife.
You must also add this chain block (always active) after the repeat block:
execute @e[tag=knifeBase] ~ ~-100 ~ teleport @e[tag=knifeVisual,c=1] ~ ~ ~ ~ ~
This moves the visual representation of the knife 100 blocks below the boat stack each tick, so the player only sees the knife and not the ugly boats in the sky.
Lastly, to detect if the throwing knife hits something (you specified an armor stand), you would run a few chain command blocks off the repeat block, all always active. The first one:
scoreboard players tag @e[type=armor_stand,tag=!knife] add invulAS {Invulnerable:1}
Then:
scoreboard players tag @e[type=armor_stand,tag=!knife] add vulAS {Invulnerable:0}
Run a these chain block after that:
execute @e[tag=knifeVisual] ~ ~ ~ scoreboard players tag @e[tag=invulAS,dx=0,dy=0,dz=0] add knifeHitInvulAS
execute @e[tag=knifeVisual] ~ ~ ~ scoreboard players tag @e[tag=vulAS,dx=0,dy=0,dz=0] add knifeHitVulAS
execute @e[tag=knifeHitInvulAS] ~ ~100 ~ kill @e[tag=knife,c=3] _c=3 for 1 boat (default speed), c=6 for double speed, etc.
execute @e[tag=knifeHitInvulAS] ~ ~ ~ scoreboard players tag @e[tag=knifeVisual,c=1] add knifeDead
scoreboard players tag @e[tag=knifeHitInvulAS] remove knifeHitInvulAS
scoreboard players tag @e[tag=knifeDead] remove knifeVisual
kill @e[tag=knifeHitVulAS]
This is assuming you want the knife to continue and NOT be stopped by the armor stand it just killed.
The code above gives a tag to invulnerable and vulnerable armor stands (different tags), and tests on them if a knifeVisual is within a 1 block radius of them. If a knifeVisual is within a 1 block radius of an invulnerable armor stand, it kills its corresponding boat stack to stop itself from moving and removes any tags to prevent any interference with other knives that are still active. If a knifeVisual is within a 1 block radius of a vulnerable armor stand, it kills that armor stand and continues on its way.
Answered by TheAfroOfDoom on September 13, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP