Jump to content

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


SanaRinomi

Recommended Posts

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.

Link to comment
Share on other sites

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.

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.



×
×
  • Create New...

Important Information

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