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
comment_388900

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");
    }
}
  • Author
comment_388910

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

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...

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.