Jump to content

Recommended Posts

Posted (edited)

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Different problem now. https://paste.ee/p/iDo8lS35
    • I would like to have a BoP sapling drop from my block if it is also installed. I think I have done everything and I cannot pinpoint the problem, which is the error in the logs that appears when joining a world:   [Worker-Main-11/ERROR] [ne.mi.co.ForgeHooks/]: Couldn't parse element loot_tables:grasses:blocks/leaves_block com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'biomesoplenty:magic_sapling' My code:   LootItemConditions.CONDITIONS.register(modEventBus); public class LootItemConditions { public static final DeferredRegister<LootItemConditionType> CONDITIONS = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Grasses.MOD_ID); public static final RegistryObject<LootItemConditionType> IS_MOD_LOADED = CONDITIONS.register("is_mod_loaded", () -> new LootItemConditionType(new IsModLoaded.ConditionSerializer())); } public class IsModLoaded implements LootItemCondition { private final boolean exists; private final String modID; public IsModLoaded(String modID) { this.exists = ModList.get().isLoaded(modID); this.modID = modID; } @Override public LootItemConditionType getType() { return LootItemConditions.IS_MOD_LOADED.get(); } @Override public boolean test(LootContext context) { return this.exists; } public static LootItemCondition.Builder builder(String modid) { return () -> new IsModLoaded(modid); } public static class ConditionSerializer implements Serializer<IsModLoaded> { @Override public void serialize(JsonObject json, IsModLoaded instance, JsonSerializationContext ctx) { json.addProperty("modid", instance.modID); } @Override public IsModLoaded deserialize(JsonObject json, JsonDeserializationContext ctx) { return new IsModLoaded(GsonHelper.getAsString(json, "modid")); } } } protected LootTable.Builder createLeavesDropsWithModIDCheck(Block selfBlock, Item sapling, Property<?>[] properties, String modIDToCheck, float... chances) { CopyBlockState.Builder blockStateCopyBuilder = CopyBlockState.copyState(selfBlock); for(Property<?> property : properties) { blockStateCopyBuilder.copy(property); } return LootTable.lootTable() .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(selfBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .apply(blockStateCopyBuilder))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionCondition(selfBlock, LootItem.lootTableItem(sapling)) .when(IsModLoaded.builder(modIDToCheck))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH)) .withPool(LootPool.lootPool().name("sticks").setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionDecay(selfBlock, LootItem.lootTableItem(Items.STICK). apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH))); } I don't know. Am I making a mistake somewhere? Am I forgetting something? Should there be something else?
    • https://paste.ee/p/h1JX9bbl
    • Add the latest.log from your logs-folder
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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