Skip to content

Commit

Permalink
Incubator/nest drop item #829
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Nov 19, 2024
1 parent 7eb86f7 commit 5857ff6
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
Expand Down Expand Up @@ -50,6 +51,17 @@ public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World w
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!state.isOf(newState.getBlock())) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof IncubatorBlockEntity && ((IncubatorBlockEntity) blockEntity).hasItem()) {
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), ((IncubatorBlockEntity) blockEntity).getItem());
}
}
super.onStateReplaced(state, world, pos, newState, moved);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
Expand Down

0 comments on commit 5857ff6

Please sign in to comment.