mojira.dev
MC-168264

Sugar cane cannot be placed on farmland

The Bug

Inconsistent behavior with many other plant blocks. One would expect that sugar cane can be planted on farmland because almost all other plants can, however, this is not the case.

Steps to Reproduce

  1. Build the setup as shown in the attachment below. setup.png

  2. Obtain some sugar cane and attempt to place one on each of the six blocks.

  3. Take note as to what blocks you can place sugar cane on and what blocks you can't.

Observed Behavior

Sugar cane cannot be placed on farmland.

Expected Behavior

Sugar cane would be able to be placed on farmland.

Code Analysis

Code Analysis done by @unknown

This happens because there is no check for farmland in the canSurvive method

Current Code

net/minecraft/world/level/block/SugarCaneBlock.java

public boolean canSurvive(BlockState p_57175_, LevelReader p_57176_, BlockPos p_57177_) {
      BlockState blockstate = p_57176_.getBlockState(p_57177_.below());
      if (blockstate.is(this)) {
         return true;
      } else {
         if (blockstate.is(BlockTags.DIRT) || blockstate.is(Blocks.SAND) || blockstate.is(Blocks.RED_SAND){
            BlockPos blockpos = p_57177_.below();

            for(Direction direction : Direction.Plane.HORIZONTAL) {
               BlockState blockstate1 = p_57176_.getBlockState(blockpos.relative(direction));
               FluidState fluidstate = p_57176_.getFluidState(blockpos.relative(direction));
               if (fluidstate.is(FluidTags.WATER) || blockstate1.is(Blocks.FROSTED_ICE)) {
                  return true;
               }
            }
         }

         return false;
      }
   }
   }

Fixed Code

net/minecraft/world/level/block/SugarCaneBlock.java

public boolean canSurvive(BlockState p_57175_, LevelReader p_57176_, BlockPos p_57177_) {
      BlockState blockstate = p_57176_.getBlockState(p_57177_.below());
      if (blockstate.is(this)) {
         return true;
      } else {
         //Adding a check for Farmland fixes MC-168264
         if (blockstate.is(BlockTags.DIRT) || blockstate.is(Blocks.SAND) || blockstate.is(Blocks.RED_SAND) || blockstate.is(Blocks.FARMLAND)) {
            BlockPos blockpos = p_57177_.below();

            for(Direction direction : Direction.Plane.HORIZONTAL) {
               BlockState blockstate1 = p_57176_.getBlockState(blockpos.relative(direction));
               FluidState fluidstate = p_57176_.getFluidState(blockpos.relative(direction));
               if (fluidstate.is(FluidTags.WATER) || blockstate1.is(Blocks.FROSTED_ICE)) {
                  return true;
               }
            }
         }

         return false;
      }
   }
   }

Linked issues

Attachments

Comments 20

doesn't this work as intended?

There are quite a few plants that can't be placed on Farmland. They are Bamboo (handle by tags), Cactus, Dead Bush, Brown Mushroom, Red Mushroom, Sea Pickles, all non-full block Coral variants, and Kelp. Surprisingly, Seagrass can be placed on underwater Farmland but not Kelp. 

So I think Sugar Cane not being on Farmland may be on purpose. But there's definitely inconsistencies with underwater plants tho.

Can confirm in 21w05b.

Can confirm in 21w06a.

10 more comments

Can confirm in 22w14a.

Can confirm in 1.19.

Can confirm in 1.19.2.

Can confirm in 24w44a.

muzikbike

(Unassigned)

Confirmed

Gameplay

Low

Block states

block-missing-from-block-tag, farmland, placement-and-support, placement-and-support-testing-area, sugar_cane

1.15.1, 1.15.2 Pre-Release 1, 1.15.2 Pre-release 2, 1.15.2, 20w06a, ..., 1.19.3, 1.20, 1.20.1, 24w44a, 1.21.4

Retrieved