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.

[1.10.2] How to get World and make it compatible both server and client side?

Featured Replies

Posted

How can I get World so that I can generate glowstone in the Nether or Ores overworld, while keeping the compatibility both server and client side? Thanks in advanced!

  • Author

First you could register a world generator or you could use the generation events

 

I'm using for normal ores WorldGenerator, but I also have a Glowstone class because I've added purple glowstone.

 

Here's my ModWorld class:

 

package com.holydevils.world;

import java.util.Random;

import com.holydevils.world.special.PurpleGlowstoneNetherGenOne;
import com.holydevils.world.special.PurpleGlowstoneNetherGenTwo;

import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModWorld implements IWorldGenerator{

public static void worldRegistry(){

}

public static void initializeWorldGen(){
	generateSpecial();
}

public static void generateSpecial(World world){
	switch(world.provider.getDimension()){
	case -1: //Nether
		new PurpleGlowstoneNetherGenOne();
		new PurpleGlowstoneNetherGenTwo();
		break;
	case 0: //Overworld

		break;
	case 1: //End

		break;
	}
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
		IChunkProvider chunkProvider) {
	switch(world.provider.getDimension()){
	case -1: //Nether
		new PurpleGlowstoneNetherGenOne();
		new PurpleGlowstoneNetherGenTwo();
		break;
	case 0: //Overworld

		break;
	case 1: //End

		break;
	}
}

private void registerWorldGen(WorldGenerator worldGen, World world, Random random, int chunkX, int chunkZ, int chanceToSpawn, int minY, int maxY){
	if(minY < 0 || maxY >world.getHeight() || minY > maxY)
		throw new IllegalArgumentException("Minimum or Maximum Height out of bounds");
	int layerDiff = maxY - minY + 1;
	for(int i = 0; i < chanceToSpawn; i++){
		int x = chunkX * 16  + random.nextInt(16);
		int y = minY + random.nextInt(layerDiff);
		int z = chunkZ * 16  + random.nextInt(16);
		worldGen.generate(world, random, new BlockPos(x, y, z));
	}
}
}

 

generateSpecial will give off errors but that's because I hadn't put in World and that why I consulted you to make it both server and client side.

 

And these are both Glowstone Generation classes:

 

 

PurpleGlowstoneNetherGenOne class:

package com.holydevils.world.special;

import java.util.Random;

import com.holydevils.blocks.ModBlocks;

import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class PurpleGlowstoneNetherGenOne extends WorldGenerator
{
    public boolean generate(World worldIn, Random rand, BlockPos position)
    {
        if (!worldIn.isAirBlock(position))
        {
            return false;
        }
        else if (worldIn.getBlockState(position.up()).getBlock() != Blocks.NETHERRACK)
        {
            return false;
        }
        else
        {
            worldIn.setBlockState(position, ModBlocks.purpleGlowstone.getDefaultState(), 2);

            for (int i = 0; i < 1500; ++i)
            {
                BlockPos blockpos = position.add(rand.nextInt( - rand.nextInt(, -rand.nextInt(12), rand.nextInt( - rand.nextInt();

                if (worldIn.isAirBlock(blockpos))
                {
                    int j = 0;

                    for (EnumFacing enumfacing : EnumFacing.values())
                    {
                        if (worldIn.getBlockState(blockpos.offset(enumfacing)).getBlock() == ModBlocks.purpleGlowstone)
                        {
                            ++j;
                        }

                        if (j > 1)
                        {
                            break;
                        }
                    }

                    if (j == 1)
                    {
                        worldIn.setBlockState(blockpos, ModBlocks.purpleGlowstone.getDefaultState(), 2);
                    }
                }
            }

            return true;
        }
    }
}

 

PurpleGlowstoneNetherGenTwo class:

package com.holydevils.world.special;

import java.util.Random;

import com.holydevils.blocks.ModBlocks;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class PurpleGlowstoneNetherGenTwo extends WorldGenerator
{
    public boolean generate(World worldIn, Random rand, BlockPos position)
    {
        if (!worldIn.isAirBlock(position))
        {
            return false;
        }
        else if (worldIn.getBlockState(position.up()).getBlock() != Blocks.NETHERRACK)
        {
            return false;
        }
        else
        {
            worldIn.setBlockState(position, ModBlocks.purpleGlowstone.getDefaultState(), 2);

            for (int i = 0; i < 1500; ++i)
            {
                BlockPos blockpos = position.add(rand.nextInt( - rand.nextInt(, -rand.nextInt(12), rand.nextInt( - rand.nextInt();

                if (worldIn.isAirBlock(blockpos))
                {
                    int j = 0;

                    for (EnumFacing enumfacing : EnumFacing.values())
                    {
                        if (worldIn.getBlockState(blockpos.offset(enumfacing)).getBlock() == ModBlocks.purpleGlowstone)
                        {
                            ++j;
                        }

                        if (j > 1)
                        {
                            break;
                        }
                    }

                    if (j == 1)
                    {
                        worldIn.setBlockState(blockpos, ModBlocks.purpleGlowstone.getDefaultState(), 2);
                    }
                }
            }

            return true;
        }
    }
}

 

 

If you wonder why I have two, it's because Minecrafts normal Glowstone has two, so to be on the safe side, I implemented both.

I dont think you are going about this correctly. You create a class that implements IWorldGenerator that class handles what you are generating. You only need to put GameRegistry.registerWorldGenerator () in your init method.

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.