Skip to content

Commit

Permalink
fix(1.20.6): Fix useWithItem being called with empty items...
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed May 23, 2024
1 parent b2b54af commit 052a0fe
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ protected MapCodec<? extends BaseEntityBlock> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt

@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 OvenBlockEntity oven)) {
return ItemInteractionResult.FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof ToasterBlockEntity toaster) {
ItemStack heldItem = player.getItemInHand(hand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {

@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 (hand != InteractionHand.MAIN_HAND) {
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Toast

public void serverTick(Level level, BlockPos pos, BlockState state) {
if (active) {
//toastTicks--;
toastTicks -= 100;
toastTicks--;
if (toastTicks <= 0 && !level.isClientSide) {
for (int i = 0; i < container.getContainerSize(); i++) {
ItemStack inputStack = container.getItem(i);
Expand Down

0 comments on commit 052a0fe

Please sign in to comment.