I had this almost exact same problem in my 1.13.2 world, and what worked for me was giving them all different name tags. I don't know why but when I named one sheep "Sheep1" and another "Sheep2" they didn't despawn. I don't know if this will help you as I am in a different version, but if worst comes to worst you can attach them to a fence using a lead. That also fixed my problem.
You'll need to "translate" the glass bottle data tag into something that works with target selectors (@a and so on). This can be achieved most easily using dummy scoreboard values or, in 1.9, scoreboard tags.
In 1.8, create an objective using
scoreboard objectives add bottleInOne dummy
Create a fill clock and run the following two commands
scoreboard players set @a[score_bottleInOne_min=1] bottleInOne 0
scoreboard players set @a[score_bottleInOne=0] bottleInOne 1 {SelectedItemSlot:0,SelectedItem:{id:minecraft:glass_bottle}}
If the team part is necessary, you can now add @a[score_bottleInOne_min=1]
to the team, and remove @a[score_bottleInOne=0]
from it, using the same fill clock. You could also use these target selectors directly for the /effect
and /replaceitem
commands, if the team part was just your idea of selecting that player for the effect.
In 1.9, you can omit the scoreboard objective in favor of tags. Using a Repeat/Chain command block chain, run
scoreboard players tag @a[tag=bottleInOne] remove bottleInOne
scoreboard players tag @a[tag=!bottleInOne] add bottleInOne {SelectedItemSlot:0,SelectedItem:{id:minecraft:glass_bottle}}
In the following commands, you can then use @a[tag=bottleInOne]
or @a[tag=!bottleInOne]
to target players with and without the bottle selected in slot 0, respectively.
Best Answer
I am not sure how you could build around the player, but I have figured out how to have a cage built around a player. I'm assuming you know some basic command block phrases (impulse, chain, repeat). First, you will need a setup like this:
(S = where silverfish will stop)
The outer bedrock blocks are where the silverfish will spawn, and the inner blocks are where they will end up.
Once you are done, put signs on the outer blocks (temporarily) noting what corners are designated as what. The block named "Top" should be the furthest north (negative Z). Then place a 9-block-long repeat chain of command blocks, filling them in with the commands listed at http://pastebin.com/LbC0xSJw .
In the last command, fill in the coordinates of the center block (where the player would be standing). Last, place an 8-block-long impulse chain to summon the silverfish, using
CustomName:"<position>"
for each, replacing position with the position it will be in according to the sign. The silverfish will move to the center, stopping on the bedrock ring. (sped up)There you go! The silverfish will now move to the center when you spawn them on the blocks and you turn on the repeating command chain. You can adjust the speed by changing the .1 in the repeat chain.