Jump to content

[1.14.4] Custom grass block behaviours


abdmoh123

Recommended Posts

I am creating a custom netherrack grass block (warped nylium)

I would like the block to turn into netherrack after placing a block on top.

I would also want grass and flowers to be placeable on it.

Also, any ideas on how to make it spreadable?

 

So far, I got the block to register with textures and everything, but I could find any tutorials on getting grass functionality for it

 

Thanks

 

Here is the block's class so far:

public class WarpedNylium extends GrassBlock {
    public WarpedNylium() {
        super(Properties.create(Material.ORGANIC)
                .sound(SoundType.STONE)
                .hardnessAndResistance(0.4F)
                .harvestTool(ToolType.PICKAXE)
        );
        setRegistryName("warped_nylium");
    }
}
Link to comment
Share on other sites

Hi

 

I very much doubt you'll find a specific tutorial for this, I think you'll probably have to spend some time understanding the vanilla code.  Some of the key words to help your search:

Block.canSustainPlant()

BushBlock

GrassBlock.grow()

SpreadableSnowyDirtBlock.tick()

 

-TGG

 

  • Like 1
Link to comment
Share on other sites

I found GrassBlock.grow() and GrassBlock.canGrow()

The first one returns a void datatype and the second one returns a boolean datatype

 

I overridden the second method to return true, but there was no change

Here is the code now:

public class WarpedNylium extends GrassBlock {
    public WarpedNylium() {
        super(Properties.create(Material.ORGANIC)
                .sound(SoundType.STONE)
                .hardnessAndResistance(0.4F)
                .harvestTool(ToolType.PICKAXE)
        );
        setRegistryName("warped_nylium");
    }

    @Override
    public boolean canGrow(IBlockReader worldIn, BlockPos pos, BlockState state, boolean isClient) {
        return true;
    }
}

 

I am unsure on how to override the grow() method, since it looks complicated:

public void grow(World worldIn, Random rand, BlockPos pos, BlockState state) {
   BlockPos blockpos = pos.up();
   BlockState blockstate = Blocks.GRASS.getDefaultState();

   for(int i = 0; i < 128; ++i) {
      BlockPos blockpos1 = blockpos;
      int j = 0;

      while(true) {
         if (j >= i / 16) {
            BlockState blockstate2 = worldIn.getBlockState(blockpos1);
            if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
               ((IGrowable)blockstate.getBlock()).grow(worldIn, rand, blockpos1, blockstate2);
            }

            if (!blockstate2.isAir()) {
               break;
            }

            BlockState blockstate1;
            if (rand.nextInt(8) == 0) {
               List<ConfiguredFeature<?>> list = worldIn.getBiome(blockpos1).getFlowers();
               if (list.isEmpty()) {
                  break;
               }

               blockstate1 = ((FlowersFeature)((DecoratedFeatureConfig)(list.get(0)).config).feature.feature).getRandomFlower(rand, blockpos1);
            } else {
               blockstate1 = blockstate;
            }

            if (blockstate1.isValidPosition(worldIn, blockpos1)) {
               worldIn.setBlockState(blockpos1, blockstate1, 3);
            }
            break;
         }

         blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
         if (worldIn.getBlockState(blockpos1.down()).getBlock() != this || worldIn.getBlockState(blockpos1).func_224756_o(worldIn, blockpos1)) {
            break;
         }

         ++j;
      }
   }

}

 

Thanks for the help

 

Edit:

I found the canSustainPlant() method but I think it could be deprecated, correct me if I am wrong

Edited by abdmoh123
Spelling
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.