Skip to content

Commit 60d6f3a

Browse files
committed
Add jspecify and use @NullMarked on all packages. Use @nullable or suppress warnings where necessary. Minor refactors.
1 parent 09fc3d0 commit 60d6f3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+356
-199
lines changed

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ repositories {
8080
dependencies {
8181
minecraft 'net.neoforged:forge:1.20.1-47.1.65'
8282

83+
compileOnly "org.jspecify:jspecify:0.3.0"
84+
8385
implementation fg.deobf("curse.maven:the-one-probe-245211:4629624")
8486
implementation fg.deobf("curse.maven:framedblocks-441647:4657096")
8587
}

src/main/java/platinpython/rgbblocks/block/RGBBlock.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.world.level.block.entity.BlockEntity;
1212
import net.minecraft.world.level.block.state.BlockState;
1313
import net.minecraft.world.phys.HitResult;
14+
import org.jspecify.annotations.Nullable;
1415

1516
public class RGBBlock extends Block implements EntityBlock {
1617
public RGBBlock(Properties properties) {
@@ -23,7 +24,13 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2324
}
2425

2526
@Override
26-
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
27+
public void setPlacedBy(
28+
Level worldIn,
29+
BlockPos pos,
30+
BlockState state,
31+
@Nullable LivingEntity placer,
32+
ItemStack stack
33+
) {
2734
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
2835
}
2936

src/main/java/platinpython/rgbblocks/block/RGBBlockUtils.java

+24-29
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,27 @@
1717
import net.minecraft.world.level.block.state.properties.SlabType;
1818
import net.minecraft.world.level.block.state.properties.StairsShape;
1919
import net.minecraft.world.phys.HitResult;
20+
import org.jspecify.annotations.Nullable;
2021
import platinpython.rgbblocks.tileentity.RGBTileEntity;
2122
import platinpython.rgbblocks.util.Color;
2223
import platinpython.rgbblocks.util.registries.TileEntityRegistry;
2324

2425
public final class RGBBlockUtils {
25-
public static BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
26+
public static @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2627
return TileEntityRegistry.RGB.get().create(pos, state);
2728
}
2829

2930
public static void setPlacedBy(
3031
Level worldIn,
3132
BlockPos pos,
3233
BlockState state,
33-
LivingEntity placer,
34+
@Nullable LivingEntity placer,
3435
ItemStack stack
3536
) {
3637
BlockEntity tileEntity = worldIn.getBlockEntity(pos);
37-
if (stack.hasTag() && tileEntity instanceof RGBTileEntity) {
38-
((RGBTileEntity) tileEntity).setColor(stack.getTag().getInt("color"));
38+
if (stack.hasTag() && tileEntity instanceof RGBTileEntity rgbTileEntity) {
39+
// noinspection DataFlowIssue
40+
rgbTileEntity.setColor(stack.getTag().getInt("color"));
3941
}
4042
}
4143

@@ -56,15 +58,15 @@ public static ItemStack getCloneItemStack(
5658
return stack;
5759
}
5860

59-
public static float[] getBeaconColorMultiplier(
61+
public static float @Nullable [] getBeaconColorMultiplier(
6062
BlockState state,
6163
LevelReader world,
6264
BlockPos pos,
6365
BlockPos beaconPos
6466
) {
6567
BlockEntity tileEntity = world.getBlockEntity(pos);
66-
if (tileEntity instanceof RGBTileEntity) {
67-
return new Color(((RGBTileEntity) tileEntity).getColor()).getRGBColorComponents();
68+
if (tileEntity instanceof RGBTileEntity rgbTileEntity) {
69+
return new Color(rgbTileEntity.getColor()).getRGBColorComponents();
6870
} else {
6971
return null;
7072
}
@@ -122,18 +124,11 @@ public static boolean slabSkipRenderingAdjacentGlassSlab(
122124
return true;
123125
}
124126

125-
switch (side) {
126-
case UP:
127-
case DOWN:
128-
return (state.getValue(SlabBlock.TYPE) != adjacentBlockState.getValue(SlabBlock.TYPE));
129-
case NORTH:
130-
case EAST:
131-
case SOUTH:
132-
case WEST:
133-
return (state.getValue(SlabBlock.TYPE) == adjacentBlockState.getValue(SlabBlock.TYPE));
134-
}
135-
136-
return false;
127+
return switch (side) {
128+
case UP, DOWN -> (state.getValue(SlabBlock.TYPE) != adjacentBlockState.getValue(SlabBlock.TYPE));
129+
case NORTH, EAST, SOUTH, WEST ->
130+
(state.getValue(SlabBlock.TYPE) == adjacentBlockState.getValue(SlabBlock.TYPE));
131+
};
137132
}
138133

139134
public static boolean slabSkipRenderingAdjacentGlassStairs(
@@ -157,9 +152,9 @@ public static boolean slabSkipRenderingAdjacentGlassStairs(
157152
if (state.getValue(SlabBlock.TYPE) == SlabType.BOTTOM
158153
&& adjacentBlockState.getValue(StairBlock.HALF) == Half.BOTTOM) {
159154
return true;
160-
} else if (state.getValue(SlabBlock.TYPE) == SlabType.TOP
161-
&& adjacentBlockState.getValue(StairBlock.HALF) == Half.TOP) {
162-
return true;
155+
} else {
156+
return state.getValue(SlabBlock.TYPE) == SlabType.TOP
157+
&& adjacentBlockState.getValue(StairBlock.HALF) == Half.TOP;
163158
}
164159
}
165160

@@ -221,9 +216,9 @@ public static boolean stairSkipRenderingAdjacentGlassSlab(
221216
if (adjacentBlockState.getValue(SlabBlock.TYPE) == SlabType.TOP
222217
&& state.getValue(StairBlock.HALF) == Half.TOP) {
223218
return true;
224-
} else if (adjacentBlockState.getValue(SlabBlock.TYPE) == SlabType.BOTTOM
225-
&& state.getValue(StairBlock.HALF) == Half.BOTTOM) {
226-
return true;
219+
} else {
220+
return adjacentBlockState.getValue(SlabBlock.TYPE) == SlabType.BOTTOM
221+
&& state.getValue(StairBlock.HALF) == Half.BOTTOM;
227222
}
228223
}
229224

@@ -419,10 +414,10 @@ public static boolean stairSkipRenderingAdjacentGlassStairs(
419414
} else if (adjacentBlockState.getValue(StairBlock.FACING) == state.getValue(StairBlock.FACING)
420415
&& adjacentBlockState.getValue(StairBlock.SHAPE) != StairsShape.OUTER_RIGHT) {
421416
return true;
422-
} else if (adjacentBlockState.getValue(StairBlock.FACING)
423-
== state.getValue(StairBlock.FACING).getOpposite()
424-
&& state.getValue(StairBlock.SHAPE) == StairsShape.OUTER_LEFT) {
425-
return true;
417+
} else {
418+
return adjacentBlockState.getValue(StairBlock.FACING)
419+
== state.getValue(StairBlock.FACING).getOpposite()
420+
&& state.getValue(StairBlock.SHAPE) == StairsShape.OUTER_LEFT;
426421
}
427422
}
428423
}

src/main/java/platinpython/rgbblocks/block/RGBCarpetBlock.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.world.level.block.entity.BlockEntity;
1414
import net.minecraft.world.level.block.state.BlockState;
1515
import net.minecraft.world.phys.HitResult;
16+
import org.jspecify.annotations.Nullable;
1617

1718
public class RGBCarpetBlock extends WoolCarpetBlock implements EntityBlock {
1819
public RGBCarpetBlock() {
@@ -25,7 +26,13 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2526
}
2627

2728
@Override
28-
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
29+
public void setPlacedBy(
30+
Level worldIn,
31+
BlockPos pos,
32+
BlockState state,
33+
@Nullable LivingEntity placer,
34+
ItemStack stack
35+
) {
2936
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
3037
}
3138

src/main/java/platinpython/rgbblocks/block/RGBConcretePowderBlock.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.minecraft.world.level.block.state.BlockState;
1717
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
1818
import net.minecraft.world.phys.HitResult;
19+
import org.jspecify.annotations.Nullable;
1920
import platinpython.rgbblocks.entity.RGBFallingBlockEntity;
2021
import platinpython.rgbblocks.tileentity.RGBTileEntity;
2122
import platinpython.rgbblocks.util.registries.BlockRegistry;
@@ -31,7 +32,13 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
3132
}
3233

3334
@Override
34-
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
35+
public void setPlacedBy(
36+
Level worldIn,
37+
BlockPos pos,
38+
BlockState state,
39+
@Nullable LivingEntity placer,
40+
ItemStack stack
41+
) {
3542
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
3643
}
3744

@@ -53,7 +60,7 @@ public void tick(BlockState state, ServerLevel worldIn, BlockPos pos, RandomSour
5360
RGBFallingBlockEntity fallingBlockEntity = new RGBFallingBlockEntity(
5461
worldIn, (double) pos.getX() + 0.5D, pos.getY(), (double) pos.getZ() + 0.5D,
5562
state.hasProperty(BlockStateProperties.WATERLOGGED)
56-
? state.setValue(BlockStateProperties.WATERLOGGED, Boolean.valueOf(false))
63+
? state.setValue(BlockStateProperties.WATERLOGGED, Boolean.FALSE)
5764
: state,
5865
tileEntity instanceof RGBTileEntity ? ((RGBTileEntity) tileEntity).getColor() : 0
5966
);
@@ -63,6 +70,7 @@ public void tick(BlockState state, ServerLevel worldIn, BlockPos pos, RandomSour
6370
}
6471
}
6572

73+
@SuppressWarnings("deprecation")
6674
@Override
6775
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
6876
if (!state.is(BlockRegistry.RGB_CONCRETE_POWDER.get()) && !newState.is(BlockRegistry.RGB_CONCRETE.get())) {
@@ -90,11 +98,9 @@ public void onLand(
9098

9199
@Override
92100
public int getDustColor(BlockState blockState, BlockGetter blockReader, BlockPos blockPos) {
93-
if (blockReader != null) {
94-
BlockEntity tileEntity = blockReader.getBlockEntity(blockPos.above());
95-
if (tileEntity instanceof RGBTileEntity) {
96-
return ((RGBTileEntity) tileEntity).getColor();
97-
}
101+
BlockEntity tileEntity = blockReader.getBlockEntity(blockPos.above());
102+
if (tileEntity instanceof RGBTileEntity rgbTileEntity) {
103+
return rgbTileEntity.getColor();
98104
}
99105
return super.getDustColor(blockState, blockReader, blockPos);
100106
}

src/main/java/platinpython/rgbblocks/block/RGBGlassBlock.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66
import net.minecraft.world.level.LevelReader;
77
import net.minecraft.world.level.block.Blocks;
88
import net.minecraft.world.level.block.state.BlockState;
9+
import org.jspecify.annotations.Nullable;
910

1011
public class RGBGlassBlock extends RGBBlock {
1112
public RGBGlassBlock() {
1213
super(Properties.copy(Blocks.GLASS));
1314
}
1415

1516
@Override
16-
public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, BlockPos pos, BlockPos beaconPos) {
17+
public float @Nullable [] getBeaconColorMultiplier(
18+
BlockState state,
19+
LevelReader world,
20+
BlockPos pos,
21+
BlockPos beaconPos
22+
) {
1723
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
1824
}
1925

26+
@SuppressWarnings("deprecation")
2027
@Override
2128
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
2229
return RGBBlockUtils.blockSkipRendering(state, adjacentBlockState, side);
2330
}
2431

32+
@SuppressWarnings("deprecation")
2533
@Override
2634
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
2735
return 1.0F;

src/main/java/platinpython/rgbblocks/block/RGBGlassPaneBlock.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
import net.minecraft.world.level.LevelReader;
77
import net.minecraft.world.level.block.Blocks;
88
import net.minecraft.world.level.block.state.BlockState;
9+
import org.jspecify.annotations.Nullable;
910

1011
public class RGBGlassPaneBlock extends RGBIronBarsBlock {
1112
public RGBGlassPaneBlock() {
1213
super(Properties.copy(Blocks.GLASS_PANE));
1314
}
1415

1516
@Override
16-
public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, BlockPos pos, BlockPos beaconPos) {
17+
public float @Nullable [] getBeaconColorMultiplier(
18+
BlockState state,
19+
LevelReader world,
20+
BlockPos pos,
21+
BlockPos beaconPos
22+
) {
1723
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
1824
}
1925

@@ -22,6 +28,7 @@ public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Di
2228
return RGBBlockUtils.blockSkipRendering(state, adjacentBlockState, side);
2329
}
2430

31+
@SuppressWarnings("deprecation")
2532
@Override
2633
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
2734
return 1.0F;

src/main/java/platinpython/rgbblocks/block/RGBGlassSlabBlock.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66
import net.minecraft.world.level.LevelReader;
77
import net.minecraft.world.level.block.Blocks;
88
import net.minecraft.world.level.block.state.BlockState;
9+
import org.jspecify.annotations.Nullable;
910

1011
public class RGBGlassSlabBlock extends RGBSlabBlock {
1112
public RGBGlassSlabBlock() {
1213
super(Properties.copy(Blocks.GLASS));
1314
}
1415

1516
@Override
16-
public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, BlockPos pos, BlockPos beaconPos) {
17+
public float @Nullable [] getBeaconColorMultiplier(
18+
BlockState state,
19+
LevelReader world,
20+
BlockPos pos,
21+
BlockPos beaconPos
22+
) {
1723
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
1824
}
1925

26+
@SuppressWarnings("deprecation")
2027
@Override
2128
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
2229
return RGBBlockUtils.slabSkipRendering(state, adjacentBlockState, side);
2330
}
2431

32+
@SuppressWarnings("deprecation")
2533
@Override
2634
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
2735
return 1.0F;

src/main/java/platinpython/rgbblocks/block/RGBGlassStairsBlock.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.world.level.LevelReader;
77
import net.minecraft.world.level.block.Blocks;
88
import net.minecraft.world.level.block.state.BlockState;
9+
import org.jspecify.annotations.Nullable;
910

1011
import java.util.function.Supplier;
1112

@@ -15,15 +16,22 @@ public RGBGlassStairsBlock(Supplier<BlockState> state) {
1516
}
1617

1718
@Override
18-
public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, BlockPos pos, BlockPos beaconPos) {
19+
public float @Nullable [] getBeaconColorMultiplier(
20+
BlockState state,
21+
LevelReader world,
22+
BlockPos pos,
23+
BlockPos beaconPos
24+
) {
1925
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
2026
}
2127

28+
@SuppressWarnings("deprecation")
2229
@Override
2330
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
2431
return RGBBlockUtils.stairSkipRendering(state, adjacentBlockState, side);
2532
}
2633

34+
@SuppressWarnings("deprecation")
2735
@Override
2836
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
2937
return 1.0F;

src/main/java/platinpython/rgbblocks/block/RGBIronBarsBlock.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.world.level.block.entity.BlockEntity;
1212
import net.minecraft.world.level.block.state.BlockState;
1313
import net.minecraft.world.phys.HitResult;
14+
import org.jspecify.annotations.Nullable;
1415

1516
public class RGBIronBarsBlock extends IronBarsBlock implements EntityBlock {
1617
public RGBIronBarsBlock(Properties properties) {
@@ -23,7 +24,13 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2324
}
2425

2526
@Override
26-
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
27+
public void setPlacedBy(
28+
Level worldIn,
29+
BlockPos pos,
30+
BlockState state,
31+
@Nullable LivingEntity placer,
32+
ItemStack stack
33+
) {
2734
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
2835
}
2936

src/main/java/platinpython/rgbblocks/block/RGBRedstoneLampBlock.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.world.level.block.entity.BlockEntity;
1313
import net.minecraft.world.level.block.state.BlockState;
1414
import net.minecraft.world.phys.HitResult;
15+
import org.jspecify.annotations.Nullable;
1516
import platinpython.rgbblocks.util.registries.TileEntityRegistry;
1617

1718
public class RGBRedstoneLampBlock extends RedstoneLampBlock implements EntityBlock {
@@ -25,7 +26,13 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2526
}
2627

2728
@Override
28-
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
29+
public void setPlacedBy(
30+
Level worldIn,
31+
BlockPos pos,
32+
BlockState state,
33+
@Nullable LivingEntity placer,
34+
ItemStack stack
35+
) {
2936
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
3037
}
3138

0 commit comments

Comments
 (0)