Skip to content

Commit 34d7ef0

Browse files
committed
refactor: Fix nullability problems
1 parent 7a9a35f commit 34d7ef0

File tree

86 files changed

+440
-869
lines changed

Some content is hidden

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

86 files changed

+440
-869
lines changed

common/src/main/java/net/blay09/mods/cookingforblockheads/CookingForBlockheadsConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.blay09.mods.balm.platform.config.reflection.NestedType;
77
import net.minecraft.resources.Identifier;
88

9+
import java.util.Objects;
910
import java.util.Set;
1011

1112
@Config(CookingForBlockheads.MOD_ID)
@@ -49,7 +50,7 @@ public class CookingForBlockheadsConfig {
4950
public Set<Identifier> excludedRecipes = Set.of();
5051

5152
public static CookingForBlockheadsConfig getActive() {
52-
return Balm.config().getActiveConfig(CookingForBlockheadsConfig.class);
53+
return Objects.requireNonNull(Balm.config().getActiveConfig(CookingForBlockheadsConfig.class));
5354
}
5455

5556
public static void initialize() {

common/src/main/java/net/blay09/mods/cookingforblockheads/api/KitchenItemProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.world.item.ItemStack;
44
import net.minecraft.world.item.crafting.Ingredient;
5+
import org.jspecify.annotations.Nullable;
56

67
import java.util.Collection;
78

@@ -21,15 +22,15 @@ public interface KitchenItemProvider {
2122
* @param cacheHint a hint on where to start looking, based on {@link #getCacheHint(IngredientToken)} for the last returned token for this type of ingredient
2223
* @return an ingredient token that matches the given ingredient, or null if none was found
2324
*/
24-
IngredientToken findIngredient(Ingredient ingredient, Collection<IngredientToken> ingredientTokens, CacheHint cacheHint);
25+
@Nullable IngredientToken findIngredient(Ingredient ingredient, Collection<IngredientToken> ingredientTokens, CacheHint cacheHint);
2526

2627
/**
2728
* @param itemStack the item to find
2829
* @param ingredientTokens the ingredient tokens that have already been provided for this type of ingredient by this provider
2930
* @param cacheHint a hint on where to start looking, based on {@link #getCacheHint(IngredientToken)} for the last returned token for this type of ingredient
3031
* @return an ingredient token that matches the given ingredient, or null if none was found
3132
*/
32-
IngredientToken findIngredient(ItemStack itemStack, Collection<IngredientToken> ingredientTokens, CacheHint cacheHint);
33+
@Nullable IngredientToken findIngredient(ItemStack itemStack, Collection<IngredientToken> ingredientTokens, CacheHint cacheHint);
3334

3435
CacheHint getCacheHint(IngredientToken ingredientToken);
3536
}

common/src/main/java/net/blay09/mods/cookingforblockheads/block/CabinetBlock.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public CabinetBlock(@Nullable DyeColor color, Properties properties) {
3838
super(color, properties);
3939
}
4040

41-
@Nullable
4241
@Override
4342
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
4443
return new CabinetBlockEntity(pos, state);

common/src/main/java/net/blay09/mods/cookingforblockheads/block/CounterBlock.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class CounterBlock extends BaseKitchenBlock {
3434
.forGetter(CounterBlock::getColor),
3535
propertiesCodec()).apply(it, CounterBlock::new));
3636

37-
private final DyeColor color;
37+
private final @Nullable DyeColor color;
3838

3939
public CounterBlock(Properties properties) {
4040
this(null, properties);
@@ -45,8 +45,7 @@ public CounterBlock(@Nullable DyeColor color, Properties properties) {
4545
this.color = color;
4646
}
4747

48-
@Nullable
49-
public DyeColor getColor() {
48+
public @Nullable DyeColor getColor() {
5049
return color;
5150
}
5251

common/src/main/java/net/blay09/mods/cookingforblockheads/block/CuttingBoardBlock.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
import net.minecraft.world.entity.player.Player;
1818
import net.minecraft.world.inventory.AbstractContainerMenu;
1919
import net.minecraft.world.inventory.ContainerLevelAccess;
20-
import net.minecraft.world.inventory.CraftingMenu;
2120
import net.minecraft.world.level.BlockGetter;
2221
import net.minecraft.world.level.Level;
2322
import net.minecraft.world.level.block.BaseEntityBlock;
2423
import net.minecraft.world.level.block.Block;
25-
import net.minecraft.world.level.block.SoundType;
2624
import net.minecraft.world.level.block.entity.BlockEntity;
2725
import net.minecraft.world.level.block.state.BlockState;
2826
import net.minecraft.world.level.block.state.StateDefinition;

common/src/main/java/net/blay09/mods/cookingforblockheads/block/FruitBasketBlock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import net.minecraft.world.level.Level;
1616
import net.minecraft.world.level.block.BaseEntityBlock;
1717
import net.minecraft.world.level.block.Block;
18-
import net.minecraft.world.level.block.SoundType;
1918
import net.minecraft.world.level.block.entity.BlockEntity;
2019
import net.minecraft.world.level.block.entity.BlockEntityTicker;
2120
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -24,6 +23,7 @@
2423
import net.minecraft.world.phys.BlockHitResult;
2524
import net.minecraft.world.phys.shapes.CollisionContext;
2625
import net.minecraft.world.phys.shapes.VoxelShape;
26+
import org.jspecify.annotations.Nullable;
2727

2828
public class FruitBasketBlock extends BaseKitchenBlock {
2929

@@ -69,7 +69,7 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
6969
}
7070

7171
@Override
72-
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
72+
public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
7373
return !level.isClientSide() ? createTickerHelper(type, ModBlockEntities.fruitBasket.value(), FruitBasketBlockEntity::serverTick) : null;
7474
}
7575

common/src/main/java/net/blay09/mods/cookingforblockheads/block/KitchenFloorBlock.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.mojang.serialization.codecs.RecordCodecBuilder;
55
import net.minecraft.world.item.DyeColor;
66
import net.minecraft.world.level.block.Block;
7-
import net.minecraft.world.level.block.SoundType;
87

98
public class KitchenFloorBlock extends Block {
109

common/src/main/java/net/blay09/mods/cookingforblockheads/block/MilkJarBlock.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import net.minecraft.world.level.block.BaseEntityBlock;
1919
import net.minecraft.world.level.block.Block;
2020
import net.minecraft.world.level.block.BucketPickup;
21-
import net.minecraft.world.level.block.SoundType;
2221
import net.minecraft.world.level.block.entity.BlockEntity;
2322
import net.minecraft.world.level.block.state.BlockState;
2423
import net.minecraft.world.level.block.state.StateDefinition;
@@ -100,7 +99,7 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
10099
@Override
101100
public ItemStack pickupBlock(@Nullable LivingEntity entity, LevelAccessor level, BlockPos pos, BlockState state) {
102101
BlockEntity blockEntity = level.getBlockEntity(pos);
103-
if (blockEntity instanceof MilkJarBlockEntity milkJar && ((MilkJarBlockEntity) blockEntity).getFluidTank().getAmount() >= 1000) {
102+
if (blockEntity instanceof MilkJarBlockEntity milkJar && milkJar.getFluidTank().getAmount() >= 1000) {
104103
int drained = milkJar.getFluidTank().drain(Compat.getMilkFluid(), 1000, false);
105104
return drained >= 1000 ? new ItemStack(Items.MILK_BUCKET) : ItemStack.EMPTY;
106105
}

common/src/main/java/net/blay09/mods/cookingforblockheads/block/OvenBlock.java

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class OvenBlock extends BaseKitchenBlock {
3636
public static final MapCodec<OvenBlock> CODEC = RecordCodecBuilder.mapCodec((it) -> it.group(DyeColor.CODEC.fieldOf("color").forGetter(OvenBlock::getColor),
3737
propertiesCodec()).apply(it, OvenBlock::new));
3838

39-
public static BooleanProperty ACTIVE = BooleanProperty.create("active");
39+
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
4040

4141
private static final Random random = new Random();
4242
private final DyeColor color;
@@ -78,33 +78,7 @@ protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Lev
7878
if (blockHitResult.getDirection() == Direction.UP) {
7979
if (itemStack.is(ModItemTags.UTENSILS)) {
8080
Direction stateFacing = state.getValue(FACING);
81-
double hx = blockHitResult.getLocation().x;
82-
double hz = blockHitResult.getLocation().z;
83-
switch (stateFacing) {
84-
case NORTH -> {
85-
hx = 1f - blockHitResult.getLocation().x;
86-
hz = 1f - blockHitResult.getLocation().z;
87-
}
88-
// case SOUTH: hx = hitX; hz = hitZ; break;
89-
case WEST -> {
90-
hz = 1f - blockHitResult.getLocation().x;
91-
hx = blockHitResult.getLocation().z;
92-
}
93-
case EAST -> {
94-
hz = blockHitResult.getLocation().x;
95-
hx = 1f - blockHitResult.getLocation().z;
96-
}
97-
}
98-
int index = -1;
99-
if (hx < 0.5f && hz < 0.5f) {
100-
index = 1;
101-
} else if (hx >= 0.5f && hz < 0.5f) {
102-
index = 0;
103-
} else if (hx < 0.5f && hz >= 0.5f) {
104-
index = 3;
105-
} else if (hx >= 0.5f && hz >= 0.5f) {
106-
index = 2;
107-
}
81+
int index = resolveToolHitIndex(blockHitResult, stateFacing);
10882
if (index != -1) {
10983
OvenBlockEntity tileOven = (OvenBlockEntity) level.getBlockEntity(pos);
11084
if (tileOven != null && tileOven.getToolItem(index).isEmpty()) {
@@ -130,6 +104,37 @@ protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Lev
130104
return super.useItemOn(itemStack, state, level, pos, player, hand, blockHitResult);
131105
}
132106

107+
private static int resolveToolHitIndex(BlockHitResult blockHitResult, Direction stateFacing) {
108+
double hx = blockHitResult.getLocation().x;
109+
double hz = blockHitResult.getLocation().z;
110+
switch (stateFacing) {
111+
case NORTH -> {
112+
hx = 1f - blockHitResult.getLocation().x;
113+
hz = 1f - blockHitResult.getLocation().z;
114+
}
115+
// case SOUTH: hx = hitX; hz = hitZ; break;
116+
case WEST -> {
117+
hz = 1f - blockHitResult.getLocation().x;
118+
hx = blockHitResult.getLocation().z;
119+
}
120+
case EAST -> {
121+
hz = blockHitResult.getLocation().x;
122+
hx = 1f - blockHitResult.getLocation().z;
123+
}
124+
}
125+
int index = -1;
126+
if (hx < 0.5f && hz < 0.5f) {
127+
index = 1;
128+
} else if (hx >= 0.5f && hz < 0.5f) {
129+
index = 0;
130+
} else if (hx < 0.5f && hz >= 0.5f) {
131+
index = 3;
132+
} else if (hx >= 0.5f && hz >= 0.5f) {
133+
index = 2;
134+
}
135+
return index;
136+
}
137+
133138
@Override
134139
public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult rayTraceResult) {
135140
final var blockEntity = level.getBlockEntity(pos);

common/src/main/java/net/blay09/mods/cookingforblockheads/block/SinkBlock.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
157157
return new SinkBlockEntity(pos, state);
158158
}
159159

160-
@Nullable
161160
@Override
162-
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
161+
public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
163162
return level.isClientSide() ? null : createTickerHelper(type, ModBlockEntities.sink.value(), SinkBlockEntity::serverTick);
164163
}
165164

0 commit comments

Comments
 (0)