Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I just started recently and have been learning a lot.

I have been trying to generate a block on grass for quite some time now. 

I managed to get it correctly generated however the block only generates if the vein is 4 or greater (the actually blocks in the world that are generated generate anything from 1 to 4). If i set it to 3 or lower nothing will be generated.

Any fix for this or any other methods i can use to generate a block in a chunk size of 1 or 2.

Here is code for the world gen

Spoiler

package world;

import java.util.Random;

import com.KOBKingobrine.FirstMod.init.ModBlocks;

import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

public class WorldGeneratorBlocks implements IWorldGenerator {

    private WorldGenerator snakePit, j4block;

    public WorldGeneratorBlocks()
    {
        snakePit = new WorldGenMinable(ModBlocks.SNAKE_PIT.getDefaultState(),1,BlockMatcher.forBlock(Blocks.GRASS));  //This block will only generate if the number parameter in the middle is higher than 4
        
    }
    
    public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunk)
    {
        switch(world.provider.getDimension())
        {
        case 0:
            runGenerator(snakePit,world,random,chunkX,chunkZ,100,50,100);
            
        }
    }
    private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight)
    {
        
        int deltaY = maxHeight - minHeight + 1;
        for(int i = 0; i<chance;i++)
        {
            int x = chunkX * 16 + rand.nextInt(16);
            int y = minHeight + rand.nextInt(deltaY);
            int z = chunkZ * 16 + rand.nextInt(16);
            
            gen.generate(world,rand,new BlockPos(x,y,z));
        }
    }
    
    

}
 

I dont get any crashes even if the value is lower than 4

 

Thank you for any help

Edited by ijuststartedmoddingplshelp
Corrections

12 hours ago, ijuststartedmoddingplshelp said:

If i set it to 3 or lower nothing will be generated.

How did you confirm this as true?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.