Jump to content

[Solved] Ores not generating with CustomOreGenerator


Insane96MCP

Recommended Posts

I have a class thats exactly like WorldGenMinable but with one more check to prevent ores spawning not near air.

Spoiler

package net.insane96mcp.galaxite.worldgen;

import java.util.Random;

import com.google.common.base.Predicate;

import net.insane96mcp.galaxite.lib.Properties;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class CustomOreGenenerator extends WorldGenerator
{
    private final IBlockState oreBlock;
    /** The number of blocks to generate. */
    private final int numberOfBlocks;
    private final Predicate<IBlockState> predicate;

    public CustomOreGenenerator(IBlockState state, int blockCount)
    {
        this(state, blockCount, new CustomOreGenenerator.StonePredicate());
    }

    public CustomOreGenenerator(IBlockState state, int blockCount, Predicate<IBlockState> p_i45631_3_)
    {
        this.oreBlock = state;
        this.numberOfBlocks = blockCount;
        this.predicate = p_i45631_3_;
    }

    public boolean generate(World worldIn, Random rand, BlockPos position)
    {
        Block blockposYUp = worldIn.getBlockState(position.add(0, 1, 0)).getBlock();
        Block blockposYDown = worldIn.getBlockState(position.add(0, -1, 0)).getBlock();
        Block blockposXUp = worldIn.getBlockState(position.add(1, 0, 0)).getBlock();
        Block blockposXDown = worldIn.getBlockState(position.add(-1, 0, 0)).getBlock();
        Block blockposZUp = worldIn.getBlockState(position.add(0, 0, 1)).getBlock();
        Block blockposZDown = worldIn.getBlockState(position.add(0, 0, -1)).getBlock();
        if (
        	((blockposXUp instanceof BlockAir || 
        	blockposXDown instanceof BlockAir || 
        	blockposYUp instanceof BlockAir || 
        	blockposYDown instanceof BlockAir || 
        	blockposZUp instanceof BlockAir || 
        	blockposZDown instanceof BlockAir) &&
        	Properties.OreGeneration.onlyNearAir) ||
        	!Properties.OreGeneration.onlyNearAir
        ) {
	        float f = rand.nextFloat() * (float)Math.PI;
	        double d0 = (double)((float)(position.getX() + 8) + MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
	        double d1 = (double)((float)(position.getX() + 8) - MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
	        double d2 = (double)((float)(position.getZ() + 8) + MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
	        double d3 = (double)((float)(position.getZ() + 8) - MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
	        double d4 = (double)(position.getY() + rand.nextInt(3) - 2);
	        double d5 = (double)(position.getY() + rand.nextInt(3) - 2);
	
	        for (int i = 0; i < this.numberOfBlocks; ++i)
	        {
	            float f1 = (float)i / (float)this.numberOfBlocks;
	            double d6 = d0 + (d1 - d0) * (double)f1;
	            double d7 = d4 + (d5 - d4) * (double)f1;
	            double d8 = d2 + (d3 - d2) * (double)f1;
	            double d9 = rand.nextDouble() * (double)this.numberOfBlocks / 16.0D;
	            double d10 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
	            double d11 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
	            int j = MathHelper.floor(d6 - d10 / 2.0D);
	            int k = MathHelper.floor(d7 - d11 / 2.0D);
	            int l = MathHelper.floor(d8 - d10 / 2.0D);
	            int i1 = MathHelper.floor(d6 + d10 / 2.0D);
	            int j1 = MathHelper.floor(d7 + d11 / 2.0D);
	            int k1 = MathHelper.floor(d8 + d10 / 2.0D);
	
	            for (int l1 = j; l1 <= i1; ++l1)
	            {
	                double d12 = ((double)l1 + 0.5D - d6) / (d10 / 2.0D);
	
	                if (d12 * d12 < 1.0D)
	                {
	                    for (int i2 = k; i2 <= j1; ++i2)
	                    {
	                        double d13 = ((double)i2 + 0.5D - d7) / (d11 / 2.0D);
	
	                        if (d12 * d12 + d13 * d13 < 1.0D)
	                        {
	                            for (int j2 = l; j2 <= k1; ++j2)
	                            {
	                                double d14 = ((double)j2 + 0.5D - d8) / (d10 / 2.0D);
	                                System.out.println("" + (d12 * d12 + d13 * d13 + d14 * d14));
	                                if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)
	                                {
	                                    BlockPos blockpos = new BlockPos(l1, i2, j2);
	                                    IBlockState state = worldIn.getBlockState(blockpos);
	                                    if (state.getBlock().isReplaceableOreGen(state, worldIn, blockpos, this.predicate))
	                                    {
	                                        worldIn.setBlockState(blockpos, this.oreBlock, 2);
	                                    }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return true;
    }

    static class StonePredicate implements Predicate<IBlockState>
        {
            private StonePredicate()
            {
            }

            public boolean apply(IBlockState p_apply_1_)
            {
                if (p_apply_1_ != null && p_apply_1_.getBlock() == Blocks.STONE)
                {
                    BlockStone.EnumType blockstone$enumtype = (BlockStone.EnumType)p_apply_1_.getValue(BlockStone.VARIANT);
                    return blockstone$enumtype.isNatural();
                }
                else
                {
                    return false;
                }
            }
        }
}

 

The problem is that here: if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D) it always fails since the value is always between 1 and 2 for some reasons and the ore is not spawning.

I really don't know why.

For some reasons if you set ore count to 2, nothing spawns

Edited by Insane96MCP
solved
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.