Jump to content

Recommended Posts

Posted

I'm trying to add my own flowers and generating them, but the base class extends WorldGenerator but I'm implementing IWorldGenerator. The generate method in IWorldGenerator doesn't have 3 integer parameters. I'm assuming that from 21 to 23, its goes from x, y, and then z.

 

http://pastebin.com/5SEmAUSb

 

My problem is on line 22.

Kain

Posted

It only has x/z because it gets an entire chunk, which is 16x16 blocks area 256 blocks tall, so all of the y coordinates are included.

 

Try setting y to a high value such as 128 and then use a while loop to find the ground level, then add your block at that position:

// Check for solid surface only above around ocean level
while (!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 62)
{
--y;
}
// If you didn't find a solid surface, return; check if your flower can stay at this point
if (!world.doesBlockHaveSolidTopSurface(x, y, z))
{
return;
}
// generate your flower 

I'd recommend checking out Wuppy's tutorial series, specifically 1.3.2 because he covers lots of world gen stuff there that is still relevant. This one in particular applies to your situtation, though it generates ore: http://wuppy29.blogspot.nl/2012/08/modding-ore-generation.html

Posted

The way you're doing it, you'll want to place the while loop within the for loop, and when you check if there was not a solid surface, instead of 'return' you'll want to use 'continue'.

 

Chunk coordinates x and z define the start position of the chunk, not any actual coordinates within it; when you get the coordinates, you don't need to add and then subtract random ints, just add nextInt(16) and you'll be fine. y doesn't need to be random at all, just set it back to 128 each iteration.

 

Are your flowers generating at all? If not, maybe you forgot to register your IWorldGenerator in the main mod class.

Posted

I registered it, and did all the changes. Still not generating. :|

 

package tlhpoe.worldgen;

import java.util.Random;

import tlhpoe.helper.BlockHelper;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

        for(int l = 0; l < 64; ++l)
        {
    		int x = chunkX;
    		int y = 128;
    		int z = chunkZ;
    		
    		while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 128)
    		{
    			
    			--y;
    			
    		}
    		
    		if(!world.doesBlockHaveSolidTopSurface(x, y, z))
    		{
    			
    			continue;
    			
    		}
        	
            int i1 = chunkX + random.nextInt(16);
            int j1 = y + random.nextInt(4) - random.nextInt(4);
            int k1 = chunkZ + random.nextInt(16);

            if (world.isAirBlock(i1, j1, k1) && (!world.provider.hasNoSky || j1 < 127) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, i1, j1, k1))
            {
                world.setBlock(i1, j1, k1, BlockHelper.heartFlower.blockID, 0, 2);
            }
        }

}

}

Kain

Posted

You are still assigning y to a random int after you've found the ground, meaning you are probably trying to generate your block underground or in the air. Also, you failed to assign coordinates before checking for ground, meaning the while loop is pretty much useless, as it isn't looking at the coordinates you want to place the block.

 

Also this: (!world.provider.hasNoSky || j1 < 127) should all be handled in your heart block's canBlockStay method.

 

One final note is that when you find the ground, that's what you've found. Try generating your block at y+1 to set the block ABOVE ground to your flower.

 

Try this code:

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

for(int l = 0; l < 64; ++l)
{
int x = chunkX + random.nextInt(16);
int y = 128;
int z = chunkZ + random.nextInt(16);
    		
while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 128)
{
--y;
}
    		
if(!world.doesBlockHaveSolidTopSurface(x, y, z))
{
continue;
}

if (world.isAirBlock(x, y+1, z) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, x, y+1, z))
{
world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);
}
}		
}

If it still doesn't work, put some println in there and see if it is being called like you think.

Posted

Everything prints except for HI3 :I

 

 

 

 

package tlhpoe.worldgen;

import java.util.Random;

import tlhpoe.helper.BlockHelper;
import tlhpoe.util.InfoUtil;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	InfoUtil.print("HI1");

	for(int l = 0; l < 64; ++l)
	{

		InfoUtil.print("HI2");

		int x = chunkX + random.nextInt(16);

		int y = 128;

		int z = chunkZ + random.nextInt(16);

		while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 128)
		{--y;}

		if(!world.doesBlockHaveSolidTopSurface(x, y, z))
		{continue;}

		if (world.isAirBlock(x, y+1, z) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, x, y+1, z))
		{
			world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);
			InfoUtil.print("HI3");

		}

	}
}

}

 

 

Kain

Posted

Then the problem is either the block at (x, y+1, z) is not an air block or your custom Block's canBlockStay method is incorrect.

 

Print out the block id at those coordinates (before the if statement) to see what it is. I'm guessing it's grass or some such. If that's the case, you can try something like this:

if (world.isAirBlock(x, y+1, z) || (Block.blocksList[world.getBlockId(x, y+1, z)] != null
&& !Block.blocksList[world.getBlockId(x, y+1, z)].blockMaterial.blocksMovement()))

It checks if the block allows movement and if so, still let's you place your block.

 

What's your block's canBlockStay method look like?

Posted

I edited my code a little, and it only printed 0 (which I'm guessing is the air block ID).

 

Here's my canBlockStay method:

 

 

@Override
    public boolean canBlockStay(World par1World, int par2, int par3, int par4)
    {
    	
        Block soil = blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
        return (par1World.getFullBlockLightValue(par2, par3, par4) >= 8 || par1World.canBlockSeeTheSky(par2, par3, par4)) && (soil != null && soil.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
        
    }

 

 

 

WorldGenEverything:

 

 

package tlhpoe.worldgen;

import java.util.Random;

import tlhpoe.helper.BlockHelper;
import tlhpoe.util.InfoUtil;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	for(int l = 0; l < 64; ++l)
	{

		int x = chunkX + random.nextInt(16);

		int y = 128;

		int z = chunkZ + random.nextInt(16);

		while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 256)
		{--y;}

		if(world.doesBlockHaveSolidTopSurface(x, y, z))
		{continue;}

		if (world.isAirBlock(x, y+1, z) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, x, y+1, z))
		{
			world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);
			InfoUtil.print("HI3");

		}

	}
}

}

 

 

Kain

Posted

It printed '0' for getBlockId(x, y+1, z) ? Try at (x, y, z) and see what that block is. If it is also air, then that would be your problem.

 

Just experiment a little on your own with the values, printing out block id s at each one, trying with your canBlockStay check and without it, etc. You'll find the problem much more easily that way than waiting for someone else to try to figure it out from snippets of code.

Posted

Yes, you did:

while(!(world.getBlockId(x, y, z) == Block.grass.blockID))
{--y;}

There's nothing in there to stop the while loop other than hitting a grass block, but if you never encounter a grass block, it will keep going forever. Add '&& y > 2' or something like that if you want to stop that low (like in a superflat world) or '&& y > 62' or something for around ocean level.

Posted

Aghh, won't generate anything or print anything.

 

package tlhpoe.rpgadditions.worldgen;

import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import tlhpoe.rpgadditions.helper.BlockHelper;
import tlhpoe.rpgadditions.util.InfoUtil;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	for(int l = 0; l < 64; ++l)
	{

		int x = chunkX + random.nextInt(16);

		int y = 128;

		int z = chunkZ + random.nextInt(16);

		while(!(world.getBlockId(x, y, z) == Block.grass.blockID || world.getBlockId(x, y, z) == Block.sand.blockID) && y > 64)
		{--y;}

		if(world.getBlockId(x, y, z) == Block.grass.blockID || world.getBlockId(x, y, z) == Block.sand.blockID)
		{continue;}

		world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);

	}

}

}

Kain

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

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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