Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-168264

Sugar cane cannot be placed on farmland

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • None
    • 1.15.1, 1.15.2 Pre-Release 1, 1.15.2 Pre-release 2, 1.15.2, 20w06a, 20w07a, 20w08a, 20w09a, 20w10a, 20w11a, 20w12a, 20w13a, 20w15a, 20w18a, 20w20a, 20w21a, 1.16 Pre-release 1, 1.16 Pre-release 2, 1.16 Pre-release 3, 1.16 Pre-release 4, 1.16 Pre-release 5, 1.16 Pre-release 7, 20w28a, 20w29a, 20w30a, 1.16.2 Pre-release 1, 1.16.2 Release Candidate 1, 1.16.2 Release Candidate 2, 1.16.2, 1.16.3, 20w45a, 20w51a, 21w03a, 1.16.5, 21w05b, 21w06a, 21w08b, 21w13a, 21w14a, 21w16a, 21w18a, 21w20a, 1.17 Pre-release 1, 1.17, 1.17.1, 1.18 Pre-release 1, 1.18, 1.18.1, 1.18.2, 22w14a, 22w15a, 1.19, 1.19.2, 22w46a, 1.19.3
    • Confirmed
    • Block states
    • Low

    Description

      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 Thumpbacker

      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;
            }
         }
         }
      

      Attachments

        1. 2019-12-17_23.50.15.png
          2019-12-17_23.50.15.png
          897 kB
        2. 2019-12-17_23.50.16.png
          2019-12-17_23.50.16.png
          607 kB
        3. 2019-12-17_23.50.17_2.png
          2019-12-17_23.50.17_2.png
          691 kB
        4. 2019-12-17_23.50.17.png
          2019-12-17_23.50.17.png
          806 kB
        5. 2019-12-17_23.50.22.png
          2019-12-17_23.50.22.png
          567 kB
        6. MC-168264.mp4
          2.55 MB
        7. setup.png
          setup.png
          160 kB

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Awesoman3000 Connor Steppie
              Votes:
              10 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                CHK: