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 have 3 different ores I am trying to have only spawn in a certain stone variant each. I have set up predicates for each stone variant, the ores are spawning but in all variants of stone

 

this is my OreGen class:

package hazmatik.sonictech.worldgen;

import java.util.Random;

import hazmatik.sonictech.blocks.BlockAntimonyOre;
import hazmatik.sonictech.init.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.block.state.pattern.BlockStateMatcher;
import net.minecraft.init.Blocks;
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.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

public class OreGen implements IWorldGenerator {
	
	private WorldGenerator antimony_ore;
	private WorldGenerator chromite_ore;
	private WorldGenerator copper_ore;
	private WorldGenerator molybdenum_ore;
	private WorldGenerator tin_ore;
	private WorldGenerator zinc_ore;
	
	public OreGen() {
		antimony_ore = new WorldGenMinable(ModBlocks.oreAntimony.getDefaultState(), 8, new DioritePredicate());
		chromite_ore = new WorldGenMinable(ModBlocks.oreChromite.getDefaultState(), 4, new NetherPredicate());
		copper_ore = new WorldGenMinable(ModBlocks.oreCopper.getDefaultState(), 6);
		molybdenum_ore = new WorldGenMinable(ModBlocks.oreMolybdenum.getDefaultState(), 8, new GranitePredicate());
		tin_ore = new WorldGenMinable(ModBlocks.oreTin.getDefaultState(), 6);
		zinc_ore= new WorldGenMinable(ModBlocks.oreZinc.getDefaultState(), 8, new AndesitePredicate());
	}
	
	private void runGenerator(WorldGenerator generator, World world, Random rand, int chunk_X, int chunk_Z, int chancesToSpawn, int minHeight, int maxHeight) {
		if (minHeight < 0 || maxHeight > 256 || minHeight > maxHeight)
			throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");

		int heightDiff = maxHeight - minHeight + 1;
		for (int i = 0; i < chancesToSpawn; i ++) {
			int x = chunk_X * 16 + rand.nextInt(16);
		    int y = minHeight + rand.nextInt(heightDiff);
		    int z = chunk_Z * 16 + rand.nextInt(16);
		    generator.generate(world, rand, new BlockPos(x, y, z));
		}
	}

	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
			IChunkProvider chunkProvider) {	
		switch(world.provider.getDimension()) {
		case 0://Overworld
			this.runGenerator(zinc_ore, world, random, chunkX, chunkZ, 20, 0, 75);
			this.runGenerator(antimony_ore, world, random, chunkX, chunkZ, 20, 0, 75);
			this.runGenerator(molybdenum_ore, world, random, chunkX, chunkZ, 20, 0, 75);
			this.runGenerator(copper_ore, world, random, chunkX, chunkZ, 20, 0, 64);
			this.runGenerator(tin_ore, world, random, chunkX, chunkZ, 20, 0, 64);
			break;
		case 1://End
			break;
		case -1://Nether
			this.runGenerator(chromite_ore, world, random, chunkX, chunkZ, 20, 0, 126);
			break;
		}	
	}
}

 

And this is the Predicate classes (same code just different names and meta for each variant of stone):

package hazmatik.sonictech.worldgen;

import com.google.common.base.Predicate;

import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;

public class GranitePredicate implements Predicate<IBlockState> {

	@Override
	public boolean apply(IBlockState input) {
		return input != null && input.getBlock() == Blocks.STONE.getStateFromMeta(1);
		
	}

}

Any help would be appreciated.

Edited by Hazmatik

Well....a Block will never equal an IBlockState...

Also, you shouldn't use getStateFromMeta, use getDefaultState().withProperty(...)

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

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.