蝙蝠森林
本帖最后由 蝙蝠森林 于 2021-2-24 19:49 编辑

问题:1.耕地无法检测周围的流体或者方块
2.周围没有需要的流体或者方块不会变回沙子


目标:
检测到对应流体不变回沙子
周围没有需要的方块和流体会 和原版耕地一样的速度变回沙子

详细代码如下


MaxSeth
为什么不直接参考原版耕地呢
  1. private boolean hasWater(World worldIn, BlockPos pos)
  2.     {
  3.         for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), pos.add(4, 1, 4)))
  4.         {
  5.             if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
  6.             {
  7.                 return true;
  8.             }
  9.         }

  10.         return net.minecraftforge.common.FarmlandWaterManager.hasBlockWaterTicket(worldIn, pos);
  11.     }
复制代码

  1. public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
  2.     {
  3.         int i = ((Integer)state.getValue(MOISTURE)).intValue();

  4.         if (!this.hasWater(worldIn, pos) && !worldIn.isRainingAt(pos.up()))
  5.         {
  6.             if (i > 0)
  7.             {
  8.                 worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(i - 1)), 2);
  9.             }
  10.             else if (!this.hasCrops(worldIn, pos))
  11.             {
  12.                 turnToDirt(worldIn, pos);
  13.             }
  14.         }
  15.         else if (i < 7)
  16.         {
  17.             worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(7)), 2);
  18.         }
  19.     }
复制代码


来自原版BlockFarmLand

道家深湖
除了判断WATER,还有个Blocks.FLOWING_WATER别忘了
另外我觉得楼上那种检测Material的也挺好

道家深湖
f (this.hasLiquidOrBlock(worldIn, pos))
        {
            worldIn.setBlockState(pos,ModBlocks.SOUL_SAND.getDefaultState());
        }
        else if  (!this.hasLiquidOrBlock(worldIn, pos))

以及你这一段有点迷啊,前面if判断好了,后面你为啥不直接else呢,还要再判断一次elseif有点多余吧