Arqade is a question and answer site for passionate videogamers on all platforms. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to do some fancy-schmancy redstone shenanigans exploiting the fact that melon blocks growing into a square can hold a charge (and thus complete a circuit). Is the direction they spawn the melon truly random?

I did a small-scale test, and got 3/4 melons spawning in the same direction. I don't want to pronounce Melons to be non-random though, as it's still a very small sample size.

enter image description here

share|improve this question
I'm curious, are you trying to utilize the (possible) randomness or to eliminate it? – Fambida Oct 4 '11 at 4:44
@Fambida Utilize it. I want to make Schrödinger's Cow. Obviously, if I can't get two equally random possibilities, the cow can't be simultaneously dead and alive. – Raven Dreamer Oct 4 '11 at 4:54
+1 for Schrödinger's Cow. – harbichidian Oct 4 '11 at 5:06
@ Raven That's assuming that dead or alive is two separate states instead of a continuum. Assuming that there's a bias towards one direction you could still have a mostly dead somewhat alive cow or a mostly alive somewhat dead cow. Or you could wire the input through multiple potential melons so that the bias is canceled out. – Fambida Oct 4 '11 at 5:12
So you ban the minecraft-enderman tag, but create the melon-mechanics tag? Care to explain yourself before I cry mod abuse? :P – John the Green Oct 4 '11 at 16:46
up vote 8 down vote accepted

I think I found the code that chooses where the melon grows. (All comments added by me.)

int i1 = random.nextInt(4);
int j1 = i;  // Assuming j1 and k1 are the horizontal axes...
int k1 = k;
if(i1 == 0)  // North
if(i1 == 1) // South
if(i1 == 2) // East
if(i1 == 3) // West
    k1++; // or somthing like that, anyway.
if(world.getBlockId(j1, j, k1) == 0 && world.getBlockId(j1, j - 1, k1) == Block.tilledField.blockID)  // Make sure the targeted block is empty and below it is farmland...
    world.setBlockWithNotify(j1, j, k1, field_35297_a.blockID); // Place a melon.

It appears to depend on how random random.nextInt(4) is.

share|improve this answer
Excellent sleuthing! This looks like it is random then. Possibly also, you're more likely to grow a melon when you have 4 tilled blocks surrounding it? – Raven Dreamer Oct 4 '11 at 22:25
Damn. Now I really want to pour through the rest of the Minecraft code. – Raven Dreamer Oct 4 '11 at 22:38
@Raven Dreamer, what makes you so sure it really is random? 4, 4, 4, 4, 4 ... would be a perfectly valid sequence. – Cyclops Oct 4 '11 at 22:59
@Cyclops - that's a problem with any program using java's rand library, though. – Raven Dreamer Oct 4 '11 at 23:12
@RavenDreamer Glad I could help. :) The code appears to select a location, then check if it's tilled, only spawning if it is. So you are more likely to grow a melon if all 4 surrounding tiles are farmland. – John the Green Oct 4 '11 at 23:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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