Jump to content

Recommended Posts

Posted

Hey, i want to have my snow block to generate 100 % on stone over the y cords 110. Is it possible to do that? This is my class rn

 

package com.studiomaker.poweredelements2.world.gen;

import java.util.Random;

import com.studiomaker.poweredelements2.init.ModBlocks;

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;
import net.minecraftforge.fml.common.Mod.EventHandler;

public class WorldGenCustomOres implements IWorldGenerator
{
	private WorldGenerator snow_mountain;
	// private WorldGenerator energetic_ore_block;
	// private WorldGenerator red_crystal;
	
	public WorldGenCustomOres() 
	{	
		
		snow_mountain = new WorldGenMinable(ModBlocks.SNOW_MOUNTAIN.getDefaultState(), 3, BlockMatcher.forBlock(Blocks.STONE));
		// energetic_ore_block = new WorldGenMinable(ModBlocks.ENERGETIC_ORE_BLOCK.getDefaultState(), 3, BlockMatcher.forBlock(Blocks.STONE));
	}
	
	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
	{
		switch(world.provider.getDimension())
		{
		case 0:
			
			runGenerator(snow_mountain, world, random, chunkX, chunkZ, 255, 110, 100);
			// runGenerator(energetic_ore_block, world, random, chunkX, chunkZ, 50, 0, 100);
			
		}
	}
	
	private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight)
	{
		if(minHeight > maxHeight || minHeight < 0 || maxHeight > 256) throw new IllegalArgumentException("Ore generated out of bounds");
		
		int heightDiff = maxHeight - minHeight + 1;
		for(int i = 0; i < chance; i++)
		{
			int x = chunkX * 32 + rand.nextInt(32);
			int y = minHeight + rand.nextInt(heightDiff);
			int z = chunkZ * 32 + rand.nextInt(32);
			
			gen.generate(world, rand, new BlockPos(x,y,z));
		}
	}
}

 

Posted

The generators are given the chunkx & chunkz coordinates.
From there, you need to manually iterate over 0-16 for both x & z. From there, calculate (chunkx << 4) + x to get the actual blockX coordinate. Do the same for z.
There should be a method in the World object to get the top block (blockY coordinate) (World::getHeight or World::getTopSolidBlock; Not at my IDE so can't provide the exact name).
Now you got all three positions, which means you should be able to spawn the snow at blockX, blockY + 1, blockZ.

(the "<< 4" is a bit-shift operator. It's equivalent to doing "n * 16". Bit shifting should be done instead of multiplying/dividing by 16 because dividing negative chunk coordinates will result in wrong coordinates as integers get rounded down)

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted
1 hour ago, Matryoshika said:

(the "<< 4" is a bit-shift operator. It's equivalent to doing "n * 16". Bit shifting should be done instead of multiplying/dividing by 16 because dividing negative chunk coordinates will result in wrong coordinates as integers get rounded down)

More or less. In this case, yes.

 

However, blockX >> 4 and blockX / 16 are not the same.

For example:

-280 >> 4 = -18

-280 / 16 = -17

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.

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



×
×
  • Create New...

Important Information

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