Math.random Help!

8 posts / 0 new
Last post
mcgooey's picture
Offline
Last seen: 5 days 18 hours ago
Joined: 08/06/2013 - 11:33
Gems: 7
Math.random Help!

Hello,

I am  not sure if this is the correct  area to be posting this. I couldnt find a specific area to post. Here it goes.

I am trying to  create a block that updates. Once it hits its final stage within the update tick it is supposed to randomly place blocks withing the (I) and "K) access and the (-I) and (-K) access but i seem to get an error when trying to compile the mode when finished.

Here is what  I am using for the Math.random: only want things to spawn 3 blocks out from NEGATIVE and POSOTIVE access of "I" and "K"   Please help

j + (int)(Math.random()*1)+3
k + (int)(Math.random()*1)+3

j - (int)(Math.random()*1)+3
k - (int)(Math.random()*1)+3

 



mcgooey's picture
Offline
Last seen: 5 days 18 hours ago
Joined: 08/06/2013 - 11:33
Gems: 7
in the J - (int)(Math.random(

in the J - (int)(Math.random()*1)+3 the "J" is an "I"

mcgooey's picture
Offline
Last seen: 5 days 18 hours ago
Joined: 08/06/2013 - 11:33
Gems: 7
>:compileApiJava UP-TO-DATE

>:compileApiJava UP-TO-DATE
>:processApiResources UP-TO-DATE
>:apiClasses UP-TO-DATE
>:sourceMainJava
>C:\Pylo\MCreator155\forge\build\sources\java\mod\mcreator\mcreator_laurel8.java:163: error: no suitable method found for setBlock(int,int,int,Item,int,int)
>world.setBlock(i - (int)(Math.random()*1)+3 , j, k - (int)(Math.random()*1)+3, mcreator_laurelSeed.block, 0, 2);
> ^
> method World.setBlock(int,int,int,Block) is not applicable
> (actual and formal argument lists differ in length)
> method World.setBlock(int,int,int,Block,int,int) is not applicable
> (actual argument Item cannot be converted to Block by method invocation conversion)
>1 error
>:compileJava FAILED
The Error:
>FAILURE: Build failed with an exception.

>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>BUILD FAILED
>Total time: 20.681 secs
>C:\Pylo\MCreator155\forge>
>Task completed with return code 0 in 22451 milliseconds

AquilaNova's picture
Offline
Last seen: 2 years 1 month ago
Joined: 04/22/2015 - 14:39
Gems: 0
you have 2 extra "int" calls

you have 2 extra "int" calls in the

World.setBlock(int,int,int,Block,int,int)

remove the last 2 "int"s


World.setBlock(int,int,int,Block)

AquilaNova's picture
Offline
Last seen: 2 years 1 month ago
Joined: 04/22/2015 - 14:39
Gems: 0
Plus reading further the

Plus reading further the Block you are calling is actually an item


(actual argument Item cannot be converted to Block by method invocation conversion)

mcgooey's picture
Offline
Last seen: 5 days 18 hours ago
Joined: 08/06/2013 - 11:33
Gems: 7
RE:Plus reading further the

@AquilaNova that fix the error but the placement is still not random it put it in the same spot.
iam not sure how to remove the init,init,init,init, unless it is pulling those from each add block i configure with the math.random.

here is what ive done so far

I chose "When Block added"

Add block, I input the math random code in "i" and "k"

I add 2 events one for positive on axis and Negative on axis

Positive:
i + (int)(Math.random()*1)+3
k + (int)(Math.random()*1)+3

Negative:
i - (int)(Math.random()*1)+3
k - (int)(Math.random()*1)+3

but somes to place in the same spot

AquilaNova's picture
Offline
Last seen: 2 years 1 month ago
Joined: 04/22/2015 - 14:39
Gems: 0
After some testing it out i

After some testing it out i discovered it is the *1

Positive:
i + (int)(Math.random()*1)+3
k + (int)(Math.random()*1)+3

Negative:
i - (int)(Math.random()*1)+3
k - (int)(Math.random()*1)+3

when i change *1 to *5

Positive:
i + (int)(Math.random()*5)+3
k + (int)(Math.random()*5)+3

Negative:
i - (int)(Math.random()*5)+3
k - (int)(Math.random()*5)+3

I got fully random results.

mcgooey's picture
Offline
Last seen: 5 days 18 hours ago
Joined: 08/06/2013 - 11:33
Gems: 7
RE:After some testing it out i

@AquilaNova omg it works and ive created a monster :(
I also forgot to add to the (i + and k -) and (i - and k +)