Jump to content

[Solved] [1.16.1] Vines Generation Help


Talp1

Recommended Posts

Hi everyone!

 

I'm pretty new to modding and I'm trying to figure out how to generate custom vines in certains biomes.

 

So far i have created the vine block and the item to place that block, but i can't figure out how to make this block generate in the world.

 

Thats what i have started with:

@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class VinesGen {

    @SubscribeEvent
    public static void generateVines(FMLLoadCompleteEvent event){

        for (Biome biome : ForgeRegistries.BIOMES){
            if (biome.getCategory()== Biome.Category.SWAMP||biome== Biomes.FLOWER_FOREST)
        }
    }

}

 

I noticed that there's a feature for vines, but it takes in NoFeatureConfig, causing my block to not be "selected" for the generation.

Here's the code i'm talking about:

biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.VINES.withConfiguration(new NoFeatureConfig()));

 

So, how could i make my vines to generate? Have I to create a custom gen?

Edited by Talp1
adding solved tag to title
Link to comment
Share on other sites

On 8/7/2020 at 4:40 PM, Talp1 said:

So, how could i make my vines to generate? Have I to create a custom gen?

Hello!

I think your best bet is to create a new feature which places your own vine block. As you noted yourself, the already existing VinesFeature is a good place to check to learn how to make your own feature.

Link to comment
Share on other sites

1 hour ago, vemerion said:

I think your best bet is to create a new feature which places your own vine block

First of all, thanks for answeing! 

 

Yup, I think I'm gonna try to create somethig that check that if a block is a leaf/log then it places my custom vine on it. It's gonna be a challenge but I'll eventually figure it out, I hope.

I'll relpy on this topic in case I need help with that.

Thank you for the hint!

Link to comment
Share on other sites

So... since I need my gen to do the exact same as the vanilla vine's one, I pretty much created a new identical feature changing the vanilla vine block with mine:

public class FlorealVineFeature extends Feature<NoFeatureConfig> {
    private static final Direction[] DIRECTIONS = Direction.values();

    public FlorealVineFeature(Codec<NoFeatureConfig> p_i232002_1_) {
        super(p_i232002_1_);
    }

    public boolean func_230362_a_(ISeedReader p_230362_1_, StructureManager p_230362_2_, ChunkGenerator p_230362_3_, Random p_230362_4_, BlockPos p_230362_5_, NoFeatureConfig p_230362_6_) {
        BlockPos.Mutable blockpos$mutable = p_230362_5_.toMutable();

        for(int i = p_230362_5_.getY(); i < 256; ++i) {
            blockpos$mutable.setPos(p_230362_5_);
            blockpos$mutable.move(p_230362_4_.nextInt(4) - p_230362_4_.nextInt(4), 0, p_230362_4_.nextInt(4) - p_230362_4_.nextInt(4));
            blockpos$mutable.setY(i);
            if (p_230362_1_.isAirBlock(blockpos$mutable)) {
                for(Direction direction : DIRECTIONS) {
                    if (direction != Direction.DOWN && VineBlock.canAttachTo(p_230362_1_, blockpos$mutable, direction)) {
                        p_230362_1_.setBlockState(blockpos$mutable, RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(direction), Boolean.TRUE), 2);
                        break;
                    }
                }
            }
        }
        return true;
    }
}

 

I then registered my feature like this: (Obviously I registered my FEATURES register as well, in an init() method)

public static final RegistryObject<Feature<NoFeatureConfig>> floreal_vine_feature = FEATURES.register("floreal_vine_feature", ()->new FlorealVineFeature(NoFeatureConfig.field_236558_a_));

 

 and finally, I used this code for the generation itself:

@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class VinesGen {

    @SubscribeEvent
    public static void generateVines(FMLLoadCompleteEvent event){
        for (Biome biome : ForgeRegistries.BIOMES){
            if (biome.getCategory()== Biome.Category.SWAMP||biome== Biomes.FLOWER_FOREST||biome.getCategory()== Biome.Category.JUNGLE){
                    biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, RegistryHandler.floreal_vine_feature.get().withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.COUNT_HEIGHT_64.configure(new FrequencyConfig(25))));
            }
        }
    }
}

 

I tried to stick as vanilla style as much as possible, but yet no luck: my vines are not generating in the world, no errors or warns in the console tho, the registrations seems to happen just fine. What am I missing? I apologize if I made a stupid error... but i cant really find out where I messed up

Edited by Talp1
Link to comment
Share on other sites

  • 2 weeks later...

If somebody would ever need this, after a bit of testing I got a pretty good result, here's what I ended up with.

 

Feature:

public class FlorealVineFeature extends Feature<NoFeatureConfig> {
    public FlorealVineFeature(Codec<NoFeatureConfig> p_i232002_1_) {
        super(p_i232002_1_);
    }

    public boolean func_230362_a_(ISeedReader worldIn, StructureManager strucManager, ChunkGenerator chucnkGen, Random rand, BlockPos pos, NoFeatureConfig config) {

        BlockPos.Mutable blockPos = new BlockPos.Mutable().setPos(pos.getX(), pos.getY(), pos.getZ());
        BlockState currentBlockState = worldIn.getBlockState(blockPos);

        for (Direction direction : Direction.Plane.HORIZONTAL) {
            if (blockPos.getY()>63 && currentBlockState==Blocks.AIR.getDefaultState()){
                checkSorroundingBlocks(blockPos, worldIn, rand, direction);
            }
        }
        return true;
    }

    private boolean checkValidSpot(Direction dir, BlockPos pos, ISeedReader worldIn,BlockPos originalPos){
        if(worldIn.getBlockState(pos).getBlock() instanceof LeavesBlock){
        return RegistryHandler.floreal_vines.get().isValidPosition(RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE),worldIn,originalPos);
        }
        return false;
    }

    private void checkSorroundingBlocks(BlockPos blockPos, ISeedReader worldIn, Random rand, Direction dir){

       if (checkValidSpot(dir, blockPos.east(),worldIn,blockPos)){
           worldIn.setBlockState(blockPos, RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
           for (int i=0; i<=rand.nextInt(3);i++) {
               if (worldIn.getBlockState(blockPos.add(0, -(i), 0)) == Blocks.AIR.getDefaultState()) {
                   worldIn.setBlockState(blockPos.add(0, -(i), 0), RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
               }
           }
       }

        if (checkValidSpot(dir, blockPos.west(),worldIn,blockPos)){
            worldIn.setBlockState(blockPos, RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
            for (int i=0; i<=rand.nextInt(3);i++) {
                if (worldIn.getBlockState(blockPos.add(0, -(i), 0)) == Blocks.AIR.getDefaultState()) {
                    worldIn.setBlockState(blockPos.add(0, -(i), 0), RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
                }
            }
        }

        if (checkValidSpot(dir, blockPos.north(),worldIn,blockPos)){
            worldIn.setBlockState(blockPos, RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
            for (int i=0; i<=rand.nextInt(3);i++) {
                if (worldIn.getBlockState(blockPos.add(0, -(i), 0)) == Blocks.AIR.getDefaultState()) {
                    worldIn.setBlockState(blockPos.add(0, -(i), 0), RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
                }
            }
        }

        if (checkValidSpot(dir, blockPos.south(),worldIn,blockPos)){
            worldIn.setBlockState(blockPos, RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
            for (int i=0; i<=rand.nextInt(3);i++) {
                if (worldIn.getBlockState(blockPos.add(0, -(i), 0)) == Blocks.AIR.getDefaultState()) {
                    worldIn.setBlockState(blockPos.add(0, -(i), 0), RegistryHandler.floreal_vines.get().getDefaultState().with(VineBlock.getPropertyFor(dir), Boolean.TRUE), 2);
                }
            }
        }
    }

}

 

Gen:

@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class VinesGen {

    @SubscribeEvent
    public static void generateVines(FMLLoadCompleteEvent event){
        for (Biome biome : ForgeRegistries.BIOMES){
            if (biome.getCategory()== Biome.Category.SWAMP||biome== Biomes.FLOWER_FOREST||biome.getCategory()== Biome.Category.JUNGLE){
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, RegistryHandler.floreal_vine_feature.get().withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.COUNT_HEIGHTMAP.configure(new FrequencyConfig(600))));
            }
        }
    }
}

 

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.

Announcements



×
×
  • Create New...

Important Information

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