Jump to content

Recommended Posts

Posted

I have a plant that I want generated in the swamps, I did that part, but I only want it to spawn near or within 2 blocks of water. I have a different plant that is using this code

 

 

 

public void randomDisplayTick(World world, int i, int j, int k, Random random)
        {
        	int dist=2;
            boolean isblocknear=false;
            for (int x0 = -dist; x0 <= dist; ++x0)
            {
            	for (int y0 = -dist; y0 <= dist; ++y0)
            	{
            		for (int z0 = -dist; z0 <= dist; ++z0)
            		{
            			if(world.getBlockId(i + x0, j + y0, k + z0)==MTJT.lovePlant.blockID && (x0!=0 || y0!=0 || z0!=0))
            			{
            				isblocknear=true;
            				world.spawnParticle("heart", i+0.5, j+1.0, k+0.5, 0.0D, 0.08D, 0.0D);
            				break;
            			}
            		}
            		if(isblocknear)
                    break;
            		}
            		if(isblocknear)
                    break;
            	} 
        			
        	}

 

 

 

This code will allow the plant if generated near another plant of the same type to spawn particles. It works great, but when applying this code to my other plant, it crashes the game...of course I changed the random display tick to on block added, and the Block love plant to the block waterstill. But this code is not working for the purpose I need.....Any help is appreciated

Posted

well first of all the three breaks is unnecessary

 

label0:
for(...
for(....
for(....)
if(....)
break label0;

 

also post the crash report please[/code]

I think its my java of the variables.

Posted

Well, I figured out it was crashing because of the else statement I had after this

 

if(world.getBlockId(i + x0, j + y0, k + z0)==MTJT.lovePlant.blockID && (x0!=0 || y0!=0 || z0!=0))
            			{
            				isblocknear=true;
            				world.spawnParticle("heart", i+0.5, j+1.0, k+0.5, 0.0D, 0.08D, 0.0D);
            				break;
            			}

 

saying basically if it is not water than dont generate. I had removed the crash reports after this had stopped crashing when I removed it. I also found a method in the block class that may be of use, canPlaceBlockAt, not sure how I would modify this code I have or use the method properly. I also removed the breaks and it still spawns everywhere but where I want it to...

Posted

You might want to look at the existing plant code.  IIRC there's already a "nearby water" detection loop for spawning reeds.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.