Jump to content

Generate plant near a certain block only


microjunk

Recommended Posts

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Never mind, Turns out it was the quilted fabric loader api or whatever causing it. I got it to work by downgrading it to the previous version.
    • It worked, but neverend-1.0.jar is the main mod I'm trying to get to work.
    • Is it possible to recover an entire folder full of files that were accidentally deleted while I was deleting a single file?
    • Recovering lost funds from online scams has been a daunting journey, and my ordeal with Rapid Digital Recovery underscores the importance of vigilance and education. I recently managed to recover over $338,000 thanks to their expertise, and sharing my story is crucial for raising awareness about these deceitful practices. I fell victim to a sophisticated scam involving fake forex and binary options investment platforms. The scammers created a facade of legitimacy with professional websites, persuasive pitches, and false assurances of high returns. They promised substantial profits and used high-pressure tactics to get me to invest large amounts of money. It wasn’t until I noticed red flags and attempted to withdraw my funds that I realized I had been duped. Rapid Digital Recovery proved to be a lifeline in this situation. Their team worked diligently to investigate the fraud, trace my funds, and liaise with financial institutions to secure the recovery. Their expertise in handling such cases was invaluable, and their efforts ultimately helped me reclaim a significant portion of my lost assets. However, I learned that while these services can be effective, they are not a guaranteed solution. Success depends on various factors, including the nature of the scam and the cooperation of involved parties.  This experience has underscored the critical need for education about online scams. Scammers use a range of tactics to deceive individuals, from fake testimonials to promises of guaranteed returns. Understanding these tactics and recognizing red flags can prevent others from falling into the same trap. Researching investment opportunities thoroughly and verifying the legitimacy of platforms before committing any money are crucial steps. I’ve come to realize that the best way to protect oneself is through education and awareness. By being informed about how scams operate and approaching investments with caution, individuals can safeguard their finances and avoid similar pitfalls. My experience with Rapid Digital Recovery highlights both the importance of being proactive in preventing scams and the value of having a recovery strategy in place if things go wrong. Sharing my story is a way to help others avoid the same mistakes and contribute to a safer online environment.                    
    • It looks like you have a problem one or more of your `.toml` files.
  • Topics

×
×
  • Create New...

Important Information

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