Take the 2-minute tour ×
Arqade is a question and answer site for passionate videogamers on all platforms. It's 100% free, no registration required.

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
1  
I'm curious, are you trying to utilize the (possible) randomness or to eliminate it? –  Fambida Oct 4 '11 at 4:44
8  
@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
3  
+1 for Schrödinger's Cow. –  harbichidian Oct 4 '11 at 5:06
2  
@ 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
1  
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
show 7 more comments

1 Answer

up vote 7 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
{
    j1--;
}
if(i1 == 1) // South
{
    j1++;
}
if(i1 == 2) // East
{
    k1--;
}
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
2  
@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
show 4 more comments

Your Answer

 
discard

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.