From 052a0fed74e07a2d82a31c78d3339d0d9f1036e8 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+blay09@users.noreply.github.com> Date: Thu, 23 May 2024 20:23:37 +0200 Subject: [PATCH] fix(1.20.6): Fix useWithItem being called with empty items... --- .../mods/cookingforblockheads/block/ConnectorBlock.java | 4 ++++ .../mods/cookingforblockheads/block/CookingTableBlock.java | 4 ++++ .../blay09/mods/cookingforblockheads/block/CounterBlock.java | 4 ++++ .../blay09/mods/cookingforblockheads/block/FridgeBlock.java | 4 ++++ .../blay09/mods/cookingforblockheads/block/MilkJarBlock.java | 4 ++++ .../net/blay09/mods/cookingforblockheads/block/OvenBlock.java | 4 ++++ .../net/blay09/mods/cookingforblockheads/block/SinkBlock.java | 4 ++++ .../blay09/mods/cookingforblockheads/block/ToasterBlock.java | 4 ++++ .../blay09/mods/cookingforblockheads/block/ToolRackBlock.java | 4 ++++ .../cookingforblockheads/block/entity/ToasterBlockEntity.java | 3 +-- 10 files changed, 37 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/ConnectorBlock.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/ConnectorBlock.java index 3d36b119..9da48bce 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/ConnectorBlock.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/ConnectorBlock.java @@ -51,6 +51,10 @@ protected MapCodec codec() { @Override protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) { + if (itemStack.isEmpty()) { + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + } + if (tryRecolorBlock(state, itemStack, level, pos, player, blockHitResult)) { return ItemInteractionResult.CONSUME_PARTIAL; } diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CookingTableBlock.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CookingTableBlock.java index 77d69d3a..5c545ef5 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CookingTableBlock.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CookingTableBlock.java @@ -65,6 +65,10 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP @Override protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) { + if (itemStack.isEmpty()) { + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + } + final var blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof CookingTableBlockEntity cookingTable) { if (tryRecolorBlock(state, itemStack, level, pos, player, blockHitResult)) { diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CounterBlock.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CounterBlock.java index 809e977c..261b5bc8 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CounterBlock.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/CounterBlock.java @@ -54,6 +54,10 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @Override protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) { + if (itemStack.isEmpty()) { + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + } + if (tryRecolorBlock(state, itemStack, level, pos, player, blockHitResult)) { return ItemInteractionResult.SUCCESS; } diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/FridgeBlock.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/FridgeBlock.java index e4149c79..faae4dae 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/FridgeBlock.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/FridgeBlock.java @@ -78,6 +78,10 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @Override protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) { + if (itemStack.isEmpty()) { + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + } + final var blockEntity = level.getBlockEntity(pos); if (!(blockEntity instanceof FridgeBlockEntity fridge)) { return ItemInteractionResult.FAIL; diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/MilkJarBlock.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/MilkJarBlock.java index 49281dfa..23052935 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/MilkJarBlock.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/MilkJarBlock.java @@ -60,6 +60,10 @@ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, Co @Override protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) { + if (itemStack.isEmpty()) { + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + } + final var blockEntity = level.getBlockEntity(pos); if (!(blockEntity instanceof MilkJarBlockEntity milkJar)) { return ItemInteractionResult.FAIL; diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/OvenBlock.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/OvenBlock.java index 1b22209b..ef6d1243 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/block/OvenBlock.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/block/OvenBlock.java @@ -70,6 +70,10 @@ protected void createBlockStateDefinition(StateDefinition.Builder