2
Okay I have been stuck on a series of commands for a multiplayer datapack game I am working on and could really use some professional help. I apologize for the long post but I am just trying to be thorough.
Basically I need a command(s) that does the following:
If a fishing_bobber with a tag of red_bobber is touching a sheep, increment red_team score by one, then kill the sheep. Only one sheep should be killed if hit with the bobber.
I have tried (unsuccessfully) multiple approaches to the problem, but ran into various issues at each step.
Problems I face
1. Accidentally killing more than 1 sheep if multiple sheep are close by.
2. Sheep are sometimes not killed by the bobber and instead the bobber stays attached to the center of the sheep's back.
3. Score increments by 2 instead of 1 even though the sheep should have been killed before the next tick.
What I have tried
The following commands have been hidden because I honestly think they will just confuse you more than they help. You may just look at the description above and give me your solution.
I have tried using a predicate. I could not get it to execute at all. Not sure if I am doing it wrong or it just doesn't work the way I thought it should.
Here is the code for my predicate attempt:
In my tick file I ran the following:
Note: the team name is "red" while the fake player used to display the scores is "Red_Team". I did it this way so multiple players can contribute to red team score.
My most successful solution albeit problematic is as follows:
I originally had the kill command after the scoreboard command but for some reason the command always executed twice, increasing the score by 2, so this hack made it somewhat usable.
Other attempts which I apparently deleted after colossal failures included tagging the sheep as "caught", tagging the bobber as "used" in an attempt to mitigate the score being incremented twice, and to mitigate multiple sheep from being removed.
I have also tried reducing the distance but that just makes it more likely the bobber will get stuck.
The limit option does not seem to work here, I am sure there is a logical reason for it but I just don't understand why.
Basically I need a command(s) that does the following:
If a fishing_bobber with a tag of red_bobber is touching a sheep, increment red_team score by one, then kill the sheep. Only one sheep should be killed if hit with the bobber.
I have tried (unsuccessfully) multiple approaches to the problem, but ran into various issues at each step.
Problems I face
1. Accidentally killing more than 1 sheep if multiple sheep are close by.
2. Sheep are sometimes not killed by the bobber and instead the bobber stays attached to the center of the sheep's back.
3. Score increments by 2 instead of 1 even though the sheep should have been killed before the next tick.
What I have tried
The following commands have been hidden because I honestly think they will just confuse you more than they help. You may just look at the description above and give me your solution.
My failures
I have tried using a predicate. I could not get it to execute at all. Not sure if I am doing it wrong or it just doesn't work the way I thought it should.
Here is the code for my predicate attempt:
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:fishing_bobber",
"team": "red",
"targeted_entity": {
"type": "minecraft:sheep"
}
}
}
In my tick file I ran the following:
execute if predicate game:attachedtosheep run say attached
Note: the team name is "red" while the fake player used to display the scores is "Red_Team". I did it this way so multiple players can contribute to red team score.
My most successful solution albeit problematic is as follows:
execute if entity @a[team=red] run execute as @e[type=fishing_bobber] run tag @s add red_bobber
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1.04,limit=1] run teleport @s ~ -500 ~
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1.04,limit=1] run scoreboard players add Red_Team catch 1
I originally had the kill command after the scoreboard command but for some reason the command always executed twice, increasing the score by 2, so this hack made it somewhat usable.
Other attempts which I apparently deleted after colossal failures included tagging the sheep as "caught", tagging the bobber as "used" in an attempt to mitigate the score being incremented twice, and to mitigate multiple sheep from being removed.
I have also tried reducing the distance but that just makes it more likely the bobber will get stuck.
The limit option does not seem to work here, I am sure there is a logical reason for it but I just don't understand why.
Create an account or sign in to comment.
16
So I manged to get this working a few days ago. I tried many different approaches, and none of them worked. Just in case anyone else stumbles on this thread looking for a solution. Here is what I did:
I used a scoreboard set to detect the used_rod stat then execute on that to call a sub function for the player to tag the bobber.
Execute at the player and look for a bobber that is within 3 blocks and not already tagged by another player.
Reset the use_rod stat to 0
Since I use various game states to manage various aspects of the game, I have a function that runs on the tick and detects when the bobber is near the sheep then runs a sub function for handling the score keeping part.
I had to do it this way, because I needed to execute as the bobber first then pass it to the caught_sheep function so the bobber could be referenced with the @s selector.
There is probably a better more elegant way to do it but this is how I got it working
I used a scoreboard set to detect the used_rod stat then execute on that to call a sub function for the player to tag the bobber.
execute as @a[scores={use_rod=1..}] at @s if block ~ ~-1 ~ red_wool run function game:misc/red_cast
Execute at the player and look for a bobber that is within 3 blocks and not already tagged by another player.
execute as @s at @s as @e[type=fishing_bobber,distance=..3,limit=1] run tag @e[type=fishing_bobber,tag=!red_bobber,tag=!gold_bobber,tag=!green_bobber,tag=!purple_bobber,limit=1] add red_bobber
Reset the use_rod stat to 0
Since I use various game states to manage various aspects of the game, I have a function that runs on the tick and detects when the bobber is near the sheep then runs a sub function for handling the score keeping part.
execute as @e[type=fishing_bobber,tag=red_bobber] at @s if entity @e[type=sheep,distance=..1.09] run function game:misc/caught_sheep_red
I had to do it this way, because I needed to execute as the bobber first then pass it to the caught_sheep function so the bobber could be referenced with the @s selector.
There is probably a better more elegant way to do it but this is how I got it working
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1.04,limit=1] run tag @s add CUSTOMTAG
execute as @e[tag=CUSTOMTAG,limit=1] at @s run (DO ALL YOUR COMMANDS, IT MAY NEED MULTIPLE STARTING LINES)
execute as @e[tag=CUSTOMTAG,limit=1] at @s run kill @s
execute as @e[tag=CUSTOMTAG,limit=1] at @s run (DO ALL YOUR COMMANDS, IT MAY NEED MULTIPLE STARTING LINES)
execute as @e[tag=CUSTOMTAG,limit=1] at @s run kill @s
They literally did this, and commented it down below and it did not work
I think I may have narrowed it down to the root issue. Essentially determining what player cast the rod is a little harder to figure out. The fishing_bobber entity is not tagged with the player that cast it. I wish Mojang would add that useful information.
Anyway, Some very old threads that I found suggested using a scoreboard to track who cast a rod, but honestly I did that with my original fishing game and when many players were all spamming their rods, I notice that the scores were not calculated correctly.
Do you think it's possible to write a command that detects the closest player to the bobber as soon as it's cast, then tag the bobber based on that players team? In other words, if I am on the "red" team, and I cast my rod, then the bobber nearest to me is tagged with "red_bobber" immediately? This could work for me as teams will be pretty far apart.
Any ideas how to write a command like that? I know it's not easy.
Anyway, Some very old threads that I found suggested using a scoreboard to track who cast a rod, but honestly I did that with my original fishing game and when many players were all spamming their rods, I notice that the scores were not calculated correctly.
Do you think it's possible to write a command that detects the closest player to the bobber as soon as it's cast, then tag the bobber based on that players team? In other words, if I am on the "red" team, and I cast my rod, then the bobber nearest to me is tagged with "red_bobber" immediately? This could work for me as teams will be pretty far apart.
Any ideas how to write a command like that? I know it's not easy.
Have you tried the LeftOwner nbt tag on the bobber to detect the nearest player? Then you can tag and apply a score id to the bobber to differentiate them from others
Thanks HoboMaggot. I am unable to find any reference to the "LeftOwner" NBT tag. Where can I find out more about it?
It's an nbt tag that exists for all projectiles which bobbers should be
https://minecraft.fandom.com/wiki/Egg#Entity_Data
In the link, expand the tab that says "tags common to all projectiles".
Ingame, you need to detect if the tag itself doesnt exist when you apply the tag and id score
https://minecraft.fandom.com/wiki/Egg#Entity_Data
In the link, expand the tab that says "tags common to all projectiles".
Ingame, you need to detect if the tag itself doesnt exist when you apply the tag and id score
I don't think the fishing_bobber counts as a projectile. At least it's not listed in the entity NBT when I do a /data get ...
that's a fat rip then
You can get better help via the r/MinecraftCommands discord server, which basically has all the expert programmers there
You can get better help via the r/MinecraftCommands discord server, which basically has all the expert programmers there
I see, makes sense. Basically the idea is to make it so that the bobber cannot be tagged if it's already been tagged by another player. I will work on adding this tonight after work. Thanks for the input fellas.
Perhaps you could use limit=1 to catch the first sheep, and then add a tag to the bobber to prevent it from killing any other sheep? Not sure if that'll work, bobbers are weird.
Thanks pleasenotme,
This is similar to one of my previous failed attempts. I don't have all of the code anymore, but it was something like this:
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1.04,limit=1] run tag @s add killed
execute at @e[type=sheep,tag=killed,distance=..1.04,limit=1] as @e[type=fishing_bobber,tag=red_bobber] run tag @s add kill_bobber
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1,limit=1.04] run kill @e[tag=red_bobber]
Probably some "as" and "at" commands that are out of order now.
If you have some idea how to rewrite the commands I would like to see what you come up with.
This is similar to one of my previous failed attempts. I don't have all of the code anymore, but it was something like this:
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1.04,limit=1] run tag @s add killed
execute at @e[type=sheep,tag=killed,distance=..1.04,limit=1] as @e[type=fishing_bobber,tag=red_bobber] run tag @s add kill_bobber
execute at @e[type=fishing_bobber,tag=red_bobber] as @e[type=sheep,distance=..1,limit=1.04] run kill @e[tag=red_bobber]
Probably some "as" and "at" commands that are out of order now.
If you have some idea how to rewrite the commands I would like to see what you come up with.
I'm not sure if this'll work but...
execute as @e[type=fishing_bobber,tag=red_bobber]at @s if entity @e[type=sheep,distance=..1.04,limit=1] run tag @s add kill_bobber
execute as @e[type=fishing_bobber,tag=red_bobber]at @s run kill @e[type=sheep,distance=..1.04,limit=1]
kill @e[tag=kill_bobber]
execute as @e[type=fishing_bobber,tag=red_bobber]at @s if entity @e[type=sheep,distance=..1.04,limit=1] run tag @s add kill_bobber
execute as @e[type=fishing_bobber,tag=red_bobber]at @s run kill @e[type=sheep,distance=..1.04,limit=1]
kill @e[tag=kill_bobber]
Thank you, this is getting much closer! :D
Okay so I have this challenge remaining. I need to tag the bobber with the team color that cast it. Below are two of my commands for tagging the bobber.
Unfortunatly, the bobber is getting tagged with both teams e.g. red_bobber and orange_bobber. I thought the sort and limit option would have prevented that but apparently not.
execute if entity @a[team=red] run execute as @e[type=fishing_bobber,limit=1,sort=nearest] run tag @s add red_bobber
execute if entity @a[team=orange] run execute as @e[type=fishing_bobber,limit=1,sort=nearest] run tag @s add orange_bobber
Okay so I have this challenge remaining. I need to tag the bobber with the team color that cast it. Below are two of my commands for tagging the bobber.
Unfortunatly, the bobber is getting tagged with both teams e.g. red_bobber and orange_bobber. I thought the sort and limit option would have prevented that but apparently not.
execute if entity @a[team=red] run execute as @e[type=fishing_bobber,limit=1,sort=nearest] run tag @s add red_bobber
execute if entity @a[team=orange] run execute as @e[type=fishing_bobber,limit=1,sort=nearest] run tag @s add orange_bobber
Try this:
scoreboard objectives add timer
(Put this into the load function)
Everything from now on can be put anywhere elese as long as repeated every tick :)
scoreboard players add @e[type=fishing_bobber] timer 0
scoreboard players add @e[tag=fishing_bobber,scores={timer=..1} timer 1
execute as @a[team=red] at @s run tag @e[type=fishing_bobber,tag=!red_bobber,distance=..2,limit=1,sort=nearest,scores={timer=1}] add red_bobber
execute as @a[team=red] at @s run tag @e[type=fishing_bobber,tag=!orange_bobber,distance=..2,limit=1,sort=nearest,scores={timer=1}] add orange_bobber
This should work i think :)
scoreboard objectives add timer
(Put this into the load function)
Everything from now on can be put anywhere elese as long as repeated every tick :)
scoreboard players add @e[type=fishing_bobber] timer 0
scoreboard players add @e[tag=fishing_bobber,scores={timer=..1} timer 1
execute as @a[team=red] at @s run tag @e[type=fishing_bobber,tag=!red_bobber,distance=..2,limit=1,sort=nearest,scores={timer=1}] add red_bobber
execute as @a[team=red] at @s run tag @e[type=fishing_bobber,tag=!orange_bobber,distance=..2,limit=1,sort=nearest,scores={timer=1}] add orange_bobber
This should work i think :)
Try making it also give the bobber a tag "team_selected" when joining either team, and making any bobbers with 'team_selected' unable to join a team.