1313import net .minecraft .world .entity .Entity ;
1414import net .minecraft .world .entity .LivingEntity ;
1515import net .minecraft .world .item .context .BlockPlaceContext ;
16+ import net .minecraft .world .level .BlockGetter ;
1617import net .minecraft .world .level .Level ;
1718import net .minecraft .world .level .block .Block ;
19+ import net .minecraft .world .level .block .SimpleWaterloggedBlock ;
1820import net .minecraft .world .level .block .state .BlockState ;
1921import net .minecraft .world .level .block .state .StateDefinition .Builder ;
2022import net .minecraft .world .level .block .state .properties .BlockStateProperties ;
2123import net .minecraft .world .level .block .state .properties .BooleanProperty ;
2224import net .minecraft .world .level .block .state .properties .DirectionProperty ;
25+ import net .minecraft .world .level .material .FluidState ;
26+ import net .minecraft .world .level .material .Fluids ;
2327import net .minecraft .world .phys .Vec3 ;
2428import net .neoforged .neoforge .client .model .generators .BlockModelProvider ;
2529import net .neoforged .neoforge .client .model .generators .ConfiguredModel ;
2630import net .neoforged .neoforge .client .model .generators .ModelFile ;
2731import net .neoforged .neoforge .client .model .generators .VariantBlockStateBuilder ;
2832import net .neoforged .neoforge .common .IShearable ;
2933
30- public class BarbedWireBlock extends Block implements IShearable {
34+ public class BarbedWireBlock extends Block implements IShearable , SimpleWaterloggedBlock {
3135 public static final BooleanProperty VERTICAL = BooleanProperty .create ("vertical" );
3236 public static final DirectionProperty HORIZONTAL_FACING = BlockStateProperties .HORIZONTAL_FACING ;
37+ public static final BooleanProperty WATERLOGGED = BlockStateProperties .WATERLOGGED ;
3338
3439 public BarbedWireBlock (Properties props ) {
3540 super (props );
36- this .registerDefaultState (this .defaultBlockState ().setValue (VERTICAL , false ).setValue (HORIZONTAL_FACING , Direction .NORTH ));
41+ this .registerDefaultState (this .defaultBlockState ().setValue (VERTICAL , false ).setValue (HORIZONTAL_FACING , Direction .NORTH ).setValue (WATERLOGGED , false ));
42+ }
43+
44+ protected boolean propagatesSkylightDown (BlockState state , BlockGetter reader , BlockPos pos ) {
45+ return !(Boolean )state .getValue (WATERLOGGED );
3746 }
3847
3948 @ Override
@@ -46,18 +55,30 @@ public void entityInside(BlockState state, Level level, BlockPos pos, Entity ent
4655 entity .makeStuckInBlock (state , new Vec3 (0.25D , 0.05D , 0.25D ));
4756 }
4857
58+ @ Override
59+ protected FluidState getFluidState (BlockState state ) {
60+ return state .getValue (WATERLOGGED ) ? Fluids .WATER .getSource (false ) : super .getFluidState (state );
61+ }
62+
4963 @ Override
5064 protected void createBlockStateDefinition (Builder <Block , BlockState > builder ) {
51- builder .add (VERTICAL , HORIZONTAL_FACING );
65+ builder .add (VERTICAL , HORIZONTAL_FACING , WATERLOGGED );
5266 }
5367
5468 @ Override
5569 public BlockState getStateForPlacement (BlockPlaceContext c ) {
70+ FluidState fluidstate = c .getLevel ().getFluidState (c .getClickedPos ());
5671 if (c .getPlayer () == null ) return defaultBlockState ();
5772 if (c .getClickedFace ().getAxis () == Axis .Y )
58- return defaultBlockState ().setValue (HORIZONTAL_FACING , c .getPlayer ().isShiftKeyDown () ? c .getHorizontalDirection ().getClockWise () : c .getHorizontalDirection ()).setValue (VERTICAL , false );
73+ return defaultBlockState ()
74+ .setValue (HORIZONTAL_FACING , c .getPlayer ().isShiftKeyDown () ? c .getHorizontalDirection ().getClockWise () : c .getHorizontalDirection ())
75+ .setValue (VERTICAL , false )
76+ .setValue (WATERLOGGED , fluidstate .getType () == Fluids .WATER );
5977 else
60- return defaultBlockState ().setValue (HORIZONTAL_FACING , c .getClickedFace ().getOpposite ()).setValue (VERTICAL , true );
78+ return defaultBlockState ()
79+ .setValue (HORIZONTAL_FACING , c .getClickedFace ().getOpposite ())
80+ .setValue (VERTICAL , true )
81+ .setValue (WATERLOGGED , fluidstate .getType () == Fluids .WATER );
6182 }
6283
6384 public static void makeBlockState (DataGenContext <Block , BarbedWireBlock > ctx , RegistrateBlockstateProvider provider ) {
0 commit comments