[1.15]如何阻止栅栏连接到方块上?

Aminor_z


版本信息
Forge版本: 1.15-latest
Minecraft版本: 1.15.2

问题
如何阻止栅栏,玻璃板之类的方块连接到自定义的方块上?

相关信息
方块构造时使用的设置:Block.Properties.create(Material.ROCK).hardnessAndResistance(4).notSolid()

我的努力/(ㄒoㄒ)/~~
查看FenceBlock.java

    public boolean canConnect(BlockState p_220111_1_, boolean p_220111_2_(这个参数判断是否有碰撞体积,即像树苗那种), Direction p_220111_3_) {
        Block lvt_4_1_ = p_220111_1_.getBlock();
        boolean lvt_5_1_ = lvt_4_1_.isIn(BlockTags.FENCES) && p_220111_1_.getMaterial() == this.material;
        boolean lvt_6_1_ = lvt_4_1_ instanceof FenceGateBlock && FenceGateBlock.isParallel(p_220111_1_, p_220111_3_);
        return !【cannotAttach】(lvt_4_1_) && p_220111_2_ || lvt_5_1_ || lvt_6_1_;
    }

以及被调用的函数cannotAttach(Block p_220073_0_)

    public static boolean cannotAttach(Block p_220073_0_) {
        return p_220073_0_ instanceof LeavesBlock || p_220073_0_ == Blocks.BARRIER || p_220073_0_ == Blocks.CARVED_PUMPKIN || p_220073_0_ == Blocks.JACK_O_LANTERN || p_220073_0_ == Blocks.MELON || p_220073_0_ == Blocks.PUMPKIN || p_220073_0_.isIn(BlockTags.SHULKER_BOXES);
    }

发现这是写死的,没法改。
而在游戏中又发现其实有很多方块栅栏不会与其相连。

我该怎么做TAT


FledgeXu


  1. 你的提问有问题,很多需要填的信息没有填,下不为例
  2. 你的方法里为什么会有「【】」?

   public BlockState getStateForPlacement(BlockItemUseContext context) {
      IBlockReader iblockreader = context.getWorld();
      BlockPos blockpos = context.getPos();
      IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
      BlockPos blockpos1 = blockpos.north();
      BlockPos blockpos2 = blockpos.east();
      BlockPos blockpos3 = blockpos.south();
      BlockPos blockpos4 = blockpos.west();
      BlockState blockstate = iblockreader.getBlockState(blockpos1);
      BlockState blockstate1 = iblockreader.getBlockState(blockpos2);
      BlockState blockstate2 = iblockreader.getBlockState(blockpos3);
      BlockState blockstate3 = iblockreader.getBlockState(blockpos4);
      return super.getStateForPlacement(context).with(NORTH, Boolean.valueOf(this.canConnect(blockstate, blockstate.isSolidSide(iblockreader, blockpos1, Direction.SOUTH), Direction.SOUTH))).with(EAST, Boolean.valueOf(this.canConnect(blockstate1, blockstate1.isSolidSide(iblockreader, blockpos2, Direction.WEST), Direction.WEST))).with(SOUTH, Boolean.valueOf(this.canConnect(blockstate2, blockstate2.isSolidSide(iblockreader, blockpos3, Direction.NORTH), Direction.NORTH))).with(WEST, Boolean.valueOf(this.canConnect(blockstate3, blockstate3.isSolidSide(iblockreader, blockpos4, Direction.EAST), Direction.EAST))).with(WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
   }

根据代码里的blockstate.isSolidSide,你把你的方块设置成noSolid的应该就不会被栅栏连接了。


system


该主题在最后一个回复创建后7天后自动关闭。不再允许新的回复。