1

I have decided that I don't like standing in front of a mob spawner for quite a while in order to reach level 30. Seeing that I don't (yet) have an Enderman farm (or a Pigman farm), I wondered if I can't simply increase the XP I get from everything by about 50% using command block magic to summon more of them.

The page for Experience states that most XP orbs have values of 1, 3, or 7, and I'll limit my contraption to working with these three.

I have set up a scoreboard objective to distinguish freshly dropped XP orbs and their value using

scoreboard players set @e[type=XPOrb] XP 1 {Age:10s,Value:1s}

I would like to either summon a copy of these orbs at their position, or simply double their value, but only for about half of them, which brings me to my question:

How can I randomly select only half of them for use with execute -> summon or entitydata? Ideally, this should be random on an entity basis, rather than "globally" (i.e. using time%2), in order to make the increase smoother.

2

One way to do this could be having each new XP orb summon an XP orb with twice the XP value at its location, and then having the original XP orb randomly kill exactly one entity at its position. This would give 1/2 probability of leaving the original orb, and 1/2 of leaving the newer increased value orb.

On a clock, for XP orbs with a value of 1:

/execute @e[type=XPOrb,score_XP=1,score_XP_min=1,tag=!MRXPIncreasedOrb] ~ ~ ~ /summon XPOrb ~ ~ ~ {Tags:["MRXPIncreasedOrb"],Value:2s}
/execute @e[type=XPOrb,score_XP=1,score_XP_min=1,tag=!MRXPIncreasedOrb] ~ ~ ~ /kill @r[type=XPOrb,r=0]

Repeat for all orb values you want to work. For example, for 3:

/execute @e[type=XPOrb,score_XP=3,score_XP_min=3,tag=!MRXPIncreasedOrb] ~ ~ ~ /summon XPOrb ~ ~ ~ {Tags:["MRXPIncreasedOrb"],Value:6s}
/execute @e[type=XPOrb,score_XP=3,score_XP_min=3,tag=!MRXPIncreasedOrb] ~ ~ ~ /kill @r[type=XPOrb,r=0]

I'm not sure how it's set up at the moment, but if you're not already doing so you should remove the XP orb's XP score after they get processed, so they aren't processed again:

/scoreboard players reset @e[type=XPOrb,score_XP_min=0] XP

For 1/3 chance rather than 1/2, have another XP orb summoned but with the same value rather than twice the value, and add c=2 to the @r selector so 2 of the orbs are killed.

5
  • You probably want to put a count in your kill command, I think it'll kill both. – MBraedley Oct 9 '15 at 2:01
  • XP is set to 0 for Orbs if not Age:10, the summoned orbs are summoned with Age:11. Your tag solution is great though, didn't know they could be set via data tags as well! I'm not running the snapshots atm, but I'll keep it in mind when I upgrade to 1.9. – MrLemon Oct 9 '15 at 8:04
  • @MBraedley @r selects 1 entity by default – SirBenet Oct 9 '15 at 16:17
  • @MrLemon Yeah, on second thoughts summoning with age of 11 would be a better way to do it than the tags. – SirBenet Oct 9 '15 at 16:19
  • @colorfusion yes, of course it does. My bad. – MBraedley Oct 9 '15 at 16:23
0

Well, it would be difficult to select a specific proportion of entities. One thing you could do, though, would be to tag each xp orb of a certain size using the data tag {Value:Xb}, then use a /entitydata command to increase the each orb's value by one (or however much you want, just make sure the resulting orb wont be tagged by another command block).

Alternatively, if selecting half is necessary, you can testfor all unmarked xp orbs, then run the comparator output from it to a certain number of command blocks based on the strength of signal, so that there's one command block per 2 xp orbs, each with the @r[type=XPOrb] command to activate once and duplicate the appropriate number of orbs, then another to mark all the rest so that they wont be doubled on subsequent runs, or counted so that the redstone signal doesn't exceed 16.

2
  • This is indeed my fallback solution to the problem at hand. But I think randomly selecting a portion of all entities can be useful in a number of cases. – MrLemon Oct 8 '15 at 17:57
  • Well, a really roundabout way (but the only one I can think of) would be to testfor all unmarked xp orbs, then run the comparator output from it to a certain number of command blocks based on the strength of signal, so that there's one command block per 2 xp orbs, each with the @r[type=XPOrb] command to activate once and duplicate the appropriate number of orbs, then another to mark all the rest so that they wont be doubled on subsequent runs, or counted so that the redstone signal doesn't exceed 16. – Silentvenom7 Oct 8 '15 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.