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 am working on a custom worldgenore. ATM i am having an issue. What i am trying to do is get the block to skip generation of the ore randomly. I put 

(rand.nextInt(10) > 3)

before the 

worldIn.setBlockState(....

This did nothing because all blocks in the vain would be the ore. no stone found with in the vain. So i did

System.out.println(state);
System.out.println(blockpos);

so it turns out that it would spawn the vain sometimes all the blocks would be set to stone and some times all to ore. Bellow is my full code that I have used so far.

public class WorldGenOreVain extends WorldGenerator {
    private final Block[] oreBlocks;
    /**
     * The number of blocks to generate.
     */
    private final int numberOfBlocks;
    private Random rand = new Random();
    //private final Predicate<IBlockState> predicate;

    public WorldGenOreVain(int blockCount, Block... blocksIn) {
        this.oreBlocks = blocksIn;
        this.numberOfBlocks = blockCount;
    }

    public boolean generate(World worldIn, Random rand, BlockPos position) {        {
            float f = rand.nextFloat() * (float) Math.PI;
            double X0 = (double) ((float) (position.getX() + 8) + MathHelper.sin(f) * (float) this.numberOfBlocks / 8.0F);
            double X1 = (double) ((float) (position.getX() + 8) - MathHelper.sin(f) * (float) this.numberOfBlocks / 8.0F);
            double Z2 = (double) ((float) (position.getZ() + 8) + MathHelper.cos(f) * (float) this.numberOfBlocks / 8.0F);
            double Z3 = (double) ((float) (position.getZ() + 8) - MathHelper.cos(f) * (float) this.numberOfBlocks / 8.0F);
            double Y4 = (double) (position.getY() + rand.nextInt(3) - 2);
            double Y5 = (double) (position.getY() + rand.nextInt(3) - 2);

            for (int i = 0; i < this.numberOfBlocks; ++i) {
                float f1 = (float) i / (float) this.numberOfBlocks;
                double X6 = X0 + (X1 - X0) * (double) f1;
                double Y7 = Y4 + (Y5 - Y4) * (double) f1;
                double Z8 = Z2 + (Z3 - Z2) * (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(X6 - d10 / 2.0D);
                int k = MathHelper.floor(Y7 - d11 / 2.0D);
                int l = MathHelper.floor(Z8 - d10 / 2.0D);
                int i1 = MathHelper.floor(X6 + d10 / 2.0D);
                int j1 = MathHelper.floor(Y7 + d11 / 2.0D);
                int k1 = MathHelper.floor(Z8 + d10 / 2.0D);

                for (int x = j; x <= i1; ++x) {
                    double d12 = ((double) x + 0.5D - X6) / (d10 / 2.0D);

                    if (d12 * d12 < 1.0D) {
                        for (int y = k; y <= j1; ++y) {
                            double d13 = ((double) y + 0.5D - Y7) / (d11 / 2.0D);

                            if (d12 * d12 + d13 * d13 < 1.0D) {
                                for (int z = l; z <= k1; ++z) {
                                    double d14 = ((double) z + 0.5D - Z8) / (d10 / 2.0D);

                                    if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D) {
                                        BlockPos blockpos = new BlockPos(x, y, z);

                                        IBlockState state = worldIn.getBlockState(blockpos);
                                        if (StoneVariant.stoneVariant.contains(state.getBlock())) {
                                            if (oreBlocks[rand.nextInt(oreBlocks.length)] instanceof BlockOre) {
                                                Block oreIn = oreBlocks[rand.nextInt(oreBlocks.length)];
                                                if (state.getBlock() == Blocks.STONE) {
                                                    if (rand.nextInt(10) > 3) {
                                                        IBlockState metaOreIn = oreIn.getStateFromMeta(0);
                                                        worldIn.setBlockState(blockpos, metaOreIn, 2);
                                                        System.out.println("spawm" + blockpos);
                                                    } else {
                                                        worldIn.setBlockState(blockpos, state, 2);
                                                        System.out.println(state);
                                                        System.out.println(blockpos);
                                                    }
                                                }
                                            } else {
                                                worldIn.setBlockState(blockpos, oreBlocks[rand.nextInt(oreBlocks.length)].getDefaultState(), 2);
                                                System.out.println(blockpos.getX() + blockpos.getY() + blockpos.getZ());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return true;
        }
    }
}

oreBlocks[rand.nextInt(oreBlocks.length)] just picks a random block in block[] to be able to make multiple blocks to spawn in the vain.

How would i get this to fully work

Edited by Mightydanp

Guest
This topic is now closed to further replies.

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.